:root {
  color-scheme: light;
  --surface-0: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success: #006300;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --seq-100: #cde2fb; --seq-300: #6da7ec; --seq-500: #256abf; --seq-700: #0d366b;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(11,11,11,0.04), 0 4px 16px rgba(11,11,11,0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #212120;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --success: #0ca30c;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 20px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #212120;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255,255,255,0.10);
  --success: #0ca30c;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1320px; margin: 0 auto; padding: 28px 24px 80px; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 28px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--series-2), var(--series-4));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
h1 { font-size: 21px; margin: 0 0 2px; letter-spacing: -0.01em; }
.subtitle { color: var(--text-secondary); font-size: 13px; margin: 0; }
.controls { display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
}
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-primary); border-radius: 999px; padding: 6px 14px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.theme-toggle:hover { background: var(--surface-1); }

.ai-cta {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: #ffffff; text-decoration: none;
  background: linear-gradient(135deg, var(--series-7), var(--series-1));
  border-radius: 999px; padding: 8px 16px 8px 14px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--series-7) 45%, transparent), var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
  animation: ai-cta-pulse 2.6s ease-in-out infinite;
}
.ai-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--series-7) 55%, transparent), var(--shadow);
}
.ai-cta-icon { font-size: 14px; }
@keyframes ai-cta-pulse {
  0%, 100% { box-shadow: 0 2px 8px color-mix(in srgb, var(--series-7) 45%, transparent), var(--shadow); }
  50% { box-shadow: 0 2px 16px color-mix(in srgb, var(--series-1) 65%, transparent), var(--shadow); }
}

nav.tabs {
  display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--grid);
  overflow-x: auto;
}
nav.tabs a {
  padding: 10px 16px; font-size: 13px; color: var(--text-secondary);
  text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs a:hover { color: var(--text-primary); }

.kpi-row {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 28px;
}
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }

.stat-tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 16px 14px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11.5px; color: var(--text-secondary); margin: 0 0 8px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat-delta { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.stat-delta.good { color: var(--success); }
.stat-delta.bad { color: var(--status-critical); }
.stat-delta.neutral { color: var(--text-muted); }

section.block { margin-bottom: 32px; }
.block-head { margin-bottom: 14px; }
.block-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.block-desc { font-size: 13px; color: var(--text-secondary); margin: 0; max-width: 780px; line-height: 1.5; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 14px; box-shadow: var(--shadow);
}
.card-title { font-size: 13.5px; font-weight: 600; margin: 0 0 2px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin: 0 0 14px; }

.callout {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); display: flex; gap: 16px; align-items: flex-start;
}
.callout .badge {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: color-mix(in srgb, var(--status-critical) 16%, transparent);
}
.callout h4 { margin: 0 0 4px; font-size: 14px; }
.callout p { margin: 0; font-size: 13px; color: var(--text-secondary); line-height: 1.55; }
.callout strong { color: var(--text-primary); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; min-width: 460px; border-collapse: collapse; font-size: 12.5px; }
table.data-table th {
  text-align: left; font-weight: 500; color: var(--text-muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 10px; border-bottom: 1px solid var(--grid);
}
table.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table td.num, table.data-table th.num { text-align: right; }
.bar-cell { display: flex; align-items: center; gap: 8px; }
.bar-track { flex: 1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar-fill { height: 100%; border-radius: 3px; }
.name-cell { font-weight: 500; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.legend-line { width: 14px; height: 2px; border-radius: 1px; flex-shrink: 0; }

.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 20;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); min-width: 120px;
  opacity: 0; transition: opacity .08s ease; transform: translate(-50%, -100%);
}
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 4px; font-size: 12px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tooltip .tt-key { display: flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.chart-tooltip .tt-swatch { width: 10px; height: 2px; border-radius: 1px; }
.chart-tooltip .tt-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; }

.mark { transition: opacity .1s ease; }
.mark:hover, .mark.hovered { opacity: 0.82; }

.axis-label { fill: var(--text-muted); font-size: 10.5px; }
.value-label { fill: var(--text-primary); font-size: 10.5px; font-weight: 600; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }

.rec-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
@media (max-width: 900px) { .rec-grid { grid-template-columns: 1fr; } }
.rec-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative;
}
.rec-num {
  position: absolute; top: 16px; right: 18px; font-size: 34px; font-weight: 700;
  color: var(--text-primary); opacity: 0.06; line-height: 1;
}
.rec-tag {
  display: inline-block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; padding: 3px 9px; border-radius: 999px; margin-bottom: 10px;
}
.rec-tag.revenue { background: color-mix(in srgb, var(--status-good) 16%, transparent); color: var(--status-good); }
.rec-tag.cost { background: color-mix(in srgb, var(--series-1) 18%, transparent); color: var(--series-1); }
.rec-title { font-size: 14.5px; font-weight: 600; margin: 0 0 10px; }
.rec-body {
  font-size: 12.5px; color: var(--text-secondary); line-height: 1.5;
  margin: 0 0 10px; padding: 0; list-style: none;
}
.rec-body li {
  position: relative; padding-left: 14px; margin-bottom: 6px;
}
.rec-body li::before {
  content: '–'; position: absolute; left: 0; color: var(--text-muted);
}
.rec-body li:last-child { margin-bottom: 0; }
.rec-body b { color: var(--text-primary); font-weight: 600; }
.rec-impact {
  font-size: 12px; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; line-height: 1.45;
  display: flex; gap: 6px; align-items: flex-start;
}
.rec-impact .impact-icon { flex-shrink: 0; opacity: 0.7; }
.rec-impact b { color: var(--success); }

