/* ──────────────────────────────────────────────────────────────────
   S3 自己的樣式。外殼是 styles.css（adam 版原樣），這裡只放 S3 多出來的東西：
   圖表（charts.js，沿用 S2 的 ECharts 元件）、分層回答、試算卡、首頁「今天先留意」、
   選身分、拖曳。顏色只用 adam 的 token，不另外發明新色。
   ────────────────────────────────────────────────────────────────── */

/* ── charts.js 讀的 token：對應到 adam 的 token ──────────────────
   charts.js 從 body 讀（adam 的深色模式掛在 body.body--dark）。
   系列色取實體前端 tokens.scss 的五色；第六色用 text-3。 */
body {
  --ink: var(--text); --muted: var(--text-3); --line: var(--border); --paper: var(--surface); --soft: var(--surface-2);
  --series-blue: #2f6fd0; --series-orange: #c08018; --series-purple: #8b3fb8;
  --series-rose: #cc4b28; --series-sky: #0d8fae; --series-slate: #727a89;
  --chart-focus: #38517f; --chart-shadow: #1f293724;
  --heat-low: #edf1f8; --heat-mid: #8fa6cf; --heat-high: #38517f;
}
body.body--dark {
  --series-blue: #5b87d8; --series-orange: #bd8a30; --series-purple: #a067c4;
  --series-rose: #d76a4a; --series-sky: #2f9eba; --series-slate: #939cac;
  --chart-focus: #c0ceed; --chart-shadow: #00000055;
  --heat-low: #262a33; --heat-mid: #485c81; --heat-high: #a0b5e1;
}

