:root {
  --bg: #070b14;
  --panel: #0d1626;
  --panel-border: #1c3148;
  --cyan: #2de2ff;
  --magenta: #ff2dd4;
  --green: #36ffb0;
  --red: #ff3b5c;
  --text: #d7e6ff;
  --text-dim: #7f93b3;
  --needle: #ff3b5c;
  --needle-hub: #2de2ff;
  --vu-face: #0a1320;
  --vu-tick: #4a6a8f;
  --vu-tick-major: #d7e6ff;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(45, 226, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 226, 255, 0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 2rem;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(45,226,255,0.06), transparent);
}

.logo-img {
  height: 72px;
  display: block;
}

.status-pill {
  font-size: 0.8rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.status-pill.connected {
  color: var(--green);
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(54,255,176,0.3);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.logout-btn {
  flex: none;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

/* Tab bar */
.tabbar {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 2rem 0;
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
}
.tab-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  border-bottom: none;
  color: var(--text-dim);
  padding: 0.6rem 1.2rem;
  border-radius: 8px 8px 0 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--cyan);
  border-color: var(--cyan);
  background: rgba(45,226,255,0.06);
  box-shadow: 0 -4px 12px rgba(45,226,255,0.15);
}

.tab-page { display: none; }
.tab-page.active {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.2rem;
}
.tab-page[data-tab="dashboard"].active {
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 2fr);
}
@media (max-width: 900px) {
  .tab-page[data-tab="dashboard"].active {
    grid-template-columns: 1fr;
  }
}

/* VU meter */
.vu-wrap {
  margin-bottom: 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: radial-gradient(circle at 50% 30%, #14233a, var(--vu-face));
  padding: 0.5rem 0.5rem 0;
}
#vuMeter { width: 100%; display: block; }
.vu-tick { stroke: var(--vu-tick); stroke-width: 2; }
.vu-tick-major { stroke: var(--vu-tick-major); stroke-width: 2.5; }
.vu-tick-red { stroke: var(--red); }
.vu-label {
  fill: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  font-family: inherit;
}
.vu-label-major { fill: var(--vu-tick-major); }
.vu-unit {
  fill: var(--text-dim);
  font-size: 10px;
  letter-spacing: 0.1em;
}
#vuNeedle {
  transition: transform 0.06s ease-out;
  filter: drop-shadow(0 0 4px rgba(255,59,92,0.7));
}

.layout {
  position: relative;
  z-index: 1;
  padding: 1.2rem 2rem 3rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 1.2rem;
  box-shadow: 0 0 25px rgba(45,226,255,0.04);
}
.panel-wide { grid-column: 1 / -1; }

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.5rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0.8rem 0 0.3rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="time"],
select {
  width: 100%;
  background: #0a1320;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="time"]:focus,
select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 8px rgba(45,226,255,0.35);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

/* Meter */
.meter-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}
.meter {
  flex: 1;
  height: 14px;
  background: #0a1320;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--magenta));
  transition: width 0.08s linear;
  box-shadow: 0 0 10px rgba(45,226,255,0.6);
}
.meter-label {
  width: 4.5rem;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Recording indicator */
.rec-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}
.rec-indicator .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
}

.live-audio-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  margin-right: auto;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  cursor: pointer;
}
.live-audio-toggle input {
  accent-color: var(--cyan);
  cursor: pointer;
}
.live-audio-toggle:has(input:checked) {
  color: var(--cyan);
}
.rec-indicator.active .dot {
  background: var(--red);
  box-shadow: 0 0 12px var(--red);
  animation: pulse 1s infinite;
}
.rec-indicator.active #recText { color: var(--red); }

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

.rec-current {
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 1.2em;
  margin-bottom: 1rem;
}

.manual-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.btn {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: #0a1320;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-rec {
  border-color: var(--red);
  color: var(--red);
}
.btn-rec:hover { box-shadow: 0 0 12px rgba(255,59,92,0.5); }
.btn-stop {
  border-color: var(--cyan);
  color: var(--cyan);
}
.btn-stop:hover { box-shadow: 0 0 12px rgba(45,226,255,0.5); }
.btn-secondary {
  border-color: var(--panel-border);
  color: var(--text-dim);
}
.btn-secondary:hover { color: var(--text); border-color: var(--cyan); }

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}
.panel-header-row h2 { margin: 0; }

