/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:       #e8eaf0;
  --surface:  rgba(255, 255, 255, 0.97);
  --surface2: rgba(0, 0, 0, 0.05);
  --surface3: rgba(0, 0, 0, 0.02);
  --border:   rgba(0, 0, 0, 0.10);
  --border2:  rgba(0, 0, 0, 0.18);
  --text:     #1a1c22;
  --muted:    #3e4555;
  --amber:    #7a4d00;
  --sky:      #003d82;
  --green:    #004d25;
  --red:      #960010;
}

/* ── Base ──────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
}

#map { height: calc(100vh - 56px); }

/* ── Navbar ────────────────────────────────────────────── */
#topnav {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--border2);
  box-shadow: 0 1px 0 rgba(180,120,0,0.15), 0 2px 12px rgba(0,0,0,0.12);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.brand-badge {
  background: var(--amber);
  color: #000;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
}
.dual-clock {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Courier New', monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
.cdt-part {
  color: var(--amber);
}
.clock-sep {
  color: var(--muted);
}
.utc-part {
  color: var(--green);
}
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.4s, box-shadow 0.4s;
}
.nav-status-dot.active  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.nav-status-dot.error   { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.nav-status-dot.warning { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
#nav-callsign {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.06em;
}
.nav-link-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid var(--border2);
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s, border-color 0.15s;
}
.nav-link-btn:hover { color: var(--text); border-color: var(--amber); }

/* ── Panel peek tabs (desktop collapse toggles) ─────── */
.panel-peek-tab {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 998;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border2);
  color: var(--muted);
  cursor: pointer;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 6px;
  font-size: 16px;
  transition: color 0.15s, border-color 0.15s,
              left  0.3s cubic-bezier(0.4,0,0.2,1),
              right 0.3s cubic-bezier(0.4,0,0.2,1);
}
.panel-peek-tab:hover { color: var(--amber); border-color: rgba(255,136,0,0.5); }
.peek-label {
  writing-mode: vertical-rl;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: 'Courier New', monospace;
}
#contacts-peek {
  left: 360px;
  border-left: none;
  border-radius: 0 8px 8px 0;
}
#contacts-peek.panel-closed { left: 0; }
#stats-peek {
  right: 330px;
  border-right: none;
  border-radius: 8px 0 0 8px;
}
#stats-peek.panel-closed { right: 0; }

@media (min-width: 768px) {
  .panel-peek-tab { display: flex; }
}

/* ── Side panels ────────────────────────────────────────── */
#stats-panel {
  position: fixed;
  top: 56px; right: 0; bottom: 0;
  z-index: 1000;
  background: var(--surface);
  border-left: 1px solid var(--border2);
  padding: 14px 12px;
  width: 330px;
  overflow-y: auto;
  font-size: 15px;
  color: var(--text);
  font-family: 'Courier New', monospace;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
#contact-list-panel {
  position: fixed;
  top: 56px; left: 0; bottom: 0;
  z-index: 1000;
  background: var(--surface);
  border-right: 1px solid var(--border2);
  padding: 10px 0 10px 0;
  width: 360px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 768px) {
  #stats-panel, #contact-list-panel {
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
  }
  #stats-panel.panel-collapsed        { transform: translateX(100%); }
  #contact-list-panel.panel-collapsed { transform: translateX(-100%); }
}

