/* MARKET DESK 2.0 — light-first design system */
:root {
  --bg: #F7F9FC; --card: #FFFFFF; --text: #17212B; --muted: #667085; --blue: #2458A6; --blue-soft: #EAF1FB;
  --pos: #159B70; --pos-soft: #E6F6F0; --neg: #DC4C4C; --neg-soft: #FDECEC; --warn: #E5A23B; --warn-soft: #FDF4E4;
  --border: #E6EAF0; --chip: #F1F4F8; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px; --sidebar: 232px; --font: Inter, "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --p1: #B42318; --p2: #DC4C4C; --p3: #E5A23B; --p4: #667085;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0F1720; --card: #16202B; --text: #E6EDF3; --muted: #94A3B8; --blue: #6EA0E8; --blue-soft: #1C2B40;
  --pos: #3CC495; --pos-soft: #133227; --neg: #F07373; --neg-soft: #3A1D1F; --warn: #F0B85A; --warn-soft: #3A2D16;
  --border: #253241; --chip: #1E2A37; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0; letter-spacing: -.005em; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 14px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: 0; }
.search { flex: 1; max-width: 520px; position: relative; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.search svg { position: absolute; left: 11px; top: 11px; color: var(--muted); }
.search-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16,24,40,.14); max-height: 70vh; overflow: auto; padding: 8px; display: none; }
.search-results.open { display: block; }
.search-results .grp { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 8px 4px; }
.search-results a { display: block; padding: 8px; border-radius: 8px; color: var(--text); }
.search-results a:hover { background: var(--chip); text-decoration: none; }
.top-meta { display: flex; align-items: center; gap: 14px; margin-left: auto; white-space: nowrap; }
.clock { font-size: 13px; color: var(--muted); }
.iconbtn { position: relative; border: 1px solid var(--border); background: var(--card); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--neg); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.badge:empty, .badge[data-n="0"] { display: none; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.open .dot { background: var(--pos); } .status-pill.pre-open .dot { background: var(--warn); }

.layout { display: flex; min-height: calc(100vh - 61px); }
.sidebar { width: var(--sidebar); flex-shrink: 0; border-right: 1px solid var(--border); background: var(--card); padding: 12px 10px; position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto; transition: width .15s; }
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .lbl, .sidebar.collapsed .nav-sec { display: none; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 1px 0; border-radius: 9px; color: var(--text); font-weight: 500; font-size: 14px; }
.nav a:hover { background: var(--chip); text-decoration: none; }
.nav a.active { background: var(--blue-soft); color: var(--blue); }
.nav svg { flex-shrink: 0; }
.nav-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 12px 4px; }
.collapse-btn { margin-top: 10px; width: 100%; border: 0; background: none; color: var(--muted); padding: 8px 12px; text-align: left; cursor: pointer; border-radius: 9px; }
.collapse-btn:hover { background: var(--chip); }
main { flex: 1; min-width: 0; padding: 22px 26px 60px; max-width: 1440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; color: var(--muted); }

/* Bottom nav (mobile) */
.bottomnav { display: none; }
.more-sheet { display: none; }

/* Cards & grids */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.gwide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.span2 { grid-column: span 2; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.section { margin-bottom: 22px; }
.stack > * + * { margin-top: 10px; }
.divider { border-top: 1px solid var(--border); margin: 12px 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; font-size: 14px; }

/* Quote tiles */
.tile { padding: 14px 16px; }
.tile .name { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.tile .px { font-size: 22px; font-weight: 650; margin: 4px 0 2px; letter-spacing: -.01em; }
.tile .chg { font-size: 14px; font-weight: 600; }
.tile .foot { margin-top: 6px; font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.spark { display: block; width: 100%; height: 34px; margin-top: 6px; }

/* Badges / chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; }
.chip.blue { background: var(--blue-soft); color: var(--blue); } .chip.pos { background: var(--pos-soft); color: var(--pos); }
.chip.neg { background: var(--neg-soft); color: var(--neg); } .chip.warn { background: var(--warn-soft); color: #9A6410; }
[data-theme="dark"] .chip.warn { color: var(--warn); }
.prio { font-weight: 700; font-size: 11.5px; padding: 3px 8px; border-radius: 6px; color: #fff; letter-spacing: .02em; }
.prio.P1 { background: var(--p1); } .prio.P2 { background: var(--p2); } .prio.P3 { background: var(--p3); } .prio.P4 { background: var(--chip); color: var(--muted); }
.fresh { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--chip); color: var(--muted); }
.fresh.delayed { background: var(--blue-soft); color: var(--blue); } .fresh.stale, .fresh.unavailable { background: var(--warn-soft); color: #9A6410; }
.fresh.unavailable { background: var(--neg-soft); color: var(--neg); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--border); background: var(--card); padding: 7px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 500; }
.tab.active { background: var(--text); color: var(--card); border-color: var(--text); }

/* News cards */
.news-card { padding: 16px 18px; border-left: 4px solid transparent; }
.news-card.P1 { border-left-color: var(--p1); } .news-card.P2 { border-left-color: var(--p2); } .news-card.P3 { border-left-color: var(--p3); }
.news-card.read { opacity: .72; }
.news-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }
.news-card .title { font-size: 16.5px; font-weight: 600; margin: 8px 0 6px; line-height: 1.38; }
.news-card .title a { color: var(--text); }
.news-card .why { font-size: 14px; color: var(--text); margin: 4px 0; }
.news-card .impact { font-size: 13.5px; color: var(--muted); }
.news-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.analysis dt { font-weight: 650; margin-top: 12px; font-size: 14px; }
.analysis dd { margin: 4px 0 0; }
.label-fact, .label-ai { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; margin-left: 6px; vertical-align: 1px; }
.label-fact { background: var(--pos-soft); color: var(--pos); } .label-ai { background: var(--warn-soft); color: #9A6410; }
.factor { display: grid; grid-template-columns: 170px 1fr 52px; gap: 10px; align-items: center; font-size: 13px; padding: 5px 0; }
.bar { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--blue); border-radius: 4px; }

/* Lists / tables */
.list > .li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list > .li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--border); }
table.t td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t td.r, table.t th.r { text-align: right; }

