:root {
  --bg: #f4f6f5; --surface: #ffffff; --surface-2: #eef2f1; --text: #17201f; --muted: #5f6b69;
  --border: #dde3e1; --brand: #0f3d3e; --brand-2: #14595a; --accent: #c9a227;
  --pos: #0f7b4a; --neg: #b3261e; --warn: #9a6700; --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1413; --surface: #161e1d; --surface-2: #1d2726; --text: #e7eeec; --muted: #9aa8a5;
          --border: #2a3533; --brand: #3fa7a2; --brand-2: #5cc3be; --pos: #4cc38a; --neg: #ff8a80; --warn: #e3b341;
          color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--neg); min-height: 1.2em; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.02rem; }
a { color: var(--brand-2); }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #fff; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
@media (prefers-color-scheme: dark) { .sidebar { background: #0b1111; border-right: 1px solid var(--border); } }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 1.1rem; margin: 0 8px 20px; }
.brand img { border-radius: 8px; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; color: #d8e6e4; text-decoration: none;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 2px; }
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.badge { background: var(--accent); color: #1b1b1b; border-radius: 999px; padding: 0 7px; font-size: .75rem; font-weight: 700; margin-left: auto; }
main { min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 24px 4px;
  position: sticky; top: 0; background: var(--bg); z-index: 5; }
.topbar h2 { margin: 0; }
.view { padding: 12px 24px 32px; max-width: 1200px; }
.bottom-nav { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 16px 6px; }
  .view { padding: 8px 16px calc(88px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 20; overflow-x: auto; }
  .bottom-nav a { flex: 1 0 64px; text-align: center; color: var(--muted); text-decoration: none; font-size: .7rem;
    padding: 6px 2px; border-radius: 10px; position: relative; }
  .bottom-nav a .ic { display: block; font-size: 1.25rem; line-height: 1.3; }
  .bottom-nav a.active { color: var(--brand-2); background: var(--surface-2); }
  .bottom-nav .badge { position: absolute; top: 2px; right: 10px; margin: 0; }
}

/* components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.35rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 10px;
  font: inherit; cursor: pointer; min-height: 38px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.good { background: var(--pos); color: #fff; border-color: var(--pos); }
.btn.bad { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-height: 38px; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
label input, label select { margin-top: 4px; }
.form-grid { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); }
.chip.BUY, .chip.COMPLIANT, .chip.COMPLETE, .chip.OK { background: rgba(15,123,74,.13); color: var(--pos); }
.chip.SELL, .chip.NON_COMPLIANT, .chip.FAILED, .chip.REJECTED { background: rgba(179,38,30,.12); color: var(--neg); }
.chip.AUTO, .chip.ORDERED { background: rgba(201,162,39,.18); color: #8a6d00; }
.chip.DOUBTFUL, .chip.PENDING, .chip.PLACED { background: rgba(154,103,0,.14); color: var(--warn); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* tables -> cards on mobile */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .78rem; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; }
tr:hover td { background: var(--surface-2); }
@media (max-width: 820px) {
  table.cards thead { display: none; }
  table.cards tr { display: block; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
  table.cards td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 10px; white-space: normal; text-align: right; }
  table.cards td::before { content: attr(data-l); color: var(--muted); font-size: .8rem; text-align: left; }
  table.cards td .cv { text-align: right; }
  table.cards td .cv .btn { margin-left: 4px; }
}

/* picks */
.pick { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.pick .sym { font-weight: 700; font-size: 1.1rem; }
.pick .meta { color: var(--muted); font-size: .85rem; }
.pick .reason { grid-column: 1 / -1; font-size: .88rem; }
.pick .actions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; align-items: end; }
.pick .actions label { margin: 0; }

/* modal / toast / login */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-box { background: var(--surface); width: min(640px, 100%); max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 821px) { .modal { align-items: center; } .modal-box { border-radius: 16px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); background: #1d2726; color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: var(--shadow); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), #071b1b); }
.login-card { width: min(380px, 100%); text-align: center; }
.login-card label { text-align: left; }
.login-card img { border-radius: 12px; }
pre.log { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; max-height: 320px; font-size: .78rem; white-space: pre-wrap; }
svg.chart { width: 100%; height: auto; display: block; }
.warn-box { border-left: 4px solid var(--warn); background: rgba(154,103,0,.08); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
