/* =======================================================================
   Voice Recorder 2.0 — dark theme, CSS Grid, mode-aware.
   Palette locked in --bg*/--text*; accent softened to #7c9aff per 2.0 spec.
   ======================================================================= */

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

:root {
  --bg: #0f1117;
  --bg2: #181a20;
  --bg3: #1e2028;
  --bg4: #262830;
  --text: #e4e6ec;
  --text2: #a0a4b0;
  --text3: #6b6f7e;
  --accent: #7c9aff;
  --accent2: #5f7ae0;
  --accent-glow: rgba(124, 154, 255, 0.15);
  --green: #34d399;
  --red: #f87171;
  --orange: #fbbf24;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* =========================================================== MODE TOGGLES */
body.mode-basic .advanced-only { display: none !important; }
body.mode-advanced .basic-only { display: none !important; }

/* ===================================================================== SIDEBAR */
.sidebar {
  width: 220px;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--bg4);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}
.sidebar-header {
  padding: 20px 16px 12px;
  display: flex; align-items: center; gap: 10px;
}
.logo { font-size: 24px; }
.logo-text { font-size: 16px; font-weight: 700; color: var(--text); }
.nav-list { list-style: none; flex: 1; padding: 8px 0; }
.nav-item {
  padding: 10px 20px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  color: var(--text2); border-left: 3px solid transparent;
  transition: 0.15s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active {
  background: var(--accent-glow); color: var(--accent);
  border-left-color: var(--accent); font-weight: 600;
}
.nav-icon { font-size: 16px; width: 22px; text-align: center; }
.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--bg4);
  font-size: 12px; color: var(--text3);
  display: flex; align-items: center; gap: 8px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text3);
}
.status-dot.online { background: var(--green); }
.status-dot.rec {
  background: var(--red); animation: pulse-dot 1.4s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(248, 113, 113, 0); }
}

/* ===================================================================== CONTENT */
.content {
  margin-left: 220px; flex: 1;
  padding: 20px 28px 40px;
  min-width: 0;
}

/* Header bar at top of content */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--bg4);
  border-radius: var(--radius);
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.breadcrumb {
  font-size: 13px; color: var(--text2);
}
.breadcrumb b { color: var(--text); font-weight: 600; }

