/* Theme system. One axis: data-theme = graphite | daylight | midnight | night.
   Every theme defines the same SEMANTIC colors, so status always means the
   same thing no matter which skin is chosen:
     --rx    receiving audio        (green)
     --tx    I am transmitting      (red)
     --busy  another operator is talking (amber)
     --accent  selection / interactive highlights (a quiet blue or teal)
     --down  link down / offline (neutral gray)
   Older rules in this file still say --phosphor / --amber / --red; those names
   are kept as aliases below so nothing unrelated breaks. */

:root {
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", "Inter", system-ui, sans-serif;
}

/* ---- Graphite (default): neutral dark slate with a steel-blue accent ---- */
:root, :root[data-theme="graphite"] {
  --bg-deep: #101318;
  --panel: #181d24;
  --panel-raised: #222a35;
  --input-bg: #12161c;
  --hairline: #2c3541;
  --text-primary: #e8ebf0;
  --text-dim: #8b96a5;
  --accent: #6aa6ff;
  --accent-dim: #3f78c9;
  --accent-glow: rgba(106, 166, 255, 0.08);
  --rx: #3fc77f;
  --tx: #f0524f;
  --busy: #f2a93b;
  --down: #5b6574;
  --on-fill: #ffffff;
}

/* ---- Daylight: light, high-contrast, for bright rooms ---- */
:root[data-theme="daylight"] {
  --bg-deep: #eef1f5;
  --panel: #ffffff;
  --panel-raised: #dfe5ee;
  --input-bg: #ffffff;
  --hairline: #d0d8e3;
  --text-primary: #17202b;
  --text-dim: #5a6878;
  --accent: #2f6fed;
  --accent-dim: #2457c0;
  --accent-glow: rgba(47, 111, 237, 0.07);
  --rx: #1a8a4f;
  --tx: #d6342f;
  --busy: #b8730f;
  --down: #8a95a3;
  --on-fill: #ffffff;
}

/* ---- Midnight: deep navy with a teal accent ---- */
:root[data-theme="midnight"] {
  --bg-deep: #0a1020;
  --panel: #111a2f;
  --panel-raised: #1b2848;
  --input-bg: #0d1527;
  --hairline: #263556;
  --text-primary: #e3eaf7;
  --text-dim: #8393b3;
  --accent: #35c9b5;
  --accent-dim: #1f9a8a;
  --accent-glow: rgba(53, 201, 181, 0.07);
  --rx: #52d68a;
  --tx: #ff5d6c;
  --busy: #ffb454;
  --down: #566485;
  --on-fill: #1a0a0c;
}

/* ---- Night shift: dim warm theme for dark rooms and overnight watches ---- */
:root[data-theme="night"] {
  --bg-deep: #120d0b;
  --panel: #1a1411;
  --panel-raised: #2a211c;
  --input-bg: #150f0d;
  --hairline: #3a2d26;
  --text-primary: #e2cdbf;
  --text-dim: #9a8173;
  --accent: #e08a4a;
  --accent-dim: #a8622b;
  --accent-glow: rgba(224, 138, 74, 0.07);
  --rx: #7fbf7a;
  --tx: #ff5a4d;
  --busy: #e0b043;
  --down: #6b5a4f;
  --on-fill: #1a0b08;
}

/* Legacy names used by older rules below (inherited from allmon-fusion). */
:root {
  --phosphor: var(--accent);
  --phosphor-dim: var(--accent-dim);
  --amber: var(--busy);
  --red: var(--tx);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--sans);
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 50% -10%, var(--accent-glow), transparent 60%);
}

::selection { background: var(--phosphor-dim); color: #04120a; }

button, input, select { font-family: inherit; }

a { color: var(--phosphor); }

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--hairline);
  background: linear-gradient(to bottom, #0d1512, #0a0f0d);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand h1 {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--text-primary);
}

.brand h1 .accent { color: var(--phosphor); }

.brand-led, .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  box-shadow: none;
  flex-shrink: 0;
}

.brand-led.up { background: var(--phosphor); box-shadow: 0 0 8px var(--phosphor); }
.brand-led.down { background: var(--red); box-shadow: 0 0 8px var(--red); }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.conn-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-transform: lowercase;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.ghost-btn:hover { border-color: var(--phosphor-dim); color: var(--phosphor); }

/* ---------------- Grid ---------------- */

.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--mono);
  padding: 60px 0;
}

/* ---------------- Node panel ---------------- */

.node-panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.node-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  background: var(--panel-raised);
}

.node-id-block { display: flex; align-items: baseline; gap: 10px; }

.node-number {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.node-callsign {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--phosphor);
  text-transform: uppercase;
}

