:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  --radius: 14px;
  --radius-sm: 9px;
  --track: #e2e8f0;
  --c-queued: #b45309;      --c-queued-bg: #fef3c7;
  --c-processing: #1d4ed8;  --c-processing-bg: #dbeafe;
  --c-encoding: #6d28d9;    --c-encoding-bg: #ede9fe;
  --c-ready: #15803d;       --c-ready-bg: #dcfce7;
  --c-failed: #b91c1c;      --c-failed-bg: #fee2e2;
  --c-uploading: #475569;   --c-uploading-bg: #e2e8f0;
  --c-cancelled: #475569;   --c-cancelled-bg: #e5e7eb;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2e;
    --surface-2: #19223a;
    --border: #232d49;
    --border-strong: #35415f;
    --text: #e6eaf5;
    --muted: #93a0bd;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #1d2447;
    --accent-text: #0b1020;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
    --track: #26304d;
    --c-queued: #fbbf24;      --c-queued-bg: #3a2c0a;
    --c-processing: #7cb2ff;  --c-processing-bg: #112a52;
    --c-encoding: #c4b5fd;    --c-encoding-bg: #2a1f55;
    --c-ready: #4ade80;       --c-ready-bg: #0f3320;
    --c-failed: #fca5a5;      --c-failed-bg: #471616;
    --c-uploading: #cbd5e1;   --c-uploading-bg: #2b3550;
    --c-cancelled: #cbd5e1;   --c-cancelled-bg: #2f3547;
    --danger: #fca5a5;
    --danger-bg: #3a1717;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.35rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: 0 1px 0 rgba(15, 23, 42, .02);
}
.appbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 0 20px; height: 60px;
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.logo { width: 30px; height: 30px; color: var(--accent); flex: none; }
.elevoc-logo { height: 28px; width: auto; flex: none; }
.elevoc-logo.big { height: 44px; }
.logo-for-dark { display: none; }
@media (prefers-color-scheme: dark) {
  .logo-for-light { display: none; }
  .logo-for-dark { display: inline; }
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; min-height: 38px;
}
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.count-pill {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; margin-left: 4px;
  background: var(--accent); color: var(--accent-text); font-size: .75rem; line-height: 20px; text-align: center;
}
.appbar-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.language select { width: auto; padding: 6px 28px 6px 10px; font-size: .9rem; }
.user-menu { position: relative; }
#user-button {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 12px 4px 4px; font: inherit; color: var(--text); cursor: pointer;
}
#user-button:hover { background: var(--surface-2); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; text-transform: uppercase;
}
#identity { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 6px; display: grid; gap: 2px;
}
.menu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; border-radius: 7px; font: inherit; color: var(--text); cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

