/* ============================================================
   S Meter Web — Stylesheet
   Aesthetic: Industrial-Modern instrument panel
   Dark canvases, clean light UI chrome, monospace data
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&family=Orbitron:wght@400;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  /* Panel / chrome */
  --bg-app:        #1a1d23;
  --bg-panel:      #22262f;
  --bg-card:       #2a2f3a;
  --bg-input:      #1e2128;
  --border:        #3a3f4d;
  --border-focus:  #5b8aff;

  /* Instrument canvas */
  --canvas-bg:     #0e1018;
  --canvas-border: #2e3340;

  /* Accent palette */
  --green:         #39e87a;
  --green-dim:     #1f6b41;
  --amber:         #f5a623;
  --amber-dim:     #7a5210;
  --red:           #e84040;
  --blue:          #5b8aff;
  --blue-dim:      #2a3d7a;
  --cyan:          #3fd6e8;

  /* Text */
  --text-primary:  #e8eaf0;
  --text-secondary:#8d93a5;
  --text-dim:      #555c6e;
  --text-value:    #39e87a;

  /* Status */
  --status-ok:     #39e87a;
  --status-warn:   #f5a623;
  --status-err:    #e84040;
  --status-idle:   #555c6e;

  /* Sizing */
  --tab-h:         44px;
  --radius:        8px;
  --radius-sm:     5px;
  --shadow:        0 4px 24px rgba(0,0,0,0.5);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── App Shell ─────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

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

#header h1 {
  font-family: 'Orbitron', monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--green);
  text-transform: uppercase;
}

#header h1 span {
  color: var(--text-secondary);
  font-weight: 400;
}

#status-bar {
  display: flex;
  align-items: center;
  gap: 20px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-idle);
  transition: background 0.3s;
  flex-shrink: 0;
}
.status-dot.ok   { background: var(--status-ok);   box-shadow: 0 0 6px var(--status-ok); }
.status-dot.warn { background: var(--status-warn);  box-shadow: 0 0 6px var(--status-warn); }
.status-dot.err  { background: var(--status-err);   box-shadow: 0 0 6px var(--status-err); }

/* SDR activity pulse — fired each second a data chunk arrives */
@keyframes sdr-data-pulse {
  0%   { transform: scale(1);   box-shadow: 0 0 6px var(--status-ok); }
  40%  { transform: scale(1.7); box-shadow: 0 0 14px var(--status-ok); }
  100% { transform: scale(1);   box-shadow: 0 0 6px var(--status-ok); }
}
.status-dot.sdr-pulse {
  animation: sdr-data-pulse 0.4s ease-out forwards;
}

/* ── Tab Bar ───────────────────────────────────────────── */
#tab-bar {
  display: flex;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  flex-shrink: 0;
  gap: 2px;
}

.tab-btn {
  height: var(--tab-h);
  padding: 0 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  white-space: nowrap;
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--green);
  transform: scaleX(0);
  transition: transform 0.2s;
  border-radius: 2px 2px 0 0;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--green); }
.tab-btn.active::after { transform: scaleX(1); }

/* ── Tab Content ───────────────────────────────────────── */
#tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-pane {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
}
.tab-pane.active { display: flex; flex-direction: column; gap: 16px; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 14px;
}

/* ── Instrument Canvas Wrapper ─────────────────────────── */
.instrument-wrap {
  background: var(--canvas-bg);
  border: 1px solid var(--canvas-border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

canvas {
  display: block;
}

/* ── S Meter Tab ───────────────────────────────────────── */
/* Inherits standard .tab-pane.active flex-column layout.
   The meter canvas is compact — S-meters are instruments, not charts. */

#meter-canvas-wrap {
  height: 150px;
  flex-shrink: 0;
}

.meter-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

.readout-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-width: 90px;
}

.readout-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.readout-value {
  font-family: 'DM Mono', monospace;
  font-size: 22px;
  font-weight: 500;
  color: var(--text-value);
  line-height: 1;
}

.readout-unit {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── History Tab ───────────────────────────────────────── */
#history-canvas-wrap {
  flex: 1;
  min-height: 300px;
}

/* ── Pattern Tab ───────────────────────────────────────── */
/* Override base flex-column so we control row heights explicitly */
#pattern-pane.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;   /* prevent outer scroll — inner areas scroll */
}

