/* =========================================================================
   Shared styles for every page: theme tokens, header/nav, buttons, forms,
   pills, dialogs, toasts and map helpers.
   Page-specific styles live in dashboard.css and map.css.
   ========================================================================= */

:root {
  --bg-base: #0a0e17;
  --bg-mesh: radial-gradient(circle at 15% 15%, rgba(37, 99, 235, 0.12) 0%, transparent 45%),
             radial-gradient(circle at 85% 75%, rgba(16, 185, 129, 0.08) 0%, transparent 45%);
  --surface: rgba(17, 24, 39, 0.75);
  --surface-sunken: rgba(15, 23, 42, 0.5);
  --surface-raised: rgba(30, 41, 59, 0.6);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ink: #f8fafc;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-ink: #93c5fd;
  --primary-gradient: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  --on: #10b981;
  --on-ink: #34d399;
  --warn: #f59e0b;
  --warn-ink: #fbbf24;
  --err: #ef4444;
  --err-ink: #f87171;
  --radius: 12px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-base) var(--bg-mesh) fixed;
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: 0.85em; background: rgba(0,0,0,.35); padding: 1px 6px; border-radius: 5px; }

/* ---------- Text helpers ---------- */
.sub  { color: var(--muted); font-size: 0.82rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.errtext { color: var(--err-ink); font-size: 0.82rem; }
.oktext  { color: var(--on-ink); font-size: 0.85rem; font-weight: 600; }
.mono { font-family: var(--mono); }

/* ---------- App header + navigation (same on every page) ---------- */
.app-header {
  display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center;
  padding: 14px 28px;
  background: var(--surface);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 20px;
  background: linear-gradient(135deg, rgba(37,99,235,.25), rgba(59,130,246,.1));
  border: 1px solid rgba(59,130,246,.35);
}
.brand-title { margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-sub { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }
.app-nav { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-sunken); border: 1px solid var(--line); }
.app-nav a {
  padding: 6px 16px; border-radius: 999px; font-size: 0.86rem; font-weight: 600;
  color: var(--muted); text-decoration: none; transition: background .15s, color .15s;
}
.app-nav a:hover { color: var(--ink); background: rgba(255,255,255,.05); }
.app-nav a[aria-current="page"] { background: var(--primary-gradient); color: #fff; }
.header-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Banner (dry-run etc.) ---------- */
.banner {
  display: flex; gap: 12px; align-items: center;
  margin: 18px 28px 0; padding: 12px 18px; border-radius: var(--radius);
  background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: var(--warn-ink);
  font-size: 0.9rem;
}
.banner.info { background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.35); color: var(--primary-ink); }
.banner .banner-icon { font-size: 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-weight: 600; font-size: 0.86rem; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: rgba(255,255,255,.05); color: var(--ink);
  cursor: pointer; text-decoration: none; user-select: none; white-space: nowrap;
  transition: background .18s, border-color .18s, transform .18s, box-shadow .18s;
}
.btn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.28); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn.primary { background: var(--primary-gradient); border-color: rgba(147,197,253,.35); color: #fff; box-shadow: 0 4px 16px rgba(37,99,235,.4); }
.btn.primary:hover { background: linear-gradient(135deg, #1d4ed8, #2563eb); }
.btn.success { background: #059669; border-color: #059669; color: #fff; }
.btn.danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.3); color: #fca5a5; }
.btn.danger:hover { background: rgba(239,68,68,.25); color: #fff; }
.btn.small { padding: 5px 11px; font-size: 0.79rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Segmented controls (tabs, view switcher, presets) ---------- */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px; border-radius: 999px; background: var(--surface-sunken); border: 1px solid var(--line); }
.segmented button {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button:hover { color: var(--ink); background: rgba(255,255,255,.05); }
.segmented button[aria-pressed="true"] { background: var(--primary-gradient); color: #fff; }

/* ---------- Form controls ---------- */
label, .label { display: block; font-weight: 600; font-size: 0.86rem; color: #e2e8f0; margin-bottom: 5px; }
input:not([type=checkbox]):not([type=range]):not([type=file]), select, textarea {
  width: 100%; padding: 9px 13px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12); background: rgba(13,19,33,.75); color: var(--ink);
  font-size: 0.9rem; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.25); outline: none; }
select {
  cursor: pointer; appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
optgroup { color: var(--muted); }
textarea { min-height: 95px; resize: vertical; font-family: var(--mono); font-size: 0.84rem; }
input[type=range] { width: 100%; accent-color: var(--primary); margin: 8px 0 4px; }
input[type=file] { font-size: 0.82rem; max-width: 100%; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.span-2 { grid-column: 1 / -1; }
.inline { display: flex; gap: 8px; }
.inline > input { flex: 1; }

/* Toggle switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; margin: 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 42px; height: 24px; border-radius: 999px; background: rgba(255,255,255,.16); position: relative; flex: none; transition: background .2s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--on); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px; border-radius: 999px;
  font-weight: 700; font-size: 0.75rem; letter-spacing: .04em; text-transform: uppercase;
  border: 1px solid transparent;
}
.pill.on      { background: rgba(16,185,129,.12); color: var(--on-ink); border-color: rgba(16,185,129,.35); }
.pill.off     { background: rgba(100,116,139,.15); color: var(--muted); border-color: rgba(148,163,184,.2); }
.pill.pending { background: rgba(245,158,11,.12); color: var(--warn-ink); border-color: rgba(245,158,11,.3); }
.pill.err     { background: rgba(239,68,68,.15); color: var(--err-ink); border-color: rgba(239,68,68,.35); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.pill.on .dot { animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,.7); } 70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: rgba(59,130,246,.12); color: var(--primary-ink); font-weight: 600; font-size: 0.76rem; }
.count-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 8px; background: rgba(255,255,255,.05); border: 1px solid var(--line); font-weight: 700; font-size: 0.84rem; }

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line-strong); border-radius: 18px; padding: 0;
  width: min(760px, 94vw); max-height: 92vh; background: rgba(15,23,42,.97); color: var(--ink);
  box-shadow: 0 25px 60px -10px rgba(0,0,0,.85);
}
dialog::backdrop { background: rgba(5,9,15,.75); backdrop-filter: blur(8px); }
dialog > form, dialog > .dlg { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.2rem; }
.dlg-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.dlg-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: rgba(10,15,26,.4); }
.dlg-foot .spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 3000;
  background: rgba(15,23,42,.96); border: 1px solid rgba(59,130,246,.5); color: var(--ink);
  padding: 10px 22px; border-radius: 999px; font-size: 0.88rem; font-weight: 600;
  box-shadow: 0 8px 32px rgba(0,0,0,.5); transition: opacity .3s; pointer-events: none;
}
.toast.err { border-color: rgba(239,68,68,.6); }

/* ---------- Leaflet helpers shared by both maps ---------- */
.sel-center-marker { background: #0284c7; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 12px rgba(2,132,199,.85); cursor: grab; }
.sel-edge-marker   { background: #f59e0b; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 12px rgba(245,158,11,.85); cursor: ew-resize; }
.dark-map:not(.no-filter) .leaflet-tile-pane { filter: brightness(.68) invert(1) contrast(3) hue-rotate(200deg) saturate(.35); }
.leaflet-pane.leaflet-trafficPane-pane { filter: none !important; }
.leaflet-container { font-family: var(--font); background: #0f172a; }
.leaflet-popup-content { font: 13.5px/1.45 var(--font); margin: 12px 14px; color: #1e293b; }
.leaflet-popup-content img { width: 100%; max-height: 140px; object-fit: cover; border-radius: 6px; margin-top: 6px; }
.leaflet-bar a { background-color: rgba(15,23,42,.85) !important; color: var(--ink) !important; border-bottom-color: var(--line) !important; }
.leaflet-control-layers { background: rgba(15,23,42,.9) !important; color: var(--ink) !important; border: 1px solid var(--line) !important; border-radius: 10px !important; }
.leaflet-control-layers-expanded { padding: 10px 12px !important; }

@media (max-width: 720px) {
  .app-header { padding: 12px 16px; }
  .banner { margin: 14px 16px 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .header-actions { margin-left: 0; }
}