/* ---------- Layout ---------- */
main { max-width: 1120px; margin: 0 auto; padding: 28px 20px 64px; }
.view { display: grid; gap: 18px; }
.page-head { display: grid; gap: 2px; margin-bottom: 2px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; min-width: 0;
}
fieldset.card { margin: 0; }
.card.narrow { max-width: 520px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h3 { display: flex; align-items: center; gap: 10px; }
.step {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: inline-grid; place-items: center; font-size: .8rem; font-weight: 700;
}
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.grow { flex: 1; min-width: 220px; }
.sub { font-weight: 600; margin: 16px 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 36px 16px; }
.hint { color: var(--muted); font-size: .88rem; margin-top: 10px; }
small.muted { display: block; font-size: .8rem; margin-top: 4px; }
.notice { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: .92rem; }
.notice[data-error="true"], .notice.error { background: var(--danger-bg); color: var(--danger); }
#startup { text-align: center; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.field + .field { margin-top: 14px; }
.row .field + .field { margin-top: 0; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 9px 12px; width: 100%; min-height: 40px;
}
select { width: 100%; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, audio:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent);
}
select[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
button {
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 9px 16px; min-height: 40px; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.link { border: 0; background: transparent; color: var(--accent); }
button.block { width: 100%; }
button.small { padding: 5px 12px; min-height: 32px; font-size: .88rem; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.actions.downloads { justify-content: space-between; }
.toolbar { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { min-width: 170px; flex: 1; max-width: 280px; }
.toolbar button { margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; padding: 3px 11px; border-radius: 999px; font-size: .82rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.chip.fixed { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chips { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; max-height: 140px; overflow: auto; }
.chips li { padding: 3px 10px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: .84rem; word-break: break-all; }
.fixed-count { align-self: center; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); padding: 32px 30px; box-shadow: var(--shadow-lg); }
.auth-brand { display: grid; justify-items: center; gap: 6px; text-align: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 1.5rem; }
.auth-card h2 { font-size: 1.1rem; margin-bottom: 14px; }
.auth-card form > * + * { margin-top: 14px; }
.auth-card .notice { margin-top: 14px; }

/* ---------- Drop zone & channel mapping ---------- */
.drop {
  width: 100%; display: grid; gap: 4px; justify-items: center; padding: 30px 16px; border: 2px dashed var(--border-strong);
  background: var(--surface-2); border-radius: var(--radius);
}
.drop:hover:not(:disabled), .drop[data-active="true"] { border-color: var(--accent); background: var(--accent-soft); }
.drop span { color: var(--muted); font-weight: 400; font-size: .9rem; }
.channel-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.channel-map label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.channel-map .role { display: flex; align-items: center; gap: 8px; }
.role-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.strip { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.slot {
  flex: 1; min-width: 78px; text-align: center; padding: 8px 6px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); font-size: .85rem;
}
.slot small { display: block; color: var(--muted); font-size: .72rem; }
.slot strong { display: block; }
.slot[data-kind="role"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.slot[data-kind="out"] { border-style: dashed; color: var(--muted); }
.slot[data-kind="conflict"] { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 18px; display: grid; gap: 2px; min-width: 0;
}
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat strong { font-size: 1.9rem; line-height: 1.2; letter-spacing: -.02em; }
.stat small { color: var(--muted); font-size: .8rem; min-height: 1.2em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Badges & progress ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  white-space: nowrap; background: var(--c-uploading-bg); color: var(--c-uploading);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge[data-state="queued"] { background: var(--c-queued-bg); color: var(--c-queued); }
.badge[data-state="processing"] { background: var(--c-processing-bg); color: var(--c-processing); }
.badge[data-state="processing"]::before, .badge[data-state="encoding"]::before { animation: pulse 1.2s ease-in-out infinite; }
.badge[data-state="encoding"] { background: var(--c-encoding-bg); color: var(--c-encoding); }
.badge[data-state="ready"] { background: var(--c-ready-bg); color: var(--c-ready); }
.badge[data-state="failed"] { background: var(--c-failed-bg); color: var(--c-failed); }
.badge[data-state="cancelled"] { background: var(--c-cancelled-bg); color: var(--c-cancelled); }
.badge[data-state="active"] { background: var(--c-ready-bg); color: var(--c-ready); }
.badge[data-state="pending"] { background: var(--c-queued-bg); color: var(--c-queued); }
.badge[data-state="expired"] { background: var(--c-cancelled-bg); color: var(--c-cancelled); }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .badge::before { animation: none !important; } .bar > i { transition: none !important; } }

.bar { height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .4s ease; }
.bar[data-state="processing"] > i { background: var(--c-processing); }
.bar[data-state="encoding"] > i { background: var(--c-encoding); }
.bar[data-state="ready"] > i { background: var(--c-ready); }
.bar[data-state="failed"] > i { background: var(--c-failed); }
.bar[data-state="cancelled"] > i { background: var(--c-cancelled); opacity: .55; }
.bar.thick { height: 10px; }

/* ---------- Batches ---------- */
.batch-list { display: grid; gap: 14px; }
.batch { padding: 0; overflow: hidden; }
.batch-head { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 16px 20px; align-items: center; cursor: pointer; }
.batch-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.batch-title strong { font-size: 1rem; }
.batch-meta { color: var(--muted); font-size: .85rem; }
.batch-toggle { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.batch-states { display: flex; gap: 6px; flex-wrap: wrap; }
.batch-progress { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.batch-progress .bar { flex: 1; }
.batch-progress span { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }
.batch-body { border-top: 1px solid var(--border); padding: 14px 20px 18px; display: grid; gap: 14px; }
.batch-tools { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.batch-tools .field { min-width: 210px; }
.batch-tools .note { color: var(--muted); font-size: .85rem; align-self: center; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 700; text-transform: none; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th.check, td.check { width: 44px; }
td .name { font-weight: 600; word-break: break-all; }
td small { display: block; color: var(--muted); font-size: .78rem; }
.status-cell { min-width: 190px; display: grid; gap: 6px; }
.status-cell .line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; }
.status-cell .pos { color: var(--c-queued); font-weight: 700; }
.status-cell .err { color: var(--danger); }
.out-cell { min-width: 250px; display: grid; gap: 6px; }
.out-cell audio { width: 100%; max-width: 320px; height: 36px; }
.dl-links { display: flex; gap: 6px; flex-wrap: wrap; }
.dl-links a, .dl-links span {
  padding: 2px 9px; border-radius: 6px; font-size: .8rem; font-weight: 700; text-decoration: none;
  background: var(--accent-soft); color: var(--accent);
}
.dl-links span { background: var(--surface-2); color: var(--muted); text-decoration: line-through; font-weight: 500; }
.dl-links a:hover { background: var(--accent); color: var(--accent-text); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .appbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px 0; gap: 8px 12px; }
  .brand { order: 1; }
  .appbar-tools { order: 2; margin-left: auto; }
  .tabs { order: 3; flex-basis: 100%; padding-bottom: 6px; }
}
@media (max-width: 560px) {
  main { padding: 18px 12px 48px; }
  .card { padding: 16px; }
  .batch-head { padding: 14px 16px; }
  .batch-body { padding: 12px 14px 16px; }
  .stat strong { font-size: 1.5rem; }
  #identity { display: none; }
  #user-button { padding: 4px; }
  .toolbar .field { max-width: none; min-width: 100%; }
  .toolbar button { margin-left: 0; }
  .actions.downloads { align-items: stretch; }
  .actions.downloads button { width: 100%; }
  .auth-card { padding: 24px 20px; }
  /* Tables become stacked cards on narrow screens. */
  table.jobs thead, table.results thead { display: none; }
  table.jobs, table.jobs tbody, table.jobs tr, table.jobs td,
  table.results, table.results tbody, table.results tr, table.results td { display: block; width: 100%; }
  table.jobs tr, table.results tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.jobs td, table.results td { border: 0; padding: 4px 0; }
  .table-wrap { border: 0; }
  th.check, td.check { width: auto; }
}
.samples a { font-weight: 600; text-decoration: none; }
.samples a:hover { text-decoration: underline; }

/* ---------- Task editing, dialogs, accounts ---------- */
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 85%, #000); }
button.outline-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
button.outline-danger:hover:not(:disabled) { background: var(--danger-bg); }
.batch-tools .spacer { flex: 1; }
.bulk { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; }
th.actions-col, td.actions-col { white-space: nowrap; }
.actions.stack { justify-content: flex-start; }
dialog#confirm {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); padding: 22px 24px; width: min(440px, calc(100vw - 32px));
}
dialog#confirm::backdrop { background: rgba(15, 23, 42, .5); }
dialog#confirm p { line-height: 1.6; word-break: break-word; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-weight: 400; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.invite-result { margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--accent-soft); }
.invite-result .hint { margin-top: 8px; }
.users-wrap { margin-top: 16px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); max-width: 520px; }
.danger-zone .card-head h3 { color: var(--danger); }
.danger-zone form { margin-top: 14px; }
#accounts .card.narrow, #accounts #admin-section { max-width: 760px; }
@media (max-width: 560px) {
  table.users thead { display: none; }
  table.users, table.users tbody, table.users tr, table.users td { display: block; width: 100%; }
  table.users tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.users td { border: 0; padding: 4px 0; }
}
