/* Poly Desk — dark trading-desk design system.
   Chart + status colors follow the validated dataviz reference palette. */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2a2a28;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-soft: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: var(--series-1);
  --r-s: 8px; --r-m: 12px; --r-l: 16px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--baseline) transparent; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: rgba(57, 135, 229, 0.35); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  position: sticky; top: 0; z-index: 20;
  background: rgba(13, 13, 13, 0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-size: 16px;
  background: linear-gradient(135deg, rgba(57,135,229,0.28), rgba(57,135,229,0.08));
  border: 1px solid rgba(57, 135, 229, 0.35);
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.2px; }
.brand .sub { color: var(--muted); font-size: 12px; display: block; margin-top: -2px; }

nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav button {
  background: none; border: 1px solid transparent; color: var(--ink-2);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font: inherit;
  white-space: nowrap; transition: background 0.15s ease, color 0.15s ease;
  display: flex; align-items: center; gap: 6px;
}
nav button:hover { background: var(--surface); color: var(--ink); }
nav button.on { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
nav .cnt {
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 11px; line-height: 1; padding: 3px 7px; font-weight: 600;
}
nav .cnt:empty { display: none; }

#conn { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.livedot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); position: relative; flex: none; }
.livedot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 1px solid var(--good); opacity: 0; animation: pulse 2.4s ease-out infinite;
}
.livedot.err { background: var(--critical); }
.livedot.err::after { border-color: var(--critical); }
@keyframes pulse { 0% { transform: scale(0.5); opacity: 0.7; } 70% { transform: scale(1.15); opacity: 0; } 100% { opacity: 0; } }

main { padding: 20px; max-width: 1240px; margin: 0 auto; }
section.tab { display: none; }
section.tab.on { display: block; animation: fadein 0.18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; } }

h2 { font-size: 13px; margin: 22px 0 10px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--good); }
.neg { color: var(--critical); }
.nowrap { white-space: nowrap; }

/* ---------- banners ---------- */
.banner {
  padding: 11px 16px; border-radius: var(--r-m); margin: 0 0 14px;
  border: 1px solid var(--border); background: var(--surface);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px;
}
.banner.crit { border-color: rgba(208, 59, 59, 0.55); background: rgba(208, 59, 59, 0.08); }
.banner.note { color: var(--ink-2); }
.banner button { margin-left: auto; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(160deg, rgba(57,135,229,0.10), rgba(57,135,229,0.02) 45%), var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-l);
  padding: 20px 22px; margin-bottom: 18px;
}
.hero .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.hero .q { font-size: 20px; line-height: 1.3; margin: 6px 0 4px; font-weight: 600; max-width: 780px; }
.hero .q a { color: var(--ink); }
.hero .meta { color: var(--muted); font-size: 12px; display: flex; gap: 14px; flex-wrap: wrap; }
.hero-grid { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: end; margin-top: 14px; }
.hero-stats { display: flex; gap: 26px; flex-wrap: wrap; align-items: end; }
.hero-stats .big { font-size: 32px; font-weight: 650; line-height: 1.1; letter-spacing: -0.5px; }
.hero-stats .unit { font-size: 15px; color: var(--muted); font-weight: 400; }
.hero-chart { min-width: 260px; }
.hero-chart svg { display: block; }
.action {
  display: inline-flex; gap: 9px; align-items: center; margin-top: 14px;
  background: rgba(57, 135, 229, 0.12); border: 1px solid rgba(57, 135, 229, 0.4);
  padding: 9px 14px; border-radius: 10px; font-size: 14px;
}
.action b { color: var(--ink); }
.action.exit { background: rgba(208, 59, 59, 0.12); border-color: rgba(208, 59, 59, 0.5); }
.backers { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 999px;
  padding: 4px 11px; font-size: 12px; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .q { font-size: 11px; color: var(--muted); }
.chip.link { cursor: pointer; }
.chip.link:hover { border-color: var(--muted); color: var(--ink); }

/* score meter */
.meter { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.meter .bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.4s ease; }
.meter .cap { font-size: 11px; color: var(--muted); }

/* state pills — icon + label, never color alone */
.state { font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.state.active { color: var(--good); }
.state.weakening { color: var(--warning); }
.state.exit { color: var(--critical); }
.state.closed { color: var(--muted); font-weight: 400; }
.badge { font-size: 12px; color: var(--ink-2); }
.badge.ok { color: var(--good); }
.badge.bad { color: var(--critical); }

/* ---------- stat tiles ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-m); padding: 13px 15px;
}
.tile .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.tile .v { font-size: 24px; margin-top: 3px; font-weight: 620; letter-spacing: -0.3px; }
.tile .s { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* ---------- tables ---------- */
.tablewrap {
  overflow: auto; border: 1px solid var(--border); border-radius: var(--r-m);
  background: var(--surface); max-height: 72vh;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--baseline);
  cursor: pointer; user-select: none;
}
thead th.nosort { cursor: default; }
thead th .dir { color: var(--accent); }
tr + tr td { border-top: 1px solid var(--grid); }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td .sub { color: var(--muted); font-size: 12px; white-space: normal; }
td.wrap { white-space: normal; min-width: 220px; }

.empty { padding: 34px 20px; text-align: center; color: var(--muted); }
.empty .ico { font-size: 26px; margin-bottom: 8px; }

/* ---------- charts ---------- */
.chart {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 14px; margin-bottom: 14px; position: relative;
}
.chart h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.tooltip {
  position: absolute; pointer-events: none; display: none; z-index: 10;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-s);
  padding: 7px 10px; font-size: 12px; color: var(--ink); white-space: nowrap;
  box-shadow: var(--shadow);
}
svg text { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }

