/* =====================================================================
   Calgary GNSS Signal Quality Monitor — Stylesheet
   ===================================================================== */

:root {
  --bg: #070b10;
  --surface: #0d1520;
  --panel: #111d2e;
  --border: #1e3a5f;
  --accent: #00d4ff;
  --accent2: #00ff9d;
  --accent3: #ff6b35;
  --text: #c8e0f4;
  --text-dim: #5a7a9a;
  --good: #00ff9d;
  --mid: #ffd700;
  --bad: #ff4444;
  --nosig: #3a3a5c;
  --font-mono: 'Share Tech Mono', monospace;
  --font-ui: 'Rajdhani', sans-serif;
}

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

html, body {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
}

/* =====================================================================
   HEADER
   ===================================================================== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 16px; }

.logo-mark {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  animation: pulse-logo 3s ease-in-out infinite;
}
@keyframes pulse-logo {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}

.header-title h1 {
  font-size: 20px; font-weight: 700; letter-spacing: 3px;
  text-transform: uppercase; color: var(--accent);
  line-height: 1.1;
}
.header-title p {
  font-size: 11px; letter-spacing: 2px; color: var(--text-dim);
  text-transform: uppercase; font-family: var(--font-mono);
}

.header-status { display: flex; gap: 24px; align-items: center; }
.status-item   { text-align: center; }

.status-label {
  font-size: 10px; color: var(--text-dim); letter-spacing: 2px;
  text-transform: uppercase; font-family: var(--font-mono);
}
.status-value {
  font-size: 15px; font-weight: 600; color: var(--accent);
  font-family: var(--font-mono);
}

.live-dot {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--accent2); font-family: var(--font-mono);
  letter-spacing: 1px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent2);
  animation: blink 1.5s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.1} }

/* =====================================================================
   LAYOUT
   ===================================================================== */
.app {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 68px);
  position: relative;
  overflow: hidden;
  /* Creates a stacking context so dock-btn z-index beats Leaflet layers */
  isolation: isolate;
}

/* =====================================================================
   SIDEBAR
   ===================================================================== */
.sidebar {
  width: 320px;
  min-width: 180px;
  max-width: 520px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  transition: width 0.25s ease, min-width 0.25s ease;
  z-index: 10;
  /* Themed scrollbar — Firefox */
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--surface);
}
.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  border-right: none;
  overflow: hidden;
}

/* Themed scrollbar — WebKit */
.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: var(--surface); }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.sidebar-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 11px; font-weight: 600; letter-spacing: 3px;
  text-transform: uppercase; color: var(--text-dim);
  font-family: var(--font-mono);
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::before {
  content: '';
  width: 3px; height: 14px;
  background: var(--accent);
}

/* =====================================================================
   DESKTOP RESIZE HANDLE + DOCK BUTTON
   ===================================================================== */
/* The resize-handle is z-index:200 within .app's isolated stacking context,
   which beats .map-container's z-index:20 — so dock-btn is always on top. */
