/* Trade Portal — palette from the validated dataviz reference (dark-first, light supported). */
:root {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface-1:   #1a1a19;
  --surface-2:   #222221;
  --text-1:      #ffffff;
  --text-2:      #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --axis:        #383835;
  --border:      rgba(255,255,255,0.10);

  --series-1:    #3987e5; /* blue  - equity */
  --series-2:    #d95926; /* orange */
  --series-3:    #199e70; /* aqua  */
  --series-4:    #c98500; /* yellow */
  --series-5:    #d55181; /* magenta */
  --series-6:    #9085e9; /* violet */

  --good:        #0ca30c;
  --good-ink:    #4bd34b;
  --bad:         #d03b3b;
  --bad-ink:     #f06a6a;
  --warn:        #fab219;

  --pl-pos:      #199e70;
  --pl-neg:      #d03b3b;

  --radius: 10px;
  --gap: 16px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page:        #f4f4f1;
  --surface-1:   #fcfcfb;
  --surface-2:   #f2f1ec;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --axis:        #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --series-1:    #2a78d6;
  --good-ink:    #067a06;
  --bad-ink:     #b22a2a;
  --pl-pos:      #1baf7a;
  --pl-neg:      #d03b3b;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}

/* Environment banner — shown on staging/local only (data-env set in each page's head).
   Production never sets a matching data-env, so the banner stays hidden there. */
.env-banner { display: none; }
:root[data-env="staging"] .env-banner,
:root[data-env="local"] .env-banner {
  display: block; position: sticky; top: 0; z-index: 30;
  text-align: center; color: #fff; background: var(--bad);
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
  line-height: 18px; padding: 6px 12px;
}
:root[data-env="staging"] .env-banner::before { content: "STAGING ENVIRONMENT — NOT PRODUCTION"; }
:root[data-env="local"] .env-banner::before { content: "LOCAL DEV ENVIRONMENT"; }
:root[data-env="staging"] .topbar,
:root[data-env="local"] .topbar { top: 30px; }
.topbar .brand { font-weight: 650; letter-spacing: .2px; font-size: 15px; display: inline-flex; align-items: center; gap: 9px; }
.topbar .brand .logo-link { display: inline-flex; line-height: 0; }
.topbar .brand .logo { height: 30px; width: 30px; border-radius: 7px; object-fit: cover; flex: 0 0 auto; display: block; }
.topbar .brand .logo-link:hover .logo { outline: 2px solid var(--series-1); outline-offset: 1px; }
.topbar .brand span { color: var(--muted); font-weight: 400; }
.topbar .spacer { flex: 1; }
.topbar .updated { color: var(--muted); font-size: 12px; }
.btn {
  background: var(--surface-2); color: var(--text-1);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; font-family: var(--sans);
}
.btn:hover { border-color: var(--muted); }
.btn.icon { padding: 6px 9px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.crumbs a { color: var(--text-2); }

/* filter bar */
.filterbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 20px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: var(--gap); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.ctrlrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segbtn { background: transparent; color: var(--text-2); border: 0; border-right: 1px solid var(--border); padding: 6px 11px; font-size: 12px; cursor: pointer; font-family: var(--sans); }
.segbtn:last-child { border-right: 0; }
.segbtn.on { background: var(--series-1); color: #fff; }
.segbtn:not(.on):hover { color: var(--text-1); }
.daterange { display: inline-flex; align-items: center; gap: 6px; }
.dateinp { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; font-size: 12px; font-family: var(--sans); color-scheme: dark; }
:root[data-theme="light"] .dateinp { color-scheme: light; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; font-size: 12px; cursor: pointer; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--series-3); border-color: var(--series-3); color: #fff; }
.chip:not(.on):hover { color: var(--text-1); border-color: var(--muted); }
.sel { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; font-family: var(--sans); }
.filterbar-tail { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.filtcount { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 24px; font-weight: 620; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pos { color: var(--good-ink); }
.neg { color: var(--bad-ink); }

/* cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: var(--gap); }
.card h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--text-1); }
.card h2 .hint { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface-1); }
th.sorted::after { content: " \25BE"; color: var(--text-2); }
th.sorted.asc::after { content: " \25B4"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.acct-name { font-weight: 600; color: var(--text-1); }

/* accounts table: make rows read as clickable (link name + chevron + hover accent bar) */
.accounts .acct-name { color: var(--series-1); }
.accounts tbody tr:hover .acct-name { text-decoration: underline; }
.accounts tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--series-1); }
th.go-h { cursor: default; width: 30px; }
.accounts td.go { width: 30px; text-align: right; padding-left: 0; }
.accounts .chev { display: inline-block; color: var(--muted); font-size: 16px; line-height: 1; transition: transform .12s, color .12s; }
.accounts tbody tr:hover .chev { color: var(--text-1); transform: translateX(3px); }
.tbl-scroll { max-height: 460px; overflow: auto; }
.mono { font-family: var(--mono); }
.dim { color: var(--muted); }

/* horizontal bar breakdown */
.bars { display: flex; flex-direction: column; gap: 6px; }
.barrow { display: grid; grid-template-columns: 130px 1fr 90px; align-items: center; gap: 10px; font-size: 13px; }
.barrow .k { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.barrow .track { position: relative; height: 16px; background: var(--surface-2); border-radius: 4px; }
.barrow .fill { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.barrow .v { text-align: right; font-variant-numeric: tabular-nums; }

/* chart hosts */
.chart { width: 100%; height: 260px; }
.chart.tall { height: 300px; }
.uplot { font-family: var(--sans) !important; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cal-head .month { font-weight: 600; font-size: 14px; min-width: 150px; text-align: center; }
.cal-head .spacer { flex: 1; }
.cal-summary { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(92px, 1.3fr); gap: 6px; }
.cal-dow { color: var(--muted); font-size: 11px; text-align: center; padding-bottom: 2px; }
.cal-dow:last-child { color: var(--text-2); font-weight: 600; }
.cal-cell { min-height: 62px; border-radius: 8px; border: 1px solid var(--border); padding: 6px 8px; display: flex; flex-direction: column; justify-content: space-between; background: var(--surface-2); position: relative; overflow: hidden; }
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.notrade { opacity: .5; }
.cal-cell.other { opacity: .35; }
.cal-cell.other .d { color: var(--muted); }
.cal-cell .d { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cal-cell .pnl { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-week .pnl { font-size: 12px; }
.cal-cell .n { font-size: 10px; color: var(--muted); }
.cal-cell.win { background: color-mix(in srgb, var(--pl-pos) var(--i,20%), var(--surface-2)); }
.cal-cell.loss { background: color-mix(in srgb, var(--pl-neg) var(--i,20%), var(--surface-2)); }
/* On tinted cells the P&L used the same hue as the background — low contrast.
   Use the theme's high-contrast text (white on dark, near-black on light) instead;
   the cell background already signals win/loss. */
.cal-cell.win .pnl, .cal-cell.loss .pnl { color: var(--text-1); }
.cal-cell.win .d, .cal-cell.loss .d { color: var(--text-1); }
.cal-cell.win .n, .cal-cell.loss .n { color: var(--text-2); }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--muted); }
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover { border-color: var(--series-1); filter: brightness(1.12); }
.cal-cell.selected { outline: 2px solid var(--series-4); outline-offset: -2px; }
.cal-week { background: var(--surface-1); border-left: 2px solid var(--axis); opacity: 1 !important; }
.cal-week .d { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: .04em; }

/* calendar notes: a bright-yellow ! flag on any day with a note */
.note-flag { position: absolute; top: 3px; right: 4px; width: 16px; height: 16px; line-height: 16px; text-align: center; font-weight: 900; font-size: 12px; color: #111; background: #ffdd00; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 0 6px rgba(255,221,0,.7); cursor: help; }
.note-flag.static { position: static; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.cal-cell.has-note.notrade { opacity: .85; }
.cal-cell.has-note.other { opacity: .5; }
.cal-notes { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.cal-note { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.cal-note-date { color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 44px; }
.cal-note-text { color: var(--text-1); }

/* admin page */
.admin-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 18px; }
.admin-form .field.grow { flex: 1 1 260px; }
.txt { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font-size: 13px; font-family: var(--sans); width: 100%; resize: vertical; }
.btn.primary { background: var(--series-1); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: color-mix(in srgb, var(--pl-neg) 16%, var(--surface-2)); border-color: color-mix(in srgb, var(--pl-neg) 45%, transparent); color: var(--bad-ink); }
.btn.danger:hover:not(:disabled) { background: var(--pl-neg); color: #fff; border-color: var(--pl-neg); }
.btn.danger.armed { background: var(--pl-neg); color: #fff; border-color: var(--pl-neg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pl-neg) 30%, transparent); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.danger-card { border-color: color-mix(in srgb, var(--pl-neg) 30%, var(--border)); }
.rule { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.note-tbl th, .note-tbl td { text-align: left; }
.note-tbl th { cursor: default; }
.note-tbl tbody tr { cursor: default; }
.note-tbl tbody tr:hover { background: transparent; }
.note-cell { white-space: normal; color: var(--text-1); }
.names-tbl td:nth-child(2) { width: 50%; }
.names-tbl input.txt { min-width: 200px; }

/* upload page */
.upload-box { max-width: 640px; margin: 40px auto; }
.dropzone { border: 2px dashed var(--axis); border-radius: 12px; padding: 40px; text-align: center; color: var(--text-2); cursor: pointer; transition: border-color .15s; }
.dropzone.drag { border-color: var(--series-1); background: var(--surface-1); }
.log { font-family: var(--mono); font-size: 12px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 16px; white-space: pre-wrap; max-height: 320px; overflow: auto; }

.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; }
.spinner { color: var(--muted); padding: 40px; text-align: center; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); color: var(--text-2); }

/* tooltip for scatter */
.tt { position: fixed; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 12px; z-index: 50; display: none; box-shadow: 0 4px 16px rgba(0,0,0,.35); font-variant-numeric: tabular-nums; }