/* ── Stats panel internals ──────────────────────────────── */
.sp-station {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.station-callsign {
  font-size: 28px;
  font-weight: 900;
  color: var(--amber);
  letter-spacing: 0.06em;
}
.station-grid {
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.solar-link {
  display: block;
}
.solar-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--border2);
  background: rgba(0,0,0,0.04);
  opacity: 0.92;
  transition: opacity 0.2s;
}
.solar-img:hover { opacity: 1; }
.sp-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}
.sp-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ── Metrics row ────────────────────────────────────────── */
.metrics-row {
  display: flex;
  border: 1px solid var(--border2);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(0,0,0,0.04);
}
.metric-cell {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  border-right: 1px solid var(--border2);
}
.metric-cell:last-child { border-right: none; }
.metric-value {
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.metric-value.clr-green { color: var(--green); }
.metric-value.clr-sky   { color: var(--sky); }
.metric-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* ── Watch status ───────────────────────────────────────── */
.watch-row {
  display: flex;
  align-items: center;
  gap: 7px;
}
.watch-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--muted);
  transition: background 0.4s, box-shadow 0.4s;
}
.watch-dot.active  { background: var(--green); box-shadow: 0 0 6px var(--green), 0 0 14px rgba(0,221,85,0.3); }
.watch-dot.error   { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.watch-dot.warning { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.watch-label { font-size: 14px; color: var(--muted); }
.last-update { font-size: 13px; color: var(--muted); margin-left: auto; }

/* ── Band legend with mini bars ─────────────────────────── */
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-size: 14px;
}
.band-pill {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.04em;
  min-width: 44px;
  text-align: center;
}
.band-bar-track {
  flex: 1;
  height: 5px;
  background: rgba(0,0,0,0.08);
  border-radius: 3px;
  overflow: hidden;
}
.band-bar {
  height: 100%;
  width: 0;
  border-radius: 3px;
  transition: width 0.5s ease, box-shadow 0.5s ease;
}
.band-count {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 2ch;
  text-align: right;
}

/* ── Mode legend ────────────────────────────────────────── */
.mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 14px;
}
.mode-key  { font-weight: 700; min-width: 38px; color: var(--text); }
.mode-lbl  { color: var(--muted); flex: 1; }
.mode-cnt  { font-variant-numeric: tabular-nums; color: var(--text); }

/* ── Stats footer ───────────────────────────────────────── */
#stats-setup-footer {
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  margin-top: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.setup-btn {
  display: block;
  width: 100%;
  padding: 7px;
  text-align: center;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background 0.15s, border-color 0.15s;
  font-family: 'Courier New', monospace;
}
.setup-btn:hover { background: rgba(255,136,0,0.1); border-color: var(--amber); color: var(--amber); }

/* ── Contact list header ────────────────────────────────── */
.cl-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #000;
  padding: 0 14px 8px;
}

/* ── Contact rows ───────────────────────────────────────── */
.contact-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px 10px 15px;
  border-left: 4px solid transparent;
  cursor: pointer;
  transition: background 0.1s;
}
.contact-item:hover { background: var(--surface2); }
.contact-item-alt   { background: var(--surface3); }
.ci-row1 {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.ci-row2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  overflow: hidden;
}
.ci-call {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  color: #000;
}
.ci-mode {
  font-size: 15px;
  color: #000;
  flex-shrink: 0;
}
.ci-dist {
  font-size: 15px;
  color: #000;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  flex-shrink: 0;
}
.ci-band {
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  color: #000;
}
.ci-name {
  font-size: 14px;
  color: #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.ci-row3 {
  display: flex;
}
.ci-loc {
  font-size: 13px;
  color: #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes contact-slide-in {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: translateX(0); }
}
.contact-item-new {
  animation: contact-slide-in 0.35s ease-out forwards;
}

/* ── Map markers ────────────────────────────────────────── */
.fd-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.45);
  color: #fff;
  font-size: 8px;
  font-weight: 900;
  font-family: 'Courier New', monospace;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  transition: opacity 1s ease;
  cursor: pointer;
  line-height: 1;
  text-align: center;
}

