:root {
  --bg: #0b1220;
  --panel: #121b2e;
  --panel-2: #16233a;
  --text: #e7ecf5;
  --muted: #93a1b8;
  --accent: #4fd1c5;
  --accent-2: #f6ad55;
  --danger: #fc8181;
  --ok: #68d391;
  --border: #22304a;
  --radius: 14px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

body {
  margin: 0;
  background: linear-gradient(180deg, #0b1220 0%, #0d1526 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  overscroll-behavior-y: contain;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { font-size: 24px; flex-shrink: 0; }
.brand h1 { margin: 0; font-size: 15px; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--accent); font-weight: 400; font-size: 12px; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; font-size: 17px; cursor: pointer;
}

/* ---------- Views ---------- */
main { padding: 14px 16px 6px; }
.view { display: none; }
.view.active { display: block; }
.view-head h2 { margin: 4px 0 2px; font-size: 19px; }
.view-help { margin: 0 0 12px; font-size: 13px; color: var(--muted); }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0;
}
.toolbar select, .toolbar input[type="search"], #idioma-select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 10px; font-size: 14px;
}
.toolbar input[type="search"] { flex: 1; min-width: 160px; }
#idioma-select { width: 100%; margin-bottom: 4px; }
.checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.count { font-size: 12px; color: var(--muted); margin-left: auto; }

.loc-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 13px; color: var(--muted);
}
.loc-banner.hidden { display: none; }

.band-tabs { display: flex; gap: 8px; margin: 8px 0; }
.band-tab {
  flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; padding: 10px 6px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.band-tab span { display: block; font-size: 10px; font-weight: 400; margin-top: 2px; }
.band-tab.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.freq-form { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.freq-form input[type="number"] {
  flex: 1; min-width: 0; font-size: 20px; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 10px 12px;
}
.freq-unit { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.freq-form button { flex-shrink: 0; }

/* ---------- Cards (lista compacta) ---------- */
.results { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.card:active { background: var(--panel); }
.card-freq { display: flex; flex-direction: column; align-items: flex-start; min-width: 64px; }
.card-freq .f { font-weight: 700; color: var(--accent); font-size: 15px; }
.card-freq .band { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); margin-top: 2px; }
.band-LW { color: #b794f4; } .band-MW { color: #f6ad55; } .band-SW { color: #4fd1c5; }
.band-otro, .band-VLF { color: var(--muted); }

.card-main { flex: 1; min-width: 0; }
.card-main .station { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-main .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.card-side { text-align: right; font-size: 11px; color: var(--muted); min-width: 58px; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.card-side .live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 4px; }
.card-side.off .live-dot { background: var(--muted); }

/* ---------- Favoritos ---------- */
.fav-btn {
  background: none; border: none; cursor: pointer; flex-shrink: 0;
  font-size: 22px; line-height: 1; padding: 4px; color: var(--muted);
}
.fav-btn.active { color: var(--accent-2); }
.fav-stale { color: var(--accent-2); font-style: italic; }

/* ---------- Utilidad genérica ---------- */
.hidden { display: none !important; }

/* ---------- Índice de probabilidad de recepción ---------- */
.rec-chip {
  font-size: 10px; padding: 1px 6px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border);
}
.rec-chip.big { font-size: 13px; padding: 4px 10px; }
.rec-chip.rec-alta { color: var(--ok); border-color: var(--ok); }
.rec-chip.rec-media { color: var(--accent-2); border-color: var(--accent-2); }
.rec-chip.rec-baja { color: var(--danger); border-color: var(--danger); }
.rec-reasons { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- Bloque de referencia (Curiosidades) ---------- */
.ref-block {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin: 10px 0; font-size: 13px; line-height: 1.5; color: var(--text);
}
.ref-block p { margin: 0 0 8px; }
.ref-block .ref-source { margin: 8px 0 0; font-size: 11px; color: var(--muted); }
.ref-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ref-list { margin: 0; padding-left: 18px; }
.ref-list li { margin-bottom: 6px; }

.empty { color: var(--muted); font-size: 14px; padding: 20px 4px; text-align: center; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--panel); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom); height: calc(var(--nav-h) + var(--safe-bottom));
}
.nav-btn {
  flex: 1; min-width: 0; background: none; border: none; color: var(--muted); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10px; cursor: pointer; padding: 6px 2px;
}
.nav-btn .nav-icon { font-size: 18px; }
.nav-btn span:last-child {
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-btn.active { color: var(--accent); }

/* ---------- Botones genéricos ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-size: 14px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); color: #06231f; border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.full { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Radios recomendadas (dentro de ajustes) ---------- */
.radio-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin: 10px 0;
}
.radio-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.radio-name { font-weight: 700; font-size: 14px; }
.radio-card .small-print { margin: 0 0 10px; }
.radio-card .btn { text-decoration: none; text-align: center; display: block; }

/* ---------- Status / meta (dentro de ajustes) ---------- */
.status { font-size: 13px; color: var(--muted); margin-top: 4px; }
.status.loading { color: var(--accent-2); }
.status.ok { color: var(--ok); }
.status.error { color: var(--danger); }
.meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Dialogs ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(560px, 92vw); max-height: 85vh; overflow-y: auto;
  padding: 18px;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h2 { margin-top: 0; font-size: 17px; }
dialog h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 4px 0 8px; }
.settings-block { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.settings-block:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.small-print { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }

.loc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.loc-row.manual label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.loc-row.manual input { width: 84px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 8px; }
.loc-status { font-size: 13px; color: var(--muted); }

dialog textarea {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; font-family: monospace; font-size: 12px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---------- Ficha de detalle ---------- */
#detail-content .d-freq { font-size: 22px; font-weight: 700; color: var(--accent); }
#detail-content .d-station { font-size: 16px; font-weight: 600; margin: 2px 0 10px; }
#detail-content .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.tag {
  font-size: 12px; color: var(--text); background: rgba(255,255,255,0.05);
  border: 1px solid var(--border); padding: 3px 8px; border-radius: 8px;
}
.tag.muted { color: var(--muted); }
.tag.warn { color: var(--accent-2); border-color: var(--accent-2); }
.tag.power { color: var(--ok); }
.tag.day { color: var(--accent-2); }
.tag.night { color: #90cdf4; }
#detail-content .raw { margin-top: 10px; }
#detail-content .raw summary { cursor: pointer; font-size: 12px; color: var(--muted); }
#detail-content .raw code { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); white-space: pre-wrap; word-break: break-all; }
