/* ubersdr_wefax — stylesheet */

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

:root {
  --bg:        #1a1a1a;
  --bg2:       #242424;
  --bg3:       #2e2e2e;
  --border:    #3a3a3a;
  --text:      #e0e0e0;
  --text-dim:  #888;
  --accent:    #4a9eff;
  --accent2:   #2d7dd2;
  --danger:    #e05252;
  --success:   #52c07a;
  --warn:      #e0a052;
  --header-h:  52px;
  --badges-h:  48px;
  --top-h:     calc(var(--header-h) + var(--badges-h));
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Header ── */

header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

#app-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ── Badges bar ── */

#badges-bar {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: var(--badges-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 99;
  gap: 8px;
}

#channel-selector-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

#channel-selector-wrap label { color: var(--text-dim); }

select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
}

select:focus { outline: 2px solid var(--accent); }

/* Status badges */
#status-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.status-running     { border-color: var(--success); color: var(--success); }
.status-reconnecting{ border-color: var(--warn);    color: var(--warn); }
.status-stopped     { border-color: var(--danger);  color: var(--danger); }
.status-receiving   { border-color: var(--accent);  color: var(--accent);
                      animation: badge-pulse 1.2s ease-in-out infinite; }

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

/* Live SNR sparkline widget — sits at the far right of #badges-bar */
#live-snr-widget {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  background: #0f3460;
  border-radius: 8px;
  padding: 3px 10px 3px 8px;
  flex-shrink: 0;
}

#live-snr-label {
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

#live-snr-chart {
  display: block;
  width: 200px;
  height: 36px;
}

#live-snr-value {
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 4.5ch;
  text-align: right;
  white-space: nowrap;
  color: #6fcf97;
}
.status-unknown     { border-color: var(--text-dim);color: var(--text-dim); }

/* ── Main layout ── */

.main-layout {
  display: grid;
  grid-template-columns: 260px 1fr 200px;
  height: calc(100vh - var(--top-h));
  margin-top: var(--top-h);
  overflow: hidden;
}

/* ── SNR bar canvas — sits inline beside the image/live canvas ── */
.snr-bar-canvas {
  display: block;
  width: 14px;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 8px;   /* match #live-canvas-wrap / #detail-image-wrap padding */
  background: var(--bg2);
  border-left: 1px solid var(--border);
}

/* ── Gallery panel ── */

#gallery-panel {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#gallery-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#gallery-title { font-weight: 600; }
#gallery-count { font-size: 12px; color: var(--text-dim); }

#gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#gallery-load-more {
  flex-shrink: 0;
}

#gallery-sentinel {
  height: 1px;
  flex-shrink: 0;
}

/* ── Day groups ── */
.day-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  position: relative;
  padding: 28px 8px 8px;
}

.day-group-label {
  position: absolute;
  top: -1px;
  left: 10px;
  background: var(--bg2);
  padding: 0 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  line-height: 1;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
}

.day-group-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  color: var(--accent2);
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 1.6em;
  text-transform: none;
  line-height: 1.4;
}

.day-group-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-items: start;
}

/* Thumb cards */
.thumb-card {
  background: var(--bg3);
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.thumb-card:hover { border-color: var(--accent); }
.thumb-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent2); }

.thumb-img-wrap { width: 100%; background: #111; overflow: hidden; }
.thumb-img { width: 100%; height: auto; display: block; image-rendering: pixelated; }

.thumb-meta {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.thumb-freq { font-weight: 600; font-size: 13px; }
.thumb-time { font-size: 11px; color: var(--text-dim); }
.thumb-size { font-size: 11px; color: var(--text-dim); }

/* ── Detail / live panel ── */

#detail-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Live strip */
#live-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#live-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  background: var(--bg2);
}

#live-label { font-weight: 600; }
#live-line-count { font-size: 12px; color: var(--text-dim); }

/* #live-body: row containing the scrollable canvas area + SNR bar */
#live-body {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

#live-canvas-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  background: #111;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px;
}

#live-canvas {
  display: block;
  image-rendering: pixelated;
  max-width: 100%;
}

/* Detail view */
#detail-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#detail-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

#detail-nav-spacer {
  flex: 1;
}

/* Image + sidebar sit side-by-side below the nav bar */
#detail-body {
  display: flex;
  flex-direction: row;
  flex: 1;
  overflow: hidden;
}

#detail-image-wrap {
  flex: 1;
  overflow: auto;
  background: #111;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px;
  min-width: 0;
}