.balance-badge {
  display: flex; gap: 14px; align-items: center;
  justify-content: center; flex-wrap: wrap;
  font-size: 13px; color: var(--text);
}
.balance-badge .bal-item {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 4px 10px;
  background: var(--bg3); border: 1px solid var(--bg4);
  border-radius: 14px; position: relative; cursor: help;
  font-family: var(--mono); font-size: 12px;
}
.balance-badge .bal-item.stale { opacity: 0.55; }
.balance-badge .bal-item .bal-spinner {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--text3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.balance-badge .bal-item[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; top: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px; font-size: 11px; color: var(--text);
  background: var(--bg4); border: 1px solid var(--bg3);
  border-radius: 6px; white-space: nowrap;
  z-index: 20; box-shadow: var(--shadow);
}

.mode-toggle {
  display: inline-flex; gap: 0; justify-self: end;
  background: var(--bg3); border: 1px solid var(--bg4);
  border-radius: 20px; padding: 3px;
}
.mode-toggle button {
  padding: 5px 14px; font-size: 12px; background: transparent;
  border: none; color: var(--text2); cursor: pointer;
  border-radius: 16px; font-family: inherit; font-weight: 500;
  transition: 0.15s;
}
.mode-toggle button.active {
  background: var(--accent); color: #fff; font-weight: 600;
}
body.mode-basic    .mode-toggle button[data-mode="basic"]    { background: var(--accent); color: #fff; font-weight: 600; }
body.mode-advanced .mode-toggle button[data-mode="advanced"] { background: var(--accent); color: #fff; font-weight: 600; }

/* Typography */
h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 8px; color: var(--text2); }
h3 { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.subtitle { color: var(--text3); margin-bottom: 16px; font-size: 13px; }

/* =========================================================== PAGES (grid) */
.page { display: none; }
.page.active {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  align-content: start;
}
.page.active > .page-header {
  grid-column: span 12;
}
.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-6  { grid-column: span 6; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-12 { grid-column: span 12; }

@media (max-width: 1024px) {
  .col-3, .col-4 { grid-column: span 6; }
  .col-6, .col-8, .col-9 { grid-column: span 12; }
}

/* Cards */
.card {
  background: var(--bg2); border: 1px solid var(--bg4);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; gap: 12px;
}

/* =========================================================== BUTTONS */
.btn {
  padding: 7px 16px; border: 1px solid var(--bg4);
  border-radius: var(--radius-sm); background: var(--bg3); color: var(--text);
  cursor: pointer; font-size: 13px; transition: 0.15s; font-family: inherit;
}
.btn:hover { background: var(--bg4); border-color: var(--text3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-lg { padding: 10px 28px; font-size: 15px; font-weight: 600; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 4px 8px; font-size: 14px; line-height: 1; }

.btn-group { display: inline-flex; gap: 0;
  background: var(--bg3); border: 1px solid var(--bg4);
  border-radius: var(--radius-sm); padding: 2px;
}
.btn-group button {
  padding: 5px 12px; font-size: 12px; background: transparent;
  border: none; color: var(--text2); cursor: pointer;
  border-radius: 4px; font-family: inherit;
}
.btn-group button.active {
  background: var(--accent); color: #fff; font-weight: 600;
}

/* =========================================================== FORMS */
.form-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.form-row label { font-size: 13px; color: var(--text2); white-space: nowrap; }
.input {
  padding: 7px 12px; border: 1px solid var(--bg4);
  border-radius: var(--radius-sm); background: var(--bg3); color: var(--text);
  font-size: 13px; outline: none; transition: 0.15s; font-family: inherit;
}
.input:focus { border-color: var(--accent); }
.input-wide { flex: 1; min-width: 240px; }
.input-sm { width: 100px; }
select.input { appearance: auto; }
.slider { flex: 1; accent-color: var(--accent); }

/* Settings-schema autolayout */
.setting-row {
  display: grid;
  grid-template-columns: 210px 1fr auto;
  align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(38, 40, 48, 0.5);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .setting-label { font-size: 13px; color: var(--text2); }
.setting-row .setting-input { display: flex; align-items: center; gap: 8px; }
.setting-row .setting-input input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.setting-row .setting-unit { font-size: 12px; color: var(--text3); font-family: var(--mono); }
.setting-group { margin-bottom: 12px; }
.setting-group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text3);
  padding: 12px 0 6px; border-bottom: 1px solid var(--bg4);
  margin-bottom: 4px;
}

/* =========================================================== TOOLTIPS */
.help {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg4); color: var(--text3); text-align: center;
  font-size: 10px; line-height: 14px; margin-left: 6px; cursor: help;
  position: relative; user-select: none;
}
.help:hover::after {
  content: attr(data-help);
  position: absolute; left: 18px; top: -4px;
  padding: 6px 10px; background: var(--bg4); color: var(--text);
  border: 1px solid var(--bg3); border-radius: 6px;
  font-size: 12px; white-space: normal; min-width: 240px; max-width: 320px;
  z-index: 30; box-shadow: var(--shadow); line-height: 1.4;
}

/* =========================================================== BADGES */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 600;
}
.badge-idle { background: var(--bg4); color: var(--text3); }
.badge-rec  { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.badge-ok   { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--orange); }
.badge-err  { background: rgba(248, 113, 113, 0.15); color: var(--red); }

.health-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text3); margin-right: 6px;
}
.health-dot.ok   { background: var(--green); }
.health-dot.warn { background: var(--orange); }
.health-dot.down { background: var(--red); }

.hint {
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 12px; margin-top: 8px;
}
.hint-warn {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.25);
  color: var(--orange);
}
.hint-soon {
  background: rgba(124, 154, 255, 0.08);
  border: 1px dashed rgba(124, 154, 255, 0.3);
  color: var(--text2); padding: 12px 14px; font-style: italic;
}
.muted { color: var(--text3); font-size: 13px; }
code {
  font-family: var(--mono); background: var(--bg3); padding: 2px 6px;
  border-radius: 4px; font-size: 12px; color: #ffc970;
}

