:root {
  --bg:       #1c1c1e;
  --bg2:      #2c2c2e;
  --bg3:      #3a3a3c;
  --blue:     #4da6ff;
  --blue-bg:  #0d2d4a;
  --green:    #4dcc77;
  --green-bg: #0d3d1a;
  --orange:   #ff8c4d;
  --orng-bg:  #3d1a0d;
  --text:     #ffffff;
  --sub:      #888888;
  --dim:      #48484a;
  --border:   #2c2c2e;
  --rb-blue:  #1a5c9e;
  --rb-orange:#b05a00;
  --rb-teal:  #0a6b6b;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ──────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
}
.screen.active { display: flex; }

/* ── LOGIN ────────────────────────────────────────────────────────── */
#scr-login {
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: max(env(safe-area-inset-top), 40px) 36px
           max(env(safe-area-inset-bottom), 32px);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}
.login-logo-icon {
  width: 64px; height: 64px;
  background: linear-gradient(145deg, #1a5c9e, #0d3060);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(26, 92, 158, .5);
  margin-bottom: 4px;
}
.login-logo-icon svg {
  width: 36px; height: 36px;
  fill: white;
}
.login-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.login-logo-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--sub);
}

#login-form {
  width: 100%;
  display: flex; flex-direction: column; gap: 12px;
}
.field {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: 14px; padding: 15px 16px;
  color: var(--text); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field::placeholder { color: var(--dim); }
.field:focus { outline: none; border-color: #1a5c9e; }

.err {
  min-height: 18px;
  font-size: 13px; color: #ff453a; text-align: center;
}
.btn-primary {
  width: 100%;
  background: #1a5c9e; color: #fff;
  border: none; border-radius: 14px; padding: 16px;
  font-size: 16px; font-weight: 600;
  -webkit-appearance: none; cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:disabled { opacity: .5; }
.btn-primary:active   { opacity: .8; }
.hint { font-size: 12px; color: var(--dim); text-align: center; }

/* ── PASSKEY ── */
.m-pk-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0;
}
.m-pk-divider span:first-child,
.m-pk-divider span:last-child {
  flex: 1; height: 1px; background: var(--bg3);
}
.m-pk-or { font-size: 11px; color: var(--sub); white-space: nowrap; }
.m-pk-btn {
  width: 100%;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--bg3); border-radius: 14px; padding: 15px;
  font-size: 15px; font-weight: 500;
  -webkit-appearance: none; cursor: pointer;
  transition: opacity .15s;
}
.m-pk-btn:active { opacity: .8; }

/* ── ACCOUNT GEAR MENU ───────────────────────────────────────────── */
.acct-wrap { position: relative; }
.acct-btn {
  background: none; border: none; padding: 4px 6px;
  font-size: 18px; color: var(--sub); cursor: pointer; line-height: 1;
  border-radius: 6px; transition: color .15s;
}
.acct-btn:active { color: var(--text); }
.acct-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: 12px; padding: 6px;
  min-width: 190px; z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.acct-item {
  display: block; width: 100%; background: none; border: none;
  color: var(--text); font-size: 14px; font-weight: 500;
  padding: 10px 14px; text-align: left;
  border-radius: 8px; cursor: pointer;
}
.acct-item:active { background: var(--bg3); }

/* ── RADIO SELECT ─────────────────────────────────────────────────── */
#scr-radios {
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}
.nav-title { font-size: 22px; font-weight: 700; }
.nav-right  { display: flex; align-items: center; gap: 10px; }
.user-chip  {
  font-size: 13px; color: var(--sub);
  background: var(--bg2); padding: 6px 11px; border-radius: 9px;
}
.sign-out-btn {
  font-size: 13px; color: #ff453a;
  background: none; border: none; cursor: pointer; padding: 4px 0;
}