.resize-handle {
  width: 20px;
  flex-shrink: 0;
  position: relative;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  /* Themed dark navy strip — visible, intentional, fits the UI */
  background: linear-gradient(to right, #0b1926 0%, #0e2038 50%, #0b1926 100%);
  border-left:  1px solid var(--border);
  border-right: 1px solid #0a3d5c;
  transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.dragging {
  background: linear-gradient(to right, #0d1f32 0%, #112644 50%, #0d1f32 100%);
  border-right-color: var(--accent);
}

/* Grip dots — three vertically stacked dots to signal draggability */
.resize-handle::after {
  content: '';
  display: block;
  width: 4px;
  height: 36px;
  background-image: radial-gradient(circle, var(--text-dim) 1.5px, transparent 1.5px);
  background-size: 4px 8px;
  background-repeat: repeat-y;
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 0.15s;
}
.resize-handle:hover::after,
.resize-handle.dragging::after { opacity: 0.85; }

/* Remove the old ::before line — grip dots replace it */
.resize-handle::before { display: none; }

.dock-btn {
  position: absolute;
  top: 50%;
  /* right:0 puts the button's right edge flush at the resize-handle/map seam.
     The button sits on the resize-handle side, not overlapping into the map.
     resize-handle z-index:200 ensures it always paints above map-container z-index:20. */
  right: -20px;
  left: auto;
  transform: translateY(-50%);
  z-index: 10;              /* within resize-handle's own stacking context */
  width: 36px;
  height: 52px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 6px 6px 0;   /* flat left edge, rounded right — hugs the seam */
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  font-family: var(--font-mono);
  line-height: 1;
}
.dock-btn:hover {
  background: var(--panel);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(0, 212, 255, 0.25);
}

/* =====================================================================
   METRIC BUTTONS
   ===================================================================== */
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-btn {
  padding: 12px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  text-transform: uppercase;
}
.metric-btn:hover            { border-color: var(--accent); color: var(--text); }
.metric-btn.active           { background: rgba(0,212,255,0.12); border-color: var(--accent); color: var(--accent); box-shadow: 0 0 12px rgba(0,212,255,0.15); }
.metric-btn--blocked.active  { background: rgba(255,68,68,0.15) !important; border-color: #ff4444 !important; color: #ff4444 !important; animation: pulse-blocked 1.5s ease-in-out infinite; }

@keyframes pulse-blocked {
  0%,100% { box-shadow: 0 0 8px rgba(255,68,68,0.3); }
  50%     { box-shadow: 0 0 20px rgba(255,68,68,0.7); }
}

.metric-btn .btn-label { font-size: 15px; font-weight: 700; display: block; }
.metric-btn .btn-sub   { font-size: 9px; color: inherit; letter-spacing: 1px; opacity: 0.7; }

/* =====================================================================
   TIME SLIDER
   ===================================================================== */
.time-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.time-label {
  font-size: 28px;
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 400;
  letter-spacing: 2px;
}
.time-date {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-align: right;
}

.slider-container { position: relative; padding: 6px 0; }

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0,212,255,0.5);
}

.time-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
}

.play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  margin-top: 12px;
  background: rgba(0,212,255,0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}
.play-btn:hover   { border-color: var(--accent); background: rgba(0,212,255,0.14); }
.play-btn.playing { color: var(--accent2); border-color: var(--accent2); }

/* =====================================================================
   COLOUR LEGEND
   ===================================================================== */
.legend-bar {
  height: 12px;
  border-radius: 4px;
  margin: 8px 0;
  background: linear-gradient(to right,
    #00ff9d 0%, #7eff00 16%, #ffd700 33%,
    #ff9500 50%, #ff4444 66%, #cc0000 83%, #880000 100%
  );
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
}
.legend-no-sig {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-no-sig-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  background: var(--nosig);
  border: 1px solid #555;
}

/* =====================================================================
   STATS
   ===================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}
.stat-name {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  font-family: var(--font-mono);
  margin-bottom: 4px;
}
.stat-val      { font-size: 18px; font-weight: 700; font-family: var(--font-mono); color: var(--accent); }
.stat-val.good { color: var(--good); }
.stat-val.mid  { color: var(--mid); }
.stat-val.bad  { color: var(--bad); }

/* =====================================================================
   HOVER / POINT DETAIL
   ===================================================================== */
.hover-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.point-detail { padding: 18px 20px; flex: 1; }
.point-empty  {
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1.8;
  margin-top: 4px;
}
.point-vals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.pv-item   { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 8px 10px; }
.pv-label  { font-size: 9px; color: var(--text-dim); font-family: var(--font-mono); letter-spacing: 1px; }
.pv-value  { font-size: 16px; font-weight: 700; font-family: var(--font-mono); color: var(--accent); margin-top: 2px; }
.pv-coords { margin-top: 8px; font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); line-height: 1.8; }

/* =====================================================================
   MAP
   ===================================================================== */
.map-container {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  z-index: 20;            /* explicit: sidebar(10) < map-container(20) < resize-handle(200) */
}

#map {
  width: 100%;
  height: 100%;
  background: #0a0f1a;
}

/* Leaflet overrides */
.leaflet-tile-pane          { filter: brightness(0.45) saturate(0.4) hue-rotate(190deg); }
.leaflet-control-attribution { display: none; }
.leaflet-control-zoom a     { background: var(--surface) !important; color: var(--accent) !important; border-color: var(--border) !important; }
.leaflet-overlay-pane canvas { pointer-events: none; }

/* =====================================================================
   MAP OVERLAY TAGS + SCAN LINE
   ===================================================================== */
