/* ── Reset & tokens ─────────────────────────────────────────────────────────
   Fifth-gen "operational glass" theme (F-22/F-35 tactical display).
   NATO color semantics: cyan = own-ship / UI / interactive, green = known /
   in-tolerance, amber = unknown / caution, red = hostile / out-of-tolerance.
   (Replaces the original phosphor-CRT look.) */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0b1119;   /* deep slate device background */
  --panel-bg:  #0e1722;   /* glass panel */
  --panel-2:   #101c28;   /* raised control surface */
  --inset:     #0a0f16;   /* recessed wells / inputs */
  --line:      #1b2733;   /* hairline border */
  --line-2:    #26384a;   /* stronger border */

  --ink:       #e8eef7;
  --dim:       #8aa0bd;
  --faint:     #5f7488;

  --cyan:      #34c9ec;
  --green:     #36d39a;
  --amber:     #f5b53f;
  --red:       #ff5468;

  --cyan-soft: rgba(52, 201, 236, 0.12);
  --cyan-ring: rgba(52, 201, 236, 0.25);

  --font:      'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono:      'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-rows: 52px 1fr;
  height: 100vh;
}

.content-area {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(260px, 1fr) 310px;
  gap: 9px;
  padding: 0 9px 9px;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--line);
}

.hdr-sys {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2.5px;
  color: var(--cyan);
}

.hdr-center {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--dim);
}

.hdr-clock {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  min-width: 220px;
  text-align: right;
}

/* Left header cluster: portal back-link + system name. */
.hdr-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Portal back-link — glass-styled to match the cockpit chrome. Resolves
   ../../index.html -> the portal landing. */
.rwr-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 7px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--dim);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.rwr-back:hover {
  background: var(--cyan-soft);
  color: var(--cyan);
  border-color: var(--cyan);
}
.rwr-back svg { flex-shrink: 0; opacity: 0.85; }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  overflow: hidden;
}

.scope-col, .history-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  gap: 9px;
}

/* Inner canvas wrapper — takes all remaining vertical space */
.canvas-panel {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Record panel in history col — fixed height, scrollable table */
#record-panel {
  flex-shrink: 0;
}

canvas {
  width: 100%;
  height: 100%;
  flex: 1;
  display: block;
}

.controls-col {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;       /* critical: lets overflow-y: auto engage in a grid cell */
  overflow-y: auto;
  padding-right: 2px;
}

.controls-col::-webkit-scrollbar { width: 6px; }
.controls-col::-webkit-scrollbar-track { background: var(--bg); }
.controls-col::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.section {
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sep {
  height: 1px;
  background: var(--line);
  margin: 3px 0;
}

/* ── Section headers ────────────────────────────────────────────────────── */
.sec-hdr {
  font-size: 9px;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: 1.7px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.sec-hdr::before {
  content: "";
  width: 5px; height: 5px;
  background: var(--cyan);
  border-radius: 1px;
  flex-shrink: 0;
}

.sec-hdr-sub {
  font-size: 8.5px;
  font-weight: 600;
  color: var(--faint);
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

/* ── Readout boxes ──────────────────────────────────────────────────────── */
.readout-row {
  display: flex;
  gap: 7px;
}

.readout-box {
  flex: 1;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
}

.readout-box.half { flex: 1; }

.ro-label {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--faint);
}

.ro-val {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  color: var(--cyan);
  text-align: right;
  line-height: 1.1;
  transition: color 0.2s;
}

.ro-med { font-size: 20px; }

.ro-unit {
  font-size: 8px;
  color: var(--faint);
  letter-spacing: 0.8px;
  text-align: right;
}

/* ── Status / signal ────────────────────────────────────────────────────── */
.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.3px;
  color: var(--green);
  border: 1px solid rgba(54, 211, 154, 0.35);
  border-radius: 4px;
  padding: 4px 9px;
}
.conn-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.sig-wrap { display: flex; flex-direction: column; gap: 4px; }

.sig-top-lbl {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--faint);
}

.sig-track {
  position: relative;
  height: 16px;
  background: var(--inset);
  border: 1px solid var(--line-2);
  border-radius: 3px;
  overflow: hidden;
}

.sig-fill {
  position: absolute;
  top: 2px; bottom: 2px; left: 2px;
  width: 0%;
  background: var(--green);
  border-radius: 1px;
  transition: width 0.15s, background 0.15s;
}

