/* Ground missions — Flow design system (scoped) */

:root {
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --primary-faint: #f0fdfa;
  --accent: #f59e0b;
  --success: #059669;
  --error: #dc2626;
  --warning: #d97706;
  --bg-page: #ecfeff;
  --bg-card: #ffffff;
  --bg-muted: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 118, 110, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --route-1: #0f766e;
  --route-2: #0369a1;
  --route-3: #7c3aed;
  --route-4: #d97706;
  --route-5: #db2777;
  --route-6: #059669;
  --font: "DM Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Outfit", sans-serif;
  --topbar-h: 64px;
}

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

html {
  height: 100%;
  margin: 0;
}

.ground-page {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-page);
  min-height: 100dvh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

h1, h2, .kpi__value { font-family: var(--font-display); }

/* —— Topbar —— */
.ground-topbar {
  flex: 0 0 auto;
  background: linear-gradient(160deg, #0f766e 0%, #134e4a 45%, #0c4a6e 100%);
  color: #fff;
  min-height: var(--topbar-h);
  box-shadow: var(--shadow-lg);
  z-index: 20;
}
.ground-topbar__inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  max-width: 100%;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #ccfbf1;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.back-link:hover { color: #fff; }
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}
.brand-logo { height: 28px; width: auto; background: #fff; border-radius: 6px; padding: 3px 6px; }
.brand-favicon { height: 28px; width: 28px; border-radius: 6px; }
.logo-divider { width: 1px; height: 28px; background: rgba(255,255,255,0.35); }
.header-titles h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.2;
}
.header-titles .tagline {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.85;
  font-family: var(--font);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ground-topbar__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.lang-pills { display: flex; gap: 0.25rem; }
.lang-pills a {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
}
.lang-pills a.active,
.lang-pills a:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #94a3b8;
}
.status-chip--live .status-dot { background: #34d399; box-shadow: 0 0 0 3px rgba(52,211,153,0.35); }
.status-chip--error .status-dot { background: #f87171; }
.status-chip--idle .status-dot { background: #cbd5e1; }

/* —— Layout —— */
.ground-layout {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}
.ground-panel {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: linear-gradient(180deg, #ecfeff 0%, #f0fdfa 100%);
  border-right: 1px solid var(--border);
}
.ground-map-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: #e2e8f0;
}
.ground-map-toolbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  background: rgba(248, 250, 252, 0.95);
  border-bottom: 1px solid var(--border);
  z-index: 510;
}
.ground-map-toolbar .btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
}
.ground-map-toolbar .btn.is-active {
  background: rgba(15, 118, 110, 0.15);
  border-color: var(--primary, #0f766e);
  color: var(--primary-dark, #115e59);
}
.ground-map-stage {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: row;
  position: relative;
}
#ground-map {
  flex: 1 1 60%;
  width: 100%;
  min-height: 0;
  height: auto;
}
.ground-map-wrap.is-sv-open #ground-map {
  flex: 1 1 58%;
}
.ground-streetview {
  flex: 0 0 42%;
  min-width: 260px;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: #0f172a;
  min-height: 0;
}
.ground-streetview[hidden] {
  display: none !important;
}
.ground-streetview__bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.45rem 0.65rem;
  color: #ecfeff;
  font-size: 0.75rem;
  font-weight: 600;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}
.ground-streetview__hint {
  font-weight: 400;
  font-size: 0.68rem;
  color: rgba(226, 232, 240, 0.7);
}
.ground-streetview__canvas {
  flex: 1 1 auto;
  min-height: 180px;
  width: 100%;
}
.ground-streetview__empty {
  margin: 0;
  padding: 0.75rem;
  color: #fca5a5;
  font-size: 0.78rem;
}
.zone-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.zone-list li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  border: 1px solid transparent;
}
.zone-list li:hover {
  background: rgba(15, 118, 110, 0.08);
}
.zone-list li.is-selected {
  border-color: rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.12);
}

/* —— Stepper —— */
.ground-stepper {
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0.4rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.step {
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.25rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  color: var(--text-muted);
  font-family: inherit;
}
.step__num {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700;
  background: var(--bg-muted);
  color: var(--text-muted);
}
.step__label { font-size: 0.65rem; font-weight: 600; text-align: center; }
.step.is-active { background: var(--primary-faint); color: var(--primary-dark); }
.step.is-active .step__num { background: var(--primary); color: #fff; }
.step.is-done .step__num { background: var(--success); color: #fff; }

/* —— Cards —— */
.card {
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  scroll-margin-top: 4.5rem;
}
.card__head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 1rem 0.35rem;
}
.card__head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.card__icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.9rem;
  flex-shrink: 0;
}
.card__body { padding: 0.5rem 1rem 1rem; }

.hint {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.hint--map { color: var(--primary-dark); }

/* —— Forms —— */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.form-group input,
.form-group select,
textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  background: #fff;
  color: var(--text);
}
.form-group input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; }

.adv-details { margin-top: 0.65rem; }
.adv-details summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.4rem;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: #fff;
  color: var(--primary-dark);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-faint); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { color: var(--primary); background: var(--primary-faint); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.55rem; font-size: 0.75rem; }
