/* Market State Planner — design system.
 * Layout language blended from Artem's two templates (NOT 1:1, re-skinned):
 * - Finor: dark navy page frame, light rounded cards, top-gainers ticker,
 *   pill top nav, line chart + donut + distribution bars + lists.
 * - Subly: black vertical icon sidebar, white cards, big KPI numbers with
 *   green deltas, gradient charts, pill nav.
 * Colours: Erthiox prestige palette + plan tokens (navy #0B2239, teal
 * #00A67E, amber #E8A317, red #D64541, slate blue #2E6FA3, gold #B89047).
 * No native <select>, no default scrollbars, no native alert/confirm.
 */
:root {
  --navy-900: #0B2239;
  --navy-800: #122C47;
  --ink: #111622;
  --ink-soft: #16222E;
  --slate: #5B6B7A;
  --slate-2: #5A606C;
  --mist: #F2F5F6;
  --cream: #FCFBF9;
  --card: #FFFFFF;
  --border: #E8E5DF;
  --divider: #F1EFEA;
  --gold: #C5A880;
  --gold-dark: #B89047;
  --teal: #00A67E;
  --teal-dark: #008A68;
  --amber: #E8A317;
  --red: #D64541;
  --red-dark: #B8322E;
  --blue: #1a73e8;
  --blue-dark: #0d47a1;
  --slate-blue: #2E6FA3;
  --green-bg: #E7F6F0;
  --red-bg: #FDECEA;
  --amber-bg: #FDF3DC;
  --blue-bg: #E8F0FE;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 34, 57, .06), 0 8px 24px rgba(11, 34, 57, .07);
  --shadow-lg: 0 12px 40px rgba(11, 34, 57, .22);
  --font-base: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Outfit', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-base); color: var(--ink);
  background: var(--navy-900); font-size: 15px; line-height: 1.5;
}
h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; color: var(--ink); letter-spacing: -.01em; }
p { margin: 0 0 10px; }
a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 14px; }
img { max-width: 100%; }

