/* ============================================
   紅鈕釦炸雞 · 財務全景 · Design Tokens
   ============================================ */

:root {
  /* Brand */
  --brand: #D23028;           /* 紅鈕釦紅 */
  --brand-dark: #8C1A14;
  --brand-tint: #FDECEA;

  /* Surface */
  --bg: #F7F6F3;              /* 暖白，餐飲感 */
  --surface: #FFFFFF;
  --surface-2: #FAFAF7;
  --ink: #1A1A1A;
  --ink-2: #4A4A4A;
  --ink-3: #8A8A8A;
  --line: #EAE7E0;

  /* Status */
  --good: #2E7D4F;
  --good-bg: #E8F3EC;
  --warn: #C77700;
  --warn-bg: #FFF4E0;
  --bad: #C43127;
  --bad-bg: #FBEBE9;

  /* Cost colors */
  --c-fixed: #5B6F89;
  --c-var: #D89B4A;
  --c-invest: #7C5BA0;

  /* Matrix */
  --star: #D23028;
  --potential: #E8824A;
  --hidden: #E8B04A;
  --base: #6BA368;
  --stable: #A8B86B;
  --weak: #B8AB7A;
  --traffic: #4E8BAD;
  --bleed: #A06B8F;
  --dead: #7A7A7A;

  /* Type */
  --font-zh: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-num: "SF Pro Display", -apple-system, "Inter", sans-serif;

  /* Space */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-zh);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid;
  grid-template-columns: 260px 1fr 260px;
  align-items: center;
  background: #1A1A1A;
  color: #fff;
  padding: 14px 28px;
  border-bottom: 1px solid #000;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(210,48,40,.25);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .02em; }
.brand-sub { font-size: 11px; opacity: .55; letter-spacing: .08em; }

.tabs { display: flex; justify-content: center; gap: 6px; }
.tab {
  background: transparent;
  color: #aaa;
  border: none;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: .06em;
  transition: all .15s;
}
.tab:hover { color: #fff; background: rgba(255,255,255,.05); }
.tab.active { color: #fff; background: var(--brand); }

.meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 14px;
  font-size: 12px;
}
.btn-import {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: .05em;
  cursor: pointer;
  font-weight: 500;
  transition: transform .15s, box-shadow .15s;
}
.btn-import:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(210,48,40,.35); }
.btn-import:active { transform: translateY(0); }
.period { opacity: .7; }
.health { color: #fff; }
.health strong { color: #7FD6A8; font-size: 16px; margin-left: 4px; }

/* View */
.view { display: none; padding: 20px 24px 64px; max-width: 1320px; margin: 0 auto; }
.view.active { display: block; }

/* ============================================
   全景 View — Hero 收緊，左重右輕
   ============================================ */
.hero {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #1A1A1A 0%, #2A1F1E 100%);
  color: #fff;
  padding: 22px 28px;
  border-radius: var(--r-lg);
  align-items: center;
}
.hero-left .label {
  font-size: 10px;
  opacity: .45;
  letter-spacing: .2em;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.hero-left blockquote {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  font-weight: 300;
  letter-spacing: .01em;
}
.hero-left blockquote b { color: #FFB8A8; font-weight: 500; }
.hero-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-left: 20px;
  border-left: 1px solid rgba(255,255,255,.1);
}

.kpi-big { text-align: right; }
.kpi-label {
  font-size: 10px;
  opacity: .5;
  letter-spacing: .2em;
  text-transform: uppercase;
}
.kpi-value {
  font-family: var(--font-num);
  font-size: 40px;
  font-weight: 300;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  margin: 6px 0 6px;
}
.kpi-note { font-size: 11px; opacity: .85; }

.four-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  min-height: 128px;
}
.card-h {
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.card .big {
  font-family: var(--font-num);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 2px;
}
.card .sub { font-size: 12px; color: var(--ink-3); margin-bottom: 10px; }
.card .delta {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.card .delta.up { color: var(--good); background: var(--good-bg); }
.card .delta.down { color: var(--bad); background: var(--bad-bg); }
.card .mini { font-size: 11px; color: var(--ink-3); }
.card.alert { border-left: 3px solid var(--warn); }

.progress {
  height: 6px; background: var(--line); border-radius: 999px;
  margin: 10px 0 8px; overflow: hidden;
}
.progress span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, var(--good) 100%);
  border-radius: 999px;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.dot.red { background: var(--bad); }
.dot.orange { background: var(--warn); }
.dot.green { background: var(--good); }

.tri {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 8px 0;
}
.tri > div { display: flex; flex-direction: column; }
.tri span { font-size: 11px; color: var(--ink-3); }
.tri b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 500;
}

.status-good { color: var(--good); }
.status-warn { color: var(--warn); }
.status-bad { color: var(--bad); }

/* Panels */
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;
}
.grid-3 {
  display: grid; grid-template-columns: 1.1fr 1.3fr 1fr; gap: 12px; margin-bottom: 12px;
}
.panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.panel-h {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: .02em;
  color: var(--ink);
}

/* Pyramid */
.pyramid { margin: 14px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.p-layer {
  padding: 10px 16px;
  border-radius: 8px;
  color: #fff;
  text-align: center;
  transition: transform .15s;
  width: 100%;
}
.p-layer:hover { transform: scale(1.01); }
.p-invest { background: var(--c-invest); max-width: 40%; }
.p-var { background: var(--c-var); max-width: 72%; }
.p-fix { background: var(--c-fixed); max-width: 100%; }
.p-layer b { font-size: 13px; display: block; font-weight: 600; }
.p-layer span { font-size: 10px; opacity: .85; display: block; margin-top: 2px; }
.p-layer em { background: rgba(255,255,255,.25); padding: 1px 6px; border-radius: 3px; font-style: normal; font-size: 10px; margin-left: 6px; }

.legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: 10px; color: var(--ink-3); }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 6px; vertical-align: middle; }
.sw-invest { background: var(--c-invest); }
.sw-var { background: var(--c-var); }
.sw-fix { background: var(--c-fixed); }