/* ── 圖表與表格卡（charts.js 的 .s3-chart／.s3-table） ─────────── */
.s3-chart {
  margin: var(--s3) 0; border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); padding: var(--s4); min-width: 0;
}
.s3-chart .chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.s3-chart .chart-heading h3 { margin: 2px 0 0; font-size: var(--fs-section); font-weight: 600; color: var(--text); }
.s3-chart .chart-heading p { margin: 2px 0 0; font-size: var(--fs-meta); color: var(--text-3); }
.s3-chart .chart-kicker { margin: 0; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; color: var(--text-3); }
.s3-chart .chart-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.s3-chart .tool-button, .s3-answer .tool-button {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  color: var(--text-2); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.s3-chart .tool-button:hover { border-color: var(--accent-border); color: var(--accent); }
.s3-chart .tool-button:disabled { opacity: .45; cursor: not-allowed; }
.s3-chart .tool-button.primary-tool { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.s3-chart .chart-metric { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: var(--s3) 0 0; }
.s3-chart .chart-metric strong { font-family: var(--font-mono); font-size: 22px; font-weight: 500; color: var(--text); }
.s3-chart .chart-metric span { font-size: var(--fs-meta); color: var(--text-3); }
.s3-chart .chart-change { margin: 2px 0 0; font-size: var(--fs-meta); color: var(--text-3); }
.s3-chart .chart-controls { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; margin: var(--s3) 0 var(--s2); }
.s3-chart .chart-form-control { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.s3-chart .chart-form-control select {
  height: 30px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
  color: var(--text); font: inherit; font-size: 12px; padding: 0 8px;
}
.s3-chart .chart-fixed-shape { font-size: 12px; color: var(--text-3); }
.s3-chart .chart-unit { margin-left: auto; font-size: 11px; color: var(--text-3); }
.s3-chart .echart { width: 100%; height: 320px; }
.s3-chart .chart-shape-note, .s3-chart .chart-footnote { margin: 6px 0 0; font-size: 11.5px; line-height: 1.75; color: var(--text-3); }
.s3-chart .chart-zoom-reset { margin-left: 6px; font-size: 11.5px; }
.s3-chart .chart-selections { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--s2); }
.s3-chart .chart-selections button {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 1px solid var(--border);
  border-radius: var(--r-pill); background: var(--surface); color: var(--text-2); font: inherit; font-size: 11.5px; cursor: pointer;
}
.s3-chart .chart-selections button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.s3-chart .choice-mark { display: inline-grid; place-items: center; width: 12px; height: 12px; border: 2px solid; border-radius: 3px; font-size: 9px; }
.s3-chart .chart-selection-slot { margin-top: var(--s2); }
.s3-chart .chart-selection-hint { margin: 0; font-size: 11px; color: var(--text-3); }
.s3-chart .chart-selection-summary {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 12px;
  border: 1px solid var(--accent-border); border-radius: var(--r-md); background: var(--accent-soft);
}
.s3-chart .chart-selection-summary > div { display: flex; flex-direction: column; margin-right: auto; }
.s3-chart .chart-selection-summary span { font-size: 10.5px; color: var(--text-3); }
.s3-chart .chart-selection-summary strong { font-size: 13px; color: var(--text); }
.s3-chart .s3-chart { border: 0; padding: 0; margin-top: var(--s3); }

/* 表格：可排序、可拖曳調整列順序 */
.s3-table .table-scroll { overflow-x: auto; margin-top: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); }
.s3-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.s3-table th, .s3-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.s3-table tbody tr:last-child td { border-bottom: 0; }
.s3-table th { background: var(--surface-2); font-size: 11px; font-weight: 500; color: var(--text-3); }
.s3-table th button { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.s3-table th button:hover { color: var(--accent); }
.s3-table .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.s3-table tr.row-warn td { background: var(--warning-soft); }
.s3-table tr.row-dragover td { box-shadow: inset 0 2px 0 var(--accent); }
.s3-table tr[draggable="true"] { cursor: grab; }
.s3-table .row-hint { margin-left: 8px; padding: 1px 6px; border-radius: var(--r-sm); background: var(--warning-soft); color: var(--warning); font-size: 10px; }
.s3-table .row-handle-head, .s3-table .row-handle { width: 58px; }
.s3-table .handle-head-label { font-size: 10px; }
.s3-table .row-handle { color: var(--text-3); }
.s3-table .handle-grip { cursor: grab; margin-right: 4px; }
.s3-table .handle-nudge button { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 0 2px; font-size: 12px; }
.s3-table .handle-nudge button:disabled { opacity: .3; cursor: default; }
.s3-table .table-order-note { display: flex; align-items: center; gap: 8px; margin: var(--s2) 0 0; font-size: 11.5px; color: var(--text-3); }
.s3-table .table-pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 11px; color: var(--text-3); }
.s3-table .table-pagination > div { display: flex; align-items: center; gap: 6px; }

/* ── 回答本體 ──────────────────────────────────────────────── */
.s3-summary p { font-weight: 500; color: var(--text); }
.s3-answer { display: flex; flex-direction: column; gap: 2px; margin-top: var(--s2); }
.s3-paragraph { color: var(--text-2); }
.s3-layer { margin-top: var(--s5); }
.s3-layer-title {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 var(--s2);
  font-size: 12px; font-weight: 500; color: var(--text-3); letter-spacing: .06em;
}
.s3-layer-title .mono { color: var(--accent); font-size: 11px; }
.s3-claims { list-style: none; margin: var(--s2) 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); counter-reset: claim; }
.s3-claims li { position: relative; padding-left: 26px; }
.s3-claims li::before {
  counter-increment: claim; content: counter(claim); position: absolute; left: 0; top: 3px;
  display: grid; place-items: center; width: 18px; height: 18px; border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--text-2); font-family: var(--font-mono); font-size: 10.5px;
}
.s3-claims strong { display: block; font-size: var(--fs-sm); color: var(--text); margin-bottom: 2px; }
.s3-claims .mdlite p { margin: 0; font-size: var(--fs-sm); color: var(--text-2); line-height: 1.85; }
.s3-actions { list-style: none; margin: var(--s2) 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s3); }
.s3-actions li { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.s3-action-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.s3-action-top strong { font-size: var(--fs-sm); color: var(--text); }
.s3-impact { flex-shrink: 0; font-size: 10.5px; padding: 1px 7px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); }
.s3-actions p { margin: 0; font-size: 13px; line-height: 1.8; color: var(--text-2); }
.s3-owner { align-self: flex-start; font-size: 10.5px; color: var(--text-3); }
.s3-followups { margin-top: var(--s5); display: flex; flex-direction: column; }
.s3-followups .suggestion-label { margin: 0 0 6px; font-size: 11px; font-weight: 500; color: var(--text-3); letter-spacing: .06em; }
.s3-followup {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 2px;
  border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text-2);
  font: inherit; font-size: 13.5px; text-align: left; cursor: pointer;
}
.s3-followup:hover { color: var(--accent); }
.s3-followup:disabled { opacity: .5; cursor: default; }
.s3-meta { margin-top: var(--s4); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.s3-meta summary { display: flex; align-items: center; gap: 6px; padding: 9px 12px; cursor: pointer; font-size: 12px; color: var(--text-2); }
.s3-verify { margin: 0; padding: 0 16px 10px 32px; font-size: 12px; line-height: 1.85; color: var(--text-2); }
.s3-meta .sql {
  margin: 0; padding: var(--s3) var(--s4); border-top: 1px solid var(--border); background: var(--surface-3);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.65; color: var(--text-2); overflow-x: auto; white-space: pre;
}
.s3-quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 20px; margin-top: var(--s2); }
.s3-quick .suggestion, .brief-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 4px;
  border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text-2);
  font: inherit; text-align: left; cursor: pointer; transition: background var(--t-fast), color var(--t-fast);
}
.s3-quick .suggestion:hover, .brief-item:hover { background: var(--surface-2); color: var(--text); }
.s3-quick .suggestion-copy { flex: 1; display: grid; gap: 4px; }
.s3-quick .suggestion-copy small { font-size: 11px; color: var(--text-3); }
.s3-quick .suggestion-copy > span { font-size: 13px; }
.s3-goto { margin-top: var(--s2); display: inline-flex; align-items: center; gap: 5px; }

