:root {
  --bg: #0e1116;
  --bg-2: #11161d;
  --panel: #161c25;
  --panel-2: #1b2330;
  --line: #232c3a;
  --line-soft: #1d2531;
  --text: #e6edf3;
  --muted: #8b97a7;
  --muted-2: #5d6878;
  --amber: #ffb000;
  --amber-dim: #c98a08;
  --teal: #34c5b3;
  --teal-dim: #1f7d73;
  --red: #ff6363;
  --green: #4ed28a;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 12px;
  --shadow: 0 18px 50px -20px rgba(0,0,0,0.8);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(52,197,179,0.06), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(255,176,0,0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
/* faint scanline texture */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px);
  opacity: 0.6;
}
.hidden { display: none !important; }

/* ── Login gate ── */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.gate-card {
  width: min(380px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 28px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.gate-mark { font-family: var(--mono); font-weight: 700; letter-spacing: 2px; color: var(--amber); font-size: 18px; }
.gate-sub { margin: 0; color: var(--muted); font-size: 13px; }
.gate-err { color: var(--red); font-size: 13px; min-height: 16px; font-family: var(--mono); }

/* ── Top bar ── */
.app { position: relative; z-index: 1; max-width: 1200px; margin: 0 auto; padding: 22px 18px 60px; }
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 22px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--amber); font-size: 22px; }
.brand-name { font-family: var(--mono); font-weight: 700; letter-spacing: 3px; font-size: 15px; }
.status-strip { display: flex; gap: 8px; margin-left: 4px; }
.chip {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 1px;
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted-2); background: var(--bg-2); position: relative; padding-left: 20px;
}
.chip::before {
  content: ""; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2);
}
.chip.ok { color: var(--teal); border-color: var(--teal-dim); }
.chip.ok::before { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.chip.warn { color: var(--amber); border-color: var(--amber-dim); }
.chip.warn::before { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }

button {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  border-radius: 9px; padding: 9px 14px; cursor: pointer; border: 1px solid transparent;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
button:active { transform: translateY(1px); }
.primary { background: var(--amber); color: #1a1300; }
.primary:hover { background: #ffc233; }
.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.ghost:hover { border-color: var(--teal-dim); color: var(--teal); }
.icon-btn { background: transparent; color: var(--muted); border: none; font-size: 16px; }
.icon-btn:hover { color: var(--text); }

/* ── Watch grid ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 12px;
  position: relative; overflow: hidden;
}
.card.paused { opacity: 0.62; }
.card .edge {
  position: absolute; top: 0; left: 0; height: 100%; width: 3px; background: var(--teal);
}
.card.paused .edge { background: var(--muted-2); }
.card.target-hit .edge { background: var(--amber); box-shadow: 0 0 14px var(--amber); }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.route { font-family: var(--mono); font-weight: 700; font-size: 22px; letter-spacing: 2px; }
.route .arrow { color: var(--amber); margin: 0 6px; }
.card-label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.state { font-family: var(--mono); font-size: 10px; letter-spacing: 1px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.state.active { color: var(--teal); border-color: var(--teal-dim); }

.price-block { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.price {
  font-family: var(--mono); font-weight: 700; font-size: 34px; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.price.hit { color: var(--amber); }
.delta { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.delta.down { color: var(--green); }
.delta.up { color: var(--red); }

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 12px; }
.meta .k { color: var(--muted-2); }
.meta .v { color: var(--text); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.airline { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.airline .tag { color: var(--teal); }

.card-foot { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line-soft); padding-top: 11px; }
.card-foot button { padding: 7px 10px; font-size: 12px; }
.card-foot .danger:hover { border-color: var(--red); color: var(--red); }
.book {
  margin-left: auto; text-decoration: none; font-size: 12px; font-weight: 600;
  color: var(--teal); border: 1px solid var(--teal-dim); border-radius: 9px; padding: 7px 12px;
}
.book:hover { background: rgba(52,197,179,0.08); }

.empty { text-align: center; color: var(--muted); padding: 80px 20px; display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ── Modal / drawer ── */
.modal, .drawer {
  position: fixed; inset: 0; z-index: 40; display: flex;
  background: rgba(6,9,13,0.72); backdrop-filter: blur(3px);
}
.modal { align-items: flex-start; justify-content: center; overflow-y: auto; padding: 30px 14px; }
.drawer { justify-content: flex-end; }
.modal-card {
  width: min(720px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin: auto 0;
}
.drawer-card {
  width: min(440px, 100%); height: 100%; background: var(--panel);
  border-left: 1px solid var(--line); padding-bottom: 20px; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; font-family: var(--mono); letter-spacing: 1px; }

.form { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span2 { grid-column: span 2; }
.field > span { font-size: 11.5px; color: var(--muted); letter-spacing: .3px; }
.field.check { flex-direction: row; align-items: center; gap: 9px; align-self: end; padding-bottom: 8px; }
.field.check span { font-size: 13px; color: var(--text); }
input, select {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-family: var(--mono); font-size: 13px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--teal-dim); box-shadow: 0 0 0 3px rgba(52,197,179,0.12); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--amber); }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12.5px; padding: 4px 0; }
.advanced > .row { margin-top: 10px; }
.hint { font-size: 11.5px; color: var(--muted-2); line-height: 1.5; margin: 2px 0 0; }
hr { border: none; border-top: 1px solid var(--line-soft); margin: 4px 0; }
.form-err, .gate-err { color: var(--red); font-family: var(--mono); font-size: 12.5px; min-height: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ── History ── */
#spark { padding: 18px 20px 6px; }
.history { padding: 6px 20px 20px; display: flex; flex-direction: column; gap: 2px; }
.hrow { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.hrow .hp { font-weight: 600; }
.hrow .ht { color: var(--muted-2); }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 10px; font-size: 13px; z-index: 60;
  box-shadow: var(--shadow); font-family: var(--mono);
}
.toast.err { border-color: var(--red); color: var(--red); }
.toast.ok { border-color: var(--teal-dim); }

@media (max-width: 620px) {
  .row { grid-template-columns: 1fr 1fr; }
  .field.span2 { grid-column: span 2; }
  .topbar-actions { width: 100%; }
  .topbar-actions .primary { margin-left: auto; }
}
