:root {
  --bg: #0b1020;
  --bg-elev: #141b2d;
  --bg-elev-2: #1b2438;
  --bg-hover: #232e48;
  --line: #2a3550;
  --text: #e8eef8;
  --muted: #93a0b8;
  --accent: #f05123;
  --accent-2: #ff8a5c;
  --accent-soft: rgba(240, 81, 35, 0.16);
  --ok: #3ecf8e;
  --warn: #f5c542;
  --danger: #ff5c7a;
  --home: #4cc9f0;
  --map-cluster: #f05123;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --font: "Segoe UI", "Source Sans 3", "Helvetica Neue", sans-serif;
  --mono: "IBM Plex Mono", "ui-monospace", "SFMono-Regular", Menlo, Consolas, monospace;
  --header-h: 58px;
  --footer-h: 34px;
  --sidebar-w: 400px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  height: 100%;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: linear-gradient(180deg, #151c30, #101726);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.brand img { width: 32px; height: 32px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 14px; letter-spacing: 0.01em; white-space: nowrap; }
.brand-text span { font-size: 11px; color: var(--muted); }
.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button, .btn, select, input, .file-btn {
  font: inherit;
  color: var(--text);
}
button, .btn, .file-btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
button:hover, .btn:hover, .file-btn:hover { background: var(--bg-hover); border-color: #3b4868; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: #d4431a;
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: #ff6330; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: rgba(255, 92, 122, 0.35); }
button.icon-only { padding: 7px 8px; }
button.small, .btn.small { padding: 4px 7px; font-size: 12px; }

.menu { position: relative; }
.menu-list {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 220px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 40;
}
.menu.open .menu-list { display: grid; }
.menu-list button {
  background: transparent;
  border: 0;
  border-radius: 7px;
  justify-content: flex-start;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
}
.menu-list button:hover { background: var(--bg-hover); }
.menu-list .hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; font-weight: 400; }

#file-input { display: none; }

/* Main */
.main {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  min-height: 0;
}

#map {
  min-height: 0;
  background: #0a1a14;
}
#map.mode-home { cursor: crosshair; }
#map.mode-survey { cursor: crosshair; }

.sidebar {
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar-scroll {
  overflow: auto;
  padding: 12px 14px 24px;
  flex: 1;
}

.panel {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-row, .defaults-grid, .survey-grid {
  display: grid;
  gap: 8px;
}
.defaults-grid { grid-template-columns: 1fr 1fr 1fr; }
.survey-grid { grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, .field-inline label {
  font-size: 11px;
  color: var(--muted);
}
.field input, .field select, .field-inline input, .name-input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  width: 100%;
  font-size: 13px;
}
.field input:focus, .field select:focus, .name-input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.name-input { font-weight: 600; margin-bottom: 8px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.home-coords { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 6px; }

.banner {
  display: none;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(240, 81, 35, 0.35);
  font-size: 13px;
}
.banner.show { display: block; }
.banner strong { color: var(--accent-2); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat {
  background: var(--bg);
  border-radius: 9px;
  padding: 8px 10px;
}
.stat .label { font-size: 11px; color: var(--muted); }
.stat .value { font-size: 16px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.wp-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.wp-count { font-size: 12px; color: var(--muted); }

.wp-list { display: flex; flex-direction: column; gap: 8px; }
.wp-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}
.wp-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.wp-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.wp-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex: none;
}
.wp-card-head select { flex: 1; background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 6px; }
.wp-card-actions { display: flex; gap: 4px; }
.wp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.wp-grid.coords { grid-template-columns: 1fr 1fr; }
.wp-grid input { background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 6px; font-family: var(--mono); font-size: 12px; width: 100%; }
.wp-extra { margin-top: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 18px 8px;
}

/* Footer */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: #0e1424;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  z-index: 20;
}
.footer a { color: var(--accent-2); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer .disclaimer { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Leaflet overrides */
.leaflet-container { background: #0a1a14; font-family: var(--font); }
.leaflet-control-layers, .leaflet-bar, .locate-btn {
  background: var(--bg-elev) !important;
  color: var(--text);
  border: 1px solid var(--line) !important;
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-control-layers { color: var(--text); }
.leaflet-control-layers-expanded { background: var(--bg-elev) !important; padding: 8px 10px; }
.leaflet-control-attribution { background: rgba(11, 16, 32, 0.75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent-2) !important; }
.leaflet-bar a {
  background: var(--bg-elev) !important;
  color: var(--text) !important;
  border-bottom-color: var(--line) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
}
.leaflet-bar a:hover { background: var(--bg-hover) !important; }
.locate-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text);
  padding: 0;
}
.locate-btn svg { width: 18px; height: 18px; fill: currentColor; }
.locate-btn.active { color: var(--accent); }

.wp-marker {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--map-cluster);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  color: #fff;
  font: 700 11px var(--font);
}
.wp-marker span { transform: rotate(45deg); }
.wp-marker.act-takeoff { background: var(--ok); }
.wp-marker.act-land, .wp-marker.act-rtl { background: var(--danger); }
.wp-marker.act-loiter { background: #7b61ff; }
.wp-marker.act-servo { background: #f5c542; color: #1a1a1a; }
.wp-marker.act-speed { background: #4cc9f0; color: #102028; }
.home-marker {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--home);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  color: #102028;
  font: 800 12px var(--font);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 52px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  font-size: 13px;
  max-width: min(90vw, 420px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

.sidebar-toggle {
  display: none;
  margin-left: 0;
}

@media (max-width: 860px) {
  :root { --header-h: 52px; --footer-h: auto; }
  .header { padding: 6px 10px; gap: 8px; }
  .brand-text span { display: none; }
  .main { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    right: 0;
    top: var(--header-h);
    bottom: 0;
    width: min(100%, 400px);
    transform: translateX(110%);
    transition: transform 0.22s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .footer { flex-direction: column; align-items: flex-start; padding: 6px 10px; gap: 2px; }
  .footer .disclaimer { white-space: normal; }
  .defaults-grid { grid-template-columns: 1fr 1fr; }
}
