:root {
  --bg: #f3f5f4; --card: #ffffff; --ink: #172624; --muted: #5d6f6c; --line: #dfe6e4;
  --brand: #134e4a; --brand-2: #0f766e; --brand-soft: #e3f1ee;
  --warn: #9a5b00; --warn-soft: #fdf1dc; --danger: #a11d1d; --danger-soft: #fbe6e4;
  --ok: #17663f; --ok-soft: #e2f3e9; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { 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, "PingFang HK", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
.boot { padding: 48px 20px; text-align: center; color: var(--muted); }
#app { max-width: 760px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(84px + var(--safe-b)); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.25rem; } h2 { font-size: 1.05rem; } h3 { font-size: .95rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand-2); }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 8px;
}
.top-main { display: flex; align-items: center; gap: 10px; }
.top h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { font-size: .78rem; opacity: .8; font-weight: 400; display: block; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 1.3rem; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.account-bar {
  margin-top: 7px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,.22);
  display: flex; align-items: center; gap: 8px; font-size: .78rem;
}
.account-identity { flex: 1; min-width: 0; line-height: 1.35; }
.account-identity > * { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-identity span { color: #d4e9e5; }
.account-model { flex: none; align-self: center; color: #fff0d5; white-space: nowrap; }
.account-model.ready { color: #ccece3; }
.account-actions { display: flex; flex: none; gap: 4px; }
.account-actions button {
  border: 0; border-radius: 7px; color: #fff; background: rgba(255,255,255,.14);
  min-height: 36px; padding: 4px 7px; cursor: pointer; white-space: nowrap;
}
.account-actions button:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.page { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.tap { cursor: pointer; }
.card.tap:active { background: #f8faf9; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.llm-settings-actions { gap: 10px; }
.llm-key-status { overflow-wrap: anywhere; }
.llm-connection-result:empty { display: none; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .tiny { font-size: .76rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 14px;
  font-weight: 600; cursor: pointer; min-height: 44px; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.danger { color: var(--danger); border-color: #e7c2be; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: .86rem; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea, .input {
  border: 1px solid #c9d4d1; border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink);
  font-size: 1rem; width: 100%;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--brand-2); flex: none; }

.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: .76rem; font-weight: 600; background: #eef1f0; color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.brand { background: var(--brand-soft); color: var(--brand); }

.banner { border-radius: var(--radius); padding: 12px 14px; font-size: .9rem; border: 1px solid; }
.banner.danger { background: var(--danger-soft); border-color: #eab8b3; color: #6f1414; }
.banner.warn { background: var(--warn-soft); border-color: #efd29c; color: #5e3a00; }
.banner.info { background: var(--brand-soft); border-color: #bcdcd6; color: #0d3a36; }
.banner ul { margin: 6px 0 0; padding-left: 20px; } .banner li { margin-bottom: 4px; }
.disclaimer { font-size: .78rem; color: var(--muted); text-align: center; padding: 4px 8px; }

.sticky-head { position: sticky; top: 0; z-index: 10; }
.sticky-head .top { position: static; }
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 12px 2px; font-size: .94rem; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand-2); }

.home-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.home-switch a {
  display: grid; place-items: center; min-height: 44px; padding: 4px 8px;
  border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600;
}
.home-switch a[aria-current] { background: var(--brand-soft); color: var(--brand); }
.workspace-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 14px 14px 0; text-align: center; }
.workspace-toolbar, .workspace-search { display: flex; align-items: center; gap: 8px; }
.workspace-toolbar { flex-wrap: wrap; }
.workspace-search { flex: 1 1 250px; min-width: 0; }
.workspace-search .input { flex: 1 1 0; min-width: 0; }
.workspace-search .btn { flex: none; }
.workspace-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0; }
.workspace-stat dt { color: var(--muted); font-size: .86rem; }
.workspace-stat dd { margin: 4px 0 0; color: var(--brand); font-size: 1.7rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.workspace-page { overflow-wrap: anywhere; }
.workspace-page p, .workspace-dialog p { margin: 0; }
.workspace-dialog {
  width: min(470px, calc(100% - 28px)); max-width: 100%; max-height: calc(100% - 28px);
  padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink);
  background: var(--card); box-shadow: 0 16px 42px rgba(23,38,36,.22);
}
.workspace-dialog::backdrop { background: rgba(23,38,36,.54); }
.customer-card .chip, .customer-profile .chip, .session-history-card .chip { white-space: normal; }
.customer-profile { border-top: 3px solid var(--brand-2); }
.customer-profile h2 { font-size: 1.3rem; }
.customer-notes { white-space: pre-wrap; }
.customer-filters { align-items: end; column-gap: 16px; }
.customer-filters .check { align-items: center; }
.preparation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.preparation-group { padding: 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 0; background: #fbfcfc; }
.preparation-group .btn, .preparation-confirmed { align-self: flex-start; }
.preparation-items, .preparation-actions { margin: 0; padding-inline-start: 20px; }
.preparation-actions { list-style: none; padding: 0; }
.preparation-actions .check { padding: 2px 0; align-items: flex-start; }
.preparation-action-edit { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.preparation-action-edit .input { flex: 1 1 130px; min-width: 0; }
.preparation-action-edit .check { white-space: nowrap; align-items: center; }
.session-fields { margin: 0; min-width: 0; padding: 0; border: 0; }
.source-fields { margin: 0; min-width: 0; }
.source-fields legend { padding-inline: 4px; font-weight: 650; }
.source-choices { gap: 6px 14px; }
.source-choices .check { align-items: center; white-space: nowrap; }
.drop-zone {
  padding: 14px; border: 2px dashed #90b9b1; border-radius: 12px;
  background: #f4faf8; overflow-wrap: anywhere;
}
.drop-zone.dragging { border-color: var(--brand-2); background: var(--brand-soft); }
.drop-zone p { margin: 0; }
.selected-file:empty, .upload-message:empty { display: none; }
.session-history-card h3 { color: var(--brand); }
.session-heading-actions { flex: none; flex-wrap: nowrap; gap: 5px; }
.closure-panel p, .risk-review p, .report-versions p { margin: 0; }
.risk-review { scroll-margin-top: 184px; }
.risk-review-group { padding-top: 10px; border-top: 1px solid var(--line); }
.risk-review-list, .report-version-list { list-style: none; margin: 0; padding: 0; }
.risk-review-item { margin: 0 0 8px; padding: 11px; border-radius: 10px; border: 1px solid var(--line); overflow-wrap: anywhere; }
.risk-reviewed { background: var(--ok-soft); border-radius: 8px; padding: 8px; }
.report-version-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line); }
.report-version-info { flex: 1 1 180px; min-width: 0; gap: 2px; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .workspace-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preparation-grid { grid-template-columns: minmax(0, 1fr); }
}
.auth-page { width: min(100%, 440px); margin: clamp(18px, 7vh, 72px) auto 0; }
.auth-page .card { padding: 20px; gap: 14px; }
.form-error:empty, .template-preview:empty, .copy-result:empty { display: none; }
.org-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 14px 14px 0; font-size: .9rem; text-align: center; }
.seat-count { color: var(--brand); font-size: .92rem; font-variant-numeric: tabular-nums; }
.org-list { margin: 0; padding: 0; list-style: none; }
.org-list-row {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 10px 18px; padding: 12px 0; border-top: 1px solid var(--line);
}
.org-list-row:last-child { padding-bottom: 0; }
.org-user { display: grid; gap: 3px; flex: 1 1 230px; min-width: 0; overflow-wrap: anywhere; }
.org-form-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.org-page form > .btn { align-self: start; }
.org-page input, .org-page select { min-width: 0; max-width: 100%; }
.system-health, .health-grid dd { min-width: 0; overflow-wrap: anywhere; }
.health-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.health-grid > div { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.health-grid dt { color: var(--muted); font-size: .84rem; }
.health-grid dd { margin: 4px 0 0; }
.health-content p, .health-feedback { margin: 0; }
.health-path { display: block; margin-top: 4px; }
.health-feedback:empty, .health-content:empty { display: none; }
@media (max-width: 520px) {
  .health-grid { grid-template-columns: minmax(0, 1fr); }
}
.template-name, .template-fields .chip { overflow-wrap: anywhere; }
.template-fields .chip { white-space: normal; max-width: 100%; }
.template-fields .row { margin-top: 6px; }
.password-dialog {
  width: min(420px, calc(100% - 28px)); max-width: 100%; max-height: calc(100% - 28px);
  padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink);
  background: var(--card); box-shadow: 0 16px 42px rgba(23,38,36,.22);
}
.password-dialog::backdrop { background: rgba(23,38,36,.54); }
.temporary-secret { font-family: ui-monospace, Consolas, monospace; }
.copy-result { margin: 0; }
@media (max-width: 520px) {
  .org-form-fields { grid-template-columns: minmax(0, 1fr); }
  .org-list-row .btn, .account-actions button { min-height: 44px; }
}
.case-list-card { display: grid; gap: 8px; justify-items: start; }
.case-list-card > .row { width: 100%; }
.case-list-card p, .case-plan p, .case-plan ul { margin: 0; }
.case-link, .case-preview, .case-overview, .case-plan li, .session-link h3 { overflow-wrap: anywhere; }
.case-link { color: var(--brand); text-underline-offset: 3px; }
.case-link:hover, .session-link:hover h3 { color: var(--brand-2); }
.case-preview { font-size: .9rem; }
.session-link { display: block; color: var(--ink); text-decoration: none; }
.session-link:hover { border-color: var(--brand-2); }
.case-fold > summary { cursor: pointer; color: var(--brand); font-weight: 650; }
.case-fold[open] > summary { margin-bottom: 12px; }
.case-plan { border-top: 3px solid var(--brand-2); }
.case-plan-section { display: grid; gap: 6px; }
.case-plan-section ul { padding-inline-start: 1.3em; }
.case-plan-section li + li { margin-top: 3px; }
.score-group + .score-group { margin-top: 4px; }
.score-table { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: .86rem; }
.score-table th, .score-table td { padding: 8px 5px; border-bottom: 1px solid var(--line); text-align: left; }
.score-table th { color: var(--muted); font-weight: 600; }
.score-table tr:last-child td { border-bottom: 0; }
.score-table td:first-child { white-space: nowrap; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.nav .inner { max-width: 760px; margin: 0 auto; display: flex; }
.nav a { flex: 1; text-align: center; padding: 10px 4px; text-decoration: none; color: var(--muted); font-size: .8rem; font-weight: 600; }
.nav a.on { color: var(--brand); }
.nav a span { display: block; font-size: 1.25rem; line-height: 1.2; }

.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 10px 14px calc(10px + var(--safe-b)); }
.actionbar .inner { max-width: 732px; margin: 0 auto; display: flex; gap: 8px; }
.actionbar .btn { flex: 1; }

/* 覆核對話 */
.page.with-composer { padding-bottom: 120px; }
.report-fields textarea { min-height: 44px; }
.msg { max-width: 88%; border-radius: 16px; padding: 10px 14px; border: 1px solid var(--line); background: var(--card); align-self: flex-start; scroll-margin-top: 130px; }
.msg.user { align-self: flex-end; background: var(--brand-soft); border-color: #bcdcd6; }
.msg.hit { box-shadow: 0 0 0 3px #e9a23b; }
.msg .who { font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg .del { border: 0; background: none; color: var(--muted); font-size: .72rem; padding: 4px 0 0; cursor: pointer; text-decoration: underline; }
.composer .inner { align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; border: 1px solid #c9d4d1; border-radius: 12px; padding: 9px 12px; resize: none; }
.composer .btn { flex: none; }
.composer .mic { width: 48px; padding: 0; font-size: 1.2rem; }
.composer .mic.on { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.4s infinite; }
.dict-partial { max-width: 732px; margin: 0 auto; font-size: .8rem; color: var(--muted); font-style: italic; min-height: 0; padding: 0 2px 4px; }
.dict-partial:empty { display: none; }
.quote.worker { border-left-color: #d3b46a; background: #fbf7ea; }
details.card > summary { list-style-position: inside; }

/* 逐字稿 */
.line { display: grid; grid-template-columns: 34px 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px solid #eef2f1; }
.line:last-child { border-bottom: 0; }
.line .no { color: #93a4a1; font-size: .78rem; text-align: right; padding-top: 3px; font-variant-numeric: tabular-nums; }
.line .meta { display: flex; gap: 6px; align-items: center; margin-bottom: 2px; }
.line .time { font-size: .74rem; color: #93a4a1; background: none; border: 0; padding: 0; cursor: pointer; font-variant-numeric: tabular-nums; }
.line .text { white-space: pre-wrap; word-break: break-word; cursor: text; }
.line.partial .text { color: #8a9a97; font-style: italic; }
.line { scroll-margin-top: 130px; }
.line.hit { background: #fff6dd; margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 8px; }
.spk { border: 1px dashed #b9c7c4; background: #fff; border-radius: 999px; font-size: .72rem; padding: 1px 8px; color: var(--muted); cursor: pointer; }
.spk.client { border-style: solid; border-color: #9ac9c1; background: var(--brand-soft); color: var(--brand); }
.spk.worker { border-style: solid; border-color: #d3c3a0; background: #f8f1df; color: #6b5210; }
audio { width: 100%; }

/* 即時錄音 */
.rec { text-align: center; padding: 18px 10px; }
.rec .timer { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.meter { height: 8px; background: #e6ecea; border-radius: 99px; overflow: hidden; margin: 10px auto; max-width: 280px; }
.meter i { display: block; height: 100%; width: 0; background: var(--brand-2); transition: width .12s; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); margin-right: 6px; animation: pulse 1.2s infinite; }
.dot.off { background: #b6c2bf; animation: none; }
@keyframes pulse { 50% { opacity: .25; } }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #c5d3d0; border-top-color: var(--brand-2); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 量表 */
.item { padding: 12px 0; border-bottom: 1px solid #eef2f1; }
.item:last-child { border-bottom: 0; }
.item .q { font-weight: 600; }
.quote { border-left: 3px solid #9ac9c1; background: #f5faf9; padding: 6px 10px; border-radius: 0 8px 8px 0; font-size: .88rem; margin-top: 6px; cursor: pointer; }
.quote.bad { border-left-color: #e0a09a; background: #fdf3f2; }
.scorepick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.scorepick button { min-width: 44px; min-height: 40px; border-radius: 10px; border: 1px solid #c9d4d1; background: #fff; font-weight: 700; cursor: pointer; }
.scorepick button.on { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.scorepick button.sug { box-shadow: inset 0 0 0 2px #e9a23b; }
.scorepick button.na { font-weight: 500; font-size: .82rem; color: var(--muted); padding: 0 10px; }
.scorepick button.na.on { background: #5d6f6c; border-color: #5d6f6c; color: #fff; }
.total { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sec h3 { color: var(--brand); margin-bottom: 6px; }
.sec ul { margin: 0; padding-left: 20px; } .sec li { margin-bottom: 6px; }
.reason { display: block; color: var(--muted); font-size: .82rem; }
details summary { cursor: pointer; font-weight: 600; color: var(--brand-2); }
pre.mono { white-space: pre-wrap; font: .8rem/1.5 ui-monospace, Menlo, Consolas, monospace; background: #f5f7f6; padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: #172624; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 88vw; z-index: 50; }
#toast.show { opacity: .96; }

@media print {
  .top, .tabs, .nav, .actionbar, .btn, #toast, .scorepick, .no-print { display: none !important; }
  body { background: #fff; } #app { max-width: none; padding: 0; }
  .card { border: 0; padding: 6px 0; break-inside: avoid; }
}

.stack:empty { display: none; }

/* 導航：返回鍵及上一步／下一步 */
.back-btn { background: rgba(255,255,255,.14); border: 0; color: #fff; font-weight: 600; font-size: .92rem; padding: 8px 12px 8px 8px; border-radius: 999px; cursor: pointer; white-space: nowrap; flex: none; }
.back-btn:active { background: rgba(255,255,255,.28); }
.stepnav { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.stepnav .btn { flex: 1; font-weight: 600; font-size: .92rem; padding: 10px 8px; }
.stepnav .btn.next { border-color: var(--brand-2); color: var(--brand-2); }
.stepnav span { flex: 1; }
.msg .row { gap: 14px; }
.return-chip { position: sticky; top: 166px; z-index: 8; align-self: flex-start; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
