/* ═══════════════════════════════════════════════════════════════
   SimplexMap — stylesheet
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --sb-width: 300px;
  --bg-dark:  #111827;
  --bg-mid:   #1f2937;
  --bg-light: #374151;
  --accent:   #e94560;
  --accent2:  #0ea5e9;
  --text:     #f3f4f6;
  --text-dim: #9ca3af;
  --border:   #374151;
  --radius:   8px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
}

body {
  display: flex;
}

/* ── Sidebar ─────────────────────────────────────────────────── */

#sidebar {
  width: var(--sb-width);
  min-width: var(--sb-width);
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  z-index: 500;
}

#sidebar-header {
  padding: 14px 16px;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
}

.app-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.app-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.subtitle {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* My station bar */
#my-station-bar {
  padding: 8px 14px;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

#my-station-bar .cs-label { flex: 1; color: var(--text-dim); }
#my-station-bar .cs-label strong { color: var(--accent); font-size: 1rem; }

/* Shared style for the small action buttons inside #my-station-bar */
#btn-edit-station,
#btn-leave {
  font-size: 0.7rem;
  padding: 3px 9px;
  background: var(--bg-light);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
#btn-edit-station { color: #93c5fd; border-color: #1d4ed8; }
#btn-edit-station:hover { background: #1e3a6e; color: #bfdbfe; }
#btn-leave:hover { color: var(--text); background: #4b5563; }

#btn-enroll-open {
  width: 100%;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
#btn-enroll-open:hover { background: #c73a52; }

/* Join bar */
#join-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-dim);
}

#join-bar.hidden { display: none; }

#join-select {
  flex: 1;
  padding: 4px 6px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.78rem;
}

#btn-join {
  padding: 4px 10px;
  background: var(--accent2);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}
#btn-join:hover { background: #0284c7; }

/* Station list */
#station-list-header {
  padding: 8px 14px 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

#station-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
}

#station-list::-webkit-scrollbar { width: 5px; }
#station-list::-webkit-scrollbar-track { background: transparent; }
#station-list::-webkit-scrollbar-thumb { background: var(--bg-light); border-radius: 3px; }

.station-item {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  margin-bottom: 3px;
}

.station-item:hover {
  background: var(--bg-mid);
  border-color: var(--border);
}

.station-item.is-me {
  border-color: #1d4ed8;
  background: #172554;
}

.station-item.clickable:hover {
  border-color: var(--accent2);
}

.si-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.si-callsign {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: 0.5px;
}

