/* Hyperliquid Viewer — palette per dataviz reference (light + dark selected) */

:root {
  color-scheme: light dark;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --good-wash: rgba(12, 163, 12, 0.10);
  --bad-wash: rgba(208, 59, 59, 0.10);
  --ghost: rgba(11, 11, 11, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series: #3987e5;
    --good: #0ca30c;
    --bad: #d03b3b;
    --ghost: rgba(255, 255, 255, 0.08);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---- top bar ---- */

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

.topbar h1 { font-size: 16px; font-weight: 600; margin: 0; white-space: nowrap; }

#address-form { display: flex; gap: 8px; flex: 1; min-width: 260px; max-width: 560px; }

#address-input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
  font: 13px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#address-input:focus { outline: 2px solid var(--series); outline-offset: 1px; }

.btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--ghost); }
.btn-primary { background: var(--series); border-color: var(--series); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--series); }
.btn-ghost { border-color: transparent; color: var(--ink-2); }

.status { color: var(--muted); font-size: 13px; margin-left: auto; white-space: nowrap; }
.status.error { color: var(--bad); }

.error-banner {
  background: var(--bad-wash);
  border: 1px solid var(--bad);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 500;
}

/* ---- layout ---- */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

main.loading .card, main.loading .kpi-row { opacity: 0.55; transition: opacity 0.15s; }

.welcome { max-width: 560px; margin: 12vh auto; padding: 0 24px; text-align: center; }
.welcome h2 { font-size: 18px; font-weight: 600; }
.welcome p { color: var(--ink-2); }

/* ---- KPI tiles ---- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.pos { color: var(--good); }
.neg { color: var(--bad); }
.flat { color: var(--ink-2); }

/* ---- filter row ---- */

.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  padding: 2px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.segmented button:hover { background: var(--ghost); }
.segmented button[aria-pressed="true"] {
  background: var(--ghost);
  color: var(--ink);
  font-weight: 600;
}

/* ---- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.card-head h2 { font-size: 14.5px; font-weight: 600; margin: 0; }
.card-foot { display: flex; align-items: center; gap: 12px; }

.meta { color: var(--muted); font-size: 12.5px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* ---- chart ---- */

.chart { position: relative; width: 100%; min-height: 120px; }
.chart:focus { outline: 2px solid var(--series); outline-offset: 4px; border-radius: 4px; }
.chart svg { display: block; }

.chart .tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  padding: 7px 10px;
  font-size: 12.5px;
  white-space: nowrap;
  z-index: 5;
}
.chart .tooltip .val { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.chart .tooltip .when { color: var(--muted); margin-top: 1px; }
.chart .tooltip .key {
  display: inline-block;
  width: 12px;
  height: 0;
  border-top: 2px solid var(--series);
  border-radius: 1px;
  vertical-align: middle;
  margin-right: 6px;
}

.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--baseline); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line {
  stroke: var(--series);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart .area { fill: var(--series); opacity: 0.1; }
.chart .end-dot, .chart .hover-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; }

.chart-table { max-height: 280px; overflow-y: auto; margin-top: 8px; }

/* ---- tables ---- */

.table-wrap { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }

th, td {
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  border-bottom: 1px solid var(--baseline);
}
th:first-child, td:first-child { text-align: left; }
th.left, td.left { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--ghost); }

td.coin { font-weight: 600; }
td .tag { color: var(--muted); font-weight: 400; font-size: 11.5px; margin-left: 4px; }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.chip.long { color: var(--good); background: var(--good-wash); }
.chip.short { color: var(--bad); background: var(--bad-wash); }
.chip.open { color: var(--ink-2); background: var(--ghost); }

@media (max-width: 640px) {
  .topbar, main { padding-left: 14px; padding-right: 14px; }
  .status { display: none; }
}