.rsel-body {
  flex: 1; overflow-y: auto;
  padding: 8px 20px max(env(safe-area-inset-bottom), 16px);
  display: flex; flex-direction: column; gap: 12px;
}
.sect-label {
  font-size: 12px; color: var(--dim);
  text-transform: uppercase; letter-spacing: .07em; padding: 4px 2px;
}
.rcard {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg2); border: 1px solid var(--bg3);
  border-radius: 17px; padding: 18px;
  width: 100%; text-align: left; cursor: pointer;
  -webkit-appearance: none; transition: background .1s;
}
.rcard:active  { background: var(--bg3); }
.rcard.loading { opacity: .6; pointer-events: none; }
.rbadge {
  width: 50px; height: 50px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: #fff;
  line-height: 1.2; text-align: center; padding: 4px;
}
.rbadge.blue   { background: var(--rb-blue);   box-shadow: 0 4px 14px rgba(26,92,158,.4); }
.rbadge.orange { background: var(--rb-orange);  box-shadow: 0 4px 14px rgba(176,90,0,.4); }
.rbadge.teal   { background: var(--rb-teal);    box-shadow: 0 4px 14px rgba(10,107,107,.4); }
.rinfo         { flex: 1; }
.rname         { font-size: 15px; font-weight: 600; color: var(--text); }
.rsub          { font-size: 12px; color: var(--sub); margin-top: 2px; }
.rarrow        { color: var(--dim); font-size: 22px; line-height: 1; }
.footer-note   { font-size: 11px; color: var(--dim); text-align: center; margin-top: auto; padding-top: 8px; }