/* 試算參數卡 */
.calc-card { margin: var(--s3) 0; border: 1px solid var(--accent-border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.calc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); }
.calc-head strong { color: var(--text); font-size: var(--fs-sm); }
.calc-head span { font-size: 12px; color: var(--text-3); }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s3) var(--s4); padding: var(--s4); }
.calc-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.calc-field > span { font-size: 10.5px; color: var(--text-3); letter-spacing: .04em; }
.calc-field .native-select { width: 100%; }
.calc-pct { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.calc-pct .field-input {
  width: 68px; height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit; font-family: var(--font-mono);
}
.calc-pct .field-input:focus { outline: none; border-color: var(--accent); }
.type-chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 3px 10px; font-size: 11.5px; font-family: var(--font-sans); cursor: pointer;
}
.type-chip:hover { border-color: var(--accent); color: var(--accent); }
.type-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.calc-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; padding: 0 var(--s4) var(--s4); }
.calc-foot small { font-size: 11.5px; color: var(--text-3); }
.calc-foot .calc-warn { color: var(--danger); }

/* ── 首頁：今天先留意（經營者） ────────────────────────────────── */
.empty .suggestion-label .label-meta { margin-left: 10px; font-size: 10.5px; color: var(--text-3); letter-spacing: 0; text-transform: none; }
.brief { list-style: none; margin: 0 0 var(--s3); padding: 0; }
.brief-item { padding: 14px 6px; align-items: flex-start; }
.brief-rank {
  flex-shrink: 0; display: grid; place-items: center; width: 22px; height: 22px; margin-top: 2px;
  border-radius: var(--r-sm); background: var(--surface-3); color: var(--text-2); font-size: 11px;
}
.brief-item.lvl-high .brief-rank { background: var(--warning-soft); color: var(--warning); }
.brief-copy { flex: 1; min-width: 0; display: grid; gap: 4px; }
.brief-copy small { display: flex; gap: 8px; font-size: 11px; color: var(--text-3); }
.brief-level { color: var(--warning); }
.brief-item.lvl-watch .brief-level { color: var(--accent); }
.brief-headline { font-size: 14px; line-height: 1.6; color: var(--text); }
.brief-action { font-size: 12px; color: var(--text-3); }
.brief-metric { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-right: 4px; }
.brief-metric strong { font-size: 15px; font-weight: 500; color: var(--text); }
.brief-metric small { font-size: 10.5px; color: var(--text-3); }
.brief-item > .q-icon { color: var(--text-3); margin-top: 4px; }
.brief-item:hover > .q-icon { color: var(--accent); }
.brief-more { margin: 0 0 var(--s4); font-size: 12.5px; color: var(--text-2); }
.brief-more summary { cursor: pointer; padding: 6px 4px; color: var(--text-3); }
.brief-more ul { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.brief-more li { padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); }
.brief-more li strong { display: block; font-size: 13px; color: var(--text); }
.brief-more li p { margin: 4px 0; line-height: 1.8; }
.brief-note { font-size: 11px; color: var(--text-3); }

