:root {
  --bg: #111317;
  --panel: #1a1d23;
  --panel-2: #22262e;
  --line: #2e333d;
  --text: #e6e8ec;
  --muted: #9097a3;
  --accent: #f0c050;
  --up: #40d95a;
  --down: #f24d40;
  --flat: #d9d9d9;
  --high: #8a8f99;
  --qty: #3a5a8c;
  --gold: #ffd36a;
  --silver: #c9ccd4;
  --copper: #e09a5a;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; flex-direction: column; text-decoration: none; }
.brand-name { color: var(--accent); font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: 12px; font-style: italic; }
.top-right { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 14px; }
.realm select { margin-left: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.link-button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; text-decoration: underline; }
.link-button:hover { color: var(--text); }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.view + .view { margin-top: 20px; }
.muted { color: var(--muted); }
.error { color: var(--down); min-height: 1.4em; margin: 8px 0 0; }
.status { color: var(--muted); font-size: 13px; margin: 8px 2px 0; min-height: 1.2em; }

/* Login */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login { max-width: 360px; margin: 10vh auto 0; display: flex; flex-direction: column; gap: 10px; }
.login h1 { margin: 0 0 6px; font-size: 20px; }
input[type=password], input[type=search] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary {
  background: var(--accent); color: #1a1407; border: none; border-radius: 6px; padding: 10px; font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: .6; cursor: default; }

/* Search */
.search { position: relative; }
.search input { font-size: 17px; padding: 12px 14px; }
.results {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-height: 60vh; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.results li {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.results li.active, .results li:hover { background: var(--panel-2); }
.results .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .price { flex: none; font-variant-numeric: tabular-nums; }
.results .empty { color: var(--muted); cursor: default; }
.results .empty:hover { background: none; }

/* Item */
.item-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.item-head h1 { margin: 0; font-size: 24px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.tile .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 18px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; margin-top: 2px; }
.up { color: var(--up); }
.down { color: var(--down); }

.chart-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.ranges { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.ranges button { background: var(--panel); border: none; padding: 6px 14px; cursor: pointer; color: var(--muted); }
.ranges button + button { border-left: 1px solid var(--line); }
.ranges button.on { background: var(--panel-2); color: var(--accent); font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.legend .l-up { background: var(--up); }
.legend .l-down { background: var(--down); }
.legend .l-high { background: repeating-linear-gradient(90deg, var(--high) 0 5px, transparent 5px 8px); }
.legend .l-qty { background: var(--qty); height: 9px; }

.chart {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  height: 380px; touch-action: pan-y;
}
.chart svg { display: block; width: 100%; height: 100%; }
.chart .grid { stroke: rgba(255, 255, 255, .07); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .qty-bar { fill: var(--qty); opacity: .55; }
.chart .high-line { stroke: var(--high); stroke-width: 1.5; stroke-dasharray: 5 3; fill: none; }
.chart .seg { stroke-width: 2.25; stroke-linecap: round; fill: none; }
.chart .seg.up, .chart .dot.up { stroke: var(--up); fill: var(--up); }
.chart .seg.down, .chart .dot.down { stroke: var(--down); fill: var(--down); }
.chart .seg.flat, .chart .dot.flat { stroke: var(--flat); fill: var(--flat); }
.chart .hover-line { stroke: rgba(255, 255, 255, .35); stroke-width: 1; }
.chart .hover-dot { stroke: var(--bg); stroke-width: 2; }
.chart .hover-dot.high { fill: var(--high); }
.chart .empty { fill: var(--muted); font-size: 14px; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: #0b0c0f; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, .5); min-width: 170px;
}
.tooltip .t-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
.tooltip .t-row span:first-child { color: var(--muted); }

/* Days table */
.days { margin-top: 18px; }
.days summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: var(--panel); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel); }

/* Money */
.money { white-space: nowrap; }
.money .g { color: var(--gold); }
.money .s { color: var(--silver); }
.money .c { color: var(--copper); }

@media (max-width: 600px) {
  .top { padding: 10px 16px; }
  main { padding: 14px 16px 40px; }
  .chart { height: 300px; }
  .item-head h1 { font-size: 20px; }
  .tile .value { font-size: 16px; }
  th, td { padding: 6px 8px; }
}