.node-status-block {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot.idle { background: var(--phosphor-dim); }
.status-dot.keyed {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  animation: pulse-tx 1s ease-in-out infinite;
}
.status-dot.offline { background: var(--red); }

@keyframes pulse-tx {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.status-text {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.node-desc {
  padding: 0 16px 10px;
  font-size: 12px;
  color: var(--text-dim);
  min-height: 14px;
}

.ruler {
  height: 6px;
  background-image: repeating-linear-gradient(
    to right,
    var(--hairline) 0,
    var(--hairline) 1px,
    transparent 1px,
    transparent 8px
  );
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.links-wrap { padding: 10px 16px; flex: 1; }

.links-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}

.links-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  padding: 4px 6px;
  border-bottom: 1px solid var(--hairline);
}

.links-table td {
  padding: 6px 6px;
  border-bottom: 1px solid rgba(37, 53, 48, 0.5);
  color: var(--text-primary);
}

.links-table tr.row-keyed td { color: var(--amber); }
.links-table tr.row-keyed { background: rgba(255, 176, 32, 0.06); }

.link-disconnect-btn {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--red);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
}
.link-disconnect-btn:hover { border-color: var(--red); }

.no-links {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 12px 0;
}

.ami-unavailable {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  font-style: italic;
  padding: 12px 0;
  opacity: 0.7;
}

.control-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
}

.connect-input {
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  font-family: var(--mono);
  padding: 6px 8px;
  border-radius: 3px;
  width: 90px;
}
.connect-input:focus { outline: none; border-color: var(--phosphor-dim); }

.connect-mode, .favorites-select {
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  font-size: 12px;
  border-radius: 3px;
  padding: 6px 4px;
}

.btn {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn:hover { border-color: var(--phosphor-dim); color: var(--phosphor); }
.btn-connect { color: var(--phosphor); border-color: var(--phosphor-dim); }
.btn-disconnect-all, .btn-reconnect-all { color: var(--text-dim); }
.btn-disconnect-all:hover { color: var(--red); border-color: var(--red); }

.control-feedback {
  padding: 0 16px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  min-height: 14px;
}
.control-feedback.error { color: var(--red); }
.control-feedback.ok { color: var(--phosphor); }

/* ---------------- View-only lock state ---------------- */

.control-locked {
  padding: 14px 16px;
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}
.control-locked a {
  color: var(--phosphor);
  text-decoration: none;
  border-bottom: 1px dotted var(--phosphor-dim);
}

.link-disconnect-btn.disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ---------------- Topbar auth + theme controls ---------------- */

.topbar-right { flex-wrap: wrap; }

.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}

.auth-area a { text-decoration: none; }

.theme-toggle {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--mono);
}
.theme-toggle:hover { border-color: var(--phosphor-dim); color: var(--phosphor); }

.accent-picker {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
}

.accent-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: pointer;
  padding: 0;
}
.accent-swatch.active {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* ---------------- Favorites manager ---------------- */

.favorites-manager {
  grid-column: 1 / -1;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 4px;
}

.favorites-manager h2 {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.favorites-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.favorite-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-raised);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
  font-family: var(--mono);
  font-size: 12px;
}

.favorite-chip .fav-node { color: var(--phosphor); }

.favorite-chip button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
}
.favorite-chip button:hover { color: var(--red); }

.favorites-add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.favorites-add-form input {
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  font-family: var(--mono);
  padding: 6px 8px;
  border-radius: 3px;
}
.favorites-add-form input[name="label"] { width: 200px; }
.favorites-add-form input[name="node"] { width: 100px; }

/* ---------------- Login page ---------------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 36px 40px;
  width: 320px;
  text-align: center;
  position: relative;
}

.login-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor);
  margin: 0 auto 18px;
}

.login-title {
  font-family: var(--mono);
  font-size: 22px;
  margin: 0;
}
.login-title .accent { color: var(--phosphor); }

.login-sub {
  color: var(--text-dim);
  font-size: 12px;
  margin: 4px 0 26px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#login-form { display: flex; flex-direction: column; gap: 12px; }

#login-form label {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
}

#login-form input, #login-form select {
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  padding: 10px;
  border-radius: 4px;
  font-family: var(--mono);
}
#login-form input:focus, #login-form select:focus { outline: none; border-color: var(--phosphor-dim); }

#login-form button {
  background: var(--phosphor-dim);
  border: none;
  color: #04120a;
  font-weight: 600;
  padding: 10px;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.15s;
}
#login-form button:hover { background: var(--phosphor); }

.login-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 4px;
}

.login-back {
  margin-top: 20px;
  font-size: 12px;
}

@media (max-width: 480px) {
  .node-grid { grid-template-columns: 1fr; padding: 12px; }
  .topbar { padding: 12px 14px; }
}

/* ---------------- allmon-dispatch additions: PTT + call controls ---------------- */

.node-panel {
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.node-panel:hover { border-color: var(--phosphor-dim); }

.node-panel.transmitting {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px var(--amber), 0 0 16px rgba(255, 176, 32, 0.15);
}

.node-panel.selected {
  border-color: var(--phosphor);
  box-shadow: 0 0 0 2px var(--phosphor), 0 0 14px var(--accent-glow);
}

.node-panel.selected.transmitting {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber), 0 0 18px rgba(255, 176, 32, 0.4);
}

.call-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--hairline);
  background: var(--panel-raised);
}

