/* StockAI dashboard — dark-first trading UI.
   Chart colours use the validated categorical palette (separate light & dark steps). */

:root, [data-theme="light"] {
  color-scheme: light;
  --page: #f4f5f7;
  --surface-1: #fcfcfb;
  --surface-2: #f1f1ef;
  --sidebar: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --good: #0ca30c; --good-text: #006300; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --accent: #2a78d6; --accent-2: #6250d6; --accent-soft: rgba(42, 120, 214, .10);
  --hero-from: #e9f1fc; --hero-to: #efedfb;
}
[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #222220;
  --sidebar: #121211;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .25);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --good-text: #0ca30c;
  --accent: #3987e5; --accent-2: #9085e9; --accent-soft: rgba(57, 135, 229, .14);
  --hero-from: #14203a; --hero-to: #1d1838;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
code { font: 12.5px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 18px rgba(57, 135, 229, .35);
}
.logo svg { width: 24px; height: 24px; stroke: #fff; stroke-width: 3; }
.logo svg circle { fill: #fff; stroke: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 16px; letter-spacing: .2px; }
.brand-text small { color: var(--text-muted); font-size: 11px; letter-spacing: .4px; text-transform: uppercase; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; padding: 14px 10px 6px; }
nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; cursor: pointer;
  color: var(--text-secondary); font: inherit; padding: 9px 10px; border-radius: 10px; text-align: left;
}
nav button:hover { background: var(--surface-2); color: var(--text-primary); }
nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--text-primary); font-weight: 600; }
nav button[aria-selected="true"] svg { color: var(--accent); }
.sidebar-foot { padding: 12px 10px 0; border-top: 1px solid var(--border); display: grid; gap: 2px; }

.content { min-width: 0; display: flex; flex-direction: column; }
.pagehead {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 16px 28px; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.pagehead h1 { margin: 0; font-size: 20px; font-weight: 650; }
.pagehead p { margin: 2px 0 0; font-size: 13px; }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
main { padding: 20px 28px 32px; max-width: 1440px; width: 100%; }
footer { padding: 8px 28px 24px; }
.panel { display: none; animation: fade .18s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- status chips ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary);
  border: 1px solid var(--border); background: var(--surface-1); padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.chip.ok .dot { background: var(--good); box-shadow: 0 0 0 3px rgba(12, 163, 12, .18); }
.chip.warn .dot { background: var(--warning); }
.chip.bad .dot { background: var(--critical); box-shadow: 0 0 0 3px rgba(208, 59, 59, .2); }

/* ---------- hero ---------- */
.hero {
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: stretch;
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to)); border: 1px solid var(--border);
  border-radius: 18px; padding: 24px; position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; right: -80px; top: -80px; width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(57, 135, 229, .28), transparent 70%); pointer-events: none;
}
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent); font-weight: 650; }
.hero h2 { margin: 6px 0 8px; font-size: 22px; }
.hero p { margin: 0; color: var(--text-secondary); max-width: 62ch; }
.hero-meta { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.hero-meta span { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; color: var(--text-secondary); }
.hero-meta b { color: var(--text-primary); font-weight: 600; }
.hero-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; position: relative; z-index: 1; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--text-secondary); }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--text-muted); }

/* ---------- verdict strip ---------- */
.verdict-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.verdict {
  display: flex; gap: 12px; align-items: flex-start; background: var(--surface-1); border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow);
}
.verdict.working { border-left-color: var(--good); }
.verdict.not_working { border-left-color: var(--critical); }
.verdict.mixed { border-left-color: var(--warning); }
.verdict.too_early { border-left-color: var(--accent); }
.verdict .icon { font-size: 20px; line-height: 1; }
.verdict b { display: block; }
.verdict .txt { font-size: 12.5px; color: var(--text-secondary); }

