/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --bg:           #f4f4f5;
  --surface:      #ffffff;
  --surface-alt:  #fafafa;
  --border:       #e4e4e7;
  --border-focus: #a1a1aa;
  --fg:           #09090b;
  --fg-subtle:    #3f3f46;
  --muted:        #71717a;
  --primary:      #18181b;
  --primary-fg:   #fafafa;
  --primary-hover:#27272a;
  --danger:       #dc2626;
  --danger-bg:    #fef2f2;
  --danger-border:#fecaca;
  --success:      #16a34a;
  --success-bg:   #f0fdf4;
  --warning:      #d97706;
  --warning-bg:   #fffbeb;
  --ring:         rgba(24,24,27,0.08);
  --radius-sm:    6px;
  --radius:       8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
  --shadow-xs:    0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg:    0 10px 24px -3px rgba(0,0,0,0.08), 0 4px 8px -2px rgba(0,0,0,0.04);
  --transition:   0.15s ease;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Geist', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  line-height: 1.5;
}
[x-cloak] { display: none !important; }

/* ════════════════════════════════════════════════════════════════════════════
   AUTH SCREEN
═══════════════════════════════════════════════════════════════════════════ */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo {
  width: 48px; height: 48px;
  background: var(--primary);
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-fg);
  margin-bottom: 16px;
}
.auth-title {
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}
.auth-subtitle { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.auth-form {
  display: flex; flex-direction: column; gap: 10px;
}
.auth-form input {
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}
.auth-form input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--ring);
}
.auth-toggle { margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-toggle a { color: var(--fg); font-weight: 500; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }
.auth-error {
  color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px;
}
.auth-hint {
  color: var(--muted); font-size: 11.5px; margin-top: 12px;
}

/* ════════════════════════════════════════════════════════════════════════════
   APP LAYOUT
═══════════════════════════════════════════════════════════════════════════ */
.app-layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 20px 48px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}
.header-brand {
  display: flex; align-items: center; gap: 10px;
}
.header-logo {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary-fg);
  flex-shrink: 0;
}
.header-title {
  font-size: 15px; font-weight: 600;
  letter-spacing: -0.2px;
  line-height: 1.2;
}
.header-subtitle {
  font-size: 11.5px; color: var(--muted); margin-top: 1px;
}
.header-right {
  display: flex; align-items: center; gap: 8px;
}

/* Worker badge */
.ws-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: 100px;
  padding: 3px 10px;
}
.ws-badge.offline {
  color: var(--muted);
  background: var(--surface-alt);
  border-color: var(--border);
}

/* ── Tab bar ─────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.tab-bar button {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 500; font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  white-space: nowrap;
}
.tab-bar button:hover { color: var(--fg-subtle); background: var(--surface-alt); }
.tab-bar button.active {
  color: var(--fg);
  background: var(--bg);
  box-shadow: var(--shadow-xs);
}

/* ── Tab panel ───────────────────────────────────────────────────────────── */
.tab-panel { min-width: 0; }

/* ════════════════════════════════════════════════════════════════════════════
   CARDS
═══════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card + .card { margin-top: 14px; }
.card-body { padding: 20px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header-title {
  font-size: 14px; font-weight: 600;
}
.warning-card { border-color: var(--danger-border); background: var(--danger-bg); }
.warning-card .card-body { color: var(--danger); font-size: 13px; }

/* ════════════════════════════════════════════════════════════════════════════
   TWO-COL GRID
═══════════════════════════════════════════════════════════════════════════ */
.two-col {
  display: grid; grid-template-columns: 2fr 3fr; gap: 16px; min-width: 0;
}
.pane-left, .pane-right { min-width: 0; }
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ════════════════════════════════════════════════════════════════════════════
   FORMS
