/* ===========================================================================
   GyungDal Invest — dashboard design system (LOC-118)

   Identity: "control room for an autonomous fund." A calm, cool-slate SaaS
   console (TailAdmin-family canvas) where the boldness is spent in two places
   only — the persistent mission-control status ribbon in the header, and the
   ledger-mono numerals that make every price/quantity read like a trading
   terminal. Everything else stays quiet and disciplined.

   Palette: cool slate neutrals + one indigo accent. Gains reuse the accent and
   losses use red (the two safety-semantic exceptions a trading panel needs);
   we deliberately avoid a green so the P&L layer never fights Korea's own
   red=up / blue=down convention or the danger-red already reserved for KILL.
   Numbers are set in a mono/tabular face — the one signature of this UI.
   No external font/CDN: this runs on a LAN-bound box that must render offline.
   =========================================================================== */
:root {
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", Helvetica, Arial, sans-serif;
  /* Tabular data (prices, quantities, timestamps, logs) is set in a mono face
     with tabular-nums — the deliberate signature of this UI. */
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;

  /* cool slate canvas */
  --color-bg: #EEF2F8;
  --color-surface: #FFFFFF;
  --color-surface-2: #F1F5F9;
  --color-surface-3: #E9EEF5;
  --color-border: #E3E8EF;
  --color-border-strong: #CDD5E0;
  --color-text: #0F1B2D;
  --color-text-muted: #64748B;
  --color-text-subtle: #94A3B8;

  --color-accent: #4F46E5;
  --color-accent-strong: #4338CA;
  --color-accent-fg: #FFFFFF;
  --color-accent-soft: #ECEBFB;
  --color-accent-border: #CDCAF6;

  --color-warn: #B45309;
  --color-warn-soft: #FCEFDD;
  --color-danger: #DC2626;
  --color-danger-soft: #FCECEC;

  --shadow-xs: 0 1px 2px rgba(15,27,45,.05);
  --shadow-card: 0 1px 2px rgba(15,27,45,.04), 0 1px 3px rgba(15,27,45,.06);
  --shadow-pop: 0 8px 24px -8px rgba(15,27,45,.18), 0 2px 8px -2px rgba(15,27,45,.10);
  --topbar-h: 66px;
}

:root[data-theme="dark"] {
  --color-bg: #0C1322;
  --color-surface: #141B2B;
  --color-surface-2: #1B2437;
  --color-surface-3: #232E46;
  --color-border: #283349;
  --color-border-strong: #3A4863;
  --color-text: #E9EEF6;
  --color-text-muted: #98A5BC;
  --color-text-subtle: #64748B;

  --color-accent: #8B85F5;
  --color-accent-strong: #A6A1FF;
  --color-accent-fg: #10142A;
  --color-accent-soft: #232447;
  --color-accent-border: #3A3D72;

  --color-warn: #F2B95E;
  --color-warn-soft: #3A2A12;
  --color-danger: #F27069;
  --color-danger-soft: #3A1613;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.35);
  --shadow-card: 0 1px 2px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.30);
  --shadow-pop: 0 12px 30px -10px rgba(0,0,0,.6), 0 2px 8px -2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-ui);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }
.muted { color: var(--color-text-muted); }
code {
  font-family: var(--font-mono); background: var(--color-surface-2);
  padding: 1px 6px; border-radius: var(--radius-xs); font-size: .9em; color: var(--color-text);
}

/* --- brand --- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 15.5px; letter-spacing: -.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; position: relative;
  background: linear-gradient(145deg, var(--color-accent), var(--color-accent-strong));
  box-shadow: 0 4px 12px -4px var(--color-accent);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  /* a tiny upward candle — the mark says "trading", not "generic app" */
  background:
    linear-gradient(var(--color-accent-fg), var(--color-accent-fg)) 9px 17px / 2.5px 7px no-repeat,
    linear-gradient(var(--color-accent-fg), var(--color-accent-fg)) 14px 12px / 2.5px 12px no-repeat,
    linear-gradient(var(--color-accent-fg), var(--color-accent-fg)) 19px 8px / 2.5px 8px no-repeat;
  opacity: .95;
}