.map-overlay-top {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  gap: 10px;
  flex-direction: column;
  align-items: center;
}
.overlay-tag {
  background: rgba(7,11,16,0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
}
.overlay-tag span { color: var(--accent); }

.scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(0,212,255,0.3), transparent);
  pointer-events: none;
  z-index: 500;
  animation: scan 6s linear infinite;
}
@keyframes scan { from { top: 0%; } to { top: 100%; } }

/* =====================================================================
   LOADING OVERLAY
   ===================================================================== */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.5s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 3px;
  text-transform: uppercase;
}
.loading-bar-wrap {
  width: 280px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  background: linear-gradient(to right, var(--accent), var(--accent2));
  animation: load-progress 1.8s ease-in-out forwards;
  border-radius: 2px;
}
@keyframes load-progress { from { width: 0%; } to { width: 100%; } }

.loading-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  white-space: pre-line;
  text-align: center;
  max-width: 520px;
  line-height: 1.9;
}

/* =====================================================================
   MOBILE  (≤ 600px)
   ===================================================================== */
@media (max-width: 600px) {
    /* Compact header */
    header {
        padding: 7px 12px;
        gap: 6px;
    }

    .logo-mark {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .header-title h1 {
        font-size: 13px;
        letter-spacing: 1px;
    }

    .header-title p {
        display: none;
    }

    .status-item {
        display: none;
    }

    .live-dot {
        font-size: 10px;
        gap: 5px;
    }

    .dot {
        width: 6px;
        height: 6px;
    }

    /* Vertical stack */
    .app {
        flex-direction: column;
        height: calc(100vh - 44px); /* Fallback for older IOS */
        height: calc(100dvh - 44px);
    }

    /* Hide desktop-only elements */
    .resize-handle {
        display: none;
    }

    .dock-btn {
        display: none;
    }

    /* Map takes remaining space after sidebar */
    .map-container {
        flex: 1;
        min-height: 0;
        order: 1;
        position: relative; /* anchor for the button */
        z-index: 20;
    }

    /* Button floats inside the map, near the bottom with breathing room */
    .mobile-dock-btn {
        position: fixed;
        bottom: calc(44vh + 2vh);
        left: 50%;
        transform: translateX(-50%);
        z-index: 1000; /* above leaflet tiles */
        width: auto;
        min-width: 160px;
        padding: 9px 20px;
        margin: 0;
        background: rgba(13, 21, 32, 0.92);
        border: 1px solid var(--accent);
        border-radius: 20px; /* pill shape — feels native on mobile */
        color: var(--accent);
        font-family: var(--font-mono);
        font-size: 11px;
        letter-spacing: 2px;
        cursor: pointer;
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
        box-shadow: 0 0 16px rgba(0, 212, 255, 0.2);
        transition: border-color 0.2s, box-shadow 0.2s, bottom 0.3s ease-in-out;
        flex-shrink: 0;
    }

        .mobile-dock-btn:hover {
            border-color: var(--accent);
            box-shadow: 0 0 24px rgba(0, 212, 255, 0.4);
        }

    /* Sidebar is a bottom sheet — sits below the map, never overlaps it */
    .sidebar {
        order: 2;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none;
        height: 44vh;
        min-height: 0;
        max-height: 78vh;
        border-right: none;
        border-top: 2px solid var(--border);
        border-radius: 14px 14px 0 0;
        overflow: hidden;
        flex-shrink: 0;
        transition: height 0.28s ease;
        position: relative;
        display: flex;
        flex-direction: column;
    }

        /* Collapsed = fully hidden, map takes all the space */
        .sidebar.collapsed {
            height: 0 !important;
            border-top: none;
        }

        /* Drag pill */
        .sidebar::before {
            content: '';
            display: block;
            width: 38px;
            height: 4px;
            background: var(--border);
            border-radius: 2px;
            margin: 8px auto 0;
            flex-shrink: 0;
        }

    /* Inner scroll area */
    .sidebar-scroll {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        transition: opacity 0.2s;
    }

    .sidebar.collapsed .sidebar-scroll {
        opacity: 0;
        pointer-events: none;
    }

    /* Touch-drag zone */
    .mobile-resize-handle {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 22px;
        cursor: ns-resize;
        z-index: 40;
    }
}

/* Hide mobile-only elements on desktop */
@media (min-width: 601px) {
    .mobile-dock-btn {
        display: none;
    }

    .mobile-resize-handle {
        display: none;
    }
}