:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --border: #2a323d;
  --text: #e6eaef;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --green: #3fb950;
  --green-dim: #1c3b24;
  --blue: #58a6ff;
  --blue-dim: #16304d;
  --amber: #d29922;
  --amber-dim: #3d2f0f;
  --red: #f85149;
  --red-dim: #45201f;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .85rem; }
.muted { color: var(--muted); }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.topbar-actions { display: flex; align-items: center; gap: .9rem; }
.who { color: var(--muted); font-size: .9rem; }

.wrap { max-width: 720px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.wrap-wide { max-width: 1500px; }
.wrap-narrow { max-width: 400px; padding-top: 4rem; }

/* ---------- flashes ---------- */

.flashes { max-width: 1500px; margin: 1rem auto 0; padding: 0 1.5rem; }
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: .5rem; font-size: .92rem; }
.flash-error { background: var(--red-dim); color: #ffb4ae; border: 1px solid #6b2b28; }
.flash-info { background: var(--blue-dim); color: #a8d0ff; border: 1px solid #24486e; }

/* ---------- cards & forms ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem;
}
.card-login h1 { margin-bottom: .2rem; }
.card-login form { margin-top: 1.4rem; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .35rem; }
label.checkbox {
  display: flex; align-items: center; gap: .5rem;
  color: var(--text); font-size: .9rem; margin: 1rem 0 1.25rem;
}
label.checkbox input { width: auto; margin: 0; }

input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%; padding: .6rem .75rem; margin-bottom: 1rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: .95rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn {
  display: inline-block; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #262e38; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #3d7bf0; }
.btn-block { width: 100%; }
.btn-quiet { background: transparent; }

/* ---------- summary ---------- */

.summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem; margin-bottom: 1rem;
}
.stat {
  display: flex; flex-direction: column; gap: .2rem; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem;
  font: inherit; color: inherit; cursor: pointer;
}
.stat:hover { border-color: #3a4553; background: var(--surface-2); }
.stat-value { font-size: 1.6rem; font-weight: 600; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-in { color: var(--green); }
.stat-below { color: var(--blue); }
.stat-target { color: var(--blue); }
.stat-stop { color: var(--red); }

.freshness {
  font-size: .85rem; color: var(--muted);
  padding: .55rem .9rem; margin-bottom: 1.25rem;
  border-left: 3px solid var(--border); background: var(--surface);
  border-radius: 0 8px 8px 0;
}
.freshness-warn { border-left-color: var(--amber); color: #e8c37a; }

/* ---------- toolbar ---------- */

.toolbar { margin-bottom: 1rem; }
.toolbar-row {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .6rem;
}
.toolbar-row input, .toolbar-row select { margin-bottom: 0; }
.search { flex: 1 1 260px; min-width: 200px; }
.select { flex: 0 1 175px; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  padding: .35rem .75rem; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  font: inherit; font-size: .82rem; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: #3a4553; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- table ---------- */

.table-scroll {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
.grid th, .grid td { padding: .6rem .8rem; text-align: left; white-space: nowrap; }
.grid thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 600;
}
.grid th.num, .grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--text); }
.grid th.sorted-asc::after { content: " \2191"; color: var(--accent); }
.grid th.sorted-desc::after { content: " \2193"; color: var(--accent); }
.grid tbody tr { border-top: 1px solid var(--border); }
.grid tbody tr:hover { background: var(--surface-2); }
.grid td a { font-weight: 600; }

.zone-in td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.zone-below td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
.row-stop td:first-child { box-shadow: inset 3px 0 0 var(--red); }

.target-tag {
  display: inline-block; min-width: 1.6em; margin-right: .35rem;
  padding: 0 .3rem; border-radius: 4px;
  background: var(--blue-dim); color: var(--blue);
  font-size: .72rem; font-weight: 600; text-align: center;
}

.delta-in { color: var(--green); }
.delta-below { color: var(--blue); }
.delta-above { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 0; }

/* ---------- badges ---------- */

.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge-active { background: var(--green-dim); color: var(--green); border-color: #245c30; }
.badge-around { background: var(--blue-dim); color: var(--blue); border-color: #24486e; }
.badge-short { background: var(--amber-dim); color: var(--amber); border-color: #5c4711; }
.badge-warn { background: var(--amber-dim); color: var(--amber); border-color: #5c4711; }
.badge-danger { background: var(--red-dim); color: var(--red); border-color: #6b2b28; }
.badge-status-buy { background: var(--green-dim); color: var(--green); border-color: #245c30; }
.badge-status-stop { background: var(--amber-dim); color: var(--amber); border-color: #5c4711; }
.badge-status-below-stop,
.badge-status-above-short-stop { background: var(--red-dim); color: var(--red); border-color: #6b2b28; }
.badge-status-1st-target,
.badge-status-2nd-target,
.badge-status-3rd-target { background: var(--blue-dim); color: var(--blue); border-color: #24486e; }

/* ---------- detail page ---------- */

.backlink { display: inline-block; font-size: .88rem; margin-bottom: 1.25rem; }
.detail-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.detail-head h1 { font-size: 2rem; letter-spacing: -.02em; }
.badges { display: flex; gap: .4rem; flex-wrap: wrap; }

.detail-price {
  display: flex; align-items: baseline; gap: 1.25rem; flex-wrap: wrap;
  margin: 1rem 0 1.5rem;
}
.detail-price-value { font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.zone-readout { font-size: .95rem; font-weight: 600; }
.zone-readout.zone-in { color: var(--green); }
.zone-readout.zone-below { color: var(--blue); }
.zone-readout.zone-above, .zone-readout.zone-unknown { color: var(--muted); }

.callout {
  background: var(--amber-dim); border: 1px solid #5c4711;
  border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1.5rem;
}
.callout strong { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--amber); }
.callout p { margin: .35rem 0 0; }

.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem;
}
.detail-grid dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; }
.detail-grid dt { color: var(--muted); font-size: .88rem; }
.detail-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .wrap { padding: 1.25rem 1rem 3rem; }
  .toolbar-right { margin-left: 0; width: 100%; }
  .select { flex: 1 1 45%; }
}
