/* ==========================================================================
   Alpha AI Trader - design system
   Tokens follow the validated data-viz palette (light + dark selected
   separately). Charts reference roles, never raw hex.
   ========================================================================== */

:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f3f3ef;
  --surface-hover: #ecebe6;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --grid: #e7e6e0;
  --axis: #c3c2b7;

  --series-1: #2a78d6;
  --pos: #2a78d6;
  --neg: #e34948;
  --mid: #f0efec;
  --up-text: #006300;
  --down-text: #c42f2f;

  --good: #0ca30c;
  --warning: #c98500;
  --serious: #d4642f;
  --critical: #d03b3b;

  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --brand: linear-gradient(135deg, #2a78d6 0%, #4a3aa7 100%);

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.05);
  --shadow-lg: 0 24px 64px rgba(11, 11, 11, 0.18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --sidebar: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-hover: #2a2a28;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8d86;
    --grid: #2c2c2a;
    --axis: #383835;
    --series-1: #3987e5;
    --pos: #3987e5;
    --neg: #e66767;
    --mid: #383835;
    --up-text: #3ccb3c;
    --down-text: #ff7a7a;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #e66767;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --brand: linear-gradient(135deg, #3987e5 0%, #9085e9 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-hover: #2a2a28;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #8f8d86;
  --grid: #2c2c2a;
  --axis: #383835;
  --series-1: #3987e5;
  --pos: #3987e5;
  --neg: #e66767;
  --mid: #383835;
  --up-text: #3ccb3c;
  --down-text: #ff7a7a;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #e66767;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --brand: linear-gradient(135deg, #3987e5 0%, #9085e9 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
}

svg.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--brand);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 6px 18px rgba(57, 135, 229, 0.35);
}

