:root {
  --bg: #f6f7f5; --surface: #ffffff; --ink: #1c2321; --muted: #6b7471; --line: #e3e6e3;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e0f2ef;
  --warn: #b45309; --warn-soft: #fef3c7; --danger: #b91c1c; --rec: #dc2626;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111514; --surface: #1a201e; --ink: #e8ecea; --muted: #9aa4a0; --line: #2b3330;
    --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #123532;
    --warn: #fbbf24; --warn-soft: #3a2e0c; --danger: #f87171; --rec: #f87171;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #111514; --surface: #1a201e; --ink: #e8ecea; --muted: #9aa4a0; --line: #2b3330;
  --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #123532;
  --warn: #fbbf24; --warn-soft: #3a2e0c; --danger: #f87171; --rec: #f87171; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.top-actions { display: flex; gap: 6px; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 80px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; text-decoration: none; color: var(--ink); font-size: .9rem; }
.btn.ghost { background: transparent; }
.danger { color: var(--danger) !important; }
.link { background: none; border: 0; color: var(--brand); padding: 0; cursor: pointer; font-size: .92rem; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }

/* 歡迎頁 */
.welcome { padding: 28px 0; }
.welcome h1 { font-size: clamp(1.6rem, 6vw, 2.2rem); line-height: 1.3; margin: 0 0 12px; }
.welcome .intro { color: var(--muted); margin: 0 0 22px; }
.steps { margin: 26px 0 0; padding-left: 1.3em; color: var(--muted); }
.steps li { margin-bottom: 8px; }
.fine { margin-top: 28px; font-size: .85rem; color: var(--muted); }

.who { font-size: .9rem; color: var(--muted); margin: 0 2px 10px; }

/* 輸入區 */
.composer-label { display: block; font-weight: 600; margin-bottom: 8px; }
.composer textarea {
  width: 100%; resize: vertical; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); min-height: 84px;
}
.composer-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.composer-row .btn { flex: 1; }
.composer-row.secondary { justify-content: space-between; flex-wrap: wrap; }
.hint { font-size: .85rem; color: var(--warn); }
.btn.mic .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); }
.btn.mic.recording { border-color: var(--rec); color: var(--rec); }
.btn.mic.recording .dot { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.8); } }

/* 預覽 */
.preview { margin-top: 14px; border-color: var(--brand); }
.preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.preview-head h3 { margin: 0; }
.transcript { margin: 10px 0; font-size: .9rem; color: var(--muted); }
.transcript p { white-space: pre-wrap; margin: 6px 0 0; }
.pitem { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.pitem.off .pbody { opacity: .45; }
.pcheck input { width: 20px; height: 20px; margin-top: 4px; }
.pbody { flex: 1; min-width: 0; }
.phead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pname { border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-weight: 700; background: var(--bg); max-width: 12em; }
.pscore { margin-left: auto; font-weight: 700; color: var(--brand); }
.badge { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.new { background: var(--brand-soft); color: var(--brand); }
.badge.upd { background: var(--warn-soft); color: var(--warn); }
.target { width: 100%; margin-top: 8px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.warn { color: var(--warn); font-size: .88rem; margin: 6px 0 0; }
.diff { list-style: none; padding: 0; margin: 8px 0 0; font-size: .92rem; }
.diff li { padding: 2px 0; overflow-wrap: anywhere; }
.diff i { font-style: normal; color: var(--muted); margin-right: 6px; }
.diff s { color: var(--muted); }

/* 工具列 */
.toolbar { display: flex; gap: 10px; align-items: center; margin: 22px 0 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
#search { flex: 1; min-width: 160px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; background: var(--surface); }

/* 該跟進 */
.due { background: var(--warn-soft); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.due-title { font-weight: 700; color: var(--warn); margin-bottom: 6px; }
.due-item { display: flex; gap: 10px; width: 100%; text-align: left; background: none; border: 0; padding: 6px 0; cursor: pointer; border-top: 1px dashed color-mix(in srgb, var(--warn) 30%, transparent); }
.due-item:first-of-type { border-top: 0; }

/* 名單卡片 */
.list { display: grid; gap: 10px; }
.lead {
  display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; box-shadow: var(--shadow);
}
.lead:focus-visible { outline: 2px solid var(--brand); }
.rank { font-weight: 800; color: var(--brand); font-size: 1.05rem; padding-top: 2px; }
.name { font-weight: 700; font-size: 1.08rem; overflow-wrap: anywhere; }
.score { text-align: center; min-width: 56px; }
.score .num { font-size: 1.6rem; font-weight: 800; line-height: 1; color: var(--brand); }
.score .of { font-size: .72rem; color: var(--muted); margin-top: 3px; }
.score.none .num { color: var(--muted); }
.dims { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; font-size: .8rem; }
.dim { background: var(--brand-soft); color: var(--brand); padding: 1px 7px; border-radius: 6px; }
.dim.missing { background: var(--warn-soft); color: var(--warn); }
.info { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: .85rem; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; overflow-wrap: anywhere; background: var(--surface); }
.tag i { font-style: normal; color: var(--muted); margin-right: 4px; font-size: .78rem; }
.tag.add { border-style: dashed; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 1px 7px; background: transparent; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: .82rem; color: var(--muted); align-items: center; }
.status { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; color: var(--ink); }
.status.s-5, .status.s-6 { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.next.due { color: var(--warn); font-weight: 700; }
.lastlog { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* 對話框 */
dialog.sheet {
  border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 18px; overflow-y: auto; max-height: calc(100dvh - 32px); }
dialog h2 { margin: 0 0 12px; font-size: 1.2rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.x { background: none; border: 0; font-size: 1.6rem; cursor: pointer; color: var(--muted); line-height: 1; }
.group { border: 0; border-top: 1px solid var(--line); padding: 12px 0 0; margin: 12px 0 0; }
.group legend { font-weight: 700; padding: 0 6px 0 0; font-size: .92rem; }
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field small { display: block; font-size: .78rem; margin: -2px 0 6px; }
.field input:not([type=hidden]), .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: var(--bg); min-height: 42px;
}
.seg { display: grid; grid-template-columns: 1.4fr repeat(5, 1fr); gap: 4px; }
.seg button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; min-height: 40px; cursor: pointer; font-size: .9rem; }
.seg button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.howto { margin: 10px 0; font-size: .92rem; }
.howto summary { cursor: pointer; color: var(--brand); }
.howto ol { padding-left: 1.3em; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: calc(100vw - 32px); font-size: .92rem;
}
.loading { display: grid; place-items: center; padding: 80px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 420px) {
  .lead { grid-template-columns: 30px 1fr auto; gap: 8px; padding: 10px; }
  .composer-row:not(.secondary) { flex-direction: column; align-items: stretch; }
}
