:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #17171a;
  --muted: #6b6b73;
  --line: #e7e5df;
  --soft: #f1efea;
  --accent: #17171a;
  --accent-ink: #ffffff;
  --gold: #e7b434;
  --ok: #1d7a4a;
  --ok-bg: #e6f4ec;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --info-bg: #eef2ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .04), 0 4px 16px rgba(20, 20, 20, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1a1a1d;
    --ink: #f2f1ee;
    --muted: #9b9aa2;
    --line: #2b2b30;
    --soft: #232327;
    --accent: #f2f1ee;
    --accent-ink: #111113;
    --ok: #5fd197;
    --ok-bg: #12301f;
    --warn: #f3c56b;
    --warn-bg: #33270e;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --info-bg: #1d2133;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 600; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--soft); }
.danger-text { color: var(--bad); }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, .drop:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px;
}

/* brand */
.mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 11px; letter-spacing: .04em; position: relative; overflow: hidden;
}
.mark::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: 6px; height: 3px; border-radius: 2px; background: var(--gold); }
.mark.big { width: 64px; height: 64px; border-radius: 16px; font-size: 18px; margin: 0 auto 18px; }
.mark.big::after { left: 12px; right: 12px; bottom: 11px; height: 5px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; text-align: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 40px 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 28px; font-weight: 700; }
.login-card p { margin: 8px 0 0; }
.login-card .btn.google { margin: 28px 0 14px; width: 100%; height: 46px; font-size: 15px; }
.error-banner { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 18px !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px;
  padding: 12px max(16px, calc((100vw - 1040px) / 2)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.brand .by { color: var(--muted); font-weight: 400; font-size: 13px; }
.tabs-top { display: flex; gap: 4px; }
.tabs-top button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.tabs-top button:hover { color: var(--ink); background: var(--soft); }
.tabs-top button.active { color: var(--ink); background: var(--soft); }
.who { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar.initials { display: grid; place-items: center; background: var(--soft); font-weight: 600; font-size: 13px; }
.who-name { font-weight: 500; }

/* layout */
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.card p { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.card > *, .layout-panel > *, .lf-group > *, .recog > * { min-width: 0; }
.notice { margin: 0; background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 12px 14px; font-size: 14px; }

/* upload */
.options { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-end; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
select, input[type=number], input[type=text], input[type=url], textarea {
  height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
  font: inherit; padding: 0 12px; min-width: 200px;
}
.segmented { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500; font-size: 14px;
  height: 32px; padding: 0 14px; border-radius: 8px; cursor: pointer;
}
.segmented button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.segmented.small button { height: 28px; font-size: 13px; padding: 0 12px; }
.drop {
  display: grid; justify-items: center; gap: 4px; padding: 40px 16px; text-align: center; cursor: pointer;
  border: 1.5px dashed color-mix(in srgb, var(--muted) 45%, transparent); border-radius: var(--radius); background: var(--soft);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--ink); background: color-mix(in srgb, var(--gold) 10%, var(--soft)); }
.drop.busy { pointer-events: none; }
.drop strong { font-size: 16px; font-weight: 600; }
.drop-icon {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); font-size: 20px; font-weight: 600;
}
.progress { width: min(420px, 100%); margin-top: 14px; display: grid; gap: 6px; }
.progress::before { content: ""; grid-area: 1 / 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress .bar { grid-area: 1 / 1; height: 6px; width: 0; border-radius: 3px; background: var(--ink); transition: width .2s; }
.progress-text { font-size: 13px; color: var(--muted); }

textarea { height: auto; padding: 8px 12px; line-height: 1.5; resize: vertical; width: 100%; min-width: 0; }
input[type=text], input[type=url] { min-width: 0; width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.custom-note { font-size: 11.5px; font-weight: 600; color: var(--warn); background: var(--warn-bg); border-radius: 999px; padding: 1px 8px; margin-inline-start: 4px; }

/* layout panel */
details > summary { cursor: pointer; font-weight: 500; font-size: 14px; width: fit-content; }
details.customize { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
details.customize[open] { padding-bottom: 14px; }
details.customize[open] > summary { margin-bottom: 12px; }
.layout-panel { display: grid; gap: 12px; }
.lf-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.lf { display: grid; gap: 4px; align-content: start; }
.lf label { font-size: 13px; font-weight: 500; color: var(--muted); }
.lf select, .lf input { min-width: 0; width: 100%; }

/* recognition options */
.recog { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; align-items: start; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.check:has(input:checked) { border-color: color-mix(in srgb, var(--ink) 40%, var(--line)); background: var(--soft); }
.check.off { cursor: default; color: var(--muted); }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--ink); flex: none; }
.check strong { font-weight: 600; font-size: 14px; }
.sub-option { margin-top: 8px; }
.sub-option select { width: 100%; min-width: 0; }
.extra-terms summary { font-size: 13px; color: var(--muted); font-weight: 500; }
.extra-terms textarea { margin-top: 8px; }

/* link */
.link-form { display: grid; gap: 8px; padding: 18px; background: var(--soft); border-radius: var(--radius); }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; }

/* files */
.files-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.rows { list-style: none; margin: 0 -22px -22px; padding: 0; border-top: 1px solid var(--line); }
.rows > li { border-bottom: 1px solid var(--line); }
.rows > li:last-child { border-bottom: 0; }
.empty { display: grid; place-items: center; padding: 36px 16px; text-align: center; }
.job { display: flex; align-items: center; gap: 16px; padding: 14px 22px; }
.job-main { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.file-icon {
  flex: none; width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center;
  background: var(--soft); font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: var(--muted);
}
.job.done .file-icon { background: color-mix(in srgb, var(--gold) 18%, var(--soft)); color: var(--ink); }
.job-text { min-width: 0; }
.job-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-meta { font-size: 13px; }
.job-error { font-size: 13px; color: var(--bad); margin-top: 2px; }
.job-wait { font-size: 13px; color: var(--warn); margin-top: 2px; }
.job-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.pill.done { background: var(--ok-bg); color: var(--ok); }
.pill.processing { background: var(--info-bg); color: var(--ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.failed { background: var(--bad-bg); color: var(--bad); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* menu */
.menu { position: relative; }
.menu summary { list-style: none; letter-spacing: .1em; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 4; min-width: 210px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .12); display: grid;
}
.menu-list a, .menu-list button {
  display: block; text-align: start; padding: 8px 10px; border-radius: 8px; border: 0; background: none; color: var(--ink);
  font: inherit; font-size: 14px; text-decoration: none; cursor: pointer;
}
.menu-list a:hover, .menu-list button:hover { background: var(--soft); }
.menu-list .danger { color: var(--bad); }

/* preview */
dialog.preview {
  width: min(720px, calc(100vw - 32px)); max-height: min(80vh, 760px); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog.preview::backdrop { background: rgba(10, 10, 12, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h3 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 8px 20px 20px; overflow-y: auto; max-height: calc(min(80vh, 760px) - 64px); }
.cues { list-style: none; margin: 0; padding: 0; }
.cues li { display: grid; grid-template-columns: 120px 1fr; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.cues .t { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.cues .c { display: block; text-align: start; }
.cues .c.ar { font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; font-size: 16px; }

/* editor */
dialog.editor {
  width: min(1180px, calc(100vw - 24px)); height: min(92vh, 980px); max-height: none; padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); display: none; flex-direction: column;
}
dialog.editor[open] { display: flex; }
dialog.editor::backdrop { background: rgba(10, 10, 12, .45); }
.dlg-title { min-width: 0; display: grid; }
.dlg-actions { display: flex; gap: 6px; align-items: center; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.editor-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px 1fr; }
.editor-side { border-inline-end: 1px solid var(--line); padding: 16px 18px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.editor-side .lf-group { grid-template-columns: 1fr 1fr; }
.editor-main { overflow-y: auto; padding: 14px 20px 24px; }
.find { display: flex; gap: 8px; position: sticky; top: -14px; background: var(--card); padding: 10px 0; z-index: 2; }
.find input { flex: 1; }
.learn-note { margin: 0 0 6px; }
.cue-edit { list-style: none; margin: 0; padding: 0; }
.cue-edit li { display: grid; grid-template-columns: 118px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cue-edit .t { font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); padding-top: 8px; }
.cue-edit textarea { resize: none; overflow: hidden; font-size: 15px; }
.cue-edit li.changed textarea { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 8%, var(--card)); }
.cue-edit .shown { font-size: 12.5px; color: var(--muted); margin-top: 4px; padding-inline: 2px; }
.speaker-names { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.speaker-names h4 { margin: 0; font-size: 14px; }
.side-actions { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }

/* settings */
.preset-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.preset-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.fix-form { display: flex; gap: 8px; align-items: center; }
.fix-form input { flex: 1; }
table.fixes tr.off td { opacity: .55; }

/* admin */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stats > div { background: var(--soft); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; }
.stats strong { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.meter { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.meter > div { height: 100%; background: var(--gold); border-radius: 4px; }
.cap-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cap-form label { font-weight: 500; font-size: 14px; }
.cap-form input { min-width: 0; width: 110px; }
.table-wrap { overflow-x: auto; margin: 0 -22px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: start; font-weight: 500; font-size: 12.5px; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-inline-start: 22px; }
th:last-child, td:last-child { padding-inline-end: 22px; text-align: end; }
tr:last-child td { border-bottom: 0; }
tr.blocked td { opacity: .55; }
.person { display: flex; align-items: center; gap: 10px; }
table select { min-width: 0; height: 32px; font-size: 13.5px; }

/* toasts, spinner */
.toasts { position: fixed; bottom: 20px; inset-inline-end: 20px; display: grid; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); transition: opacity .35s, transform .35s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 100vh; display: grid; place-items: center; }

/* phones */
@media (max-width: 640px) {
  .top { gap: 10px; flex-wrap: wrap; }
  .brand .by, .who-name { display: none; }
  .tabs-top { order: 3; width: 100%; }
  .card { padding: 18px 16px; }
  .rows { margin: 0 -16px -18px; }
  .table-wrap { margin: 0 -16px; }
  th:first-child, td:first-child { padding-inline-start: 16px; }
  th:last-child, td:last-child { padding-inline-end: 16px; }
  .job { flex-wrap: wrap; padding: 14px 16px; gap: 10px; }
  .job-actions { width: 100%; padding-inline-start: 56px; flex-wrap: wrap; }
  .options, .field, select { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .cues li { grid-template-columns: 1fr; gap: 2px; }
  .upload-head .segmented { width: 100%; }
  .link-row { flex-direction: column; }
  dialog.editor { width: 100vw; height: 100dvh; max-width: 100vw; border-radius: 0; }
  .editor-body { grid-template-columns: 1fr; overflow-y: auto; }
  .editor-side { border-inline-end: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .editor-main { overflow: visible; }
  .find { flex-wrap: wrap; top: 0; }
  .cue-edit li { grid-template-columns: 1fr; gap: 4px; }
  .cue-edit .t { padding-top: 0; }
  .dlg-head { flex-wrap: wrap; }
  .fix-form { flex-wrap: wrap; }
}