/* --- login --- */
.login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(1100px 520px at 15% -10%, var(--color-accent-soft), transparent 60%),
    radial-gradient(900px 480px at 100% 120%, var(--color-surface-3), transparent 55%),
    var(--color-bg);
}
.login-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 40px 36px; width: 366px; max-width: 100%; display: flex; flex-direction: column; gap: 15px;
}
.login-card .brand { font-size: 17px; margin-bottom: 6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); }
.login-card input {
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 11px 13px; color: var(--color-text); font-size: 14px; font-family: inherit;
}
.login-card input:focus { background: var(--color-surface); }
.login-card .primary-btn { margin-top: 6px; justify-content: center; padding: 11px; }
.error { color: var(--color-danger); font-size: 13px; }

/* --- app shell: left sidebar + content column --- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--color-surface); border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column; gap: 20px; padding: 20px 16px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 2px 8px 4px; }
.side-nav { display: flex; flex-direction: column; gap: 18px; flex: 1; overflow-y: auto; }
.nav-section { display: flex; flex-direction: column; gap: 3px; }
.nav-section-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--color-text-subtle); padding: 2px 12px 4px;
}
.sidebar-footer { border-top: 1px solid var(--color-border); padding-top: 12px; display: flex; flex-direction: column; gap: 3px; }

/* mobile nav affordances — hidden on desktop, activated in the ≤900px block */
.nav-toggle, .nav-close { display: none; }
.nav-overlay { display: none; }

.tab-btn {
  display: flex; align-items: center; gap: 11px;
  background: transparent; border: none; color: var(--color-text-muted); padding: 9px 12px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; text-align: left;
  font-family: inherit; font-weight: 550; width: 100%; letter-spacing: -.01em;
  transition: background-color .13s ease, color .13s ease;
}
.tab-btn svg { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 1.9; opacity: .9; }
.tab-btn:hover { background: var(--color-surface-2); color: var(--color-text); }
.tab-btn.active { background: var(--color-accent-soft); color: var(--color-accent); font-weight: 650; }
.tab-btn.active svg { opacity: 1; }

/* content column */
.content-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* --- top bar with mission-control status ribbon (the signature) --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  min-height: var(--topbar-h); padding: 12px 32px;
  background: color-mix(in srgb, var(--color-surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--color-border);
}
.page-heading { display: flex; flex-direction: column; gap: 2px; margin-right: auto; min-width: 0; }
.page-title { font-size: 19px; font-weight: 750; letter-spacing: -.02em; margin: 0; }
.page-sub { font-size: 12.5px; color: var(--color-text-muted); }

