/* ============================================================
   CP-Tracker dashboard — stylesheet
   Dark operations-room identity:
     background  #0D1318  (deep blue-black)
     panels      #141C24
     lines       #243140
     text        #DCE6EE / muted #7C8B99
     accent      #46C8B4  (signal teal — primary actions)
     status      pending #F2B33D · ok #46D183 · stale #F2B33D
                 offline #5B6B7A · rejected #E5484D
   Typography:
     Saira Condensed — headings / brand (operational, compact)
     Inter           — interface text
     IBM Plex Mono   — data values (times, coords, battery)
   ============================================================ */

/* ---- Design tokens ---------------------------------------- */
:root {
  --bg:        #0D1318;
  --panel:     #141C24;
  --panel-2:   #1B2630;   /* hover / nested surfaces */
  --line:      #243140;
  --text:      #DCE6EE;
  --muted:     #7C8B99;
  --accent:    #46C8B4;
  --accent-dk: #2E9486;
  --ok:        #46D183;
  --warn:      #F2B33D;
  --off:       #5B6B7A;
  --danger:    #E5484D;

  --font-display: "Saira Condensed", sans-serif;
  --font-body:    "Inter", sans-serif;
  --font-mono:    "IBM Plex Mono", monospace;

  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

button, select {
  font: inherit;
  cursor: pointer;
  color: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

/* ---- Buttons ----------------------------------------------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 4px;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231E;          /* dark text on teal for contrast */
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }

.btn-mini {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border-radius: 3px;
  line-height: 1.2;
}
.btn-mini:hover { border-color: var(--accent-dk); background: var(--panel); }
.btn-mini.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231E;
}

/* Small approve / reject buttons inside pending cards */
.btn-approve, .btn-reject {
  padding: 5px 10px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.btn-approve { background: var(--ok); color: #062B16; }
.btn-approve:hover { filter: brightness(1.1); }
.btn-reject { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-reject:hover { background: rgba(229, 72, 77, 0.12); }

/* ---- Brand mark: rotating radar-sweep square ---------------
   The one decorative signature: a small square with a conic
   sweep, evoking a radar ping. Used on login + top bar.       */
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 6px;
  display: inline-block;
  background:
    conic-gradient(from 0deg, rgba(70,200,180,0) 0deg,
                   rgba(70,200,180,0.85) 40deg,
                   rgba(70,200,180,0) 80deg),
    radial-gradient(circle at center, #10242C 0 100%);
  border: 1px solid var(--accent-dk);
  animation: sweep 4s linear infinite;
}
.brand-mark.small { width: 22px; height: 22px; border-radius: 4px; }

@keyframes sweep { to { filter: hue-rotate(0deg); transform: rotate(360deg); } }

/* Respect users who prefer no motion */
@media (prefers-reduced-motion: reduce) {
  .brand-mark { animation: none; }
}

/* ---- Login screen ------------------------------------------ */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1100px 600px at 70% -10%, #14222C 0%, var(--bg) 60%);
}

.login-card {
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}

.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 3px;
  margin-top: 10px;
}
.login-sub { color: var(--muted); font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; color: var(--muted); }
.field input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login-error { color: var(--danger); font-size: 13px; }

/* ---- App layout -------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* mobile browsers: exclude dynamic URL bar */
}

#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-title {
  font-family: var(--font-display);
  font-weight: 700; font-size: 19px; letter-spacing: 2px;
}
.topbar-org { color: var(--muted); font-size: 12px; }

.topbar-stats { display: flex; gap: 24px; margin-left: auto; }
.stat { text-align: right; }
.stat-value {
  font-family: var(--font-mono);
  font-size: 17px; font-weight: 500;
  display: block; line-height: 1.1;
}
.stat-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted);
}

#workspace {
  display: flex;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}

/* ---- Sidebar ------------------------------------------------ */
#sidebar {
  width: 300px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.panel { border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; }

.panel-title {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px 8px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 10px;
}
.panel-title-row .panel-title { padding-bottom: 8px; }

.panel-hint {
  color: var(--muted);
  font-size: 11px;
  padding: 0 14px 8px;
  line-height: 1.35;
}

.roster-actions { display: flex; align-items: center; gap: 6px; }

.panel-body { padding: 0 10px 12px; }

/* Pending approval cards */
.pending-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);   /* amber = waiting */
  border-radius: 4px;
  padding: 10px;
  margin-bottom: 8px;
}
.pending-name { font-weight: 600; }
.pending-meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.pending-actions { display: flex; gap: 8px; }

/* Roster rows */
.roster-row {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 6px;
  border-radius: 4px;
  border: 0; width: 100%;
  background: transparent; color: var(--text);
  text-align: left;
}
.roster-row:hover { background: var(--panel-2); }
.roster-row.hidden-map { opacity: 0.55; }

.roster-map-toggle {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
.roster-map-toggle:disabled { cursor: not-allowed; opacity: 0.35; }

/* Freshness dot — same colors as the map markers */
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--off);
}
.dot.ok    { background: var(--ok); }
.dot.stale { background: var(--warn); }
.dot.off   { background: var(--off); }
.dot.rejected { background: var(--danger); }

.roster-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-callsign { font-family: var(--font-mono); font-size: 11px; color: var(--accent); }
.roster-age { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.empty-note { color: var(--muted); font-size: 12px; padding: 4px 6px 8px; }

/* ---- Map ---------------------------------------------------- */
#map-wrap {
  /* flex-basis 0% — required when children are position:absolute
     (no in-flow content), otherwise height collapses on mobile. */
  flex: 1 1 0%;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  background: #10181F;
  z-index: 1;
}

#map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.map-toolbar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  white-space: nowrap;
}

.map-select {
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%237C8B99' d='M1 1l4 4 4-4'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 28px 6px 10px;
  min-width: 72px;
}
.map-select:hover { border-color: var(--accent-dk); }
.map-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Leaflet zoom sits below our toolbar */
.leaflet-top.leaflet-left { margin-top: 8px; margin-left: 8px; }

/* Custom marker: callsign badge + freshness ring */
.op-marker {
  display: flex; flex-direction: column; align-items: center;
  transform: translate(-50%, -100%);
}
.op-badge {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 600;
  background: var(--panel);
  border: 1.5px solid var(--ok);
  color: var(--text);
  padding: 2px 6px; border-radius: 3px;
  white-space: nowrap;
}
.op-badge.stale { border-color: var(--warn); }
.op-badge.off   { border-color: var(--off); color: var(--muted); }
.op-pin {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg);
  margin-top: 2px;
}
.op-pin.stale { background: var(--warn); }
.op-pin.off   { background: var(--off); }

/* Leaflet popup tuned to the dark theme */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line);
}
.popup-mono { font-family: var(--font-mono); font-size: 12px; }

/* ---- Small screens: sidebar collapses on top ---------------- */
@media (max-width: 760px) {
  #topbar { flex-wrap: wrap; gap: 10px; padding: 8px 12px; }
  .topbar-stats { margin-left: 0; width: 100%; justify-content: flex-end; }

  #workspace { flex-direction: column; }

  #sidebar {
    flex: 0 0 auto;
    width: 100%;
    max-height: 38vh;
    max-height: 38dvh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #map-wrap {
    flex: 1 1 0%;
    min-height: 200px;
  }

  #map-controls {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
    justify-content: space-between;
  }

  .map-toolbar-label { font-size: 9px; }
}