/* ---------- cards, tiles ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin: 16px 0;
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2, .card > h2 { font-size: 15px; margin: 0; font-weight: 650; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.grid-2 .card { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--text-secondary); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.tile .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.note {
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  color: var(--text-secondary); margin-bottom: 4px;
}
.danger-zone { border-color: rgba(208, 59, 59, .35); }

/* ---------- controls ---------- */
.toolbar, .filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filters { margin: 8px 0; }
.toolbar label, .filters label { display: flex; gap: 8px; align-items: center; color: var(--text-secondary); font-size: 13px; }
.check { cursor: pointer; }
select, input, textarea {
  font: inherit; color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 550;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 10px; padding: 7px 13px; cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn.primary svg { fill: #fff; stroke: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--critical); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- tables ---------- */
.table-wrap { max-height: 540px; overflow: auto; border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
  color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
}
tbody tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }
.empty { padding: 28px; text-align: center; color: var(--text-muted); border: 1px dashed var(--border); border-radius: 12px; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary); white-space: nowrap;
}
.badge.BUY, .badge.working, .badge.approved, .badge.ok { color: var(--good-text); border-color: rgba(12, 163, 12, .4); background: rgba(12, 163, 12, .10); }
.badge.SELL, .badge.not_working, .badge.rejected, .badge.error { color: var(--critical); border-color: rgba(208, 59, 59, .4); background: rgba(208, 59, 59, .10); }
.badge.mixed, .badge.pending { color: var(--text-primary); border-color: rgba(250, 178, 25, .55); background: rgba(250, 178, 25, .14); }
.badge.too_early, .badge.planned { color: var(--accent); border-color: rgba(57, 135, 229, .45); background: var(--accent-soft); }
.badge.neutral { font-weight: 500; }

/* ---------- masters ---------- */
.split { display: grid; grid-template-columns: 290px 1fr; gap: 16px; }
.split .card { margin: 0; }
.split .side { max-height: calc(100vh - 150px); overflow: auto; }
.tree-kind { margin: 12px 0 4px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.tree-item {
  display: flex; justify-content: space-between; width: 100%; text-align: left; background: none; border: 0;
  padding: 6px 10px; border-radius: 8px; color: var(--text-primary); cursor: pointer; font: inherit;
}
.tree-item:hover { background: var(--surface-2); }
.tree-item.sel { background: var(--accent-soft); }
.layer { color: var(--accent); font-size: 11px; }
textarea#master-editor {
  width: 100%; min-height: 540px; margin-top: 12px; font: 12.5px/1.55 ui-monospace, Consolas, monospace;
  white-space: pre; tab-size: 2; background: var(--page);
}
.ok { color: var(--good-text); }
.err { color: var(--critical); white-space: pre-wrap; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.proposal { border-left: 4px solid var(--border); }
.proposal.pending { border-left-color: var(--warning); }
.proposal.approved { border-left-color: var(--good); }
.proposal.not_better { border-left-color: var(--text-muted); }

/* ---------- charts ---------- */
.chart { width: 100%; min-height: 280px; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; fill: initial; stroke: initial; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; stroke: none; }
.chart text.series-label { font-size: 12px; fill: var(--text-secondary); font-weight: 600; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 6px; color: var(--text-secondary); font-size: 12px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 20; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); min-width: 150px;
}
.tooltip .row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .key i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .hero { grid-template-columns: minmax(0, 1fr); } .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  /* phone: compact sticky top bar with a swipeable tab strip */
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: auto; padding: 10px 10px 0;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 2px 4px 8px; }
  .logo { width: 30px; height: 30px; }
  .logo svg { width: 20px; height: 20px; }
  nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 8px; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav button { width: auto; flex: 0 0 auto; padding: 7px 11px; font-size: 13px; gap: 6px; }
  nav button svg { width: 16px; height: 16px; }
  .nav-label, .sidebar-foot { display: none; }
  .pagehead { position: static; flex-direction: column; align-items: flex-start; padding: 12px 14px; gap: 10px; }
  .pagehead h1 { font-size: 18px; }
  .head-actions { justify-content: flex-start; }
  .chip { font-size: 11px; padding: 3px 8px; }
  main { padding: 10px 14px 24px; }
  footer { padding: 8px 14px 20px; }
  .hero { padding: 16px; border-radius: 14px; }
  .hero h2 { font-size: 18px; }
  .kpi .value, .tile .value { font-size: 18px; }
  .card { padding: 14px; border-radius: 14px; }
  .split { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  th, td { padding: 7px 8px; }
}

/* -- login page ------------------------------------------------------------------ */
[hidden] { display: none !important; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { padding: 28px 26px 18px; }
.login-card h1 { font-size: 20px; margin: 18px 0 14px; }
.login-card form { display: grid; gap: 12px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.login-card input { width: 100%; font-size: 15px; padding: 10px 12px; }
.login-card .btn.primary { justify-content: center; padding: 10px 14px; font-size: 15px; margin-top: 4px; }
.login-brand { padding: 0; }
.login-error { color: var(--critical); font-size: 13px; margin: 12px 0 0; }
.login-foot { text-align: center; margin-top: 18px; }

/* -- account / users -------------------------------------------------------------- */
.user-chip { display: inline-flex; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: grid; gap: 6px; font-size: 13px; color: var(--text-secondary); }
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-actions .btn { padding: 4px 9px; font-size: 12px; }

