:root {
  --navy: #0f2438;
  --navy-2: #16324f;
  --ink: #1c2733;
  --ink-soft: #5b6b7a;
  --ink-faint: #97a3ae;
  --line: #e6eaee;
  --paper: #ffffff;
  --canvas: #f4f6f8;
  --blue: #2f6fed;
  --blue-soft: #e8f0fe;
  --amber: #d98324;
  --amber-soft: #fbf0e2;
  --green: #1f9d63;
  --green-soft: #e5f6ee;
  --red: #d1453b;
  --red-soft: #fbeae9;
  --grey-dot: #a9b4bd;
  --shadow: 0 1px 2px rgba(15, 36, 56, 0.04), 0 4px 16px rgba(15, 36, 56, 0.05);
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  color: white;
  padding: 28px 32px;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.header-title h1 {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.next-cycle {
  font-size: 11.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#monitor-status {
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: background 0.3s, color 0.3s;
}

#monitor-status.alive {
  background: rgba(31, 157, 99, 0.18);
  color: #7be3ae;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  box-shadow: 0 0 6px rgba(46, 204, 113, 0.7);
  animation: pulse-dot 1.6s ease-in-out infinite;
  vertical-align: middle;
  margin-right: 2px;
}

#monitor-status.dead {
  background: rgba(209, 69, 59, 0.2);
  color: #ff9d96;
}

#monitor-status.connecting {
  background: rgba(217, 131, 36, 0.2);
  color: #f5c377;
}

/* ---------- Layout ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 8px 24px 40px;
}

section {
  background: var(--paper);
  margin-top: 20px;
  padding: 22px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  transition: box-shadow 0.2s;
}

section:hover {
  box-shadow: 0 2px 4px rgba(15, 36, 56, 0.06), 0 8px 24px rgba(15, 36, 56, 0.07);
}

section h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 16px;
}

.section-hint {
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink-faint);
}

footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--ink-faint);
}

/* ---------- Aggregate stat cards ---------- */

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--canvas);
  border-radius: 8px;
  padding: 16px 18px;
  border-top: 3px solid var(--blue);
}

.stat-card.site {
  border-top-color: var(--amber);
}

.stat-card.delta {
  border-top-color: #8b5cf6;
}

