:root {
  --blue: #3a55e8;
  --blue-dark: #2c42c4;
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e6e8f0;
  --text: #11162a;
  --text-dim: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --ring-border: #dde1f5;
  --ring-inner-border: #e3e6f5;
  --ring-glow: rgba(58, 85, 232, 0.08);
  --gauge-track: #eceefb;
  --badge-bg: #eef0fb;
  --row-hover: #fafbff;
  --dropzone-border: #cdd3f0;
  --waveform-bg: #f3f4fb;
  --btn-primary-disabled: #c7cdf7;
  --warning-bg: #fff7ed;
  --warning-border: #fed7aa;
  --warning-text: #9a5b1f;
  --toast-bg: #11162a;
  --toast-text: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue: #5b7cfa;
    --blue-dark: #7c93fb;
    --bg: #0f1220;
    --card: #171b2e;
    --border: #2a2f45;
    --text: #e8eaf4;
    --text-dim: #9199b8;
    --green: #22c55e;
    --red: #f87171;
    --ring-border: #2a2f52;
    --ring-inner-border: #242a48;
    --ring-glow: rgba(91, 124, 250, 0.14);
    --gauge-track: #262b47;
    --badge-bg: #232849;
    --row-hover: #1c2038;
    --dropzone-border: #343a5c;
    --waveform-bg: #1c2038;
    --btn-primary-disabled: #343a5c;
    --warning-bg: #3a2a14;
    --warning-border: #6b4a1f;
    --warning-text: #f0b878;
    --toast-bg: #e8eaf4;
    --toast-text: #11162a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --blue: #5b7cfa;
  --blue-dark: #7c93fb;
  --bg: #0f1220;
  --card: #171b2e;
  --border: #2a2f45;
  --text: #e8eaf4;
  --text-dim: #9199b8;
  --green: #22c55e;
  --red: #f87171;
  --ring-border: #2a2f52;
  --ring-inner-border: #242a48;
  --ring-glow: rgba(91, 124, 250, 0.14);
  --gauge-track: #262b47;
  --badge-bg: #232849;
  --row-hover: #1c2038;
  --dropzone-border: #343a5c;
  --waveform-bg: #1c2038;
  --btn-primary-disabled: #343a5c;
  --warning-bg: #3a2a14;
  --warning-border: #6b4a1f;
  --warning-text: #f0b878;
  --toast-bg: #e8eaf4;
  --toast-text: #11162a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--blue), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 15px;
}

.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.tab {
  border: none;
  background: transparent;
  padding: 7px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 12px; color: var(--text-dim); }

main { flex: 1 1 auto; min-height: 0; display: flex; width: 100%; }

.view { display: none; }
.view.active {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 28px 40px;
  overflow-y: auto;
}

/* Monitor is the one view laid out as a fixed 2/3 (status+ring+gauges) /
   1/3 (activity+library) split that fills the viewport with no outer
   scrollbar -- the two panels below scroll internally instead. */
#view-monitor.active { overflow: hidden; gap: 20px; }

/* ---------------- Monitor ---------------- */

.monitor-top { flex: 1.7 1 0; min-height: 0; display: flex; flex-direction: column; gap: 16px; }

.monitor-head {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.monitor-visual {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.channel-status-label { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--text-dim); text-transform: uppercase; }
.channel-status-big { font-size: 40px; font-weight: 800; margin-top: 4px; }

.live-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--green); font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.live-dot .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

.monitor-controls { text-align: right; }
.btn-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 999px; font-weight: 700; font-size: 14px;
  cursor: pointer; border: 1.5px solid var(--blue); background: var(--card); color: var(--blue);
}
.btn-pill.live { background: var(--blue); color: white; }
.station-picker { display: block; margin-top: 10px; font-size: 12px; color: var(--text-dim); text-decoration: underline; cursor: pointer; background: none; border: none; }

.live-listen { margin-top: 12px; }
.live-listen audio { height: 32px; width: 220px; }

.row-play {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 11px; display: inline-flex;
  align-items: center; justify-content: center; margin-right: 8px; flex-shrink: 0;
}

