/* Thème sobre, lisible, fond sombre */
:root {
  --bg: #1a1d23;
  --card: #232830;
  --border: #3d4450;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4a9eff;
  --accent-dim: #356a99;
  --danger: #e85d4c;
  --danger-hover: #ff7a6a;
  --warn-bg: #3d2f1a;
  --warn-border: #8b6914;
  --ok: #3dd68c;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

.header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.header-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-nav-link {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  background: rgba(74, 158, 255, 0.08);
}

.header-nav-link:hover {
  background: rgba(74, 158, 255, 0.18);
  border-color: var(--accent);
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.banner-warn {
  margin: 1rem 1.5rem;
  padding: 0.85rem 1rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  font-size: 0.88rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  padding: 0 1.5rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* —— Layout onglets : zone principale ~2/3 + télémétrie ~1/3 —— */
.main-app {
  padding: 0 1.5rem 2rem;
  max-width: 1680px;
  margin: 0 auto;
}

.tabs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: var(--font);
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.is-active {
  color: var(--text);
  background: var(--card);
  border-color: var(--border);
  font-weight: 600;
}

.tab-workspace {
  display: flex;
  gap: 1.25rem;
  align-items: stretch;
}

.tab-panels-region {
  flex: 2;
  min-width: 0;
}

.telemetry-rail {
  flex: 1;
  min-width: 260px;
  max-width: 420px;
  position: sticky;
  top: 0.75rem;
  align-self: flex-start;
  max-height: calc(100vh - 7rem);
  overflow-y: auto;
  padding-bottom: 0.5rem;
}

.telemetry-rail .telemetry-cols {
  grid-template-columns: 1fr;
}

.telemetry-rail .tel-block-wide {
  grid-column: auto;
}

.tab-panel-scroll {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.tab-log-slot {
  margin-top: 0.25rem;
}

.tab-log-slot .log-box {
  height: min(240px, 32vh);
}

.proto-packets-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 1024px) {
  .tab-workspace {
    flex-direction: column;
  }

  .telemetry-rail {
    max-width: none;
    position: relative;
    top: auto;
    max-height: none;
    /* Panneaux d'onglets d'abord : sinon la télémétrie pousse le contenu hors écran. */
  }

  .proto-packets-row {
    grid-template-columns: 1fr;
  }
}

.tab-panel[hidden] {
  display: none !important;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.card.span-2 {
  grid-column: 1 / -1;
}

@media (min-width: 900px) {
  .card.span-2 {
    grid-column: span 2;
  }
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.row label {
  flex: 0 0 100px;
  font-size: 0.88rem;
  color: var(--muted);
}

.row input[type="text"],
.row input[type="number"] {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.row.row-with-action {
  flex-wrap: wrap;
}

.row.row-with-action input[type="number"] {
  flex: 1 1 6rem;
  min-width: 5rem;
}

.row.row-with-action .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-row.wrap {
  margin-bottom: 0.5rem;
}

.btn {
  padding: 0.55rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #2f3540;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  background: #3a4250;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
}

.btn.secondary {
  background: transparent;
}

.btn.small {
  padding: 0.3rem 0.55rem;
  font-size: 0.85rem;
}

.btn.ghost {
  background: transparent;
  text-decoration: none;
  display: inline-block;
}

.btn.ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.btn.stop {
  flex: 1;
  min-height: 48px;
  font-weight: 700;
  font-size: 1rem;
  background: #5c2a24;
  border-color: var(--danger);
  color: #fff;
}

.btn.stop:hover:not(:disabled) {
  background: var(--danger);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.dot.offline {
  background: #666;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.error-text.ok-text {
  color: #6bc96b;
}

.warn-text {
  color: #e6b84d;
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
}

.checks {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.checks label {
  cursor: pointer;
  user-select: none;
}

.slider-block {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.slider-row {
  display: grid;
  grid-template-columns: 90px 1fr 40px minmax(100px, auto);
  align-items: center;
  gap: 0.5rem;
}

.slider-row label {
  font-size: 0.88rem;
  color: var(--muted);
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.val-proto {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.mono {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  margin: 0 0 0.35rem;
}

.hex {
  margin: 0;
  padding: 0.65rem;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.72rem;
  line-height: 1.4;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 140px;
}

.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.logs-header h2 {
  margin: 0;
}

.log-box {
  height: 220px;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  line-height: 1.35;
}

.log-line {
  margin: 0.15rem 0;
  border-bottom: 1px solid #2a2f38;
  padding-bottom: 0.15rem;
}

.log-line.warn {
  color: #e6b84d;
}

.log-line.error {
  color: var(--danger);
}

.tel-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.telemetry-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem 1.25rem;
}

.tel-block-wide {
  grid-column: 1 / -1;
}

.tel-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.tel-dl {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.tel-dl dt {
  color: var(--muted);
  margin-top: 0.35rem;
  font-weight: 500;
}

.tel-dl dt:first-child {
  margin-top: 0;
}

.tel-dl dd {
  margin: 0.1rem 0 0;
  font-family: ui-monospace, monospace;
  word-break: break-all;
}

.tel-sub {
  color: var(--muted);
  font-size: 0.72rem;
}

.tel-unit {
  color: var(--muted);
  font-size: 0.7rem;
}

.lat-good {
  color: var(--ok);
}

.lat-warn {
  color: #e6b84d;
}

.lat-bad {
  color: var(--danger);
}

.scan-disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
}

.profile-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.65rem 0.85rem;
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border, #2a3140);
  border-radius: var(--radius, 8px);
}

.profile-bar-title {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent, #6ec1ff);
}

.profile-bar-hint {
  flex: 1 1 100%;
  margin: -0.25rem 0 0.15rem;
}

.profile-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted, #9aa3b2);
}

.profile-bar select,
.profile-bar input[type="text"] {
  min-width: 10rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border, #2a3140);
  background: var(--input-bg, #12151a);
  color: inherit;
}

.profile-bar .btn-row {
  margin: 0;
}

.profile-bar .status-line {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.85rem;
}

.status-line.ok {
  color: #6dcea0;
}

.status-line.err {
  color: #f07178;
}

.scan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .scan-grid {
    grid-template-columns: 1fr;
  }
}

.scan-sub {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.scan-sub:first-of-type {
  margin-top: 0;
}

.scan-hint {
  margin-top: 0.35rem;
}

.scan-slider-row {
  margin-top: -0.35rem;
  margin-bottom: 0.5rem;
}

.scan-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.row input.readonly,
.row select {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1e2228;
  color: var(--text);
  font-size: 0.95rem;
}

.row input.readonly {
  color: var(--muted);
}

.scan-viz {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#scan-canvas {
  width: 100%;
  max-width: 520px;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #12151a;
  display: block;
}

#coverage-canvas {
  width: 100%;
  max-width: 640px;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #10141a;
  display: block;
}

.scan-footprint-wrap {
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.scan-summary {
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.scan-dl dt {
  font-size: 0.72rem;
}

.scan-dl dd {
  font-size: 0.75rem;
}

.scan-status-line {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
}

.scan-stop-inline {
  flex: 0 1 auto;
  min-height: auto;
  font-size: 0.88rem;
}

.still-wrap {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #11161d;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#video-snap-image {
  max-width: 100%;
  max-height: 320px;
  display: block;
}

.footer {
  padding: 1rem 1.5rem 2rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.mission-map-leaflet {
  width: 100%;
  height: min(72vh, 720px);
  min-height: 420px;
  display: block;
  background: #1a2332;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: 0;
}

.mission-map-leaflet.mission-map-measuring,
.mission-map-leaflet.mission-map-measuring .leaflet-container {
  cursor: crosshair !important;
}

/* Mode mesure : laisser les clics traverser calques KML / pastilles / fauchées */
.mission-map-leaflet.mission-map-measuring .leaflet-missionOverlayLayersPane-pane,
.mission-map-leaflet.mission-map-measuring .leaflet-missionOverlayLayersPane-pane *,
.mission-map-leaflet.mission-map-measuring .leaflet-missionDetsPane-pane,
.mission-map-leaflet.mission-map-measuring .leaflet-missionDetsPane-pane *,
.mission-map-leaflet.mission-map-measuring .leaflet-missionKlvPane-pane,
.mission-map-leaflet.mission-map-measuring .leaflet-missionKlvPane-pane *,
.mission-map-leaflet.mission-map-measuring .leaflet-missionTilesPane-pane,
.mission-map-leaflet.mission-map-measuring .leaflet-missionTilesPane-pane *,
.mission-map-leaflet.mission-map-measuring .leaflet-missionTrackPane-pane,
.mission-map-leaflet.mission-map-measuring .leaflet-missionTrackPane-pane * {
  pointer-events: none !important;
}

.mission-measure-label {
  background: transparent !important;
  border: none !important;
}

.mission-measure-label span {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(21, 101, 192, 0.92);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.btn.is-active[aria-pressed="true"] {
  outline: 2px solid var(--accent, #1e88e5);
  outline-offset: 1px;
}

/* Calques KML */
.map-layers-dropdown {
  position: relative;
  display: inline-block;
}

.map-layers-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1200;
  min-width: 14rem;
  max-width: 20rem;
  max-height: 16rem;
  overflow: auto;
  padding: 0.4rem 0;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #cfd8dc);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.map-layers-menu-head {
  padding: 0.25rem 0.75rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #607d8b);
  border-bottom: 1px solid var(--border, #eceff1);
  margin-bottom: 0.25rem;
}

.map-layers-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.map-layers-item:hover {
  background: rgba(30, 136, 229, 0.08);
}

.map-layers-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.map-layers-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-layers-empty {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
}

.map-layers-upload {
  max-width: 36rem;
}

#map-layers-table .map-layer-color-input {
  width: 2.4rem;
  height: 1.6rem;
  padding: 0;
  border: 1px solid var(--border, #cfd8dc);
  background: transparent;
  cursor: pointer;
}

#map-layers-table td {
  vertical-align: middle;
}

.mission-aircraft-icon {
  background: transparent !important;
  border: none !important;
}

.mission-aircraft-rot {
  width: 32px;
  height: 32px;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
  will-change: transform;
}

.mission-map-canvas {
  display: none;
}

.mission-map-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.35rem 0;
  font-size: 0.82rem;
}

.mission-map-stats .stat-pill {
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}

/* Couverture : détections au-dessus des tuiles / fauchées (pane Leaflet dédié). */
.leaflet-pane.leaflet-missionDetsPane-pane {
  z-index: 680 !important;
}

.leaflet-pane.leaflet-missionTrackPane-pane {
  z-index: 600 !important;
}

.leaflet-pane.leaflet-missionKlvPane-pane {
  z-index: 450 !important;
}

.leaflet-pane.leaflet-missionTilesPane-pane {
  z-index: 410 !important;
}

.mission-det-marker {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 5px rgba(0, 0, 0, 0.55));
  pointer-events: auto;
}

.mission-tile-img.mission-tile-identify {
  filter: saturate(1.05) hue-rotate(-8deg);
}

.mission-identify-link {
  pointer-events: none;
}

/* Détections couverture — pane Leaflet au-dessus des fauchées */
.leaflet-missionDetsPane-pane path.mission-det-marker {
  stroke: #ffffff;
  stroke-width: 2.5px;
  paint-order: stroke fill;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.75));
}

.mission-cluster-panel {
  margin-top: 0.55rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #3a4556;
  background: #1a2030;
  border-radius: 6px;
}
.mission-cluster-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.mission-cluster-frames {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-height: 11rem;
  overflow: auto;
}
.mission-cluster-frame {
  width: 5.5rem;
  border: 1px solid #4a5568;
  border-radius: 4px;
  overflow: hidden;
  background: #0f141c;
  cursor: pointer;
  padding: 0;
  color: inherit;
  text-align: left;
}
.mission-cluster-frame img {
  display: block;
  width: 100%;
  height: 3.6rem;
  object-fit: cover;
  background: #111;
}
.mission-cluster-frame span {
  display: block;
  font-size: 0.68rem;
  padding: 0.2rem 0.3rem;
  color: #c5cad3;
}

/* Chat sécurisé Kite ↔ sol (operator+) */
.mission-chat {
  display: grid;
  gap: 0.55rem;
}
.mission-chat-log {
  min-height: 14rem;
  max-height: min(42vh, 360px);
  overflow: auto;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border, #2a3545);
  border-radius: 8px;
  background: #0b1016;
}
.mission-chat-msg {
  margin: 0.45rem 0;
  max-width: 92%;
  padding: 0.4rem 0.55rem;
  border-radius: 8px;
}
.mission-chat-msg.is-mine {
  margin-left: auto;
  background: #1e3a2f;
  border: 1px solid #2d5a45;
}
.mission-chat-msg.is-theirs {
  margin-right: auto;
  background: #1a2433;
  border: 1px solid #2a3a52;
}
.mission-chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.72rem;
  color: #8fa3bc;
  margin-bottom: 0.2rem;
}
.mission-chat-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.92rem;
}
.mission-chat-compose {
  display: flex;
  gap: 0.45rem;
}
.mission-chat-compose input {
  flex: 1;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #3a4658;
  background: #121820;
  color: inherit;
}
.mission-chat-status {
  margin: 0;
  font-size: 0.8rem;
}

@media (max-width: 600px) {
  .slider-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .slider-row .val,
  .slider-row .val-proto {
    text-align: left;
  }
}