.btn.is-loading { pointer-events: none; opacity: 0.7; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.5rem 0; }
.mission-actions { margin-top: 0.75rem; }

/* —— Chips —— */
.chip-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.65rem; }
.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.chip.is-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* —— Fleet list —— */
.fleet-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.65rem; }
.fleet-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.fleet-item:hover { border-color: var(--primary); }
.fleet-item.is-selected {
  border-color: var(--primary);
  background: var(--primary-faint);
}
.fleet-item input { accent-color: var(--primary); width: 16px; height: 16px; }
.fleet-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.fleet-item__meta { flex: 1; min-width: 0; }
.fleet-item__name { font-weight: 600; font-size: 0.875rem; }
.fleet-item__sub { font-size: 0.72rem; color: var(--text-muted); }
.new-drone-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

/* —— Stops table —— */
.table-wrap { overflow-x: auto; margin-bottom: 0.5rem; }
.stops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.stops-table th {
  text-align: left;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.stops-table td {
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.stops-table input {
  width: 100%;
  min-width: 48px;
  padding: 0.25rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  background: transparent;
}
.stops-table input:focus {
  border-color: var(--primary);
  background: #fff;
  outline: none;
}
.stops-table .btn-icon {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
}
.stops-table .btn-icon:hover { color: var(--error); }
.badge-depot {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  margin-left: 0.25rem;
}

/* —— KPI —— */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.kpi {
  background: var(--bg-muted);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.65rem;
}
.kpi__label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.kpi__value {
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 0.15rem;
  color: var(--text);
}
.kpi--ok .kpi__value { color: var(--success); }
.kpi--bad .kpi__value { color: var(--error); }

/* —— Per-drone list —— */
.per-drone-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.per-drone {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  background: #fff;
}
.per-drone__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.per-drone__name { font-weight: 700; font-size: 0.875rem; flex: 1; }
.per-drone__meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.45rem; }
.per-drone__actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge--ok { background: #d1fae5; color: #065f46; }
.badge--bad { background: #fee2e2; color: #991b1b; }
.badge--warn { background: #fef3c7; color: #92400e; }
.badge--info { background: #e0f2fe; color: #075985; }

/* —— NFZ / Recent —— */
.nfz-list, .recent-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.nfz-list li, .recent-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  border: 1px solid var(--border);
  margin-bottom: 0.35rem;
  background: #fff;
}
.recent-list li { cursor: pointer; }
.recent-list li:hover { border-color: var(--primary); background: var(--primary-faint); }
.recent-list .meta { flex: 1; min-width: 0; }
.recent-list .meta small { display: block; color: var(--text-muted); font-size: 0.7rem; }
.empty-hint { color: var(--text-muted); font-size: 0.8rem; margin: 0.35rem 0 0; }

.ground-status {
  margin: 0;
  padding: 0.65rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
}

/* —— Map chrome —— */
.telemetry-bar {
  padding: 0.45rem 1rem;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.map-legend {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 500;
  background: rgba(255,255,255,0.95);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.55rem 0.75rem;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  min-width: 120px;
}
.map-legend__row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.2rem 0;
}
.map-legend__swatch {
  width: 14px; height: 4px; border-radius: 2px;
}
.draw-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background: var(--primary);
  color: #fff;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

/* While drawing NFZ: existing map layers must not steal clicks.
   First vertex (.sg-draw-first) stays clickable to close the polygon. */
#ground-map.is-drawing .leaflet-interactive {
  pointer-events: none !important;
}
#ground-map.is-drawing .sg-draw-first {
  pointer-events: auto !important;
  cursor: pointer;
}

/* Leaflet markers */
.ground-num-marker {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-display);
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(15,23,42,0.25);
}
.ground-drone-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.5);
  animation: ground-pulse 1.6s infinite;
}
@keyframes ground-pulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(15, 118, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 118, 110, 0); }
}

/* —— Toasts —— */
.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
}
.toast {
  background: #fff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--primary);
  font-size: 0.85rem;
  animation: toast-in 0.25s ease;
}
.toast--success { border-left-color: var(--success); }
.toast--error { border-left-color: var(--error); }
.toast--warning { border-left-color: var(--warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* —— Locked overlay —— */
.ground-locked {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.ground-locked[hidden] { display: none !important; }
.ground-locked__card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.ground-locked__card .card__icon {
  margin: 0 auto 1rem;
  width: 48px; height: 48px;
  font-size: 1.2rem;
}
.ground-locked__card h2 { margin: 0 0 0.5rem; }
.ground-locked__card p { color: var(--text-muted); margin: 0 0 1.25rem; }
.ground-locked__card .btn { margin: 0.25rem; }

@media (max-width: 900px) {
  .ground-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 42%) minmax(0, 58%);
    overflow: hidden;
  }
  .ground-panel {
    min-height: 0;
    height: 100%;
    max-height: none;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .ground-map-wrap {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }
  #ground-map { min-height: 0; }
  .ground-map-stage {
    flex-direction: column;
  }
  .ground-map-wrap.is-sv-open #ground-map {
    flex: 1 1 55%;
  }
  .ground-streetview {
    flex: 0 0 220px;
    max-width: none;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .header-titles .tagline { display: none; }
  .form-row { grid-template-columns: 1fr; }
}