/* segmented overlay — notches the continuous fill into a level meter */
.sig-track::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg, transparent 0 9px, var(--inset) 9px 11px);
  pointer-events: none;
}

.sig-lbl {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ink);
  text-shadow: 0 0 3px var(--bg);
  pointer-events: none;
}

/* ── AoA Slider ─────────────────────────────────────────────────────────── */
.aoa-readout {
  font-family: var(--mono);
  font-size: 38px;
  font-weight: 600;
  color: var(--cyan);
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  padding: 4px 0;
  letter-spacing: 1px;
}

.aoa-slider {
  width: 100%;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 22px;
}

.aoa-slider::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--inset);
  border: 1px solid var(--line-2);
  border-radius: 3px;
}
.aoa-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  margin-top: -6px;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(52, 201, 236, 0.6);
  transition: box-shadow 0.1s;
}
.aoa-slider::-webkit-slider-thumb:hover { box-shadow: 0 0 12px rgba(52, 201, 236, 0.9); }
.aoa-slider::-moz-range-track {
  height: 6px;
  background: var(--inset);
  border: 1px solid var(--line-2);
  border-radius: 3px;
}
.aoa-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(52, 201, 236, 0.6);
}

.tick-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 8px;
  color: var(--faint);
  padding: 0 2px;
  margin-top: -2px;
}

/* ── Preset buttons ─────────────────────────────────────────────────────── */
.preset-row {
  display: flex;
  gap: 4px;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.btn-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-btn {
  background: var(--panel-2);
  color: var(--dim);
  border: 1px solid var(--line-2);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  padding: 6px 3px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  flex: 1;
}

.preset-btn:hover {
  background: var(--cyan-soft);
  color: var(--cyan);
  border-color: var(--line-2);
}

.preset-btn.active {
  background: var(--cyan-soft);
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: inset 0 0 0 1px var(--cyan-ring);
}

/* ── Custom input row ───────────────────────────────────────────────────── */
.custom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  color: var(--faint);
}

.cust-lbl { white-space: nowrap; letter-spacing: 0.5px; }

.cust-spin {
  flex: 1;
  background: var(--inset);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 6px;
  outline: none;
  min-width: 0;
}

.cust-spin:focus { border-color: var(--cyan); }

.set-btn {
  background: var(--panel-2);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}

.set-btn:hover { background: var(--cyan-soft); }

/* ── Record panel ───────────────────────────────────────────────────────── */
/* RECORD is the primary action -> cyan (red is reserved for threats). */
.record-btn {
  width: 100%;
  background: var(--cyan-soft);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  padding: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.1s;
}

.record-btn:hover  { background: rgba(52, 201, 236, 0.2); box-shadow: 0 0 14px rgba(52, 201, 236, 0.25); }
.record-btn:active { background: rgba(52, 201, 236, 0.3); }

.table-wrap {
  height: 220px;     /* fixed: ~10 data rows + header, never grows */
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar { width: 5px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--line-2); }

#record-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 9px;
}

#record-table thead th {
  background: var(--panel-2);
  color: var(--faint);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 5px 3px;
  border-bottom: 1px solid var(--line-2);
  text-align: right;
  position: sticky;
  top: 0;
}

#record-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
#record-table tbody tr:hover { background: var(--cyan-soft); }

#record-table td {
  padding: 4px 4px;
  border-bottom: 1px solid #14202c;
  text-align: right;
  color: var(--dim);
}
#record-table td:first-child { text-align: left; color: var(--ink); }

.btn-row {
  display: flex;
  gap: 6px;
}

.action-btn {
  flex: 1;
  background: var(--panel-2);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  padding: 7px;
  cursor: pointer;
  border: 1px solid;
  transition: background 0.1s;
}

.action-btn:hover { background: var(--cyan-soft); }
.action-btn.export { color: var(--cyan); border-color: var(--line-2); }
.action-btn.export:hover { border-color: var(--cyan); }
.action-btn.clear  { color: var(--red);  border-color: var(--line-2); }
.action-btn.clear:hover { background: rgba(255, 84, 104, 0.12); border-color: var(--red); }

.count-lbl {
  font-family: var(--mono);
  font-size: 8px;
  color: var(--faint);
  text-align: center;
}