.status-ribbon { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.ribbon-net {
  display: flex; align-items: baseline; gap: 9px;
  padding: 7px 14px; border-radius: 999px; background: var(--color-surface-2); border: 1px solid var(--color-border);
}
.ribbon-net .rl { font-size: 11px; font-weight: 600; color: var(--color-text-muted); letter-spacing: .01em; }
.ribbon-net .rv { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.ribbon-delta { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700; }
.ribbon-delta.pos { color: var(--color-accent); }
.ribbon-delta.neg { color: var(--color-danger); }
.ribbon-state {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px 7px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 650; white-space: nowrap;
  background: var(--color-surface-2); border: 1px solid var(--color-border); color: var(--color-text);
}
.ribbon-state.ok    { background: var(--color-accent-soft); border-color: var(--color-accent-border); color: var(--color-accent); }
.ribbon-state.warn  { background: var(--color-warn-soft);   border-color: transparent; color: var(--color-warn); }
.ribbon-state.danger{ background: var(--color-danger-soft); border-color: transparent; color: var(--color-danger); }

main { flex: 1; padding: 26px 32px 40px; max-width: 1320px; width: 100%; }
.tab-panel { display: flex; flex-direction: column; gap: 18px; }
.tab-panel .intro { font-size: 13px; color: var(--color-text-muted); margin: -2px 0 0; max-width: 78ch; }

@media (max-width: 900px) {
  /* Safety net: keep an off-canvas drawer or a wide table from adding page-level
     horizontal scroll. overflow-x: clip (unlike hidden/auto) does NOT create a
     scroll container, so the sticky topbar keeps working. */
  html { overflow-x: clip; }

  /* --- nav becomes an off-canvas drawer (all tabs stay labeled & reachable) --- */
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: min(82vw, 300px); height: 100dvh;
    padding: 18px 14px; gap: 16px; box-shadow: var(--shadow-pop);
    transform: translateX(-100%); transition: transform .22s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar .brand { padding-right: 42px; }

  .nav-overlay {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(15, 27, 45, .5);
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .nav-toggle {
    display: inline-grid; place-items: center; flex-shrink: 0;
    width: 40px; height: 40px; margin-left: -4px;
    background: var(--color-surface-2); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); color: var(--color-text); cursor: pointer;
  }
  .nav-toggle svg { width: 22px; height: 22px; }
  .nav-close {
    display: inline-grid; place-items: center; position: absolute; top: 14px; right: 12px;
    width: 34px; height: 34px; background: var(--color-surface-2);
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    color: var(--color-text-muted); cursor: pointer;
  }
  .nav-close svg { width: 18px; height: 18px; }

  /* --- topbar (now the only sticky bar on mobile, so no sidebar overlap) --- */
  .topbar { padding: 10px 14px; gap: 12px; flex-wrap: wrap; }
  .page-title { font-size: 17px; }
  .page-sub { font-size: 12px; }
  .status-ribbon { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 10px; }

  /* --- content density --- */
  main { padding: 16px 14px 40px; }
  .card { padding: 16px 15px; }
  .card > h2, .panel-head h2, .toolbar h2, #log-stream-title { margin-bottom: 12px; }
  .ai-grid { grid-template-columns: 1fr; }

  /* toolbars: stack labeled filters full-width, let inputs fill the row */
  .toolbar { gap: 8px; }
  .toolbar label { flex: 1 1 100%; }
  .toolbar input[type=text], .toolbar input[type=datetime-local], .toolbar select { flex: 1 1 auto; min-width: 0; }
  .control-row { gap: 8px; }
  .control-row input[type=number], .control-row input[type=text] { flex: 1 1 140px; min-width: 0; }

  /* log lines wrap instead of forcing a horizontal overflow */
  .log-line { flex-wrap: wrap; gap: 4px 8px; }
  .log-line .stage { width: auto; }
  .log-fields { margin-left: 0; }
}

/* --- cards / grid --- */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: 20px 22px; box-shadow: var(--shadow-card);
}
.card.danger { border-color: color-mix(in srgb, var(--color-danger) 45%, var(--color-border)); }
/* One readable title style shared by every card/panel/toolbar section header,
   so no two sections at the same level render at different sizes. */
.card > h2, .panel-head h2, .toolbar h2, #log-stream-title {
  margin: 0 0 16px; font-size: 15px; color: var(--color-text); font-weight: 700;
  text-transform: none; letter-spacing: -.015em;
}
.card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card > p.muted { font-size: 12.5px; margin: -6px 0 14px; line-height: 1.55; }

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

/* --- KPI stat cards (icon chip + big number + delta) --- */
.kpi {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: 18px 20px 16px; box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; gap: 10px; min-height: 132px;
}
.kpi-head { display: flex; align-items: center; gap: 11px; }
.kpi-icon {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--color-accent-soft); color: var(--color-accent);
}
.kpi-icon svg { width: 20px; height: 20px; stroke-width: 1.9; }
.kpi-icon.tint-cash { background: var(--color-surface-2); color: var(--color-text-muted); }
.kpi-icon.tint-up   { background: var(--color-accent-soft); color: var(--color-accent); }
.kpi-icon.tint-down { background: var(--color-danger-soft); color: var(--color-danger); }
.kpi-label { font-size: 12px; color: var(--color-text-muted); font-weight: 650; letter-spacing: -.01em; }
.kpi-label .unit { font-weight: 600; opacity: .7; font-size: 11px; }
.kpi-value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 27px; font-weight: 700; letter-spacing: -.02em; line-height: 1.05;
}
.kpi-value.pos { color: var(--color-accent); }
.kpi-value.neg { color: var(--color-danger); }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 3px; align-self: flex-start;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: var(--color-surface-2); color: var(--color-text-muted);
}
.kpi-delta.pos { background: var(--color-accent-soft); color: var(--color-accent); }
.kpi-delta.neg { background: var(--color-danger-soft); color: var(--color-danger); }
.kpi-foot { font-size: 11.5px; color: var(--color-text-muted); margin-top: auto; }
.kpi-spark { margin-top: auto; }
.kpi-spark .spark { width: 100%; height: 36px; display: block; }
/* signed money cells in the 계좌 tables */
.data-table td.pos { color: var(--color-accent); }
.data-table td.neg { color: var(--color-danger); }