═══════════════════════════════════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 11.5px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
textarea, input[type="text"], input[type="number"], input[type="password"],
input[type="email"], select {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 13.5px; font-family: inherit;
  outline: none;
  appearance: none; -webkit-appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
textarea { padding: 10px 12px; resize: vertical; line-height: 1.6; }
input[type="text"], input[type="number"], input[type="password"], input[type="email"] {
  padding: 9px 12px;
}
select { padding: 9px 34px 9px 12px; cursor: pointer; }
textarea:focus, input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--ring);
}
textarea::placeholder, input::placeholder { color: #a1a1aa; }
input[type="file"] { font-size: 13px; }
hr {
  border: none; border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ── Sliders ─────────────────────────────────────────────────────────────── */
.slider-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: var(--fg-subtle);
}
.slider-row .val {
  font-size: 12px; font-weight: 600; color: var(--fg);
  min-width: 32px; text-align: right;
  font-variant-numeric: tabular-nums;
}
input[type="range"] {
  flex: 1; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: var(--border);
  border-radius: 100px;
  cursor: pointer; padding: 0; border: none; box-shadow: none; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
  transition: transform var(--transition);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface); cursor: pointer;
}
.chars { font-size: 12px; color: var(--muted); }

/* ── Accordion ───────────────────────────────────────────────────────────── */
.accordion {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.acc-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; font-family: inherit;
  color: var(--fg-subtle);
  transition: background var(--transition);
}
.acc-header:hover { background: var(--bg); }
.acc-chevron {
  transition: transform var(--transition); flex-shrink: 0; color: var(--muted);
}
.acc-chevron.open { transform: rotate(180deg); }
.acc-body {
  border-top: 1px solid var(--border);
  padding: 16px; background: var(--surface);
  display: flex; flex-direction: column; gap: 10px;
}

/* ════════════════════════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: var(--radius);
  font-family: inherit; font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              transform 0.1s ease, box-shadow var(--transition);
  white-space: nowrap; outline: none; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-sm  { padding: 6px 12px; font-size: 12.5px; }
.btn-md  { padding: 9px 16px; font-size: 13.5px; }
.btn-lg  { padding: 11px 20px; font-size: 14px; }
.btn-full { width: 100%; }
.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost {
  background: transparent; color: var(--fg-subtle);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--fg); }

/* ════════════════════════════════════════════════════════════════════════════
   QUEUE
═══════════════════════════════════════════════════════════════════════════ */
.queue-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  flex-wrap: wrap;
}
.queue-pos {
  font-weight: 600; font-size: 12px; color: var(--muted);
  min-width: 22px;
}
.queue-status {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  padding: 2px 7px; border-radius: 100px;
  letter-spacing: 0.04em;
}
.q-pending    { background: var(--bg); color: var(--muted); }
.q-processing { background: #dbeafe; color: #2563eb; }
.q-completed  { background: var(--success-bg); color: var(--success); }
.q-failed     { background: var(--danger-bg); color: var(--danger); }
.queue-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--fg-subtle);
}
.queue-error {
  width: 100%; margin-top: 2px;
  font-size: 11.5px; color: var(--danger);
}
.muted { color: var(--muted); font-size: 13px; }

/* ════════════════════════════════════════════════════════════════════════════
   AUDIO TABLE
═══════════════════════════════════════════════════════════════════════════ */
.audio-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.audio-table th {
  text-align: left;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}
.audio-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.audio-table tbody tr:hover { background: var(--surface-alt); }
.td-preview {
  max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--fg-subtle);
}
.td-actions {
  display: flex; align-items: center; gap: 6px;
}

/* ════════════════════════════════════════════════════════════════════════════
   VOICE GRID
═══════════════════════════════════════════════════════════════════════════ */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.voice-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 8px;
  transition: border-color var(--transition);
}
.voice-card:hover { border-color: var(--border-focus); }
.voice-card-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.voice-card-size {
  font-size: 11px; color: var(--muted);
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════════════════
   TOOLS
═══════════════════════════════════════════════════════════════════════════ */
.result-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}

/* ════════════════════════════════════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════════════════════════════════ */
.stack   { display: flex; flex-direction: column; gap: 14px; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.row     { display: flex; align-items: center; gap: 10px; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-layout { padding: 12px 12px 32px; }
  .two-col { grid-template-columns: 1fr; }
  .auth-card { padding: 32px 24px 28px; }
  .audio-table td, .audio-table th { padding: 8px; }
  .td-preview { max-width: 120px; }
  .td-actions audio { width: 120px !important; }
  .tab-bar button { font-size: 11.5px; padding: 8px 10px; gap: 4px; }
  .tab-bar button svg { width: 12px; height: 12px; }
}