/* ── 選身分 ─────────────────────────────────────────────────── */
.role-page { min-height: 100%; display: grid; place-items: center; padding: 40px 16px; background: var(--bg); }
.role-inner { width: 100%; max-width: 620px; }
.role-inner .identity { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.role-inner .identity h2 { margin: 0; font-size: 26px; font-weight: 500; color: var(--text); }
.role-inner .identity h2.latin { letter-spacing: .08em; }
.role-title { margin: 0 0 6px; font-size: var(--fs-page); font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.role-sub { margin: 0 0 24px; font-size: 13.5px; line-height: 1.8; color: var(--text-2); }
.role-grid { display: flex; flex-direction: column; gap: 10px; }
.role-card {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.role-card:hover, .role-card:focus-visible { border-color: var(--accent-border); box-shadow: var(--shadow-md); outline: none; }
.role-card > .q-icon { color: var(--text-3); }
.role-card:hover > .q-icon { color: var(--accent); }
.role-copy { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.role-copy strong { font-size: 15px; font-weight: 600; }
.role-copy small { font-size: 12.5px; color: var(--text-3); }
.avatar {
  flex-shrink: 0; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600;
}
.avatar.small { width: 26px; height: 26px; font-size: 11px; }
.role-card[data-role="boss"] .avatar { background: var(--accent); color: var(--accent-ink); }

/* 側欄左下：目前身分 */
.rail .user-chip { height: auto; padding-top: 8px; padding-bottom: 8px; }
.rail .user-chip .avatar { width: 28px; height: 28px; font-size: 11px; }
.rail .user-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; text-align: left; }
.rail .user-copy strong { font-size: 13px; font-weight: 500; color: var(--text); }
.rail .user-copy small { font-size: 11px; color: var(--text-3); }
.rail .user-more { color: var(--text-3); }
.rail .nav-count { margin-left: auto; font-size: 10.5px; color: var(--text-3); }
.rail .nav-count.alert { padding: 0 6px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink); }
.role-menu { min-width: 220px; }

/* ── 拖曳 ───────────────────────────────────────────────────── */
/* 一、收據拖進對話 */
.chat-page { position: relative; }
.drop-overlay {
  position: absolute; inset: 12px; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--accent); border-radius: var(--r-lg); background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--accent); pointer-events: none;
}
.drop-overlay strong { font-size: 16px; color: var(--text); }
.drop-overlay span { font-size: 12.5px; color: var(--text-3); }
/* 二、Dashboard 卡片拖曳排序 */
.board-pin .pin-grip { display: inline-flex; align-items: center; color: var(--text-3); cursor: grab; margin-right: 2px; touch-action: none; }
body.pin-sorting, body.pin-sorting * { cursor: grabbing !important; user-select: none; }
.board-pin .pin-grip:active { cursor: grabbing; }
.board-pin.dragging { opacity: .45; }
.board-pin.drag-over { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.board-pin .pin-body .s3-chart { border: 0; margin: 0; border-radius: 0; }
.board-page .board-grid { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }

/* 放大的圖 */
.big-chart-card { display: flex; flex-direction: column; background: var(--bg); }
.big-chart-body { flex: 1; overflow-y: auto; }
.big-chart-body .s3-chart { max-width: 1100px; margin: 0 auto; }
.big-chart-body .s3-chart .echart { height: 480px; }

@media (max-width: 860px) {
  .board-page .board-grid { grid-template-columns: 1fr; }
  .s3-chart { padding: var(--s3); }
  .s3-chart .chart-heading { flex-direction: column; }
  .s3-chart .chart-actions { justify-content: flex-start; }
  .brief-metric { display: none; }
}