/* =========================================================== MIC LIST */
.mic-list { display: flex; flex-direction: column; gap: 6px; }
.mic-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  background: var(--bg3); border-radius: var(--radius-sm);
  transition: 0.15s;
}
.mic-row:hover { background: var(--bg4); }
.mic-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.mic-row label { flex: 1; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mic-id   { font-family: var(--mono); color: var(--text3); font-size: 12px; min-width: 28px; }
.mic-name { color: var(--text); }
.mic-ch   { color: var(--text3); font-size: 11px; margin-left: auto; }

/* =========================================================== UPLOAD */
.upload-dropzone {
  border: 2px dashed var(--bg4); border-radius: var(--radius);
  padding: 26px 20px; text-align: center;
  color: var(--text2); background: var(--bg3);
  transition: 0.15s; cursor: pointer;
}
.upload-dropzone.dragover {
  border-color: var(--accent); background: var(--accent-glow); color: var(--text);
}
.upload-dropzone .upload-icon { font-size: 28px; margin-bottom: 8px; }
.upload-dropzone input[type="file"] { display: none; }
.upload-progress {
  margin-top: 12px; height: 6px; background: var(--bg3); border-radius: 3px;
  overflow: hidden; display: none;
}
.upload-progress.active { display: block; }
.upload-progress > div {
  height: 100%; background: var(--accent); width: 0%; transition: width 0.2s;
}
.upload-result {
  margin-top: 10px; font-size: 12px; font-family: var(--mono);
}

/* =========================================================== PIPELINE */
.pipeline-status { padding: 10px 0 4px; }
.pipeline-steps {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; justify-content: center;
}
.pipeline-step {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 10px; border-radius: var(--radius);
  background: var(--bg3); border: 2px solid transparent;
  transition: 0.25s; min-width: 66px; opacity: 0.5;
}
.pipeline-step.active {
  border-color: var(--accent); background: var(--accent-glow); opacity: 1;
  animation: pulse-step 1.5s ease-in-out infinite;
}
.pipeline-step.ok      { border-color: var(--green);  opacity: 0.9; background: rgba(52, 211, 153, 0.08); }
.pipeline-step.failed  { border-color: var(--red);    opacity: 1;   background: rgba(248, 113, 113, 0.08); }
.pipeline-step.skipped { border-color: var(--orange); opacity: 0.7; background: rgba(251, 191, 36, 0.05); }
.pipeline-step .step-icon  { font-size: 18px; }
.pipeline-step .step-label {
  font-size: 10px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.pipeline-arrow { color: var(--text3); font-size: 14px; opacity: 0.4; }
@keyframes pulse-step {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124, 154, 255, 0.3); }
  50%      { box-shadow: 0 0 12px 4px rgba(124, 154, 255, 0.2); }
}

/* =========================================================== LOG */
.log-box {
  background: var(--bg); border: 1px solid var(--bg4);
  border-radius: var(--radius-sm); padding: 10px 14px;
  max-height: 260px; overflow-y: auto;
  font-family: var(--mono); font-size: 12px; color: var(--text2); line-height: 1.7;
}
.log-row { padding: 2px 0; display: flex; gap: 8px; align-items: baseline; }
.log-row .ts { color: var(--text3); font-size: 11px; }
.log-row .evt { font-weight: 700; font-size: 11px; min-width: 68px; }
.log-row.started .evt { color: var(--accent); }
.log-row.ok .evt      { color: var(--green); }
.log-row.failed .evt  { color: var(--red); }
.log-row.skipped .evt { color: var(--orange); }

