:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #c3c2b7;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 13px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.secondary { color: var(--ink-2); }
.up { color: var(--good); }
.down { color: var(--critical); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #17202c 0%, var(--page) 60%);
}
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.brand { font-weight: 700; letter-spacing: 0.14em; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--series-1); }
.login-card h1 { font-size: 21px; margin: 6px 0 2px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.login-card input[type="password"] {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: #101010; color: var(--ink); font-size: 15px; outline: none;
}
.login-card input[type="password"]:focus { border-color: var(--series-1); }
.login-card button {
  width: 100%; margin-top: 16px; padding: 11px 12px; border: 0; border-radius: 8px;
  background: var(--series-1); color: #fff; font-weight: 600;
}
.login-card button:hover { background: #4a93ea; }
.error { margin-top: 12px; color: var(--critical); font-size: 13px; }

/* ---------- app shell ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 9px 18px; background: rgba(13, 13, 13, 0.94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.top .acct { color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.ea-strip { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.ea-strip .warn { color: var(--warning); }
.top .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--border); font-size: 11.5px; color: var(--ink-2); background: var(--surface);
  white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.good .dot { background: var(--good); }
.pill.warn .dot { background: var(--warning); }
.pill.crit .dot { background: var(--critical); }

.ghost {
  background: transparent; color: var(--ink-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 10px; font-size: 12px;
}
.ghost:hover { border-color: var(--muted); color: var(--ink); }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
  border-radius: 7px; padding: 6px 11px; font-size: 12px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #4a93ea; }
.btn.warn { color: var(--warning); border-color: rgba(250, 178, 25, 0.4); }
.btn.good { color: var(--good); border-color: rgba(12, 163, 12, 0.4); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.top form { display: inline-flex; margin: 0; }

main { width: 100%; padding: 12px 18px 6px; display: grid; gap: 12px; }
footer { width: 100%; padding: 2px 18px 12px; color: var(--muted); font-size: 11px; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; min-height: 84px; display: flex; flex-direction: column; gap: 2px;
}
.tile .label { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.tile .sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cap-track { height: 5px; border-radius: 3px; background: var(--grid); margin-top: auto; overflow: hidden; }
.cap-fill { height: 100%; width: 0; background: var(--good); border-radius: 3px; transition: width 0.3s ease, background 0.3s ease; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; min-width: 0;
}
.card h2 { font-size: 11.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 8px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 12px; }
.grid.primary { grid-template-columns: minmax(0, 1.65fr) minmax(340px, 0.6fr); }
.grid.secondary { grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.85fr); }
.ea-card { display: flex; flex-direction: column; }

/* ---------- chart ---------- */
.chart { position: relative; width: 100%; height: 250px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .tooltip {
  position: absolute; pointer-events: none; transform: translate(-50%, -110%);
  background: #101010; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 9px; font-size: 11px; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  color: var(--ink); z-index: 5;
}
.chart .tooltip .t { color: var(--muted); font-size: 10px; }
.chart .tooltip .row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-empty { height: 250px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

.substats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.substats .s .k { font-size: 9.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.substats .s .v { font-size: 13.5px; font-weight: 600; }

/* ---------- EA card ---------- */
.ea-status { font-size: 18px; font-weight: 650; margin: 0 0 1px; }
.ea-sub { color: var(--muted); font-size: 11.5px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 86px 1fr; gap: 4px 8px; font-size: 12px; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--ink); font-variant-numeric: tabular-nums; }
.stale { margin-top: 8px; font-size: 11px; color: var(--warning); }

/* ---------- range picker / legend ---------- */
.range { display: flex; align-items: center; gap: 5px; }
.range input[type="date"] {
  background: #111; color: var(--ink-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 6px; font: inherit; font-size: 11px; color-scheme: dark;
}
.range input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }
.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 2px 0 4px; font-size: 11px; color: var(--ink-2); }
.legend .item { display: inline-flex; align-items: center; gap: 5px; }
.legend .swatch { width: 13px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .note { color: var(--muted); font-size: 10px; }

/* ---------- tabs ---------- */
.tabs { display: inline-flex; gap: 3px; padding: 2px; background: #111; border: 1px solid var(--border); border-radius: 8px; }
.tab {
  border: 0; background: transparent; color: var(--muted); padding: 4px 10px; border-radius: 6px;
  font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 600;
}
.tab:hover { color: var(--ink-2); }
.tab.active { background: var(--surface-2); color: var(--ink); }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.history-scroll { max-height: 380px; overflow-y: auto; }
.history-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
th {
  text-align: left; font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); font-weight: 600; padding: 5px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 5px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.empty { color: var(--muted); padding: 14px 8px; font-size: 12px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding-top: 6px; font-size: 11px; color: var(--muted); }
.pager button { min-width: 30px; }
.pager button:disabled { opacity: 0.35; cursor: default; }

/* ---------- calendar ---------- */
.cal-nav { display: flex; align-items: center; gap: 4px; }
.cal-month { font-size: 12px; font-weight: 600; color: var(--ink); min-width: 110px; text-align: center; }
.cal-nav .ghost { padding: 3px 7px; font-size: 11px; }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 10px; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-head div { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  min-height: 56px; border: 1px solid var(--grid); border-radius: 7px; padding: 4px 6px;
  display: flex; flex-direction: column; justify-content: space-between; background: #141413;
}
.cal-cell.blank { background: transparent; border-color: transparent; }
.cal-cell.today { border-color: var(--series-1); box-shadow: inset 0 0 0 1px rgba(57, 135, 229, 0.22); }
.cal-day { font-size: 11px; color: var(--ink-2); }
.cal-cell.blank .cal-day { color: #3a3a37; }
.cal-meta { text-align: right; line-height: 1.2; }
.cal-count { font-size: 9px; color: var(--muted); }
.cal-pnl { font-size: 10px; font-weight: 600; }
.cal-pnl.up { color: var(--good); }
.cal-pnl.down { color: var(--critical); }
.weeks { display: flex; flex-direction: column; gap: 6px; }
.week { background: #141413; border: 1px solid var(--grid); border-radius: 7px; padding: 7px 9px; }
.week .wk-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin-bottom: 2px; }
.week .wk-date { color: var(--muted); font-size: 9.5px; }
.week .wk-body { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.week .wk-pnl { font-weight: 600; font-size: 11px; }
.week .wk-pnl.up { color: var(--good); }
.week .wk-pnl.down { color: var(--critical); }

@media (max-width: 1500px) {
  .grid.secondary { grid-template-columns: 1fr; }
  .cal-layout { grid-template-columns: minmax(0, 1fr) 220px; }
}
@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top { flex-wrap: wrap; }
  main { padding: 10px 12px; }
  .cal-layout { grid-template-columns: 1fr; }
  .substats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- VNC ---------- */
.vnc-page { height: 100dvh; display: flex; flex-direction: column; background: #000; }
.vnc-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--surface); border-bottom: 1px solid var(--border); font-size: 13px;
}
.vnc-bar .spacer { flex: 1; }
#screen { flex: 1; background: #000; outline: none; }
#screen canvas { image-rendering: auto; }
.vnc-error {
  position: absolute; inset: auto 16px 16px 16px; padding: 12px 14px; border-radius: 8px;
  background: #2a1414; border: 1px solid var(--critical); color: var(--ink); font-size: 13px;
}
