/* 基礎版面與共用元件：頁首、進度列、按鈕、輸入框、面板、選單、分頁、提示、載入骨架。 */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px) }
body { margin: 0 }
img { max-width: 100% }
[hidden] { display: none !important }

* { box-sizing: border-box }
body { background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.65 }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--sheet) }
button, input, textarea { font: inherit; color: inherit }
button { cursor: pointer }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
.wrap { max-width: 820px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)) }

/* 頂端列：品牌＋目前進度＋下一步 */
.wide { max-width: 1240px }
.appbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--sheet); border-bottom: 1px solid var(--line) }
.appbar-in { display: flex; align-items: center; gap: 10px 20px; min-height: 60px; padding-block: 8px; flex-wrap: wrap }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; flex: none }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--f-clause); font-size: 15px }
.turn { flex: 1 1 420px; display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; min-width: 0 }
.turn:empty { display: none }
.stage { display: flex; gap: 10px; align-items: center; min-width: 0; flex: 1 1 300px; padding: 4px 12px; border-left: 1px solid var(--line) }
.stage-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted) }
.stage[data-mine="1"] { background: var(--turn-bg); border-left-color: transparent; border-radius: 8px }
.stage[data-mine="1"] .stage-dot { background: var(--turn-fg) }
.stage[data-mine="1"] .stage-title { color: var(--turn-fg) }
.stage-text { min-width: 0 }
.stage-title { font-weight: 700; font-size: 14px; line-height: 1.4; text-wrap: balance }
.stage-sub { color: var(--muted); font-size: 12px; line-height: 1.4 }

/* 版面：契約頁左側為條文目錄，首頁為單欄 */
.layout.with-outline { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 0 36px; align-items: start }
.content { min-width: 0 }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap }
.only-narrow { display: none }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center }
.btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 8px; padding: 7px 14px; font-size: 14px; font-weight: 500; white-space: nowrap }
.btn:hover { border-color: var(--muted) }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink) }
.btn.good { background: var(--ins-fg); border-color: var(--ins-fg); color: var(--sheet) }
.btn.bad { color: var(--del-fg); border-color: var(--del-fg); background: transparent }
.btn.danger { background: var(--del-fg); border-color: var(--del-fg); color: var(--sheet) }
.btn.block { width: 100%; padding-block: 10px }
.btn[disabled] { opacity: .45; cursor: not-allowed }
.btn.sm { padding: 4px 10px; font-size: 13px }
.btn.icon { padding: 4px 8px; font-size: 13px; min-width: 32px; min-height: 32px }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 3px }

/* Header */
header.top { padding-block: 24px 4px; display: grid; gap: 4px }
.eyebrow { font-size: 12px; letter-spacing: .12em; color: var(--muted) }
h1 { margin: 0; font-family: var(--f-clause); font-size: 26px; font-weight: 700; letter-spacing: .04em; text-wrap: balance }
.lede { color: var(--muted); margin: 0; max-width: 62ch }
.exportbar { display: flex; gap: 10px 14px; align-items: center; flex-wrap: wrap; margin-top: 14px }
.exportbar:empty { display: none }
.exportbar .hint { color: var(--muted); font-size: 13px; flex: 1 1 240px }
.warnline { color: var(--turn-fg); background: var(--turn-bg); padding: 8px 12px; border-radius: 8px; font-size: 13px; flex: 1 1 100% }
.dangerline { color: var(--del-fg); background: var(--del-bg); padding: 10px 12px; border-radius: 8px; font-size: 13px }
.news { margin-top: 14px; background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px }
.news h2 { margin: 0; font-size: 14px }
.news ul { margin: 0; padding-left: 1.2em }
.news .row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 12px; overflow-x: auto }
.tab { border: 0; background: none; padding: 10px 14px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent) }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: var(--turn-bg); color: var(--turn-fg); font-size: 12px; font-family: var(--f-data); text-align: center; line-height: 20px }

/* Cloudflare edition: admin list, invite and name panels */
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 12px; margin-top: 14px }
.panel h2 { margin: 0; font-size: 16px }
.panel p { margin: 0; color: var(--muted); font-size: 14px }
.field { display: grid; gap: 4px }
.field label { font-size: 13px; color: var(--muted) }
.field input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: var(--paper) }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center }
.row .grow { flex: 1 1 220px; min-width: 0 }
.linkbox { font-family: var(--f-data); font-size: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; word-break: break-all; user-select: all }
.plist2 { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px }
.plist2 li { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 8px 10px; background: var(--paper); border-radius: 6px }
a.btn { text-decoration: none; display: inline-block }
.tplgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-top: 4px }
.tpl { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: pointer; min-width: 0 }
.tpl:has(input:checked) { border-color: var(--accent); background: var(--accent-soft) }
.tpl input[type=radio] { margin: 4px 0 0; flex: none; width: auto; padding: 0; border: 0; background: none }
.tpl > span { display: grid; gap: 2px; min-width: 0 }
.tpl strong { font-size: 14px }
.tpl .meta { font-family: var(--f-body); line-height: 1.5 }