.brand-mark svg.icon {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.brand small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-link[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #e34948 0%, #9b1c3a 100%);
}

.nav-game:hover .nav-badge {
  box-shadow: 0 0 0 3px rgba(227, 73, 72, 0.18);
}

.engine-card {
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
}

.engine-card strong {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 6px;
}

.engine-card p {
  margin: 4px 0 0;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar);
  padding: 20px 28px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.topbar-title {
  flex: 1;
  min-width: 200px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view[hidden] {
  display: none !important;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
}

.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.chart {
  position: relative;
  width: 100%;
}

.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---------- Buttons & controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover {
  background: var(--surface-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-icon {
  width: 36px;
  padding: 0;
}

.btn-icon.btn-sm {
  width: 30px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented button {
  border: 0;
  background: none;
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
}

.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.input,
.select,
.textarea {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}

.textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.ok { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.dot.warn { background: var(--warning); }
.dot.bad { background: var(--critical); }

/* ---------- Hero & stat tiles ---------- */
.hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: '';
  position: absolute;
  inset: -40% -30% auto auto;
  width: 260px;
  height: 260px;
  background: var(--brand);
  opacity: 0.08;
  border-radius: 50%;
  filter: blur(10px);
  pointer-events: none;
}

.hero-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-figure {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.hero-value {
  font-size: 64px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.hero-value small {
  font-size: 20px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

.grade {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 18px;
  background: var(--accent-soft);
  color: var(--accent);
}

.hero-summary {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 118px;
}

.tile-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.tile-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tile-sub {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile .spark {
  margin-top: auto;
  height: 34px;
}

.up { color: var(--up-text); }
.down { color: var(--down-text); }

/* ---------- Meters (Trader DNA) ---------- */
.meters {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.meter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
}

.meter-row .meter-name {
  font-weight: 500;
  font-size: 13px;
}

.meter-row .meter-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.meter {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--meter-color, var(--accent)) 16%, transparent);
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--meter-color, var(--accent));
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.meter-detail {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Insights & biases ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.insight {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.insight-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

.insight[data-tone='negative'] .insight-icon {
  background: color-mix(in srgb, var(--critical) 14%, transparent);
  color: var(--critical);
}

.insight[data-tone='positive'] .insight-icon {
  background: color-mix(in srgb, var(--good) 14%, transparent);
  color: var(--good);
}

.insight strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.insight span {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}

.bias {
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.bias-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.bias-head strong {
  font-size: 13px;
}

.bias-cost {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bias p {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-2);
}

.bias .bias-fix {
  display: flex;
  gap: 6px;
  color: var(--text);
  margin: 0;
}

.severity {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text);
  background: color-mix(in srgb, var(--sev) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--sev) 45%, transparent);
}

.severity svg.icon {
  width: 13px;
  height: 13px;
  color: var(--sev);
}

.severity[data-level='high'] { --sev: var(--critical); }
.severity[data-level='medium'] { --sev: var(--serious); }
.severity[data-level='low'] { --sev: var(--warning); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td.num,
table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.data td.notes {
  white-space: normal;
  min-width: 200px;
  max-width: 340px;
  color: var(--text-2);
}

table.data tbody tr:hover {
  background: var(--surface-2);
}

table.data tr:last-child td {
  border-bottom: 0;
}

.side {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar .spacer {
  flex: 1;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Chart chrome ---------- */
.c-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.c-axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.c-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-label { fill: var(--text-2); font-size: 11px; font-weight: 500; }
.c-value { fill: var(--text); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.c-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-line-neg { fill: none; stroke: var(--neg); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-area { fill: var(--series-1); fill-opacity: 0.1; }
.c-area-neg { fill: var(--neg); fill-opacity: 0.12; }
.c-band-outer { fill: var(--series-1); fill-opacity: 0.1; }
.c-band-inner { fill: var(--series-1); fill-opacity: 0.2; }
.c-ref { stroke: var(--axis); stroke-width: 1; }
.c-pos { fill: var(--pos); }
.c-neg { fill: var(--neg); }
.c-dot { stroke: var(--surface); stroke-width: 2; }
.c-crosshair { stroke: var(--text-2); stroke-width: 1; opacity: 0.5; pointer-events: none; }
.c-hit { fill: transparent; cursor: default; }
.c-hit:focus { outline: none; }
.c-bar:hover,
.c-cell:hover { filter: brightness(1.12); }
.c-cell { stroke: var(--surface); stroke-width: 2; }
.c-cell-text { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-2);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 3px;
}

.tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  min-width: 140px;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s, transform 0.12s;
}

.tooltip.show {
  opacity: 1;
  transform: none;
}

.tooltip .tt-title {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 6px;
}

.tooltip .tt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
}

.tooltip .tt-row b {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
}

.tooltip .tt-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
}

.tooltip .tt-key {
  width: 10px;
  height: 2px;
  border-radius: 2px;
}

.chart-toggle {
  margin-left: auto;
}

/* ---------- Coach ---------- */
.chat {
  display: flex;
  flex-direction: column;
  height: min(72vh, 760px);
  min-height: 460px;
  padding: 0;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.chat-head .avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--brand);
  display: grid;
  place-items: center;
  color: #fff;
}

.chat-head h2 {
  margin: 0;
  font-size: 15px;
}

.chat-head p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 88%;
  animation: rise 0.25s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.msg-ai .msg-avatar {
  background: var(--brand);
  border: 0;
  color: #fff;
}

.bubble {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  min-width: 0;
}

.msg-user .bubble {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
}

.chip span {
  color: var(--muted);
}

.chip b {
  font-variant-numeric: tabular-nums;
}

.chip[data-tone='positive'] b { color: var(--up-text); }
.chip[data-tone='negative'] b { color: var(--down-text); }
.chip[data-tone='warning'] b { color: var(--warning); }

.msg-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.msg-user .msg-meta {
  text-align: right;
}

.typing {
  display: none;
  align-self: flex-start;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.typing.show {
  display: inline-flex;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}

.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  line-height: 1.4;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer .btn {
  height: 44px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestion {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
}

.suggestion:hover {
  border-color: var(--accent);
  color: var(--text);
}

.modules {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.modules li {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 12px;
  color: var(--text-2);
}

.modules li strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.modules .mod-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Dialog ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 16px 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
}

.field.full {
  grid-column: 1 / -1;
}

.form-errors {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  color: var(--text);
  font-size: 12px;
}

.form-errors:empty {
  display: none;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 20px 18px;
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: rise 0.2s ease;
}

.toast[data-type='success'] svg.icon { color: var(--good); }
.toast[data-type='warning'] svg.icon { color: var(--warning); }
.toast[data-type='error'] svg.icon { color: var(--critical); }

/* ---------- Mobile tab bar ---------- */
.tabbar {
  display: none;
}

.skeleton {
  color: var(--muted);
}

.loading {
  opacity: 0.55;
  transition: opacity 0.2s;
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  :root { --sidebar: 0px; }
  .sidebar { display: none; }
  .main { padding: 16px 16px 92px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid { gap: 12px; }
  .hero-value { font-size: 52px; }
  .topbar-actions .btn-label { display: none; }
  .tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }
  .tabbar .nav-link {
    flex-direction: column;
    gap: 2px;
    padding: 8px 4px;
    font-size: 11px;
    text-align: center;
    justify-content: center;
  }
  .modal-body { grid-template-columns: 1fr; }
  .msg { max-width: 96%; }
  .chat { height: calc(100vh - 210px); }
}

@media (max-width: 480px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile-value { font-size: 21px; }
  .card { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  .sidebar, .tabbar, .topbar-actions, .composer { display: none !important; }
  .main { margin: 0; }
}