.ring-wrap { display: flex; justify-content: center; flex: 1 1 auto; min-height: 0; align-items: center; }
.ring {
  width: clamp(140px, 26vh, 260px); height: clamp(140px, 26vh, 260px); border-radius: 50%;
  border: 1px solid var(--ring-border);
  background: radial-gradient(circle, var(--ring-glow), transparent 70%);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ring .inner-ring { width: 73%; height: 73%; border-radius: 50%; border: 1px solid var(--ring-inner-border); display: flex; align-items: center; justify-content: center; }
.waveform-canvas { width: 160px; height: 46px; max-width: 60%; }

.gauges { display: flex; justify-content: center; gap: 48px; flex: 0 0 auto; }
.gauge-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.gauge-ring {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  background: conic-gradient(var(--blue) calc(var(--pct, 0) * 1%), var(--gauge-track) 0);
}
.gauge-ring .hole { width: 56px; height: 56px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; }

.split { flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px;
  position: relative; height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
}
.panel-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.badge { background: var(--badge-bg); color: var(--blue); font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.empty-state { color: var(--text-dim); font-size: 13px; text-align: center; margin-top: 60px; }

.fab {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--blue); color: white; font-size: 18px; cursor: pointer;
}

.row-list { flex: 1 1 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.row-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--border); font-size: 13px; }
.row-item:last-child { border-bottom: none; }
.row-main { font-weight: 600; }
.row-sub { color: var(--text-dim); font-size: 12px; }
.row-meta { color: var(--text-dim); font-size: 12px; text-align: right; }

.keyword-add-row { display: flex; gap: 10px; margin: 16px 0 20px; max-width: 520px; }
.keyword-add-row input { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 14px; }
.keyword-add-row select { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 14px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th { text-align: left; color: var(--text-dim); font-weight: 600; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.data-table tr:hover td { background: var(--row-hover); }

.btn-link { background: none; border: none; color: var(--blue); font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-danger { color: var(--red); }

/* ---------------- Studio ---------------- */

.studio-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.dropzone {
  border: 2px dashed var(--dropzone-border); border-radius: 12px; padding: 46px; text-align: center;
  color: var(--text-dim); cursor: pointer; font-size: 14px;
}
.dropzone:hover { border-color: var(--blue); color: var(--blue); }

#waveform { margin: 24px 0 10px; border-radius: 8px; overflow: hidden; background: var(--waveform-bg); }
.studio-controls { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.studio-time { font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 22px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 14px;
}

.btn-primary {
  background: var(--blue); color: white; border: none; padding: 12px 26px;
  border-radius: 10px; font-weight: 700; font-size: 14px; cursor: pointer;
}
.btn-primary:disabled { background: var(--btn-primary-disabled); cursor: not-allowed; }
.btn-secondary { background: var(--card); border: 1px solid var(--border); padding: 12px 20px; border-radius: 10px; font-weight: 600; cursor: pointer; }

.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
  padding: 12px 24px;
  display: none;
  align-items: center;
  gap: 16px;
  z-index: 50;
}
.player-bar.show { display: flex; }
.player-bar audio { display: none; }
.player-bar .icon-btn { text-decoration: none; color: var(--text); flex-shrink: 0; }
.player-info { min-width: 160px; max-width: 280px; }
.player-title { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-sub { font-size: 12px; color: var(--text-dim); }
.player-seek { flex: 1; accent-color: var(--blue); }
.player-time { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; flex-shrink: 0; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-text); padding: 12px 20px; border-radius: 10px; font-size: 13px;
  display: none;
}
.toast.show { display: block; }

.notice-warning {
  display: none;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.theme-toggle-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--card); color: var(--text-dim); cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.theme-toggle-btn:hover { color: var(--text); border-color: var(--blue); }

.lead-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.lead-overlay.show { display: flex; }
.lead-modal {
  background: var(--card); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.lead-modal h3 { margin: 0 0 8px; font-size: 18px; }
.lead-modal p { margin: 0 0 16px; color: var(--text-dim); font-size: 13px; }
.lead-modal input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  font-size: 14px; margin-bottom: 6px; background: var(--card); color: var(--text);
}
.lead-modal-error { color: var(--red); font-size: 12px; min-height: 16px; margin-bottom: 10px; }
.lead-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.google-signin-wrap { display: flex; justify-content: center; margin: 4px 0 14px; min-height: 44px; }
.lead-terms { font-size: 11px; color: var(--text-dim); line-height: 1.4; margin: 0 0 14px; }
