/* 委員合約審查系統 — 手機優先樣式
   要求：最小字級 16px、行高 1.7、點擊目標 ≥44px、深色模式、繁中字型、不引用外部資源 */

:root {
  --font: "Microsoft JhengHei", "微軟正黑體", "PingFang TC", "Noto Sans TC",
          "Hiragino Sans CNS", "Heiti TC", system-ui, sans-serif;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #17202a;
  --text-dim: #56616e;
  --line: #d3d8e0;
  --brand: #1d3a5f;
  --brand-soft: #e6edf6;
  --accent: #8a5a00;
  --accent-soft: #fdf1d8;
  --ok: #1c6b3a;
  --ok-soft: #e3f3e8;
  --warn: #9a3412;
  --warn-soft: #fdeae2;
  --shadow: 0 2px 8px rgba(20, 30, 45, .10);
  --shadow-lg: 0 -6px 28px rgba(20, 30, 45, .22);
  --tap: 44px;
  --radius: 10px;
  --maxw: 780px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #17202b;
    --surface-2: #1e2936;
    --text: #e9edf2;
    --text-dim: #a3b0bf;
    --line: #2e3b4a;
    --brand: #7fb0e8;
    --brand-soft: #1b2a3c;
    --accent: #f0c26b;
    --accent-soft: #33280f;
    --ok: #7ed4a0;
    --ok-soft: #14301f;
    --warn: #f3a48a;
    --warn-soft: #37201a;
    --shadow: 0 2px 10px rgba(0, 0, 0, .5);
    --shadow-lg: 0 -6px 28px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

/* 本檔多處以 display 指定版面（flex／grid），會覆蓋 [hidden] 之預設 display:none，
   故此處統一強制之。缺此一行，橫幅、選單與 bottom sheet 會恆常顯示。 */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  overflow-wrap: break-word;
  word-break: break-word;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }

a { color: var(--brand); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--surface); padding: 12px 16px;
}
.skip:focus { left: 8px; top: 8px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------- 頂部列 */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--brand); color: #fff;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  box-shadow: var(--shadow);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: #16222f; border-bottom: 1px solid var(--line); }
}

.topbar-row { display: flex; align-items: center; gap: 8px; }

.whoami { flex: 1; min-width: 0; line-height: 1.35; padding: 2px 0; }
.whoami-role { display: block; font-weight: 700; font-size: 17px; }
.whoami-sub { display: block; font-size: 14px; opacity: .85; }

.topbar .iconbtn {
  min-width: var(--tap); min-height: var(--tap);
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff; border-radius: var(--radius);
  padding: 0 12px; cursor: pointer; white-space: nowrap;
}
.topbar .iconbtn:active { background: rgba(255, 255, 255, .3); }
.back-btn span { font-size: 22px; line-height: 1; vertical-align: -2px; }

.menu { display: grid; gap: 2px; padding: 8px 0 4px; }
.menu a {
  display: flex; align-items: center; min-height: var(--tap);
  padding: 0 12px; color: #fff; text-decoration: none;
  background: rgba(255, 255, 255, .1); border-radius: var(--radius);
}
.menu a[aria-current="page"] { background: rgba(255, 255, 255, .26); font-weight: 700; }

/* ---------------------------------------------------------- 橫幅 */

.banner {
  padding: 10px 14px; font-size: 15.5px; line-height: 1.6;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.banner.offline { background: var(--warn-soft); color: var(--warn); }
.banner.outbox { background: var(--accent-soft); color: var(--accent); }
.linkbtn {
  background: none; border: 0; padding: 8px 4px; min-height: var(--tap);
  text-decoration: underline; cursor: pointer; font-weight: 700;
}

/* ---------------------------------------------------------- 版面 */

.layout { display: block; }
.pane-detail { display: none; }
body.view-detail .pane-list { display: none; }
body.view-detail .pane-detail { display: block; }

@media (min-width: 900px) {
  .layout {
    display: grid; grid-template-columns: minmax(320px, 400px) 1fr;
    gap: 0; align-items: start;
    max-width: 1400px; margin: 0 auto;
  }
  .pane-list, body.view-detail .pane-list { display: block; }
  .pane-detail, body.view-detail .pane-detail { display: block; }
  .pane-list {
    position: sticky; top: 64px; max-height: calc(100vh - 64px);
    overflow-y: auto; border-right: 1px solid var(--line);
  }
  .back-btn { display: none !important; }
}

/* ---------------------------------------------------------- 分頁與搜尋 */

.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; text-align: center; text-decoration: none; color: var(--text-dim);
  min-height: var(--tap); display: flex; align-items: center; justify-content: center;
  gap: 4px; font-size: 16px; border-bottom: 3px solid transparent; padding: 4px 2px;
}
.tab[aria-selected="true"] { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }
.tab-n { font-size: 13px; opacity: .8; }