/* --- badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .005em; white-space: nowrap;
  background: var(--color-surface-2); color: var(--color-text-muted); border: 1px solid var(--color-border);
}
.badge.ok { background: var(--color-accent-soft); color: var(--color-accent); border-color: transparent; }
.badge.warn { background: var(--color-warn-soft); color: var(--color-warn); border-color: transparent; }
.badge.danger { background: var(--color-danger-soft); color: var(--color-danger); border-color: transparent; }

/* --- tables --- */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table thead th { position: sticky; top: 0; background: var(--color-surface); z-index: 1; }
.data-table th {
  color: var(--color-text-subtle); font-weight: 700; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; border-bottom-color: var(--color-border-strong);
}
.data-table td { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td:first-child, .data-table th:first-child { white-space: nowrap; }
.data-table td.nowrap { white-space: nowrap; }
.data-table tbody tr { transition: background-color .1s ease; }
.data-table tbody tr:hover { background: var(--color-surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }

/* --- chips / tags in cells --- */
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-family: var(--font-ui);
  font-size: 11px; font-weight: 650; background: var(--color-surface-2);
  color: var(--color-text-muted); border: 1px solid var(--color-border); white-space: nowrap;
}
.dir { display: inline-flex; align-items: center; gap: 3px; font-family: var(--font-ui); font-weight: 650; font-size: 12px; white-space: nowrap; }
.dir.buy { color: var(--color-accent); }
.dir.buy::before { content: "▲"; font-size: 8px; }
.dir.sell { color: var(--color-text-muted); }
.dir.sell::before { content: "▼"; font-size: 8px; }
.dir.hold { color: var(--color-text-muted); }
.tag.sim {
  display: inline-block; font-family: var(--font-ui); font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 5px; letter-spacing: .02em;
  color: var(--color-text-muted); border: 1px dashed var(--color-border-strong); background: transparent;
}

/* --- confidence meter --- */
.conf { display: flex; align-items: center; gap: 8px; }
.conf-val { min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.meter { flex: 1; min-width: 40px; max-width: 90px; height: 6px; border-radius: 999px; background: var(--color-surface-3); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--color-accent); border-radius: 999px; }

/* --- toolbars / inputs / buttons --- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; margin-right: auto; }
.toolbar label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--color-text-muted); }
.toolbar select, .toolbar input[type=text], .toolbar input[type=datetime-local],
.control-row input[type=number], .control-row input[type=text] {
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 8px 11px; color: var(--color-text); font-size: 13px; font-family: inherit;
}
.toolbar select:focus, .toolbar input:focus, .control-row input:focus { background: var(--color-surface); }

button { font-family: inherit; }
.ghost-btn, .primary-btn, .ok-btn, .warn-btn, .danger-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: var(--radius-sm); padding: 9px 15px; cursor: pointer; font-size: 13px; font-weight: 650;
  border: 1px solid transparent; letter-spacing: -.01em;
  transition: background-color .12s ease, border-color .12s ease, box-shadow .15s ease, transform .08s ease, filter .12s ease, opacity .12s ease;
}
button.is-busy { color: transparent !important; pointer-events: none; position: relative; }
button.is-busy::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px;
  margin: -7px 0 0 -7px; border-radius: 50%; border: 2px solid; border-top-color: transparent;
  animation: btn-spin .6s linear infinite;
}
.ghost-btn.is-busy::after   { border-color: var(--color-text);      border-top-color: transparent; }
.warn-btn.is-busy::after    { border-color: var(--color-warn);      border-top-color: transparent; }
.ok-btn.is-busy::after      { border-color: var(--color-accent);    border-top-color: transparent; }
.primary-btn.is-busy::after { border-color: var(--color-accent-fg); border-top-color: transparent; }
.danger-btn.is-busy::after  { border-color: #fff;                   border-top-color: transparent; }
.ghost-btn:disabled, .primary-btn:disabled, .ok-btn:disabled, .warn-btn:disabled, .danger-btn:disabled {
  opacity: .5; cursor: not-allowed; transform: none; box-shadow: none;
}
.ghost-btn:active:not(:disabled), .primary-btn:active:not(:disabled), .ok-btn:active:not(:disabled),
.warn-btn:active:not(:disabled), .danger-btn:active:not(:disabled) { transform: translateY(1px); }
.btn-icon { font-size: 12px; line-height: 1; }

.ghost-btn { background: var(--color-surface); border-color: var(--color-border-strong); color: var(--color-text); }
.ghost-btn:hover:not(:disabled) { background: var(--color-surface-2); }
.primary-btn { background: var(--color-accent); color: var(--color-accent-fg); box-shadow: 0 1px 2px rgba(79,70,229,.25); }
.primary-btn:hover:not(:disabled) { background: var(--color-accent-strong); box-shadow: 0 4px 14px -4px var(--color-accent); }
.ok-btn { background: var(--color-accent-soft); color: var(--color-accent); }
.ok-btn:hover:not(:disabled) { background: var(--color-accent); color: var(--color-accent-fg); }
.warn-btn { background: var(--color-warn-soft); color: var(--color-warn); }
.warn-btn:hover:not(:disabled) { filter: brightness(.97); }
.danger-btn { background: var(--color-danger); color: #fff; font-weight: 700; padding: 10px 17px; }
.danger-btn:hover:not(:disabled) { filter: brightness(1.06); box-shadow: 0 4px 16px -4px var(--color-danger); }

@keyframes btn-spin { to { transform: rotate(360deg); } }

button:focus-visible, input:focus-visible, select:focus-visible, .tab-btn:focus-visible, .segmented-btn:focus-visible, .range-btn:focus-visible {
  outline: 2px solid var(--color-accent); outline-offset: 2px;
}

.control-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.live-tail { font-size: 13px; color: var(--color-text-muted); display: flex; align-items: center; gap: 6px; }

/* --- segmented controls (theme + market filters) --- */
.segmented { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; background: var(--color-surface-2); }
.segmented-btn {
  border: none; background: transparent; color: var(--color-text-muted); padding: 7px 14px; border-radius: var(--radius-xs);
  cursor: pointer; font-size: 12.5px; font-family: inherit; font-weight: 600;
  transition: background-color .12s ease, color .12s ease;
}
.segmented-btn.active { background: var(--color-surface); color: var(--color-text); font-weight: 650; box-shadow: var(--shadow-xs); }
.segmented-btn:hover:not(.active) { color: var(--color-text); }

/* --- panels: a card with a header row (title + controls/legend) --- */
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }

/* --- gauges + status panels --- */
.gauge-panel, .status-panel { display: flex; flex-direction: column; }
.gauge { width: 100%; height: 118px; display: block; }
.gauge-val { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 30px; font-weight: 700; fill: var(--color-text); }
.gauge-sub { font-size: 11px; fill: var(--color-text-muted); font-family: var(--font-ui); }
.gauge-cap { font-size: 11px; text-align: center; margin-top: 4px; }

.status-list { display: flex; flex-direction: column; gap: 11px; font-size: 13px; padding-top: 2px; }
.status-row { display: flex; align-items: center; gap: 8px; }
.led { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px transparent; }
.led.off { background: var(--color-border-strong); }
.led.ok { background: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }
.led.warn { background: var(--color-warn); box-shadow: 0 0 0 3px var(--color-warn-soft); }
.led.danger { background: var(--color-danger); box-shadow: 0 0 0 3px var(--color-danger-soft); }
.led.lg { width: 13px; height: 13px; }
/* the ribbon's live pulse — the one ambient motion in the UI */
.led.pulse { animation: led-pulse 2.2s ease-in-out infinite; }
@keyframes led-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  60% { box-shadow: 0 0 0 6px transparent; }
}

.status-headline { display: flex; align-items: center; gap: 12px; padding: 4px 0 14px; }
.status-headline-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status-state { font-size: 18px; font-weight: 750; letter-spacing: -.02em; }
.status-state.ok { color: var(--color-accent); }
.status-state.warn { color: var(--color-warn); }
.status-state.danger { color: var(--color-danger); }
.status-note { font-size: 12px; }
.status-guards { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; margin-top: auto; }