.me-badge {
  font-size: 0.6rem;
  background: #1d4ed8;
  color: #bfdbfe;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.si-info {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Two-column report badges in sidebar */
.si-badges {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  flex-shrink: 0;
}

.si-badge-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.si-badge-label {
  font-size: 0.58rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* Signal badges in sidebar */
.sig-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.sig-s89  { background: #14532d; color: #4ade80; }
.sig-s67  { background: #365314; color: #a3e635; }
.sig-s45  { background: #7c2d12; color: #fb923c; }
.sig-s13  { background: #450a0a; color: #f87171; }
.sig-none { background: var(--bg-light); color: #6b7280; }

/* ── Map ─────────────────────────────────────────────────────── */

#map {
  flex: 1;
  position: relative;
}

/* ── Floating panels ─────────────────────────────────────────── */

.panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 360px;
  max-height: 85vh;
  background: #fff;
  color: #111;
  border-radius: 12px 0 0 0;
  box-shadow: -4px -4px 24px rgba(0,0,0,0.25);
  padding: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s ease;
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 12px;
  background: var(--bg-dark);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.panel-close:hover { color: var(--text); background: var(--bg-light); }

/* Panel body scroll area */
.panel form,
#enroll-panel form,
#report-panel form {
  overflow-y: auto;
  padding: 14px 18px 18px;
  flex: 1;
}

/* ── Forms ───────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 12px;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 0;
}
.form-row .form-group {
  flex: 1;
}

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #374151;
  margin-bottom: 4px;
}

.req { color: var(--accent); }

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.88rem;
  color: #111;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(14,165,233,0.2);
}

textarea { resize: vertical; }

.hint {
  font-size: 0.72rem;
  color: #6b7280;
  margin-bottom: 4px;
}

.location-display {
  font-size: 0.82rem;
  font-family: monospace;
  color: #374151;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 7px 10px;
}

.location-display.set {
  color: #065f46;
  background: #ecfdf5;
  border-color: #6ee7b7;
}

.form-actions {
  display: flex;
  gap: 8px;
  padding: 12px 18px 14px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}

.form-actions button[type="submit"] {
  flex: 1;
  padding: 9px;
  background: var(--bg-dark);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s;
}
.form-actions button[type="submit"]:hover { background: var(--accent); }

.form-actions button[type="button"] {
  padding: 9px 16px;
  background: #e5e7eb;
  color: #374151;
  border: none;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
}
.form-actions button[type="button"]:hover { background: #d1d5db; }

/* ── RS buttons ──────────────────────────────────────────────── */

.rs-hint {
  font-size: 0.65rem;
  font-weight: 400;
  text-transform: none;
  color: #6b7280;
  letter-spacing: 0;
}

.rs-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.rs-btn {
  padding: 7px 12px;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.1s;
  min-width: 40px;
  text-align: center;
}

.rs-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.rs-btn.active {
  background: var(--bg-dark);
  border-color: var(--bg-dark);
  color: #fff;
}

/* Report route header */
.report-route {
  padding: 10px 18px 0;
  font-size: 0.9rem;
  color: #374151;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rpt-label { font-size: 0.7rem; color: #9ca3af; text-transform: uppercase; }
.rpt-arrow { color: var(--accent); font-weight: 700; }
.report-route strong { font-size: 1rem; }

/* ── Popup ───────────────────────────────────────────────────── */

.popup-wrap {
  min-width: 200px;
  max-width: 280px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.popup-wrap h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 6px;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.popup-table th {
  text-align: left;
  color: #6b7280;
  font-weight: 500;
  padding: 2px 8px 2px 0;
  white-space: nowrap;
  vertical-align: top;
}
.popup-table td {
  color: #111;
  padding: 2px 0;
  word-break: break-word;
}

.popup-section {
  margin-top: 8px;
}
.popup-section h4 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #6b7280;
  margin-bottom: 4px;
  font-weight: 700;
}
.popup-section ul {
  list-style: none;
  padding: 0;
}
.popup-section ul li {
  padding: 2px 0;
  color: #374151;
  font-size: 0.8rem;
}
.popup-section .empty {
  color: #9ca3af;
  font-style: italic;
}

.popup-report-btn {
  margin-top: 10px;
  width: 100%;
  padding: 7px;
  background: var(--bg-dark, #111827);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.popup-report-btn:hover { background: var(--accent, #e94560); }

.popup-edit-btn {
  margin-top: 10px;
  width: 100%;
  padding: 7px;
  background: #1e3a5f;
  color: #93c5fd;
  border: 1px solid #1d4ed8;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.popup-edit-btn:hover { background: #1d4ed8; color: #fff; }

/* ── Animated pair lines ─────────────────────────────────────── */
/* dashArray "12 6" → period = 18 px                              */
/* smx-dash-fwd: dashoffset 18→0  (dashes travel forward)         */
/* smx-dash-bwd: dashoffset 9→27  (dashes travel backward,        */
/*   starts half-period offset so the two streams interleave)     */

@keyframes smx-dash-fwd {
  from { stroke-dashoffset: 18; }
  to   { stroke-dashoffset:  0; }
}

@keyframes smx-dash-bwd {
  from { stroke-dashoffset:  9; }
  to   { stroke-dashoffset: 27; }
}

/* ── Legend ──────────────────────────────────────────────────── */

#legend {
  position: fixed;
  bottom: 28px;
  left: calc(var(--sb-width) + 10px);
  background: rgba(17,24,39,0.88);
  color: #f3f4f6;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.72rem;
  z-index: 900;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.legend-title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 5px;
  font-size: 0.65rem;
  color: #9ca3af;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.legend-dot {
  display: inline-block;
  width: 22px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Toast ───────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #111827;
  color: #f3f4f6;
  padding: 9px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  max-width: 360px;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Drop-pin station markers (Leaflet divIcon) ──────────────── */

/* Wrapper — Leaflet sizes this to iconSize ([22, 32]).
   overflow:visible lets the label float above without clipping. */
.pin-wrap {
  position: relative;
  overflow: visible;
  cursor: pointer;
}

/* Callsign label floats above the pin circle */
.pin-label {
  position: absolute;
  /* Sit just above the top of the pin-circle */
  bottom: calc(100% - 2px);   /* 100% = 32px (iconSize height); -2px overlap for snug look */
  left:  50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size:   11px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: #fff;
  /* Thick outline shadow in every direction → readable on any map tile */
  text-shadow:
    -1px -1px 0 #000,
     0px -1px 0 #000,
     1px -1px 0 #000,
    -1px  0px 0 #000,
     1px  0px 0 #000,
    -1px  1px 0 #000,
     0px  1px 0 #000,
     1px  1px 0 #000,
     0 0 8px rgba(0,0,0,0.7);  /* soft halo for extra pop */
  pointer-events: none;
  line-height: 1;
}

/* Filled circle — the "head" of the pin */
.pin-circle {
  width:  22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.75);
  box-shadow:
    0 2px 6px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.3);  /* subtle highlight */
}

/* Downward-pointing triangle — the "tip" of the pin.
   border-top-color is set inline to match the circle colour. */
.pin-tip {
  width:  0;
  height: 0;
  border-left:  7px solid transparent;
  border-right: 7px solid transparent;
  border-top:   10px solid;   /* colour injected via inline style */
  /* drop-shadow continues through the triangle */
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}