/* Forms & buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-weight: 550; font-size: 14px; min-height: 38px; white-space: nowrap; }
.btn:hover { background: var(--chip); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; } .btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--neg); } .btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
input.in, select.in, textarea.in { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--card); min-height: 40px; }
textarea.in { min-height: 110px; resize: vertical; line-height: 1.5; }
label.f { display: block; font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--blue); }
.note-box { background: var(--blue-soft); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.warn-box { background: var(--warn-soft); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.err-box { background: var(--neg-soft); color: var(--neg); border-radius: 10px; padding: 12px 14px; font-size: 14px; }

/* Kanban (tasks / research) */
.board { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(240px, 1fr)); gap: 14px; align-items: start; }
.col { background: var(--chip); border-radius: 12px; padding: 10px; min-height: 120px; }
.col h3 { display: flex; justify-content: space-between; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 4px 6px 8px; margin: 0; }
.kcard { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.kcard .t { font-weight: 600; font-size: 14.5px; }
.kcard.overdue { border-color: var(--neg); }
.kcard .row { margin-top: 6px; }
.check { width: 20px; height: 20px; accent-color: var(--pos); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,32,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 20px; box-shadow: 0 24px 48px rgba(0,0,0,.2); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: 90vw; }
.login { max-width: 400px; margin: 10vh auto; }
.skeleton { background: linear-gradient(90deg, var(--chip), var(--border), var(--chip)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; height: 90px; }
@keyframes sk { to { background-position: -200% 0; } }
.offline-bar { background: var(--warn-soft); color: #9A6410; text-align: center; font-size: 13px; padding: 6px; display: none; }
body.offline .offline-bar { display: block; }
.chart { width: 100%; height: 180px; display: block; }
.ptr { text-align: center; font-size: 13px; color: var(--muted); height: 0; overflow: hidden; transition: height .15s; }

/* Responsive */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 860px) {
  body { font-size: 16px; }
  .sidebar { display: none; }
  .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); gap: 8px; }
  .topbar .search { display: none; }
  .topbar .search.mobile-open { display: block; position: absolute; left: 10px; right: 10px; top: calc(100% + 6px); max-width: none; }
  .brand small, .clock-long { display: none; }
  main { padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .gauto { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gwide { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 7px; font-size: 11.5px; color: var(--muted); font-weight: 600; position: relative; }
  .bottomnav a.active { color: var(--blue); }
  .bottomnav a:hover { text-decoration: none; }
  .bottomnav .badge { top: 3px; right: calc(50% - 22px); }
  .more-sheet.open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(15,23,32,.4); }
  .more-sheet .sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--card); border-radius: 18px 18px 0 0; padding: 14px 14px calc(80px + env(safe-area-inset-bottom)); }
  .more-sheet .sheet a { display: flex; align-items: center; gap: 12px; padding: 14px 12px; border-radius: 10px; color: var(--text); font-weight: 550; font-size: 16px; }
  .more-sheet .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
  .tile .px { font-size: 20px; }
  .news-card { padding: 14px; } .news-card .title { font-size: 16px; }
  .factor { grid-template-columns: 1fr 70px 44px; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .btn { min-height: 44px; } .btn.sm { min-height: 38px; }
  input.in, select.in { min-height: 46px; font-size: 16px; } /* 16px avoids iOS zoom */
  textarea.in { font-size: 16px; }
  table.t.stackable thead { display: none; }
  table.t.stackable tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.t.stackable td { display: flex; justify-content: space-between; border: 0; padding: 4px 0; }
  table.t.stackable td::before { content: attr(data-l); color: var(--muted); font-size: 13px; margin-right: 12px; }
  .hide-m { display: none !important; }
}
@media (min-width: 861px) { .show-m { display: none !important; } }