/* --- time-series charts --- */
.chart-wrap { position: relative; }
svg#equity-chart, svg#acct-chart { width: 100%; height: 300px; display: block; }
.grid-line { stroke: var(--color-border); stroke-width: 1; opacity: .7; }
.axis-label { fill: var(--color-text-subtle); font-size: 10.5px; font-family: var(--font-mono); }
.line { fill: none; stroke-width: 2.25; vector-effect: non-scaling-stroke; }
.area { stroke: none; }
.line.s-equity { stroke: var(--color-accent); }
.area.s-equity { fill: var(--color-accent); opacity: .1; }
.line.s-pos { stroke: var(--color-warn); stroke-width: 1.5; opacity: .95; }
.line.s-cash { stroke: var(--color-text-subtle); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: .85; }
.crosshair { stroke: var(--color-text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-dot { fill: var(--color-accent); stroke: var(--color-surface); stroke-width: 2; }
.equity-empty { fill: var(--color-text-muted); font-size: 13px; font-family: var(--font-ui); }

.chart-range { display: inline-flex; gap: 2px; background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 3px; }
.range-btn { border: none; background: transparent; color: var(--color-text-muted); padding: 5px 11px; border-radius: var(--radius-xs); cursor: pointer; font-size: 12px; font-family: var(--font-mono); font-weight: 650; transition: background-color .12s ease, color .12s ease; }
.range-btn.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-xs); }
.range-btn:hover:not(.active) { color: var(--color-text); }

.legend { display: flex; gap: 14px; margin-left: auto; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--color-text-muted); }
.swatch { width: 13px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.s-equity { background: var(--color-accent); }
.swatch.s-pos { background: var(--color-warn); }
.swatch.s-cash { background: var(--color-text-subtle); }

.chart-tip {
  position: absolute; top: 8px; pointer-events: none; z-index: 3;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); padding: 10px 12px; font-size: 12px; min-width: 168px;
}
.chart-tip .tip-ts { color: var(--color-text-muted); font-size: 11px; margin-bottom: 5px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; padding: 1px 0; }
.chart-tip .tip-row b { margin-left: auto; font-weight: 700; }
.chart-tip .swatch { width: 11px; height: 3px; }

/* --- cycle timeline / logs --- */
.cycle-row { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 13px 15px; background: var(--color-surface-2); }
.cycle-row + .cycle-row { margin-top: 9px; }
.cycle-row .cycle-head { display: flex; align-items: center; gap: 10px; font-size: 12.5px; flex-wrap: wrap; }
.cycle-row .cycle-head .cycle-id { font-family: var(--font-mono); color: var(--color-text-muted); cursor: pointer; }
.cycle-row .cycle-head .cycle-id:hover { color: var(--color-accent); }
.stepper { display: flex; gap: 6px; margin-top: 11px; flex-wrap: wrap; }
.step {
  border-radius: var(--radius-xs); padding: 4px 10px; font-size: 11.5px; cursor: pointer; font-family: var(--font-mono);
  background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text-muted);
}
.step.ok { color: var(--color-accent); border-color: var(--color-accent-border); }
.step.error { color: var(--color-danger); border-color: transparent; background: var(--color-danger-soft); }
.step:hover { filter: brightness(.98); }

.log-stream { max-height: 460px; overflow-y: auto; font-family: var(--font-mono); font-size: 12px; background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 6px 12px; }
.log-line { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--color-border); }
.log-line .ts { color: var(--color-text-subtle); white-space: nowrap; }
.log-line .lvl { width: 46px; flex-shrink: 0; font-weight: 700; }
.log-line .lvl.ERROR { color: var(--color-danger); }
.log-line .lvl.WARN { color: var(--color-warn); }
.log-line .lvl.INFO { color: var(--color-accent); }
.log-line .lvl.DEBUG, .log-line .lvl.TRACE { color: var(--color-text-subtle); }
.log-line .stage { color: var(--color-text-muted); width: 90px; flex-shrink: 0; }
.log-line .msg { flex: 1; word-break: break-word; color: var(--color-text); }
.log-fields { color: var(--color-text-muted); font-size: 11px; margin-left: 156px; white-space: pre-wrap; }