@keyframes marker-pop-in {
  0%   { transform: scale(0) rotate(-12deg); opacity: 0; }
  55%  { transform: scale(1.3) rotate(4deg);  opacity: 1; }
  80%  { transform: scale(0.93) rotate(0deg); }
  100% { transform: scale(1)   rotate(0deg); }
}
.fd-marker-new {
  animation: marker-pop-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ── Home station marker ────────────────────────────────── */
.fd-marker-home-wrap {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fd-marker-home {
  font-size: 26px;
  line-height: 1;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255,136,0,0.95), 0 0 4px #000, 0 1px 3px #000;
  position: relative;
  z-index: 1;
}
.fd-marker-home-ring {
  position: absolute;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  top: 50%; left: 50%;
  margin: -15px 0 0 -15px;
  animation: home-ring-pulse 2.5s ease-out infinite;
  pointer-events: none;
}
@keyframes home-ring-pulse {
  0%   { transform: scale(0.5); opacity: 0.85; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ── Popups ─────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.06);
  font-family: 'Courier New', monospace;
  overflow: hidden;
}
.leaflet-popup-tip { background: rgba(255, 255, 255, 0.98); }
.leaflet-popup-content { margin: 10px 14px; }
.popup-accent {
  height: 3px;
  margin: -10px -14px 10px;
  opacity: 0.85;
  border-radius: 0;
}
.popup-call {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1.1;
}
.popup-name { color: #555; margin: 2px 0 6px; font-size: 12px; font-family: system-ui, sans-serif; }
.popup-grid {
  display: inline-block;
  background: rgba(0,0,0,0.07);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  margin-right: 4px;
}
.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.popup-row:last-of-type { border-bottom: none; }
.popup-label { color: var(--muted); }
.popup-dist { font-size: 15px; font-weight: 700; color: var(--sky); }
.popup-source { color: #888; font-size: 10px; margin-top: 5px; font-family: system-ui, sans-serif; }

/* ── Map tile filter ────────────────────────────────────── */
.map-tiles {
  filter: grayscale(0.15) brightness(1.0);
}

/* ── Leaflet overrides ──────────────────────────────────── */
.leaflet-control-attribution {
  background: rgba(255,255,255,0.75) !important;
  color: #555 !important;
  font-size: 9px !important;
}
.leaflet-control-zoom a {
  background: rgba(255,255,255,0.95) !important;
  color: var(--text) !important;
  border-color: var(--border2) !important;
  backdrop-filter: blur(8px);
}
.leaflet-control-zoom a:hover {
  background: rgba(240,240,248,0.95) !important;
  color: var(--amber) !important;
}

/* ── Setup page ─────────────────────────────────────────── */
.form-control {
  background: rgba(255,255,255,0.9) !important;
  border-color: var(--border2) !important;
  color: var(--text) !important;
}
.form-control:focus {
  border-color: var(--amber) !important;
  box-shadow: 0 0 0 .15rem rgba(255,136,0,.2) !important;
}
.text-muted { color: #5a6070 !important; }
.form-label { color: var(--text); font-size: 13px; font-weight: 500; }
.card {
  color: var(--text);
  background: rgba(255,255,255,0.92) !important;
  border-color: var(--border2) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.card-header {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-color: var(--border2) !important;
  background: rgba(0,0,0,0.03) !important;
}

/* ── Mobile layout ──────────────────────────────────────── */
.panel-top-row {
  display: none;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 52px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.panel-handle {
  display: none;
  width: 40px; height: 4px;
  background: rgba(0,0,0,0.2);
  border-radius: 2px;
}
.panel-close-btn {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  background: rgba(255,136,0,0.12);
  border: 1px solid rgba(255,136,0,0.45);
  color: var(--amber);
  border-radius: 5px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.04em;
}
.panel-close-btn:active { background: rgba(255,136,0,0.25); }

#mobile-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 999;
  background: rgba(0,0,0,0.65);
}
#mobile-backdrop.active { display: block; }

/* ── Mobile bottom nav ──────────────────────────────────── */
#mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 64px;
  background: #ffffff;
  border-top: 1px solid var(--border2);
  z-index: 1002;
}
.mnav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Courier New', monospace;
}
.mnav-btn.mnav-active { color: var(--amber); }
.mnav-icon { font-size: 20px; line-height: 1; }
.mnav-label { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

@media (max-width: 767px) {
  #map { height: calc(100vh - 56px - 64px) !important; }

  #stats-panel, #contact-list-panel {
    position: fixed;
    top: auto; bottom: 64px; left: 0 !important; right: 0 !important;
    width: 100%; height: 62vh;
    border-left: none; border-right: none;
    border-top: 1px solid var(--border2);
    border-radius: 12px 12px 0 0;
    transform: translateY(110%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    font-size: 14px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(250, 250, 252, 0.97);
  }
  #stats-panel.panel-open,
  #contact-list-panel.panel-open { transform: translateY(0); }

  .panel-top-row { display: flex; }
  .panel-handle  { display: block; }
  #mobile-nav    { display: flex; }

  .contact-item { padding: 8px 10px 8px 12px; }
  .ci-call { font-size: 17px; }
  .ci-mode, .ci-dist { font-size: 13px; }
  .ci-band, .ci-name { font-size: 12px; }
  .metrics-row { margin: 0; }
  .metric-value { font-size: 28px; }
  .leaflet-popup-content { min-width: unset !important; }
  .leaflet-popup-content-wrapper { max-width: 85vw; }
  .dual-clock { display: none; }
}