/* ============================================
   Risk Panel — 全店體質分數（主 CTA 區）
   ============================================ */
.risk-panel {
  background: linear-gradient(135deg, #FFF9E8 0%, #FDECEA 100%);
  border-left: 4px solid var(--brand);
  padding: 20px 22px;
}
.risk-panel .panel-h {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 14px;
  margin-bottom: 8px;
}
.score-big {
  font-family: var(--font-num);
  font-size: 32px;
  font-weight: 700;
  color: var(--brand);
  margin-left: auto;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.score-unit { font-size: 11px; color: var(--ink-3); margin-left: 2px; }
.zone-tag {
  margin-left: 10px;
  background: var(--bad-bg);
  color: var(--bad);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: .08em;
  font-weight: 600;
  white-space: nowrap;
}
.risk-sentence {
  font-size: 13px;
  color: var(--ink);
  padding: 8px 0 12px;
  border-bottom: 1px dashed rgba(210,48,40,.18);
  margin-bottom: 12px;
  line-height: 1.6;
}
.top-actions .ta-head {
  font-size: 10px;
  color: var(--brand);
  letter-spacing: .2em;
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
}
.top-actions ol {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: action;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.top-actions li {
  counter-increment: action;
  padding: 10px 12px 10px 38px;
  background: #fff;
  border-radius: 8px;
  position: relative;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.top-actions li::before {
  content: counter(action);
  position: absolute;
  left: 10px; top: 10px;
  width: 20px; height: 20px;
  background: var(--brand);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

/* Trend findings */
.panel-sub {
  font-size: 11px;
  font-weight: normal;
  color: var(--ink-3);
  margin-left: 8px;
}
.trend-findings {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.trend-finding {
  font-size: 11px;
  color: var(--ink-2);
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}

/* Insights */
.insights .count {
  background: var(--brand); color: #fff;
  padding: 2px 10px; border-radius: 999px;
  font-size: 10px; font-weight: 500;
  letter-spacing: .08em;
}
.insight {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.insight:first-of-type { border-top: none; padding-top: 4px; }
.insight:last-of-type { padding-bottom: 4px; }
.agent-tag {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.agent-red { background: var(--brand); }
.agent-black { background: #1A1A1A; }
.agent-blue { background: #4A6FA5; }
.agent-green { background: #5B8B5C; }
.agent-purple { background: var(--c-invest); }

.insight-body h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; line-height: 1.5; }
.insight-body p { margin: 0 0 8px; color: var(--ink-2); font-size: 12px; line-height: 1.65; }
.insight-foot { display: flex; gap: 6px; }
.insight-foot button {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: opacity .15s;
}
.insight-foot button:hover { opacity: .85; }
.insight-foot button.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }

/* 採購 */
.hhi-bar {
  display: flex; height: 28px; border-radius: 6px; overflow: hidden; margin: 10px 0 8px;
}
.hhi-bar span {
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
}
.sup-a { background: #C43127; }
.sup-b { background: #D89B4A; }
.sup-c { background: #8A8A8A; }

.rd-list { list-style: none; padding: 0; margin: 0; }
.rd-list li { padding: 10px 0; border-top: 1px solid var(--line); }
.rd-list li:first-child { border-top: none; }
.rd-list li b { font-size: 14px; margin-right: 6px; }
.rd-list .mini { color: var(--ink-3); font-size: 11px; margin-top: 4px; }
.pill {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: .05em;
}
.pill-live { background: var(--good-bg); color: var(--good); }
.pill-plan { background: #EEE; color: var(--ink-3); }

/* Canvas 高度約束 — 避免 Chart.js 無限展開
   Chart.js 讀的是容器高度，必須同時設 container + canvas。 */
.panel {
  position: relative;
}
.panel > canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
  height: 240px !important;
  max-height: 240px !important;
}
.panel.small > canvas {
  height: 160px !important;
  max-height: 160px !important;
}
/* Chart 被放在 flex/grid 容器內要撐高 */
.panel.chart-panel {
  display: flex;
  flex-direction: column;
}
.panel.chart-panel > canvas {
  flex: 0 0 auto;
}

/* ============================================
   九宮格 View
   ============================================ */
.matrix-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
}
.matrix-header h2 { margin: 0; font-size: 20px; font-weight: 600; }
.filter { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.chip {
  background: transparent;
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-2);
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.matrix-layout {
  display: grid; grid-template-columns: 1fr 380px; gap: 16px;
}
.matrix-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  aspect-ratio: 1.2 / 1;
  background: var(--surface);
  padding: 20px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  position: relative;
}
.m-cell {
  padding: 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: flex; flex-direction: column;
  min-height: 0;
}
.m-cell:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,.1); }
.m-cell.star { background: linear-gradient(135deg, #C43127 0%, #E15347 100%); color: #fff; }
.m-cell.potential { background: #FFF0E0; color: #6B3A17; border: 1px dashed #E8824A; }
.m-cell.hidden { background: #FFF9E8; color: #745914; border: 1px dashed #E8B04A; }
.m-cell.base { background: #E6F0E3; color: #2E5C2C; }
.m-cell.stable { background: #F0F2E5; color: #555C22; }
.m-cell.weak { background: #F2EFE3; color: #6B6142; }
.m-cell.traffic { background: #E3EEF5; color: #2A5673; }
.m-cell.bleed { background: #F2E5EB; color: #6B3954; }
.m-cell.dead { background: #EAEAEA; color: #555; border: 1px dashed #999; }

.cell-h { font-weight: 600; margin-bottom: 8px; font-size: 13px; }
.cell-products {
  display: flex; flex-wrap: wrap; gap: 4px 8px;
  font-size: 11px;
}
.cell-products span {
  background: rgba(255,255,255,.5);
  padding: 2px 6px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}
.m-cell.star .cell-products span { background: rgba(255,255,255,.2); color: #fff; }
.cell-products em { font-style: normal; font-weight: 600; margin-left: 3px; opacity: .9; }

.axis-y, .axis-x {
  position: absolute;
  font-size: 10px; color: var(--ink-3);
  letter-spacing: .1em;
}
.axis-y { left: -2px; top: 50%; transform: rotate(-90deg) translateX(50%); transform-origin: left top; }
.axis-x { bottom: 4px; right: 20px; }

/* Product card */
.product-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  height: fit-content;
}
.pc-head { display: flex; justify-content: space-between; align-items: baseline; }
.pc-head h3 { margin: 0; font-size: 18px; }
.pc-tag { font-size: 11px; color: var(--ink-3); font-family: var(--font-num); }
.pc-badge {
  background: var(--brand-tint);
  color: var(--brand);
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-block;
  font-size: 11px;
  margin: 8px 0 16px;
}
.pc-stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;
}
.pc-stat-grid > div {
  background: var(--surface-2);
  padding: 8px 10px;
  border-radius: 6px;
}
.pc-stat-grid label { font-size: 11px; color: var(--ink-3); display: block; }
.pc-stat-grid b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
}
.pc-benchmark {
  background: var(--good-bg);
  color: var(--good);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 14px;
}
.pc-costs { margin-bottom: 14px; font-size: 12px; }
.cost-row {
  display: flex; justify-content: space-between; padding: 4px 0;
  border-top: 1px solid var(--line);
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.cost-row:first-child { border-top: none; }
.cost-row.minus b { color: var(--ink-3); }
.cost-row.total { border-top: 2px solid var(--ink); font-weight: 600; padding-top: 6px; margin-top: 4px; }

.pc-insights { margin-bottom: 14px; }
.mini-insight {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 6px;
  border-left: 3px solid;
}
.mini-insight.red { background: #FDECEA; border-color: var(--brand); }
.mini-insight.black { background: #F0F0F0; border-color: #1A1A1A; }
.mini-insight.green { background: #E8F3EC; border-color: var(--good); }
.mini-insight b { margin-right: 4px; }

.pc-actions { display: flex; flex-direction: column; gap: 6px; }
.pc-actions button {
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  text-align: left;
}
.pc-actions button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* Composition */
.composition { margin-top: 10px; }
.comp-row {
  display: grid;
  grid-template-columns: 100px 1fr 50px 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.comp-row:first-child { border-top: none; }
.comp-row label { font-size: 12px; color: var(--ink-2); }
.comp-row .bar {
  background: var(--line);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}
.comp-row .bar span {
  display: block; height: 100%;
}
.b-star { background: var(--star); }
.b-pot { background: var(--potential); }
.b-traffic { background: var(--traffic); }
.b-dead { background: var(--dead); }
.comp-row b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.comp-row .mini { font-size: 11px; color: var(--ink-3); }

/* ============================================
   顧問 View
   ============================================ */
.consult-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  height: calc(100vh - 180px);
  min-height: 600px;
}
.agent-list {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 12px;
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.agent-card {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background .15s;
}
.agent-card:hover { background: var(--surface-2); }
.agent-card.active { background: var(--ink); color: #fff; }
.agent-card.active h4 { color: #fff; }
.agent-card.active p { color: #bbb; }
.agent-card.active .credit { color: #FFB8A8; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.avatar-red { background: var(--brand); }
.avatar-blue { background: #4A6FA5; }
.avatar-black { background: #1A1A1A; }
.avatar-green { background: #5B8B5C; }
.avatar-purple { background: var(--c-invest); }
.agent-card h4 { margin: 0 0 2px; font-size: 13px; }
.agent-card p { margin: 0; font-size: 11px; color: var(--ink-3); }
.credit { font-size: 10px; color: var(--brand); font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.chat {
  background: var(--surface);
  border-radius: var(--r-lg);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  min-height: 0;
}
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.chat-head h3 { margin: 0; font-size: 15px; }
.chat-head .mini { font-size: 11px; color: var(--ink-3); }
.chat-head b { color: var(--brand); }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
}
.msg {
  margin-bottom: 14px;
  max-width: 80%;
}
.msg.user {
  margin-left: auto;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px 14px 2px 14px;
}
.msg.user.ghost { background: var(--surface-2); color: var(--ink-3); }
.msg.user p { margin: 0; font-size: 13px; }

.msg.agent {
  background: var(--brand-tint);
  border-left: 3px solid var(--brand);
  padding: 12px 16px;
  border-radius: 2px 12px 12px 12px;
}
.msg.agent p, .msg.agent ol { margin: 4px 0; font-size: 13px; color: var(--ink); }
.msg.agent ol { padding-left: 20px; }
.msg.agent ol li { margin-bottom: 4px; }
.msg-head { font-size: 11px; color: var(--brand); font-weight: 600; letter-spacing: .1em; margin-bottom: 4px; }

.chat-input {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line);
}
.chat-input input {
  flex: 1; padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  font-family: inherit;
  font-size: 13px;
}
.chat-input button {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 22px;
  font-size: 13px;
  opacity: .5;
}

/* ============================================
   歸因 View
   ============================================ */
.sections { display: flex; flex-direction: column; gap: 20px; }
.section {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}
.section:first-child { border-top: none; padding-top: 0; }
.section h4 {
  font-size: 15px;
  margin: 0 0 10px;
}
.stat-line {
  background: var(--surface-2);
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.stat-line b {
  color: var(--brand);
  font-family: var(--font-num);
  margin: 0 4px;
}
.miss-box {
  background: var(--bad-bg);
  padding: 12px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 8px;
}
.miss-box i { font-style: italic; color: var(--ink-2); }
.fix { display: inline-block; margin-top: 6px; background: var(--good-bg); color: var(--good); padding: 4px 10px; border-radius: 4px; font-size: 11px; }

.conclusion { font-size: 13px; color: var(--ink-2); margin-top: 6px; }

table.deci {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.deci th, table.deci td {
  text-align: left;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
table.deci th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: .05em;
}
table.deci .right { color: var(--good); font-weight: 600; }
table.deci .wrong { color: var(--bad); font-weight: 600; }
table.deci .pending { color: var(--warn); font-weight: 600; }

.bugs { list-style: none; padding: 0; }
.bugs li {
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.bugs li:first-child { border-top: none; }
.bugs b { margin-right: 6px; }

.self-blame {
  background: #FFF9E8;
  padding: 16px 18px;
  border-radius: 10px;
  border-left: 4px solid var(--warn);
}
.self-blame h4 { color: var(--warn); }
.self-blame p { margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }

.directive {
  background: var(--brand-tint);
  padding: 18px 20px;
  border-radius: 10px;
  border: 2px solid var(--brand);
}
.directive h4 { color: var(--brand); margin-bottom: 10px; }
.big-directive {
  font-size: 20px;
  font-weight: 600;
  margin: 8px 0 12px;
  color: var(--ink);
}
.directive p { font-size: 13px; margin: 6px 0; color: var(--ink-2); }
.success-criteria {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 6px;
  margin-top: 10px;
  font-size: 12px;
}
.success-criteria b { color: var(--brand); }

.tagline {
  background: #1A1A1A;
  color: #fff;
  padding: 22px 28px;
  border-radius: 12px;
  text-align: center;
}
.tagline blockquote {
  margin: 0;
  font-size: 15px;
  line-height: 1.8;
  font-weight: 300;
}

/* ============================================
   Upload Modal
   ============================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,10,10,.55);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn .18s ease-out;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  max-width: 960px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.modal-head h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.modal-close {
  background: transparent; border: none;
  font-size: 28px; line-height: 1;
  color: var(--ink-3); cursor: pointer;
  padding: 4px 10px; border-radius: 50%;
  transition: background .15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-sub { font-size: 13px; color: var(--ink-2); margin: 6px 0 22px; }

.upload-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.upload-slot {
  background: var(--surface-2);
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 22px 18px;
  text-align: center;
  cursor: pointer;
  transition: all .18s;
  display: block;
}
.upload-slot:hover {
  border-color: var(--brand);
  background: #FFF8F7;
  transform: translateY(-2px);
}
.upload-slot.dragover {
  border-color: var(--brand);
  border-style: solid;
  background: var(--brand-tint);
}
.upload-slot.filled {
  border-color: var(--good);
  border-style: solid;
  background: #F3FAF5;
}
.upload-slot.error {
  border-color: var(--bad);
  background: #FDF2F1;
}
.slot-icon { font-size: 28px; margin-bottom: 6px; }
.slot-label { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.slot-hint { font-size: 10px; color: var(--ink-3); line-height: 1.5; margin-bottom: 10px; font-family: var(--font-num); }
.slot-status {
  font-size: 11px; color: var(--ink-3);
  padding: 6px 10px;
  background: #fff;
  border-radius: 6px;
  letter-spacing: .02em;
}
.upload-slot.filled .slot-status {
  color: var(--good); font-weight: 600; background: #fff;
}
.upload-slot.error .slot-status {
  color: var(--bad); font-weight: 600; background: #fff;
}
.modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.upload-log {
  font-size: 11px; color: var(--ink-3);
  font-family: var(--font-num);
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
}
.upload-log .ok { color: var(--good); }
.upload-log .err { color: var(--bad); }
.btn-primary {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 12px 26px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .05em;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary:not(:disabled):hover { background: var(--brand); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* ============================================
   Responsive — Tablet
   ============================================ */
@media (max-width: 1200px) {
  .four-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .matrix-layout { grid-template-columns: 1fr; }
  .consult-layout { grid-template-columns: 1fr; height: auto; min-height: 720px; }
  .topbar { grid-template-columns: 1fr; gap: 8px; padding: 12px 16px; }
  .meta { justify-content: flex-start; }
}

/* ============================================
   Responsive — Mobile（老闆手機）
   ============================================ */
@media (max-width: 720px) {
  body { font-size: 13px; }
  .view { padding: 16px 12px 60px; }

  /* Topbar — 收緊 */
  .topbar { padding: 10px 14px; }
  .brand-name { font-size: 14px; }
  .brand-sub { display: none; }
  .tabs { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { padding: 6px 14px; font-size: 12px; white-space: nowrap; }
  .meta { display: none; }

  /* Hero — 垂直排列，KPI 上方 */
  .hero {
    grid-template-columns: 1fr;
    padding: 20px 18px;
    margin-bottom: 14px;
    gap: 14px;
  }
  .hero-left blockquote { font-size: 14px; line-height: 1.7; }
  .hero-right { justify-content: flex-start; }
  .kpi-big { text-align: left; }
  .kpi-value { font-size: 38px; }

  /* Four cards — 2×2 → 1 row 垂直 */
  .four-cards {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .card { padding: 14px 16px; }
  .card .big { font-size: 24px; }
  .card-h { font-size: 11px; }
  .tri { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .tri b { font-size: 15px; }

  /* Pyramid 縮小 */
  .pyramid { margin: 14px 0 6px; }
  .p-layer { padding: 10px 14px; }
  .p-layer b { font-size: 12px; }
  .p-layer span { font-size: 10px; }

  /* Panel */
  .panel { padding: 16px; margin-bottom: 12px; }
  .panel-h { font-size: 13px; }

  /* Insights — 縮小 agent tag */
  .insight { grid-template-columns: 40px 1fr; gap: 10px; padding: 12px 0; }
  .agent-tag { width: 36px; height: 36px; font-size: 11px; }
  .insight-body h4 { font-size: 13px; }
  .insight-body p { font-size: 12px; }

  /* Matrix — 垂直堆疊 */
  .matrix-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .matrix-header h2 { font-size: 18px; }
  .filter { flex-wrap: wrap; }
  .matrix-grid { aspect-ratio: auto; padding: 12px; gap: 4px; }
  .m-cell { padding: 10px 8px; min-height: 72px; }
  .cell-h { font-size: 11px; margin-bottom: 4px; }
  .cell-products { font-size: 10px; gap: 2px 4px; }
  .cell-products span { padding: 1px 4px; }

  /* Product card */
  .product-card { padding: 16px; }
  .pc-head h3 { font-size: 16px; }
  .pc-stat-grid b { font-size: 16px; }
  .pc-actions button { font-size: 11px; padding: 10px 14px; }

  /* Composition */
  .comp-row {
    grid-template-columns: 60px 1fr 40px;
    font-size: 11px;
    gap: 8px;
  }
  .comp-row .mini { display: none; }

  /* Consultant chat */
  .agent-list {
    display: flex; overflow-x: auto;
    padding: 8px; gap: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .agent-card {
    min-width: 160px; flex-shrink: 0;
    flex-direction: column; gap: 6px;
    text-align: center;
  }
  .agent-card p { display: none; }
  .chat { min-height: 520px; }
  .msg { max-width: 92%; }
  .chat-input input { font-size: 14px; padding: 8px 12px; }
  .chat-input button { padding: 8px 16px; font-size: 12px; }

  /* Attribution */
  .big-directive { font-size: 17px; }
  table.deci { font-size: 11px; }
  table.deci th, table.deci td { padding: 8px 6px; }
  .tagline blockquote { font-size: 13px; line-height: 1.7; }
}

/* ============================================
   Small phones (< 380px)
   ============================================ */
@media (max-width: 380px) {
  .four-cards { grid-template-columns: 1fr; }
  .tri { grid-template-columns: repeat(3, 1fr); }
  .kpi-value { font-size: 32px; }
  .card .big { font-size: 22px; }
}

/* ============================================
   Touch-friendly tap targets
   ============================================ */
@media (hover: none) {
  .tab, .chip, .pc-actions button, .insight-foot button {
    min-height: 40px;
  }
  .m-cell {
    min-height: 80px;
  }
  .m-cell:hover { transform: none; box-shadow: none; }
  .m-cell:active { transform: scale(0.98); }
}

/* ============================================
   Print（給會計 / 列印月報用）
   ============================================ */
@media print {
  .topbar, .tabs, .chat-input, .pc-actions, .insight-foot { display: none; }
  .view { display: block !important; padding: 0; }
  .panel { box-shadow: none; border: 1px solid var(--line); break-inside: avoid; }
  body { background: #fff; }
  .hero { background: #fff; color: #000; border: 1px solid var(--line); }
  .hero-left blockquote, .kpi-label, .kpi-note { color: #000; }
}