.ai-card { display: flex; flex-direction: column; gap: 14px; }

.ai-status {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted);
}
.ai-status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0;
}
.ai-status-dot.ok { background: var(--status-good); }
.ai-status-dot.err { background: var(--status-critical); }
.ai-status-dot.pending { background: var(--status-warning); }

.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-chip {
  font-family: inherit; font-size: 12px; color: var(--text-secondary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 13px; cursor: pointer; text-align: left;
}
.ai-chip:hover { background: var(--surface-0); color: var(--text-primary); }

.ai-thread {
  display: flex; flex-direction: column; gap: 14px; min-height: 40px;
  max-height: 520px; overflow-y: auto; padding-right: 4px;
}
.ai-empty { font-size: 12.5px; color: var(--text-muted); padding: 6px 0; }

.ai-msg { display: flex; gap: 10px; max-width: 92%; }
.ai-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.ai-msg.assistant { align-self: flex-start; }
.ai-avatar {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  background: var(--surface-1); border: 1px solid var(--border);
}
.ai-msg.user .ai-avatar { background: var(--series-1); color: #fff; border: none; }
.ai-bubble {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 13px; font-size: 13px; line-height: 1.55; color: var(--text-primary);
}
.ai-msg.user .ai-bubble { background: color-mix(in srgb, var(--series-1) 12%, var(--surface-1)); }
.ai-bubble.error { border-color: color-mix(in srgb, var(--status-critical) 40%, var(--border)); }
.ai-bubble p { margin: 0 0 8px; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul { margin: 0 0 8px; padding-left: 18px; }
.ai-bubble ul:last-child { margin-bottom: 0; }
.ai-bubble li { margin-bottom: 3px; }
.ai-bubble code {
  background: var(--surface-0); border-radius: 4px; padding: 1px 5px;
  font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.ai-trace {
  margin-top: 8px; font-size: 11px;
}
.ai-trace summary {
  cursor: pointer; color: var(--text-muted); list-style: none; user-select: none;
}
.ai-trace summary::-webkit-details-marker { display: none; }
.ai-trace summary::before { content: '▸ '; }
.ai-trace[open] summary::before { content: '▾ '; }
.ai-trace-step {
  margin-top: 6px; padding: 6px 8px; background: var(--surface-0);
  border-radius: 6px; border: 1px solid var(--border);
}
.ai-trace-tool {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px;
  color: var(--series-1); font-weight: 600;
}
.ai-trace-detail { color: var(--text-muted); margin-top: 3px; word-break: break-word; }

.ai-thinking { display: flex; gap: 4px; padding: 4px 2px; }
.ai-thinking span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: ai-bounce 1.1s infinite ease-in-out;
}
.ai-thinking span:nth-child(2) { animation-delay: .15s; }
.ai-thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.ai-input-row { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--grid); padding-top: 14px; }
.ai-input {
  flex: 1; resize: none; font-family: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; line-height: 1.4; max-height: 140px;
}
.ai-input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.ai-send {
  font-family: inherit; font-size: 13px; font-weight: 600; color: #fff;
  background: var(--series-1); border: none; border-radius: 10px; padding: 10px 18px;
  cursor: pointer; flex-shrink: 0;
}
.ai-send:disabled { opacity: 0.5; cursor: default; }
.ai-send:not(:disabled):hover { opacity: 0.9; }

.foot-note {
  font-size: 11.5px; color: var(--text-muted); line-height: 1.6; margin-top: 36px;
  padding-top: 16px; border-top: 1px solid var(--grid);
}

@media (max-width: 700px) {
  .stat-value { font-size: 21px; }
  h1 { font-size: 18px; }
  .wrap { padding: 18px 14px 60px; }
  .card, .rec-card { padding: 14px 14px 12px; }
}