.controls-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.status-info { display: flex; align-items: center; gap: 12px; }

/* =========================================================== LEVEL MONITOR */
.level-monitor {
  background: var(--bg); border: 1px solid var(--bg4);
  border-radius: var(--radius); padding: 12px; position: relative;
}
.level-monitor canvas {
  width: 100%; height: 200px; display: block;
  border-radius: var(--radius-sm);
}
.threshold-control {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
}
.threshold-control label {
  font-size: 13px; color: var(--text2); white-space: nowrap;
}
.threshold-slider { flex: 1; }
.threshold-val {
  font-size: 14px; font-weight: 700; color: var(--accent);
  min-width: 50px; text-align: right; font-family: var(--mono);
}
.level-legend { display: flex; gap: 16px; margin-top: 10px; }
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text3);
}
.legend-color {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}

/* =========================================================== CHARTS */
.chart-card { position: relative; }
.chart-card canvas {
  width: 100%; height: 120px; display: block;
  background: var(--bg); border-radius: var(--radius-sm);
  border: 1px solid var(--bg4);
}
.chart-card .chart-meta {
  display: flex; justify-content: space-between;
  margin-top: 6px; font-size: 11px; color: var(--text3);
  font-family: var(--mono);
}

.sparkline-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.spark-card {
  padding: 10px 12px; background: var(--bg2); border: 1px solid var(--bg4);
  border-radius: var(--radius-sm);
}
.spark-card .spark-title {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text3);
  margin-bottom: 4px;
}
.spark-card .spark-value {
  font-size: 16px; font-weight: 700; color: var(--text);
}
.spark-card canvas {
  width: 100%; height: 40px; display: block; margin-top: 6px;
}

@media (max-width: 900px) {
  .sparkline-row { grid-template-columns: repeat(2, 1fr); }
}

/* =========================================================== SETTINGS */
.save-bar {
  margin-top: 14px; display: flex; align-items: center;
  gap: 16px; padding: 14px 0 0; border-top: 1px solid var(--bg4);
}
.settings-categories {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px;
}

/* =========================================================== TABLE */
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td {
  padding: 8px 12px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--bg4);
}
.history-table th {
  color: var(--text3); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.history-table tr:hover td { background: var(--bg3); }
td.mono { font-family: var(--mono); font-size: 12px; }

.ledger-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ledger-table th, .ledger-table td {
  padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--bg4);
  font-family: var(--mono);
}
.ledger-table th {
  color: var(--text3); text-transform: uppercase;
  letter-spacing: 0.5px; font-size: 10px;
}

/* =========================================================== AUTH */
.auth-overlay {
  position: fixed; inset: 0; background: rgba(15, 17, 23, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.auth-box {
  background: var(--bg2); border: 1px solid var(--bg4);
  border-radius: var(--radius); padding: 28px 32px;
  max-width: 420px; box-shadow: var(--shadow);
}
.auth-box h2 { font-size: 18px; color: var(--text); margin-bottom: 10px; }
.auth-box .muted { margin-bottom: 14px; line-height: 1.5; }
.auth-box .form-row { margin-top: 10px; }
.auth-box input { width: 100%; }

/* =========================================================== RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .logo-text, .sidebar-footer span:last-child { display: none; }
  .nav-item { padding: 12px 0; justify-content: center; }
  .nav-item .nav-icon { margin: 0; }
  .content { margin-left: 60px; padding: 14px; }
  .pipeline-step { min-width: 50px; padding: 6px 8px; }
  .pipeline-arrow { font-size: 12px; }
  .level-monitor canvas { height: 150px; }
  .topbar { grid-template-columns: 1fr; }
  .balance-badge { justify-content: flex-start; }
  .mode-toggle { justify-self: start; }
  .setting-row { grid-template-columns: 1fr; }
}