/* Middle belt: polar canvas (grows) + right sidebar (fixed) */
#pattern-main {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 12px;
  flex: 1;            /* fill remaining vertical space */
  min-height: 0;      /* allow grid to shrink below content size */
}

#pattern-canvas-wrap {
  min-height: 0;      /* let canvas shrink with the grid cell */
}

#pattern-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
}

/* Sample log — 6 visible lines */
#pattern-log {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: #8d93a5;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  height: calc(6 * 1.6em + 16px);   /* 6 lines at 1.6 line-height + padding */
  overflow-y: auto;
  white-space: pre;
  line-height: 1.6;
}

/* Thin vertical divider reused in the controls bar */
.v-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

#pattern-controls-row {
  /* already flex-shrink:0 inline; nothing extra needed */
}

/* ── Calibration Tab ───────────────────────────────────── */
.cal-table-wrap {
  overflow-x: auto;
}

.cal-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'DM Mono', monospace;
  font-size: 13px;
}

.cal-table th {
  background: var(--bg-input);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.cal-table td {
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-primary);
}

.cal-table tr:hover td { background: rgba(255,255,255,0.03); }

.cal-table input[type="number"],
.cal-table input[type="text"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 3px 7px;
  width: 80px;
  outline: none;
}
.cal-table input:focus { border-color: var(--border-focus); }

/* ── Config Tab ────────────────────────────────────────── */
#config-pane.active {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-content: start;
}

.config-full { grid-column: 1 / -1; }

.form-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
  align-items: center;
}

.form-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Form Controls ─────────────────────────────────────── */
select, input[type="text"], input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
select:focus, input:focus { border-color: var(--border-focus); }
select option { background: var(--bg-panel); }

input[type="checkbox"] {
  accent-color: var(--green);
  width: 15px; height: 15px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--green);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--amber);
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--green);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
}

input[type="range"]::-moz-range-thumb:hover {
  background: var(--amber);
  transform: scale(1.1);
}

input[type="range"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="range"]:disabled::-webkit-slider-thumb {
  cursor: not-allowed;
  background: var(--text-dim);
}

input[type="range"]:disabled::-moz-range-thumb {
  cursor: not-allowed;
  background: var(--text-dim);
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-secondary); background: var(--bg-panel); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: #fff;
}
.btn-primary:hover { background: var(--blue); }

.btn-green {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green);
}
.btn-green:hover { background: var(--green); color: #000; }

.btn-red {
  background: rgba(232,64,64,0.15);
  border-color: var(--red);
  color: var(--red);
}
.btn-red:hover { background: var(--red); color: #fff; }

.btn-amber {
  background: var(--amber-dim);
  border-color: var(--amber);
  color: var(--amber);
}
.btn-amber:hover { background: var(--amber); color: #000; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Toggle Button ─────────────────────────────────────── */
.toggle-btn {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px;
  gap: 2px;
}

.toggle-opt {
  padding: 5px 14px;
  border-radius: 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-opt.active {
  background: var(--green);
  color: #000;
}

/* ── Segmented Control ─────────────────────────────────── */
.seg-ctrl {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg-btn {
  padding: 5px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  border-right: 1px solid var(--border);
  transition: all 0.15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: var(--blue-dim); color: var(--blue); }
.seg-btn:hover:not(.active) { background: rgba(255,255,255,0.05); color: var(--text-primary); }

/* ── CI-V Section (shown/hidden) ───────────────────────── */
.civ-section, .cat-section { display: none; }
.civ-section.visible, .cat-section.visible { display: contents; }

/* ── Divider ───────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Tooltip ───────────────────────────────────────────── */
[title] { cursor: help; }

/* ── Ruler info box ────────────────────────────────────── */
#ruler-readout {
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  color: var(--amber);
  min-width: 80px;
}

/* ── Pattern info ──────────────────────────────────────── */
.pattern-stat {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
}
.pattern-stat-label { color: var(--text-secondary); }
.pattern-stat-value { font-family: 'DM Mono', monospace; color: var(--text-value); }

/* ── Bearing input row ─────────────────────────────────── */
#bearing-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#bearing-display {
  font-family: 'Orbitron', monospace;
  font-size: 28px;
  font-weight: 600;
  color: var(--cyan);
  min-width: 70px;
  text-align: center;
}

/* ── Notification toast ────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 1000;
  pointer-events: none;
  max-width: 320px;
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}
#toast.ok  { border-color: var(--green); }
#toast.err { border-color: var(--red); }
#toast.warn{ border-color: var(--amber); }