/* ── CHANNEL LIST ─────────────────────────────────────────────────── */
#scr-channels {
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.ch-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.back-btn {
  color: var(--blue); font-size: 14px; font-weight: 500;
  background: none; border: none; cursor: pointer; padding: 0;
  -webkit-appearance: none; white-space: nowrap;
}
.back-btn:active { opacity: .7; }
.ch-header-mid { flex: 1; text-align: center; }
.locate-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  font-size: 22px; min-width: 72px; text-align: right;
  -webkit-appearance: none; line-height: 1;
  transition: opacity 0.15s, filter 0.15s;
}
.locate-btn:active { opacity: 0.6; }
.locate-btn.active { filter: drop-shadow(0 0 5px #1a7fe8); }
.rh-badge {
  display: inline-block;
  font-size: 12px; font-weight: 700; color: #fff;
  padding: 3px 10px; border-radius: 7px; letter-spacing: -.2px;
}
.rh-badge.blue   { background: var(--rb-blue);   }
.rh-badge.orange { background: var(--rb-orange);  }
.rh-badge.teal   { background: var(--rb-teal);    }
.ch-count        { font-size: 11px; color: var(--sub); margin-top: 2px; }

.col-hdrs {
  display: grid;
  grid-template-columns: 36px 1fr 92px 74px;
  padding: 6px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--bg3);
  flex-shrink: 0;
}
.ch-hdr {
  font-size: 10px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .06em;
}
.ch-hdr:not(:first-child) { text-align: center; }

.ch-rows {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ch-row {
  display: grid;
  grid-template-columns: 36px 1fr 92px 74px;
  padding: 9px 12px;
  border-bottom: 1px solid #222;
  align-items: center;
  gap: 4px;
}
.cn { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.cn.rpt { color: #f4a259; }

.nm {
  background: var(--bg2); border-radius: 8px;
  padding: 6px 9px; font-size: 12.5px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; display: flex; align-items: center; gap: 5px;
  min-width: 0;
}
.nm:active { background: var(--bg3); }
.tt {
  font-size: 9px; color: var(--sub);
  background: var(--bg3); padding: 2px 4px; border-radius: 4px;
  flex-shrink: 0;
}

.fr {
  background: var(--blue-bg); border: 1px solid #1a5c9e44;
  border-radius: 8px; padding: 5px 6px;
  font-size: 10.5px; font-weight: 500; color: var(--blue);
  text-align: center; cursor: pointer; white-space: nowrap;
}
.fr:active { opacity: .7; }

.tp { border-radius: 8px; padding: 5px 6px; font-size: 10.5px; font-weight: 600; text-align: center; cursor: pointer; white-space: nowrap; }
.tp:active { opacity: .7; }
.tc { background: var(--green-bg);  border: 1px solid #1a773355; color: var(--green);  }
.td { background: var(--orng-bg);   border: 1px solid #cc5a1a55; color: var(--orange); }
.tn { background: #2a2a2c;          border: 1px solid var(--bg3); color: var(--dim);   }

/* ── POPUP ────────────────────────────────────────────────────────── */
.popup-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: flex-end;
  padding-bottom: env(safe-area-inset-bottom);
  transition: opacity .25s;
}
.popup-overlay.hidden { opacity: 0; pointer-events: none; }
.popup-overlay.open   { opacity: 1; pointer-events: auto; }

.popup-sheet {
  width: 100%;
  background: var(--bg2);
  border-radius: 22px 22px 0 0;
  padding: 10px 20px 28px;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1);
}
.popup-overlay.open .popup-sheet { transform: translateY(0); }

.sh-handle {
  width: 36px; height: 4px; background: var(--bg3);
  border-radius: 2px; margin: 0 auto 14px;
}
.sh-hdr {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 14px;
}
.sh-title { font-size: 17px; font-weight: 700; }
.sh-sub   { font-size: 12px; color: var(--sub); margin-top: 2px; }
.sh-x {
  width: 28px; height: 28px; background: var(--bg3);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: var(--sub); font-size: 13px; cursor: pointer; flex-shrink: 0;
}
.sh-x:active { opacity: .7; }

.pgrid  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pgrid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.pf     { background: var(--bg); border-radius: 11px; padding: 10px 12px; }
.pgrid3 .pf { padding: 8px 10px; }
.pfull { grid-column: 1 / -1; }
.pfl   { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.pfv   { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.pfv.blue   { color: var(--blue);   }
.pfv.green  { color: var(--green);  }
.pfv.orange { color: var(--orange); }
.pfv.dim    { color: var(--sub); font-weight: 400; }

.pnotes {
  background: var(--bg); border-radius: 11px;
  padding: 12px; margin-top: 10px;
}
.pntext { font-size: 13px; color: #ccc; line-height: 1.6; }

/* ── MAP ──────────────────────────────────────────────────────────── */
.map-badge {
  background: #0d2d4a;
  box-shadow: 0 4px 14px rgba(13,45,74,.5);
}
#scr-map {
  padding-top: env(safe-area-inset-top);
}
#map-wrap {
  flex: 1;
  position: relative;
  min-height: 0;       /* lets flex child shrink below content size */
  overflow: hidden;
}
.map-no-results {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(13,17,23,.82); border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px; padding: 14px 22px;
  color: #e2e8f0; font-size: 14px; font-weight: 500;
  pointer-events: none; z-index: 500; white-space: nowrap;
}
#leaflet-map {
  width: 100%;
  height: 100%;
}
/* Leaflet dark theme tweaks */
.leaflet-container {
  background: #2c2c2e;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
}
.leaflet-control-attribution {
  background: rgba(28,28,30,.8) !important;
  color: #888 !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: #4da6ff !important; }
.leaflet-control-zoom a {
  background: #2c2c2e !important;
  color: #ccc !important;
  border-color: #3a3a3c !important;
}
.leaflet-control-zoom a:hover { background: #3a3a3c !important; }

.map-legend {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 48px);
  right: 10px;
  background: rgba(28,28,30,.92);
  border: 1px solid #3a3a3c;
  border-radius: 12px;
  padding: 8px 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.leg-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: #ccc;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.18s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.map-legend.filtered .leg-item         { opacity: 0.45; }
.map-legend.filtered .leg-item.active  { opacity: 1; color: #fff; }
.leg-emoji {
  font-size: 16px; line-height: 1; flex-shrink: 0;
}
.leaflet-div-icon {
  background: transparent !important;
  border: none !important;
}
.map-emoji-marker {
  width: 32px; height: 32px;
  font-size: 22px; line-height: 32px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.map-antenna-icon {
  width: 30px; height: 30px;
  object-fit: contain;
  display: block;
}
.leg-antenna-icon {
  width: 18px; height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}

/* Raise popup above Leaflet controls when on map screen */
.popup-overlay { z-index: 1000; }

/* Coverage polygon tooltip */
.coverage-tip {
  background: rgba(13,17,23,.85);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  white-space: nowrap;
}

/* ── LANDSCAPE ────────────────────────────────────────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  #scr-login {
    flex-direction: row; flex-wrap: wrap; gap: 14px;
    justify-content: center; align-items: center;
  }
  .app-icon  { width: 60px; height: 60px; font-size: 20px; }
  .app-title { font-size: 20px; }
  .app-sub   { display: none; }
  #login-form { max-width: 320px; }

  .col-hdrs, .ch-row {
    grid-template-columns: 36px 1fr 108px 88px;
  }

}

/* Channel detail sheet — pull in 5% from each side in landscape so the
   iPhone status bar / notch area doesn't overlap the content */
@media (orientation: landscape) {
  .popup-sheet {
    width: 90%;
    margin-left: auto;
    margin-right: auto;
    border-radius: 30px;
  }
}