/* --- benchmark detail --- */
details summary { cursor: pointer; margin-top: 8px; color: var(--color-text-muted); font-size: 13px; }
pre { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: 12px; font-size: 12px; overflow-x: auto; font-family: var(--font-mono); }

/* --- AI market view --- */
.ai-market { margin-bottom: 0; }
.tab-panel .ai-market + .ai-market { margin-top: 16px; }
.ai-market-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.ai-market-head h2 { margin: 0; font-size: 16px; font-weight: 750; text-transform: none; letter-spacing: -.01em; color: var(--color-text); }
.verdict { font-size: 12px; font-weight: 700; padding: 4px 13px; border-radius: 999px; }
.verdict.buy { background: var(--color-accent-soft); color: var(--color-accent); }
.verdict.sell { background: var(--color-danger-soft); color: var(--color-danger); }
.verdict.hold { background: var(--color-surface-2); color: var(--color-text-muted); }

.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 15px; }
.ai-card { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px 17px; background: var(--color-surface-2); transition: box-shadow .15s ease, border-color .15s ease; }
.ai-card:hover { box-shadow: var(--shadow-card); border-color: var(--color-border-strong); }
.ai-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ai-sym { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-weight: 700; font-size: 14px; }
.ai-conf { display: flex; align-items: center; gap: 11px; margin-top: 12px; }
.ai-conf-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 27px; font-weight: 700; min-width: 64px; letter-spacing: -.02em; }
.ai-conf-meter { flex: 1; height: 8px; border-radius: 999px; background: var(--color-surface-3); overflow: hidden; }
.ai-conf-meter span { display: block; height: 100%; background: var(--color-accent); border-radius: 999px; }
.ai-conf-label { font-size: 11px; margin-top: 5px; }
.ai-sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--color-text-subtle); margin: 14px 0 7px; font-weight: 700; }
.ai-evidence { margin: 0; padding-left: 16px; display: flex; flex-direction: column; gap: 5px; }
.ai-evidence li { font-size: 12px; line-height: 1.5; }
.ai-contribs { display: flex; flex-direction: column; gap: 11px; }
.contrib-top { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.contrib-src { font-weight: 650; }
.contrib-bar { height: 6px; border-radius: 999px; background: var(--color-surface-3); overflow: hidden; margin-top: 5px; }
.contrib-fill { display: block; height: 100%; background: var(--color-accent); border-radius: 999px; }
.contrib-fill.sell { background: var(--color-danger); }
.contrib-detail { font-size: 11px; margin-top: 5px; font-family: var(--font-mono); }
.ai-foot { font-size: 11px; margin-top: 14px; }
.tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 5px; border: 1px dashed var(--color-border-strong); color: var(--color-text-muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  button.is-busy::after { border-style: dotted; }
  .led.pulse { animation: none !important; }
}

/* LOC-120: AI market search, held badges, pagination */
.ai-search {
  flex: 1 1 220px;
  min-width: 160px;
  max-width: 340px;
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}
.ai-search::placeholder { color: var(--color-text-subtle); }
.ai-search:focus-visible { outline: none; border-color: var(--color-accent-border); box-shadow: 0 0 0 3px var(--color-accent-soft); }

.ai-card.held { border-color: var(--color-accent-border); background: var(--color-surface); }
.ai-card.no-signal { background: var(--color-surface-2); }
.held-tag { border-style: solid; border-color: var(--color-accent-border); color: var(--color-accent); }
.ai-held {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 8px 0 2px;
  font-size: 12px;
}
.ai-held .pos { color: var(--color-accent); font-weight: 650; }
.ai-held .neg { color: var(--color-danger); font-weight: 650; }

.ai-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}
.pager-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 14px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { border-color: var(--color-accent-border); color: var(--color-accent); }
.pager-btn:disabled { opacity: .45; cursor: default; }

/* LOC-120: company/instrument name shown next to a code */
.sym-name { color: var(--color-text-muted); font-weight: 500; font-size: 0.88em; }