.stat-label {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.stat-value.empty {
  color: var(--ink-faint);
  font-size: 20px;
}

.stat-detail {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 8px;
  line-height: 1.4;
}

/* ---------- Airport classification badges ---------- */

.classification-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge .badge-code {
  font-weight: 700;
}

.badge .badge-frac {
  font-weight: 400;
  opacity: 0.75;
}

.badge.static {
  background: var(--green-soft);
  color: var(--green);
}

.badge.mixed {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.dynamic {
  background: var(--red-soft);
  color: var(--red);
}

/* ---------- Legend ---------- */

.flights-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.flights-section-head h2 {
  margin-bottom: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-weight: 500;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.legend-dot.scheduled { background: var(--grey-dot); }
.legend-dot.dhmi { background: var(--blue); }
.legend-dot.site { background: var(--amber); }
.legend-dot.landed { background: var(--green); }
.legend-dot.landed.coarse { background: transparent; border: 1.5px dashed var(--green); }
.legend-dot.correction { background: #8b5cf6; }
.legend-dot.mismatch { background: var(--red); }

/* ---------- Flight toolbar (search + filters) ---------- */

.flights-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.flight-search {
  flex: 1 1 220px;
  min-width: 160px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--ink);
  background: var(--canvas);
  outline: none;
  transition: border-color 0.15s;
}

.flight-search:focus {
  border-color: var(--blue);
  background: var(--paper);
}

.filter-group {
  display: inline-flex;
  gap: 4px;
  background: var(--canvas);
  border-radius: 7px;
  padding: 3px;
}

.filter-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.filter-btn:hover {
  color: var(--ink);
}

.filter-btn.active {
  background: var(--paper);
  color: var(--navy);
  box-shadow: 0 1px 2px rgba(15, 36, 56, 0.1);
}

.flight-count {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ---------- Airport groups ---------- */

.airport-group {
  margin-bottom: 22px;
}

.airport-group:last-child {
  margin-bottom: 0;
}

.airport-group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.airport-group-title .group-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--canvas);
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}

.airport-group-title .group-count {
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 11.5px;
}

/* ---------- Flight rows ---------- */

.flight-row {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.flight-row:last-child {
  margin-bottom: 0;
}

.flight-row:hover {
  border-color: #c9d3dc;
}

.flight-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  background: var(--paper);
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.flight-header:hover {
  background: var(--canvas);
}

.flight-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.flight-no {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.flight-meta {
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* ---------- Belt badges ---------- */

.belt-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  border: 1.5px solid transparent;
}

.belt-badge.dhmi {
  background: var(--blue-soft);
  color: var(--blue);
}

.belt-badge.site {
  background: var(--amber-soft);
  color: var(--amber);
}

.belt-badge.pending {
  background: transparent;
  border-style: dashed;
}

.belt-badge.dhmi.pending {
  border-color: var(--blue);
  color: var(--blue);
}

.belt-badge.site.pending {
  border-color: var(--amber);
  color: var(--amber);
}

/* ---------- Mismatches ---------- */

#mismatches-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mismatch-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--canvas);
  border-radius: 7px;
  font-size: 12.5px;
}

.mismatch-flight {
  font-weight: 700;
  color: var(--ink);
  min-width: 90px;
}

.mismatch-airport {
  font-weight: 400;
  color: var(--ink-faint);
}

.mismatch-values {
  color: var(--ink-soft);
}

.mismatch-values b {
  color: var(--ink);
}

.mismatch-time {
  color: var(--ink-faint);
  font-size: 11.5px;
}

.mismatch-status {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.mismatch-status.corrected {
  background: var(--green-soft);
  color: var(--green);
}

.mismatch-status.unresolved {
  background: var(--red-soft);
  color: var(--red);
}

.flight-status {
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.flight-status.resolved {
  background: var(--green-soft);
  color: var(--green);
}

.flight-status.inprogress {
  background: var(--amber-soft);
  color: var(--amber);
}

.flight-status.cancelled,
.flight-status.dhmineverappeared,
.flight-status.sitenoverappeared {
  background: var(--red-soft);
  color: var(--red);
}

/* ---------- Timeline ---------- */

.timeline-strip {
  position: relative;
  background: var(--paper);
  padding: 10px 16px 16px;
  border-top: 1px solid var(--line);
}

.avg-timeline-container {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.avg-timeline-container:empty {
  display: none;
}

.avg-axis {
  background: var(--blue-soft);
}

.timeline-label {
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.timeline-label b {
  color: var(--ink);
  font-weight: 600;
}

.timeline-axis-wrap {
  padding: 0 6px;
}

.timeline-axis {
  position: relative;
  height: 30px;
  background: var(--line);
  border-radius: 4px;
}

.timeline-axis::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(15, 36, 56, 0.06);
  transform: translateY(-50%);
}

.timeline-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 10px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 13px;
  height: 13px;
  border-radius: 50%;
  cursor: help;
  border: 2.5px solid var(--paper);
  box-shadow: 0 0 0 1px rgba(15, 36, 56, 0.12);
  z-index: 1;
}

.marker.scheduled {
  background: var(--grey-dot);
  z-index: 0;
}

/* dhmi/site are pulled to separate lanes above/below center - when a poll
   catches both sources at the same instant (common on the very first
   cycle), the dots land at the same x but different y, so neither one
   hides behind the other. */
.marker.dhmi {
  background: var(--blue);
  top: 28%;
}

.marker.site {
  background: var(--amber);
  top: 72%;
}

.marker.landed {
  background: var(--green);
}

.marker.landed.coarse {
  background: var(--paper);
  border: 2.5px dashed var(--green);
  box-shadow: none;
}

.marker.correction {
  background: #8b5cf6;
  top: 50%;
  width: 11px;
  height: 11px;
}

.marker.mismatch {
  background: var(--red);
  top: 50%;
  width: 11px;
  height: 11px;
}

.marker:hover {
  z-index: 5;
}

.marker:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: white;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.marker:hover::before {
  content: '';
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--navy);
  z-index: 10;
}

/* ---------- Drill-down log ---------- */

.log-table {
  display: none;
  margin: 4px 16px 16px;
  border-collapse: collapse;
  width: calc(100% - 32px);
  font-size: 11.5px;
}

.log-table.visible {
  display: table;
}

.log-table th,
.log-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
}

.log-table th {
  background: var(--canvas);
  font-weight: 650;
  color: var(--ink-soft);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.log-table tr:hover td {
  background: var(--canvas);
}

.empty-state {
  color: var(--ink-faint);
  font-size: 12.5px;
  padding: 12px 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
  header {
    padding: 20px;
  }

  main {
    padding: 8px 12px 32px;
  }

  section {
    padding: 16px;
  }

  .stats-cards {
    grid-template-columns: 1fr;
  }

  .flight-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .legend {
    gap: 10px 14px;
  }
}

/* ---------- Live terminal ---------- */

.terminal-section {
  padding: 0;
  overflow: hidden;
  background: #0b1420;
  border-color: #1c2f42;
}

.terminal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid #1c2f42;
}

.terminal-head h2 {
  margin-bottom: 0;
  color: #d8e4ee;
  text-transform: none;
  letter-spacing: normal;
  font-size: 13px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
}

.terminal-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.terminal-toggle {
  font-size: 11.5px;
  color: #7d93a8;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

.terminal-toggle input {
  accent-color: var(--blue);
}

.terminal-btn {
  font-size: 11px;
  font-weight: 600;
  color: #d8e4ee;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid #2a3f54;
  border-radius: 5px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background 0.15s;
}

.terminal-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.terminal-output {
  margin: 0;
  padding: 16px 20px;
  max-height: 260px;
  overflow-y: auto;
  font-family: 'SF Mono', Menlo, Consolas, 'Courier New', monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #c3d3e0;
  white-space: pre-wrap;
  word-break: break-word;
  transition: max-height 0.25s ease, padding 0.25s ease;
}

.terminal-section.collapsed .terminal-output {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

.term-ts {
  color: #5b7a94;
}

.term-error {
  color: #ff8a80;
}

.term-resolved {
  color: #6ee7a8;
}

.term-refresh {
  color: #7db8ff;
}
