:root {
  --bg: #07090d;
  --panel: #0e1319;
  --panel-alt: #141b24;
  --border: #1f2937;
  --border-bright: #2d3a4d;
  --text: #dbe4ee;
  --text-dim: #7d8ea3;
  --accent: #35a3ff;
  --green: #2fbf71;
  --amber: #eba33b;
  --red: #ec5550;
  --blue: #35a3ff;
  --purple: #a988ff;
  --mono: "IBM Plex Mono", "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(180deg, #0d131b, #07090d);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #175a9e);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  margin-left: 8px;
}

.subtitle {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--text-dim);
  max-width: 560px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right { display: flex; align-items: center; gap: 18px; flex-shrink: 0; }

.clock-block { text-align: right; }
.clock {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 1px;
}
.clock-label {
  font-size: 9.5px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-align: right;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 13px;
  border-radius: 8px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  min-width: 200px;
}

.conn-status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.conn-detail { display: flex; flex-direction: column; min-width: 0; }
.conn-text { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.conn-meta { font-size: 10.5px; color: var(--text-dim); font-family: var(--mono); }

.conn-status[data-status="connected"] .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.conn-status[data-status="connecting"] .dot,
.conn-status[data-status="reconnecting"] .dot {
  background: var(--amber);
  animation: pulse 1.2s infinite ease-in-out;
}
.conn-status[data-status="error"] .dot { background: var(--red); box-shadow: 0 0 8px var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  padding: 12px 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.8px; }

.stat-dep .stat-value { color: var(--blue); }
.stat-arr .stat-value { color: var(--purple); }
.stat-delayed .stat-value { color: var(--amber); }
.stat-avgdelay .stat-value { color: var(--amber); }
.stat-alerts .stat-value { color: var(--red); }
.stat-events .stat-value { color: var(--green); }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 10px;
  flex-wrap: wrap;
}

.seg {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn:not(.active):hover { color: var(--text); }

#searchBox {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  flex: 1;
  min-width: 200px;
}
#searchBox:focus { outline: none; border-color: var(--accent); }

.chips { display: flex; gap: 6px; }

.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 13px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.chip:hover { color: var(--text); border-color: var(--border-bright); }
.chip.active { background: rgba(53,163,255,0.15); border-color: var(--accent); color: var(--accent); }

.result-count { color: var(--text-dim); font-size: 11.5px; font-family: var(--mono); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.ghost-btn:hover { background: var(--panel-alt); }

/* ---------- table ---------- */

.table-wrap {
  padding: 0 20px 20px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-alt);
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-bright);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted-asc::after { content: " ▲"; color: var(--accent); }
thead th.sorted-desc::after { content: " ▼"; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
tbody tr:hover { background: var(--panel-alt); }
tbody td {
  padding: 6px 10px;
  white-space: nowrap;
  font-size: 12.5px;
  font-family: var(--mono);
}

td.cell-flight { font-family: var(--sans); }

tbody tr.row-delayed td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
tbody tr.row-alert td:first-child { box-shadow: inset 3px 0 0 var(--red); }

@keyframes rowflash {
  0% { background: rgba(53,163,255,0.22); }
  100% { background: transparent; }
}
tbody tr.flash { animation: rowflash 1.6s ease-out; }

.flight-name { font-weight: 700; font-size: 13px; }
.flight-sub { color: var(--text-dim); font-size: 10.5px; font-family: var(--mono); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--panel-alt);
  border: 1px solid var(--border-bright);
  font-family: var(--mono);
}

.pill-dep { color: var(--blue); border-color: rgba(53,163,255,0.45); background: rgba(53,163,255,0.08); }
.pill-arr { color: var(--purple); border-color: rgba(169,136,255,0.45); background: rgba(169,136,255,0.08); }

/* CDM state colors */
.state-SCH { color: var(--text-dim); }
.state-INI, .state-TOB, .state-TSA { color: var(--blue); border-color: rgba(53,163,255,0.4); }
.state-BRD { color: var(--amber); border-color: rgba(235,163,59,0.5); background: rgba(235,163,59,0.08); }
.state-GCL, .state-SUG, .state-TAX { color: var(--green); border-color: rgba(47,191,113,0.5); background: rgba(47,191,113,0.08); }
.state-AIR, .state-DEP { color: var(--purple); border-color: rgba(169,136,255,0.5); }
.state-CNX { color: var(--red); border-color: rgba(236,85,80,0.5); background: rgba(236,85,80,0.1); }

.time-cell { font-weight: 600; }
.time-dim { color: var(--text-dim); font-weight: 400; }
.time-rel { font-size: 10px; color: var(--text-dim); display: block; }

.delay-ontime { color: var(--green); }
.delay-minor { color: var(--amber); }
.delay-major { color: var(--red); font-weight: 700; }
.delay-none { color: var(--text-dim); }
.delay-early { color: var(--green); }

.gate-changed {
  color: var(--amber);
  font-weight: 700;
}
.gate-changed::after { content: " ⇄"; font-size: 10px; }

.alert-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 5px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
}

/* ---------- drawers ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
.scrim.visible { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: -520px;
  width: 500px;
  max-width: 94vw;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--border-bright);
  transition: right 0.22s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
}
.drawer.open { right: 0; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0; font-size: 14px; }

.drawer-body { padding: 14px 18px; overflow-y: auto; flex: 1; }

.detail-section { margin-bottom: 18px; }
.detail-section h3 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin: 0 0 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.kv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 12px;
}
.kv-grid .kv-label { color: var(--text-dim); font-size: 11.5px; }
.kv-grid .kv-value { font-size: 12.5px; font-weight: 600; font-family: var(--mono); }

.timeline-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--mono);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-key { color: var(--text-dim); }

.alert-item {
  background: rgba(236, 85, 80, 0.09);
  border: 1px solid rgba(236, 85, 80, 0.3);
  border-radius: 6px;
  padding: 9px 12px;
  margin-bottom: 8px;
  font-size: 12px;
}
.alert-item strong { display: block; margin-bottom: 3px; color: var(--red); }
.alert-item .alert-code { font-family: var(--mono); font-size: 10.5px; opacity: 0.8; }

.handler-chip {
  display: inline-block;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  margin: 0 5px 5px 0;
  font-family: var(--mono);
}

.log-drawer .log-body { font-family: var(--mono); font-size: 11px; }
.log-entry { padding: 5px 0; border-bottom: 1px solid var(--border); }
.log-ts { color: var(--text-dim); margin-right: 8px; }
.log-event { color: var(--accent); margin-right: 8px; }

/* ---------- watchlist & notifications ---------- */

.th-watch { width: 34px; text-align: center; }

.cell-watch { text-align: center; padding: 4px 4px !important; }

.watch-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-bright);
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.watch-btn:hover { border-color: var(--accent); color: var(--accent); }
.watch-btn.active {
  background: rgba(53,163,255,0.15);
  border-color: var(--accent);
  font-size: 12px;
}

tbody tr.row-watched { background: rgba(53,163,255,0.05); }
tbody tr.row-watched:hover { background: rgba(53,163,255,0.1); }

.toasts {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 340px;
  max-width: 90vw;
}

.toast {
  background: var(--panel-alt);
  border: 1px solid var(--accent);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease-out;
}
.toast-info { border-color: var(--border-bright); border-left-color: var(--green); }
.toast-out { opacity: 0; transform: translateX(20px); transition: all 0.35s; }

.toast-title { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.toast-body { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .clock-block { display: none; }
}
