*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #000;
  color: #ccc;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

/* ── Login ─────────────────────────────────────────────── */
#login {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.login-card {
  width: min(360px, 92vw);
  padding: 32px 24px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 14px;
}
.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}
.login-card p { font-size: 13px; color: #555; margin-bottom: 22px; }
.login-card input {
  width: 100%;
  padding: 11px 13px;
  background: #141414;
  border: 1px solid #2e2e2e;
  border-radius: 9px;
  color: #fff;
  font-size: 15px;
  margin-bottom: 10px;
  outline: none;
}
.login-card input:focus { border-color: #0057ff; }
.login-card input::placeholder { color: #444; }
.login-card button {
  width: 100%;
  padding: 12px;
  background: #0057ff;
  color: #fff;
  border: none;
  border-radius: 9px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.login-card button:active { background: #0049d9; }
#login-error { color: #f55; font-size: 13px; margin-top: 10px; display: none; }

/* ── App shell ─────────────────────────────────────────── */
#app { display: none; flex-direction: column; height: 100%; }

/* ── Header ────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 44px;
  background: #080808;
  border-bottom: 1px solid #1c1c1c;
  flex-shrink: 0;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #2a2a2a;
  flex-shrink: 0;
  transition: background 0.3s;
}
.dot.ok  { background: #0f0; box-shadow: 0 0 5px #0f0a; }
.dot.err { background: #f33; box-shadow: 0 0 5px #f33a; }
#freq-range { font-size: 12px; color: #666; flex: 1; letter-spacing: 0.02em; }
.hbtn {
  padding: 5px 10px;
  background: #161616;
  border: 1px solid #2c2c2c;
  border-radius: 7px;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.hbtn:active { background: #222; }
.hbtn.active { border-color: #ffcc00; color: #ffcc00; }

/* ── Chart ─────────────────────────────────────────────── */
.chart-wrap {
  flex: 1;
  min-height: 0;
  padding: 6px 8px 2px;
  position: relative;
}
#spectrum { width: 100%; height: 100%; }

/* ── Controls ──────────────────────────────────────────── */
.controls {
  padding: 7px 12px;
  background: #080808;
  border-top: 1px solid #1c1c1c;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.controls label { font-size: 11px; color: #666; white-space: nowrap; }
#threshold-slider { flex: 1; accent-color: #ffcc00; cursor: pointer; min-width: 0; }
#threshold-val { font-size: 12px; color: #ffcc00; width: 58px; text-align: right; flex-shrink: 0; }
.csv-btns { display: flex; gap: 5px; flex-shrink: 0; }
.csv-btn {
  padding: 5px 8px;
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  color: #777;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.csv-btn:active { background: #1e1e1e; }
.csv-btn input { display: none; }

/* ── Alerts ────────────────────────────────────────────── */
.alerts {
  flex-shrink: 0;
  border-top: 1px solid #1c1c1c;
  background: #050505;
}
.alerts-hdr {
  background: #0a0a0a;
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 700;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.alerts-hdr:active { background: #111; }
.alerts-chevron {
  font-size: 10px;
  color: #444;
  transition: transform 0.2s;
  margin-left: 6px;
}
.alerts.open .alerts-chevron { transform: rotate(180deg); }
.alerts-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.alerts.open .alerts-body {
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* ── Jump input (header) ───────────────────────────────── */
#jump-inp {
  width: 72px;
  padding: 4px 7px;
  background: #141414;
  border: 1px solid #2e2e2e;
  border-radius: 7px;
  color: #fff;
  font-size: 12px;
  outline: none;
  -moz-appearance: textfield;
  flex-shrink: 0;
}
#jump-inp::-webkit-inner-spin-button,
#jump-inp::-webkit-outer-spin-button { -webkit-appearance: none; }
#jump-inp:focus { border-color: #0057ff; }
#jump-inp::placeholder { color: #444; }

/* landscape: shrink everything, hide alerts */
@media (orientation: landscape) and (max-height: 520px) {
  header { height: 36px; }
  .controls { padding: 4px 10px; }
.alerts { display: none; }
  .chart-wrap { padding: 2px 6px; }
}
#alert-badge {
  background: #c0392b;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  display: none;
}
#alert-badge.on { display: inline; }
.alert-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid #0e0e0e;
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.alert-row:active { background: #111; }
.a-freq { color: #5af; font-weight: 600; width: 82px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.a-pwr  { color: #f55; width: 52px; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.a-bw   { color: #555; flex: 1; font-size: 11px; }
.no-alert { padding: 14px 12px; color: #2a2a2a; font-size: 12px; text-align: center; }

/* === View shell === */
#view-root { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* === Card screens (login, events, settings) === */
.card-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: #000; overflow-y: auto; }
.card { width: min(420px, 100%); padding: 28px 22px; background: #0d0d0d; border: 1px solid #2a2a2a; border-radius: 14px; }
.card h1 { font-size: 22px; color: #fff; margin-bottom: 4px; }
.card p  { font-size: 13px; color: #555; margin-bottom: 18px; }
.card h3 { color: #aaa; font-size: 13px; }
.card input, .card select { width: 100%; padding: 11px 13px; background: #141414; border: 1px solid #2e2e2e; border-radius: 9px; color: #fff; font-size: 15px; margin-bottom: 10px; outline: none; }
.card input:focus { border-color: #0057ff; }
.card button { width: 100%; padding: 12px; background: #0057ff; color: #fff; border: none; border-radius: 9px; font-size: 16px; font-weight: 600; cursor: pointer; }
.card button.secondary { background: #1a1a1a; border: 1px solid #2c2c2c; }
.card .err { color: #f55; font-size: 13px; margin-top: 8px; }

/* === Events list === */
.events-list { list-style: none; padding: 0; margin-bottom: 14px; }
.events-list li { padding: 14px; background: #0d0d0d; border: 1px solid #2a2a2a; border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.events-list li:active { background: #161616; }