/* Custom scrollbars everywhere (rule 2) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--mist); }
::-webkit-scrollbar-thumb { background: #C9CDD3; border-radius: 8px; border: 2px solid var(--mist); }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }
* { scrollbar-width: thin; scrollbar-color: #C9CDD3 var(--mist); }

/* ---------- app frame ---------- */
.app { display: flex; min-height: 100vh; }
.rail {
  width: 76px; flex: 0 0 76px; background: var(--navy-900);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0; gap: 6px; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.rail-logo { width: 46px; height: 46px; margin-bottom: 10px; border-radius: 12px; }
.rail-btn {
  width: 48px; height: 48px; border: 0; border-radius: 12px; background: transparent;
  color: #9FB0C3; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 9px; font-weight: 600; letter-spacing: .02em; position: relative;
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { background: var(--navy-800); color: #fff; }
.rail-btn.active { background: var(--gold-dark); color: #fff; }
.rail-btn .dot { position: absolute; top: 8px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.rail-spacer { flex: 1; }
.main { flex: 1; min-width: 0; background: var(--mist); display: flex; flex-direction: column; }

/* Top bar: brand + pill nav + state badge + user */
.topbar {
  background: var(--cream); border-bottom: 1px solid var(--border);
  padding: 10px 22px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 38px; height: 38px; }
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 18px; color: var(--ink); white-space: nowrap; }
.brand-name span { color: var(--gold-dark); font-weight: 400; font-size: 13px; }
.pillnav { display: flex; gap: 4px; background: var(--divider); border-radius: 999px; padding: 4px; overflow-x: auto; max-width: 100%; }
.pillnav a {
  padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600; color: var(--slate);
  white-space: nowrap; text-decoration: none;
}
.pillnav a:hover { color: var(--ink); }
.pillnav a.active { background: var(--navy-900); color: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Ticker strip (Finor top-gainers) */
.ticker {
  background: var(--navy-900); color: #D7DEE8; display: flex; gap: 0; overflow-x: auto;
  font-size: 12.5px; padding: 7px 22px; align-items: center;
}
.ticker-label { color: var(--gold); font-weight: 700; margin-right: 14px; white-space: nowrap; }
.tick { display: flex; gap: 6px; align-items: center; padding: 0 14px; border-right: 1px solid rgba(255,255,255,.12); white-space: nowrap; }
.tick b { color: #fff; font-weight: 600; }
.up { color: #3ECF9B; } .down { color: #FF7A72; } .flat { color: #9FB0C3; }

/* State badge (visible on every screen, plan 9.2) */
.state-badge {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700;
  padding: 6px 12px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.state-badge .pulse { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.state-live { background: var(--green-bg); color: var(--teal-dark); border-color: #BFE6D8; }
.state-close { background: var(--blue-bg); color: var(--blue-dark); border-color: #C4D8F8; }
.state-stale, .state-partial { background: var(--amber-bg); color: #8A6100; border-color: #F2DFA9; }
.state-error { background: var(--red-bg); color: var(--red-dark); border-color: #F5C6C2; }
.state-scenario { background: #F3EAFB; color: #6B3FA0; border-color: #DCC9F2; }
.state-live .pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- content ---------- */
.page { padding: 20px 22px 40px; max-width: 1460px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 26px; }
.page-head .sub { color: var(--slate); font-size: 13.5px; margin-top: 3px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g-main { grid-template-columns: 2fr 1fr; }
.g-7030 { grid-template-columns: 7fr 3fr; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card h2 { font-size: 17px; margin-bottom: 4px; }
.card h3 { font-size: 15px; }
.card .hint { color: var(--slate); font-size: 12.5px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.muted { color: var(--slate); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* KPI blocks (Subly big numbers + green delta) */
.kpi-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--slate); }
.kpi-value { font-family: var(--font-head); font-size: 32px; font-weight: 700; line-height: 1.1; margin: 4px 0 2px; }
.kpi-value.sm { font-size: 24px; }
.kpi-delta { font-size: 13px; font-weight: 700; }
.kpi-delta.pos { color: var(--teal-dark); }
.kpi-delta.neg { color: var(--red); }
.kpi-sub { font-size: 12.5px; color: var(--slate); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 15px; font-size: 13.5px; font-weight: 700;
  background: var(--navy-900); color: #fff; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--navy-800); text-decoration: none; }
.btn.gold { background: var(--gold-dark); color: #fff; }
.btn.gold:hover { background: #A67F3E; }
.btn.ghost { background: #fff; border-color: var(--border); color: var(--ink); }
.btn.ghost:hover { border-color: var(--gold-dark); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--slate); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--divider); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr.hl td { background: var(--amber-bg); }
.tbl tr.total td { font-weight: 700; background: var(--mist); }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: #F8F6F2; }
.pos { color: var(--teal-dark); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }
.tag {
  display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--divider); color: var(--slate);
}
.tag.teal { background: var(--green-bg); color: var(--teal-dark); }
.tag.amber { background: var(--amber-bg); color: #8A6100; }
.tag.red { background: var(--red-bg); color: var(--red-dark); }
.tag.blue { background: var(--blue-bg); color: var(--blue-dark); }
.tag.gold { background: #F6EEDD; color: #8A6A2B; }
.tag.navy { background: var(--navy-900); color: #fff; }

/* Alerts strip */
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start; border-radius: 12px; padding: 11px 14px;
  font-size: 13.5px; border: 1px solid;
}
.alert .ic { font-weight: 800; flex: 0 0 auto; }
.alert.warn { background: var(--amber-bg); border-color: #F2DFA9; color: #6B4A00; }
.alert.err { background: var(--red-bg); border-color: #F5C6C2; color: #7A1F1B; }
.alert.info { background: var(--blue-bg); border-color: #C4D8F8; color: #123B78; }
.alert.ok { background: var(--green-bg); border-color: #BFE6D8; color: #0B5C44; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 5px; color: var(--ink-soft); }
.field .req { color: var(--red); }
.input, .textarea {
  width: 100%; border: 1px solid #D5D9DE; border-radius: 10px; padding: 10px 12px;
  background: #fff; color: var(--ink); outline: none;
}
.input:focus, .textarea:focus { border-color: var(--gold-dark); box-shadow: 0 0 0 3px rgba(184,144,71,.18); }
.input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(214,69,65,.15); }
.field-err { color: var(--red); font-size: 12.5px; margin-top: 4px; display: none; }
.field-err.show { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* Custom dropdown (no native <select>) */
.dd { position: relative; }
.dd-btn {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border: 1px solid #D5D9DE; border-radius: 10px; padding: 10px 12px; background: #fff;
  font-size: 14px; color: var(--ink); text-align: left;
}
.dd-btn:hover { border-color: var(--gold-dark); }
.dd-btn .caret { color: var(--slate); font-size: 11px; }
.dd-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  max-height: 260px; overflow-y: auto; display: none;
}
.dd.open .dd-list { display: block; }
.dd-item { padding: 10px 12px; font-size: 13.5px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.dd-item:hover { background: var(--mist); }
.dd-item.sel { background: #F6EEDD; font-weight: 700; }

/* Tabs / segmented */
.seg { display: inline-flex; background: var(--divider); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--slate); }
.seg button.active { background: var(--navy-900); color: #fff; }

/* Charts (hand-drawn SVG) */
.chart-box { width: 100%; overflow: hidden; }
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--slate); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 90px; gap: 10px; align-items: center; padding: 7px 0; font-size: 13px; }
.bar-track { height: 10px; border-radius: 99px; background: var(--divider); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut-center { font-family: var(--font-head); font-weight: 700; }

/* Modal / toast (custom, never alert()/confirm()) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11, 22, 34, .55); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 18px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg);
  max-width: 560px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 22px;
}
.modal h2 { font-size: 19px; margin-bottom: 8px; }
.modal .btn-row { margin-top: 18px; justify-content: flex-end; }
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast {
  background: var(--navy-900); color: #fff; border-radius: 12px; padding: 12px 16px;
  font-size: 13.5px; box-shadow: var(--shadow-lg); border-left: 4px solid var(--teal);
}
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

/* Empty states */
.empty {
  text-align: center; padding: 34px 18px; color: var(--slate);
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--cream);
}
.empty .big { font-size: 34px; margin-bottom: 6px; }
.empty h3 { margin-bottom: 4px; }

/* Auth gate */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--navy-900); }
.auth-card { background: var(--cream); border-radius: 20px; box-shadow: var(--shadow-lg); max-width: 460px; width: 100%; padding: 30px 28px; }
.auth-card .logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-card .logo-row img { width: 52px; height: 52px; }
.auth-tabs { display: flex; background: var(--divider); border-radius: 999px; padding: 3px; margin: 18px 0; }
.auth-tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--slate); }
.auth-tabs button.active { background: var(--navy-900); color: #fff; }
.auth-note { font-size: 12.5px; color: var(--slate); margin-top: 14px; text-align: center; }
.demo-box { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }

/* Footer */
.footer {
  margin-top: auto; background: var(--cream); border-top: 1px solid var(--border);
  padding: 18px 22px; font-size: 12.5px; color: var(--slate); display: flex; gap: 18px;
  flex-wrap: wrap; align-items: center; justify-content: space-between;
}
.footer a { color: var(--ink-soft); font-weight: 600; }
.kofi-btn {
  display: inline-flex; align-items: center; gap: 8px; background: var(--gold-dark); color: #090d16 !important;
  font-weight: 800; padding: 9px 16px; border-radius: 999px; font-size: 13.5px; text-decoration: none;
}
.kofi-btn:hover { text-decoration: none; background: #A67F3E; }

/* Misc */
.hr { border: 0; border-top: 1px solid var(--divider); margin: 16px 0; }
.formula { background: var(--mist); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13.5px; overflow-x: auto; }
.formula code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; padding: 8px 0 8px 34px; position: relative; font-size: 13.5px; border-bottom: 1px solid var(--divider); }
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 8px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--navy-900); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.shock-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.shock-chip:hover { border-color: var(--gold-dark); }
.shock-chip.active { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }
.shock-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.progress { height: 8px; border-radius: 99px; background: var(--divider); overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); }
.offline-banner { background: var(--amber-bg); color: #6B4A00; font-size: 13px; font-weight: 600; padding: 8px 22px; border-bottom: 1px solid #F2DFA9; }
.demo-banner { background: #F3EAFB; color: #5B2D8E; font-size: 13px; font-weight: 600; padding: 8px 22px; border-bottom: 1px solid #DCC9F2; }
.demo-banner a { color: #5B2D8E; text-decoration: underline; }
.src { font-size: 11.5px; color: var(--slate); }
.linklike { background: none; border: 0; color: var(--blue-dark); font-size: 13px; font-weight: 700; padding: 0; }
.linklike:hover { text-decoration: underline; }

/* Print: morning brief */
@media print {
  .rail, .topbar, .ticker, .footer, .btn-row, .no-print { display: none !important; }
  body { background: #fff; }
  .main { background: #fff; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .g-main, .g-7030 { grid-template-columns: 1fr; }
  .g3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .rail { display: none; }
  .g3, .g2 { grid-template-columns: 1fr; }
  .page { padding: 16px 14px 32px; }
  .topbar { padding: 10px 14px; }
  .ticker { padding: 7px 14px; }
  .brand-name { font-size: 16px; }
  .kpi-value { font-size: 26px; }
  .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 96px 1fr 74px; }
}
@media (max-width: 480px) {
  .g4 { grid-template-columns: repeat(2, 1fr); }
  .page-head h1 { font-size: 21px; }
  .kpi-value { font-size: 17px; white-space: nowrap; }
  .kpi-value.sm { font-size: 17px; }
  .card { padding: 15px 14px; }
  .topbar-right .btn span.lbl { display: none; }
}
