:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #e2e4ec;
  --text: #171a23;
  --muted: #646b7d;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --danger: #c2261d;
  --danger-soft: #fdeceb;
  --highlight: #fff3b0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171a23;
    --surface-2: #1f2330;
    --border: #2a2f3d;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #23264a;
    --accent-text: #0f1117;
    --success: #4ade80;
    --success-soft: #16301f;
    --warning: #fbbf24;
    --warning-soft: #33280f;
    --danger: #f87171;
    --danger-soft: #3a1b1b;
    --highlight: #4a3f0f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.empty { text-align: center; padding: 16px 0; margin: 0; }
.error { color: var(--danger); margin: 0; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 1.05rem; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  background-image: linear-gradient(var(--accent-text), var(--accent-text)), linear-gradient(var(--accent-text), var(--accent-text)), linear-gradient(var(--accent-text), var(--accent-text));
  background-size: 14px 2px, 10px 2px, 12px 2px;
  background-position: 6px 8px, 6px 12px, 6px 16px;
  background-repeat: no-repeat;
}

/* ---------- Botones y campos ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 11px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 4px 6px; border-radius: 6px; font: inherit; font-size: .8rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input[type="password"], input[type="search"], select {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .dropzone:focus-within {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}

/* ---------- Login ---------- */
.login { display: grid; place-items: center; padding: 80px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card p { margin: 0; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px;
  padding: 16px; max-width: 1500px; margin: 0 auto; align-items: start;
}
.sidebar {
  display: grid; gap: 16px; position: sticky; top: 16px; max-height: calc(100vh - 90px);
  grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-width: 0;
}
.sidebar > * { min-width: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .sidebar { position: static; max-height: none; }
}

/* ---------- Zona de subida ---------- */
.dropzone {
  display: grid; justify-items: center; gap: 4px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 10px; padding: 22px 12px;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone svg { width: 34px; height: 34px; color: var(--accent); }
.dropzone .muted { font-size: .85rem; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.options label { display: grid; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 550; }
.options select { font-size: .875rem; }
.model-hint { grid-column: 1 / -1; margin: -2px 0 0; font-size: .8rem; }

.upload-list, .job-list { list-style: none; margin: 0; padding: 0; }
.upload-list:not(:empty) { margin-top: 12px; display: grid; gap: 8px; }
.upload-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: .85rem;
  display: grid; gap: 6px;
}
.upload-item .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; min-width: 0; }
.upload-item .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Lista de trabajos ---------- */
.jobs-card { display: flex; flex-direction: column; min-height: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.job-list { overflow-y: auto; min-height: 0; margin: 0 -8px; padding: 0 8px; }
.job {
  display: grid; gap: 6px; padding: 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.job + .job { margin-top: 4px; }
.job:hover { background: var(--surface-2); }
.job.active { background: var(--accent-soft); border-color: var(--accent); }
.job { min-width: 0; }
.job .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.job .name { font-weight: 550; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .sub { font-size: .78rem; color: var(--muted); }
.privacy-note { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--border); }

.badge {
  flex: none; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.done { background: var(--success-soft); color: var(--success); }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.cancelled, .badge.queued { background: var(--warning-soft); color: var(--warning); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .4s; }
.progress.indeterminate > div { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { margin-left: -30%; } to { margin-left: 100%; } }

/* ---------- Visor ---------- */
.viewer { min-height: calc(100vh - 90px); display: flex; flex-direction: column; min-width: 0; }
.viewer > div:not([hidden]) { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.viewer-empty { align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.viewer-empty svg { width: 48px; height: 48px; opacity: .6; }
.viewer-empty p { margin: 0; max-width: 360px; }
.steps { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; text-align: left; }
.steps li { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: .9rem; }
.steps b {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem;
}

.viewer-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.viewer-title { min-width: 0; }
.viewer-title h1 { word-break: break-word; }
.viewer-title p { margin: 4px 0 0; font-size: .875rem; }
.viewer-actions { display: flex; gap: 8px; flex: none; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15); padding: 4px;
}
.dropdown-menu a {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--text);
  text-decoration: none; cursor: pointer; font-size: .875rem;
}
.dropdown-menu a:hover { background: var(--surface-2); }

.status-box { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; }
.status-box p { margin: 0; }
.status-line { display: flex; justify-content: space-between; font-weight: 550; font-size: .9rem; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 12px 14px; margin: 0; }

.player video { width: 100%; max-height: min(420px, 50vh); border-radius: 10px; background: #000; display: block; }
.player audio { width: 100%; display: block; }
.player .note { font-size: .85rem; margin: 6px 0 0; }

.transcript-tools {
  display: flex; gap: 12px; align-items: center;
  position: sticky; top: 0; z-index: 5; background: var(--surface); padding: 8px 0; margin: -8px 0;
}
.transcript-tools input[type="search"] { flex: 1; }
.toggle { display: flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); white-space: nowrap; cursor: pointer; }

.transcript { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.seg {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; padding: 6px 8px; border-radius: 8px;
  cursor: pointer; scroll-margin: 120px;
}
.seg:hover { background: var(--surface-2); }
.seg.current { background: var(--accent-soft); }
.seg time { color: var(--accent); font-variant-numeric: tabular-nums; font-size: .82rem; padding-top: 2px; }
.seg p { margin: 0; }
.seg mark { background: var(--highlight); color: inherit; border-radius: 3px; padding: 0 1px; }

@media (max-width: 600px) {
  .transcript-tools { flex-direction: column; align-items: stretch; gap: 8px; }
  .seg { grid-template-columns: 1fr; gap: 0; }
  .viewer-actions { width: 100%; }
  .viewer-actions .btn, .viewer-actions .dropdown { flex: 1; }
  .viewer-actions .dropdown .btn { width: 100%; }
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px);
}