.fx-cell:hover { color: var(--accent) }
.pop { position: absolute; z-index: 30; background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 12px; display: grid; gap: 8px; width: min(320px, calc(100vw - 16px)) }
.pop label { font-size: 13px; color: var(--muted) }
.inp { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; background: var(--paper); font: inherit; color: inherit }
.inp:focus { outline: 2px solid var(--accent); outline-offset: -1px }
.grow { flex: 1 1 auto }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted) }
.btn.ghost:hover { background: var(--paper); color: var(--ink) }
.crumb { color: var(--accent); text-decoration: none }
.crumb:hover { text-decoration: underline }
/* 工具列：選項顯示切換＋匯入／匯出／成員 */
.exportbar { gap: 8px; align-items: center }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--sheet) }
.seg button { border: 0; background: none; padding: 6px 12px; font-size: 13px; color: var(--muted) }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500 }
.menu-wrap { position: relative }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); min-width: 260px; padding: 4px; display: grid }
.menu button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; display: grid; gap: 2px }
.menu button:hover, .menu button:focus-visible { background: var(--paper) }
.menu button strong { font-size: 14px; font-weight: 500 }
.menu button span { font-size: 12px; color: var(--muted) }
.panel.export { flex: 1 1 100% }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px }
.count.plain { background: var(--paper); color: var(--muted) }
/* 載入中 */
.skel { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--paper), var(--line), var(--paper)); background-size: 200% 100%; margin: 10px 0 }
@media (prefers-reduced-motion: no-preference) { .skel { animation: shimmer 1.2s linear infinite } @keyframes shimmer { to { background-position: -200% 0 } } }
.skel-block { padding: 24px 0 }


/* 首頁：契約案件列表 */
.seg .n { font-family: var(--f-data); font-size: 12px; margin-left: 2px; opacity: .8 }
.search { width: min(300px, 100%) }
select.inp { appearance: auto }
.card { background: var(--sheet); border-radius: 10px; box-shadow: var(--shadow) }
.table-card { margin: 16px 0 48px }
.ctable { width: 100%; border-collapse: collapse; font-size: 14px }
.ctable th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap }
.ctable td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle }
.ctable tbody tr:last-child td { border-bottom: 0 }
.ctable tbody tr { position: relative }
.ctable tbody tr:not(.editing):hover td { background: var(--accent-soft) }
.ctable tbody tr:first-child td:first-child { border-top-left-radius: 0 }
.ctable .t { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; font-family: var(--f-clause); letter-spacing: .02em }
.ctable .t::after { content: ""; position: absolute; inset: 0 }
.ctable .t:focus-visible { outline: none }
.ctable .t:focus-visible::after { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px }
.ctable .c-act { position: relative; z-index: 1; width: 56px; text-align: right }
.ctable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap }
.ctable .c-other { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.ctable tr.editing td { background: var(--accent-soft) }
.ctable tr.danger td { background: var(--del-bg) }
.meta-s { color: var(--muted); font-size: 12px }
.menu .danger strong { color: var(--del-fg) }
.menu { min-width: 180px }
@media (max-width: 760px) {
  .ctable thead { display: none }
  .ctable tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line) }
  .ctable td { padding: 0; border: 0; text-align: left !important }
  .ctable td.c-title { grid-column: 1 }
  .ctable td.c-act { grid-column: 2; grid-row: 1 }
  .ctable td[data-label] { grid-column: 1 / -1; display: flex; gap: 8px; font-size: 13px }
  .ctable td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; min-width: 4.5em }
  .ctable tr.editing { display: block }
}

/* 登入 */
.login { max-width: 380px; margin: 12vh auto 48px; background: var(--sheet); border-radius: 12px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 16px }
.login p { margin: 0; color: var(--muted); font-size: 14px }
.brand.big { font-size: 18px }
.brand.big .brand-mark { width: 36px; height: 36px; font-size: 18px; border-radius: 9px }

/* 窄螢幕：頂端列只留品牌標誌、目前進度與下一步 */
@media (max-width: 640px) {
  .appbar-in { min-height: 52px; gap: 8px 12px }
  .brand-name { display: none }
  .turn { flex-basis: 0; flex-grow: 1 }
  .stage { flex: 1 1 160px; border-left: 0; padding: 4px 8px }
  .stage-sub { display: none }
  .turn .actions { flex: 1 1 100% }
  .turn .actions .btn { flex: 1 1 auto }
  h1 { font-size: 21px }
  header.top { padding-top: 16px }
}