/* Interactive controls inside the (now clickable) card must not trigger
   node selection when used - handled via stopPropagation in app.js, but
   also keep their own cursor so it's visually obvious they're distinct. */
.volume-slider {
  flex: 1;
  accent-color: var(--phosphor);
  cursor: pointer;
}

.vu-meter {
  height: 5px;
  margin: 0 16px 12px;
  background: var(--input-bg);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow: hidden;
}
.vu-fill {
  height: 100%;
  width: 0%;
  background: var(--phosphor);
  transition: width 0.06s linear;
}
.node-panel.vu-clip .vu-fill { background: var(--red); }

.ptt-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-top: 1px solid var(--hairline);
  background: linear-gradient(to top, #0d1512, #0a0f0d);
  z-index: 10;
}

.node-grid { padding-bottom: 100px; }

.ptt-bar-label {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-dim);
}
.ptt-bar-label strong { color: var(--phosphor); }

.ptt-btn {
  flex: 1;
  max-width: 420px;
  padding: 18px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--panel-raised);
  color: var(--phosphor-dim);
  border: 2px solid var(--hairline);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.ptt-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ptt-btn.active {
  background: var(--amber);
  color: #2a1c00;
  border-color: var(--amber);
  box-shadow: 0 0 18px rgba(255, 176, 32, 0.4);
}

.status-dot.transmitting {
  background: var(--amber);
  box-shadow: 0 0 10px var(--amber);
  animation: pulse-tx 1s ease-in-out infinite;
}

.status-dot.receiving {
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor);
  animation: pulse-tx 0.4s ease-in-out infinite;
}

.node-panel.active:not(.transmitting) {
  border-color: var(--phosphor-dim);
}

/* ---- Floor control: another operator is talking, and notifications ---- */

.status-dot.busy { background: var(--amber); }
.node-panel.busy { border-color: var(--amber); }
.ptt-btn.busy { color: var(--amber); border-color: var(--amber); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%) translateY(8px);
  max-width: min(90vw, 460px);
  padding: 10px 16px;
  background: var(--panel-raised);
  color: var(--text-primary);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { border-color: var(--amber); color: var(--amber); }

/* =====================================================================
   Stage 2: semantic status colors, per-card PTT, keyboard hint bar.
   These come last so they win over the inherited rules above.
   ===================================================================== */

.topbar { background: var(--panel); }
.ptt-bar { background: var(--panel); }
::selection { background: var(--accent-dim); color: var(--on-fill); }

.brand-led.up { background: var(--rx); box-shadow: 0 0 8px var(--rx); }
.brand-led.down { background: var(--down); box-shadow: none; }

.status-dot.idle { background: var(--text-dim); box-shadow: none; animation: none; }
.status-dot.receiving { background: var(--rx); box-shadow: 0 0 10px var(--rx); }
.status-dot.transmitting { background: var(--tx); box-shadow: 0 0 10px var(--tx); }
.status-dot.busy { background: var(--busy); box-shadow: 0 0 10px var(--busy); }
.status-dot.offline { background: var(--down); box-shadow: none; }

.node-panel { border-color: var(--hairline); }
.node-panel:hover { border-color: var(--accent-dim); }
.node-panel.active:not(.transmitting) { border-color: var(--rx); }
.node-panel.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.node-panel.busy,
.node-panel.selected.busy { border-color: var(--busy); box-shadow: 0 0 0 2px var(--busy); }
.node-panel.transmitting,
.node-panel.selected.transmitting {
  border-color: var(--tx);
  box-shadow: 0 0 0 2px var(--tx), 0 0 18px color-mix(in srgb, var(--tx) 35%, transparent);
}

.vu-fill { background: var(--rx); }
.node-panel.vu-clip .vu-fill { background: var(--tx); }
.links-table tr.row-keyed td { color: var(--busy); }
.links-table tr.row-keyed { background: color-mix(in srgb, var(--busy) 8%, transparent); }
.toast.warn { border-color: var(--busy); color: var(--busy); }

/* ---- Per-card PTT button ---- */
.card-ptt {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--hairline);
}
.card-ptt-btn {
  width: 100%;
  padding: 15px 10px;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent-dim);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.card-ptt-btn:hover:not(:disabled) { background: var(--accent-glow); border-color: var(--accent); }
.card-ptt-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.card-ptt-btn.busy { color: var(--busy); border-color: var(--busy); }
.card-ptt-btn.active {
  background: var(--tx);
  border-color: var(--tx);
  color: var(--on-fill);
  box-shadow: 0 0 16px color-mix(in srgb, var(--tx) 45%, transparent);
}

/* ---- Footer: now only a keyboard hint (PTT lives on each card) ---- */
.ptt-bar { justify-content: space-between; gap: 16px; }
.ptt-hint-line { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 7px;
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-raised);
  color: var(--text-primary);
}

/* ---- Skin picker in the top bar ---- */
.theme-select {
  background: var(--panel-raised);
  color: var(--text-primary);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}
.theme-select:hover { border-color: var(--accent-dim); }
.operators-line { color: var(--text-dim); }
.operators-line .me { color: var(--accent); }