#detail-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  cursor: zoom-in;
}

/* Compact right sidebar: meta + delete button */
#detail-sidebar {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

#detail-meta {
  padding: 8px 10px;
  flex: 1;
}

#detail-meta-table { width: 100%; border-collapse: collapse; }
#detail-meta-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: normal;
  font-size: 11px;
  padding: 2px 6px 2px 0;
  white-space: nowrap;
}
#detail-meta-table td {
  padding: 2px 0;
  font-size: 11px;
  word-break: break-word;
}

#detail-actions {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Download link styled as a button */
#btn-download {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
#btn-download:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Audio panel ── */

#audio-panel {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
  overflow-y: auto;
}

#audio-panel-header { font-weight: 600; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

#audio-channel-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#audio-channel-wrap label { font-size: 12px; color: var(--text-dim); }
#audio-channel-wrap select { width: 100%; }

#audio-controls { display: flex; gap: 6px; }

/* SNR display */
#snr-display {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#snr-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}
.snr-label { color: var(--text-dim); }
#snr-value { font-weight: 600; font-variant-numeric: tabular-nums; }
#snr-bar-wrap {
  height: 6px;
  background: #111;
  border-radius: 3px;
  overflow: hidden;
}
#snr-bar {
  height: 100%;
  width: 0%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.4s ease, background-color 0.4s;
}

/* Spectrum / waterfall */
#marker-spectrum,
#marker-waterfall {
  display: block;
  width: 100%;
  height: 8px;
  background: #111;
}

#spectrum-canvas {
  display: block;
  width: 100%;
  height: 80px;
  background: #00007f;
  border-radius: 2px;
}

#waterfall-canvas {
  display: block;
  width: 100%;
  height: 160px;
  background: #000;
  border-radius: 2px;
}

/* VU meter */
#vu-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
#vu-label { font-size: 10px; color: var(--text-dim); flex-shrink: 0; }
#vu-track {
  flex: 1;
  height: 8px;
  background: #111;
  border-radius: 4px;
  overflow: hidden;
}
#vu-bar {
  height: 100%;
  width: 0%;
  background: #6fcf97;
  border-radius: 4px;
  transition: width 0.05s linear, background-color 0.1s;
}

/* Display controls */
#audio-panel-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#audio-panel-controls label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-dim);
}
#audio-panel-controls input[type="number"] {
  width: 60px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 11px;
  text-align: right;
}

/* ── Buttons ── */

button {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) { background: var(--bg2); border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

/* ── Lightbox ── */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 200;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 16px;
}

#lightbox-body {
  position: relative;
  flex-shrink: 0;
}

#lightbox-img {
  display: block;
  image-rendering: pixelated;
  /* Show at native pixel size — no scaling */
}

#lightbox-controls {
  position: fixed;
  top: 10px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 201;
}

#lightbox-controls button {
  background: rgba(0,0,0,0.6);
  border: 1px solid #555;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s;
}

#lightbox-controls button:hover {
  background: rgba(60,60,60,0.85);
  border-color: var(--accent);
}

/* ── Utility ── */

.hidden { display: none !important; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* Responsive: collapse audio panel on narrow screens */
@media (max-width: 900px) {
  .main-layout { grid-template-columns: 220px 1fr; }
  #audio-panel { display: none; }
  .snr-bar-canvas { display: none; }
}
@media (max-width: 600px) {
  .main-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #gallery-panel { max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  #gallery-grid { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
  .thumb-card { min-width: 140px; }
}

/* ── Auth modal ─────────────────────────────────────────────────────────── */
#auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 3000;
  align-items: center;
  justify-content: center;
}

#auth-modal.open {
  display: flex;
}

#auth-modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 340px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  overflow: hidden;
}

#auth-modal-header {
  background: var(--bg3);
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

#auth-modal-body {
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-modal-message {
  font-size: 0.88rem;
  color: var(--text-dim);
}

#auth-password-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

#auth-password-input:focus {
  border-color: var(--accent);
}

#auth-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#auth-submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 18px;
  font-size: 0.88rem;
  cursor: pointer;
  font-weight: 600;
}

#auth-submit-btn:hover { background: var(--accent2); }

#auth-cancel-btn {
  background: var(--bg3);
  color: var(--text-dim);
  border: none;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 0.88rem;
  cursor: pointer;
}

#auth-cancel-btn:hover { color: var(--text); }

.auth-error {
  color: var(--danger);
  font-size: 0.82rem;
  min-height: 1.1em;
}