/* ---------- buttons & forms ---------- */
button.act {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 7px 15px; cursor: pointer; font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
button.act:hover { border-color: var(--muted); }
button.act.primary { background: rgba(57, 135, 229, 0.18); border-color: rgba(57, 135, 229, 0.5); }
button.act.primary:hover { background: rgba(57, 135, 229, 0.28); }
button.act:disabled { opacity: 0.55; cursor: default; }
button.mini {
  padding: 3px 9px; font-size: 12px; background: none;
  border: 1px solid var(--border); border-radius: 6px; color: var(--ink-2); cursor: pointer;
}
button.mini:hover { border-color: var(--muted); color: var(--ink); }
button.mini.on { color: var(--good); border-color: rgba(12, 163, 12, 0.6); }

form.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
form.inline label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select {
  background: var(--page); color: var(--ink); border: 1px solid var(--border);
  border-radius: var(--r-s); padding: 7px 10px; font: inherit; min-width: 90px;
}
input:focus { outline: none; border-color: var(--accent); }

.filters { display: flex; gap: 6px; margin: 0 0 10px; flex-wrap: wrap; }
.filters button {
  background: none; border: 1px solid var(--border-soft); color: var(--ink-2);
  border-radius: 999px; padding: 4px 12px; font-size: 12.5px; cursor: pointer;
}
.filters button.on { background: var(--surface-2); color: var(--ink); border-color: var(--border); }

/* ---------- drawer ---------- */
#overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease;
}
#overlay.on { opacity: 1; pointer-events: auto; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 31;
  background: var(--surface); border-left: 1px solid var(--border);
  transform: translateX(102%); transition: transform 0.2s ease;
  overflow-y: auto; padding: 20px 22px 40px;
}
#drawer.on { transform: none; box-shadow: var(--shadow); }
#drawer .close {
  position: sticky; top: 0; float: right; z-index: 2;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-size: 15px;
}
#drawer h2 { margin-top: 4px; }
#drawer .q { font-size: 17px; font-weight: 600; line-height: 1.35; margin: 2px 0 10px; max-width: 92%; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 12px 0; }
.kv > div { background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-s); padding: 8px 11px; }
.kv .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.kv .v { font-size: 16px; margin-top: 2px; font-weight: 600; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-m);
  padding: 11px 15px; font-size: 13px; box-shadow: var(--shadow);
  animation: toastin 0.2s ease; max-width: 340px;
}
.toast.err { border-color: rgba(208, 59, 59, 0.6); }
.toast.ok { border-color: rgba(12, 163, 12, 0.5); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ---------- skeleton ---------- */
.skel { border-radius: var(--r-m); background: var(--surface); border: 1px solid var(--border-soft); position: relative; overflow: hidden; min-height: 54px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.045), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- login ---------- */
#login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 500px at 50% 20%, rgba(57,135,229,0.09), transparent), var(--page);
}
#login[hidden] { display: none; }
#login .box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l);
  padding: 30px; width: 340px; box-shadow: var(--shadow);
}
#login .mark { width: 44px; height: 44px; border-radius: 13px; font-size: 22px; display: grid; place-items: center; margin-bottom: 12px;
  background: linear-gradient(135deg, rgba(57,135,229,0.3), rgba(57,135,229,0.08)); border: 1px solid rgba(57,135,229,0.4); }
#login h2 { margin: 0 0 4px; font-size: 19px; text-transform: none; letter-spacing: 0; color: var(--ink); }
#login p { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
#login input { width: 100%; margin: 0 0 10px; padding: 10px 12px; }
#login .err { color: var(--critical); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
#login button { width: 100%; padding: 10px; }

/* ---------- config ---------- */
.cfggrid { display: grid; grid-template-columns: 1fr; gap: 8px; max-width: 780px; }
.cfggrid .row {
  display: grid; grid-template-columns: 230px 130px 1fr; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-s); padding: 9px 13px;
}
.cfggrid .row.changed { border-color: rgba(57, 135, 229, 0.5); }
.cfggrid .row.changed input { border-color: var(--accent); }
.cfggrid input { width: 100%; min-width: 0; }
.cfggrid .d { color: var(--muted); font-size: 12px; }

/* ---------- status ---------- */
.jobgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 16px; }
.job { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); padding: 12px 14px; }
.job .name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.job .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.job .dot.bad { background: var(--critical); }
.job .info { color: var(--muted); font-size: 12px; margin-top: 4px; }
.job .errtxt { color: var(--critical); font-size: 12px; margin-top: 4px; word-break: break-word; white-space: normal; }

@media (max-width: 760px) {
  main { padding: 12px 10px 70px; }
  header { padding: 8px 10px; gap: 8px; }
  .brand .sub { display: none; }
  .hero { padding: 15px; }
  .hero .q { font-size: 17px; }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-stats { gap: 18px; }
  .hero-stats .big { font-size: 26px; }
  .cfggrid .row { grid-template-columns: 1fr; gap: 6px; }
  #drawer { width: 100vw; }
}