.btn-danger-outline {
  flex: none;
  border-color: var(--red);
  color: var(--red);
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
}
.btn-danger-outline:hover { box-shadow: 0 0 10px rgba(255,59,92,0.35); }

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0.5rem 0 0;
  line-height: 1.4;
}

/* Toggle group */
.toggle-group {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.toggle-option {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  margin: 0;
  color: var(--text-dim);
  transition: all 0.15s;
}
.toggle-option input { accent-color: var(--cyan); }
.toggle-option:has(input:checked) {
  border-color: var(--cyan);
  color: var(--text);
  box-shadow: 0 0 10px rgba(45,226,255,0.25);
}

.field-group { display: none; }
.field-group.visible { display: block; }

/* Save path row */
.save-path-row {
  display: flex;
  gap: 0.6rem;
}
.save-path-row input { flex: 1; }
.save-path-row .btn { flex: none; }

/* Recordings table */
.recordings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;
}
.recordings-table th:first-child,
.recordings-table td:first-child {
  word-break: break-all;
}
.recordings-table th:last-child,
.recordings-table th:nth-child(1), .recordings-table td:nth-child(1) { width: 40%; }
.recordings-table th:nth-child(2), .recordings-table td:nth-child(2) { width: 12%; }
.recordings-table th:nth-child(3), .recordings-table td:nth-child(3) { width: 28%; }
.recordings-table th:nth-child(4), .recordings-table td:nth-child(4) { width: 20%; }

.recordings-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--panel-border);
  padding: 0.5rem 0.6rem;
}
.recordings-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid rgba(28,49,72,0.5);
}
.recordings-table tr:hover { background: rgba(45,226,255,0.04); }

.action-select {
  width: 100%;
  background: #0a1320;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.action-select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 8px rgba(45,226,255,0.35);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 14, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-backdrop.visible { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 1.4rem;
  width: min(480px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal h3 { margin: 0 0 0.6rem; color: var(--cyan); }
.current-path {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
  word-break: break-all;
}
.dir-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}
.dir-list li {
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(28,49,72,0.5);
}
.dir-list li:hover { background: rgba(45,226,255,0.08); color: var(--cyan); }
.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.error-banner {
  position: relative;
  z-index: 1;
  margin: 0.8rem 2rem 0;
  padding: 0.7rem 1rem;
  border: 1px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  background: rgba(255,59,92,0.08);
  font-size: 0.85rem;
}

/* Login page */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 0 30px rgba(45,226,255,0.08);
}
.login-logo {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 1.5rem;
}
.login-error {
  background: rgba(255,59,92,0.08);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.login-btn {
  width: 100%;
  margin-top: 1.2rem;
}

/* Settings */
.settings-message {
  margin-top: 0.8rem;
  font-size: 0.85rem;
  min-height: 1.2em;
}
.settings-message.success { color: var(--green); }
.settings-message.error { color: var(--red); }

/* Backup & Cloud connector rows */
.connector-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.2rem;
  padding: 1rem 0;
  border-bottom: 1px solid rgba(28,49,72,0.5);
  flex-wrap: wrap;
}
.connector-row:last-child { border-bottom: none; }

.connector-info { flex: 1; min-width: 220px; }
.connector-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.connector-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 0.4rem;
}
.connector-status {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.connector-status .status-enabled { color: var(--green); }
.connector-status .status-disabled { color: var(--text-dim); }
.connector-status .status-warn { color: var(--magenta); }
.connector-status .status-fail { color: var(--red); }

.connector-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: none;
}
.connector-configure {
  flex: none;
  text-decoration: none;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex: none;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #0a1320;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  transition: all 0.15s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all 0.15s;
}
.switch input:checked + .switch-slider {
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(54,255,176,0.3);
}
.switch input:checked + .switch-slider::before {
  background: var(--green);
  transform: translateX(20px);
}