.searchrow { display: flex; gap: 8px; padding: 10px; background: var(--surface); align-items: center; }
.searchrow input {
  flex: 1; min-height: var(--tap); padding: 8px 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
.clearq { min-width: var(--tap); min-height: var(--tap); background: none; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }

.filterrow {
  display: flex; gap: 8px; padding: 0 10px 10px; background: var(--surface);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.chip-toggle {
  min-height: var(--tap); padding: 4px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 15px;
}
.chip-toggle[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }
#collapseAll { margin-left: auto; }

/* ---------------------------------------------------------- 清單 */

.listbody { padding-bottom: 40px; }

.chapter { border-bottom: 1px solid var(--line); background: var(--surface); }
.chapter-head {
  width: 100%; display: flex; gap: 10px; align-items: center; text-align: left;
  min-height: 52px; padding: 8px 12px; background: var(--surface-2);
  border: 0; border-top: 1px solid var(--line); cursor: pointer; font-size: 16px;
}
.chapter-head .caret { transition: transform .15s; font-size: 13px; color: var(--text-dim); }
.chapter-head[aria-expanded="false"] .caret { transform: rotate(-90deg); }
.chapter-head .ch-title { flex: 1; font-weight: 700; line-height: 1.45; }
.chapter-head .ch-meta { font-size: 13.5px; color: var(--text-dim); white-space: nowrap; }
.ch-contract {
  font-size: 12.5px; padding: 1px 7px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-weight: 700;
}

.artrow {
  display: flex; gap: 10px; align-items: flex-start;
  min-height: var(--tap); padding: 11px 12px; text-decoration: none; color: inherit;
  border-top: 1px solid var(--line);
}
.artrow:active { background: var(--surface-2); }
.artrow[aria-current="true"] { background: var(--brand-soft); }
.artrow .no { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 15px; white-space: nowrap; min-width: 5.6em; }
.artrow .ti { flex: 1; line-height: 1.55; }
.artrow .badges { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }

.badge { font-size: 12.5px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.badge.told { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
.badge.nottold { background: var(--surface-2); color: var(--text-dim); }
.badge.cmt { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.empty { padding: 28px 18px; color: var(--text-dim); text-align: center; }
.hint { padding: 12px 14px; color: var(--text-dim); font-size: 15px; }

/* ---------------------------------------------------------- 條文詳讀 */

.detailbody { padding: 0 0 180px; max-width: var(--maxw); margin: 0 auto; }
.placeholder { padding: 40px 20px; color: var(--text-dim); text-align: center; }

.art-head { padding: 16px 16px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
.art-crumb { font-size: 14.5px; color: var(--text-dim); }
.art-title { margin: 6px 0 8px; font-size: 21px; line-height: 1.5; }
.art-title .no { color: var(--brand); }
.art-flags { display: flex; gap: 6px; flex-wrap: wrap; }

.art-body { padding: 14px 16px 8px; background: var(--surface); }

/* 條項款目階層：以縮排＋標記樣式清楚分層，各層不得擠成一段 */
.node { margin: 0 0 12px; }
.node > .marker { font-weight: 700; color: var(--brand); margin-right: .15em; }
.lv-para   { margin-left: 0;     }
.lv-sub    { margin-left: 1.35em; }
.lv-item   { margin-left: 2.7em;  }
.lv-subitem{ margin-left: 4em;    }
.lv-sub, .lv-item, .lv-subitem { border-left: 2px solid var(--line); padding-left: .7em; }
.lv-item > .marker, .lv-subitem > .marker { font-variant-numeric: tabular-nums; }
.lv-text { margin-left: .2em; color: var(--text); }
.node .kids { margin-top: 10px; }

/* 條文中以「>」書寫之註記：與本文明顯區隔 */
.quote {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: 8px 12px; margin: 6px 0; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 16px;
}
.chips { margin-top: 6px; }

.node table, .md-table {
  width: 100%; border-collapse: collapse; font-size: 15.5px; margin: 6px 0 4px;
}
.node th, .node td, .md-table th, .md-table td {
  border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top;
}
.node th, .md-table th { background: var(--surface-2); }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 引用 chip */
.refchip {
  display: inline-flex; align-items: center; min-height: var(--tap);
  padding: 4px 14px; margin: 3px 6px 3px 0; font-size: 15px;
  background: var(--brand-soft); color: var(--brand); border: 1px solid var(--brand);
  border-radius: 999px; cursor: pointer; font-weight: 700; line-height: 1.4;
}
.refchip::before { content: "▸"; margin-right: 4px; font-size: 12px; }
.refrow { padding: 4px 16px 14px; background: var(--surface); }
.refrow h3 { font-size: 15.5px; margin: 12px 0 4px; color: var(--text-dim); font-weight: 700; }

/* ---------------------------------------------------------- 評論 */

.comments { padding: 16px 16px 10px; }
.comments h3 { font-size: 17px; margin: 0 0 10px; }

.cmt {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px;
}
.cmt.reply { margin-left: 18px; border-left: 4px solid var(--brand-soft); }
.cmt.pending { border-style: dashed; background: var(--accent-soft); }
.cmt-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: 14.5px; color: var(--text-dim); }
.cmt-who { font-weight: 700; color: var(--text); font-size: 16px; }
.cmt-body { margin: 4px 0 6px; white-space: pre-wrap; }
.cmt-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.status { font-size: 12.5px; padding: 1px 8px; border-radius: 999px; font-weight: 700; }
.status.open { background: var(--brand-soft); color: var(--brand); }
.status.adopted { background: var(--ok-soft); color: var(--ok); }
.status.rejected { background: var(--warn-soft); color: var(--warn); }
.status.pending { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 8px 18px; border-radius: var(--radius);
  background: var(--brand); color: #fff; border: 1px solid var(--brand);
  text-decoration: none; cursor: pointer; font-weight: 700; font-size: 16px;
}
@media (prefers-color-scheme: dark) { .btn { color: #0f1720; } }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { min-height: var(--tap); padding: 4px 14px; font-size: 15px; font-weight: 400; }
.btn[disabled] { opacity: .55; cursor: default; }

/* 固定於底部的建議輸入區 */
.composer {
  position: sticky; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -3px 14px rgba(20, 30, 45, .10);
}
.composer label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 16px; }
.composer .replyto { font-size: 14.5px; color: var(--text-dim); margin-bottom: 6px; }
.composer textarea {
  width: 100%; min-height: 84px; padding: 10px 12px; font-size: 16px; line-height: 1.6;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text); resize: vertical;
}
.composer-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.composer-row .draft { font-size: 14px; color: var(--text-dim); flex: 1; }

/* ---------------------------------------------------------- bottom sheet */

.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 15, 22, .5); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 82vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 900px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    transform: translate(-50%, -50%);
    width: min(680px, 92vw); border-radius: var(--radius); max-height: 80vh;
  }
}
.sheet-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 6px 12px 8px; border-bottom: 1px solid var(--line); }
.sheet-title { flex: 1; font-size: 17px; margin: 0; line-height: 1.5; }
.sheet-head .iconbtn { min-width: var(--tap); min-height: var(--tap); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
.sheet-body { overflow-y: auto; padding: 12px 14px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }

/* ---------------------------------------------------------- 進度／輸出頁 */

.page { padding: 16px 16px 60px; max-width: var(--maxw); margin: 0 auto; }
.page h1 { font-size: 22px; margin: 4px 0 14px; }
.page h2 { font-size: 18px; margin: 22px 0 8px; padding-top: 12px; border-top: 2px solid var(--line); }
.page p { margin: 6px 0 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card .card-t { font-weight: 700; }
.card .card-m { font-size: 14.5px; color: var(--text-dim); }
a.card { display: block; text-decoration: none; color: inherit; }
a.card .card-t::after { content: " ›"; color: var(--brand); font-weight: 700; }
a.card:active { background: var(--surface-2); }

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 26px; line-height: 1.3; color: var(--brand); }
.stat span { font-size: 14.5px; color: var(--text-dim); }

.grouphead { font-weight: 700; margin: 14px 0 6px; color: var(--accent); font-size: 16px; }

.export-actions { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.export-actions .btn { width: 100%; }
@media (min-width: 560px) { .export-actions { flex-direction: row; } .export-actions .btn { width: auto; flex: 1; } }
.mdbox {
  width: 100%; min-height: 260px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14.5px; line-height: 1.65; padding: 10px; background: var(--surface);
  color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  white-space: pre; overflow: auto;
}

/* ---------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
  max-width: min(560px, 92vw);
  background: #17202a; color: #fff; padding: 12px 18px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 16px; line-height: 1.6;
}
@media (prefers-color-scheme: dark) { .toast { background: #e9edf2; color: #17202a; } }

.spinner { padding: 30px 16px; text-align: center; color: var(--text-dim); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
