/* ── Fonts (self-hosted woff2 — no CDN) ────────────── */
@font-face {
  font-family: "Cairo";
  src: url("/static/fonts/cairo-200-1000-latin.woff2") format("woff2");
  font-weight: 200 1000; font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "Cairo";
  src: url("/static/fonts/cairo-200-1000-arabic.woff2") format("woff2");
  font-weight: 200 1000; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-400-latin.woff2") format("woff2");
  font-weight: 400; font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-400-arabic.woff2") format("woff2");
  font-weight: 400; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-500-latin.woff2") format("woff2");
  font-weight: 500; font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-500-arabic.woff2") format("woff2");
  font-weight: 500; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-700-latin.woff2") format("woff2");
  font-weight: 700; font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("/static/fonts/plex-700-arabic.woff2") format("woff2");
  font-weight: 700; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}

/* ── Theme ─────────────────────────────────────────── */
:root {
  --bg: #0f1419;
  --bg-2: #171d24;
  --bg-3: #1f2731;
  --border: #2c3946;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4da3ff;
  --accent-2: #2f81f7;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
  --radius: 10px;
  --font: "Cairo", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --font-editor: "Cairo", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); }

/* ── Login ─────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 360px;
  display: flex; flex-direction: column; gap: 1rem;
}
.login-card h1 { margin: 0; font-size: 1.4rem; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; }

/* ── Shell layout ──────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-2);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 1.1rem; padding: 1.2rem 1rem; border-bottom: 1px solid var(--border); }
#main-nav { display: flex; flex-direction: column; padding: .8rem .5rem; gap: 2px; flex: 1; }
#main-nav a {
  color: var(--muted); text-decoration: none;
  padding: .55rem .8rem; border-radius: 8px; font-size: .95rem;
}
#main-nav a:hover { background: var(--bg-3); color: var(--text); }
#main-nav a.active { background: var(--bg-3); color: var(--accent); font-weight: 600; }
.sidebar-footer {
  padding: .9rem 1rem; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
#main-content { flex: 1; padding: 1.4rem 1.8rem; min-width: 0; }

/* ── Controls ──────────────────────────────────────── */
.btn {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem 1rem; cursor: pointer; font-family: inherit; font-size: .92rem;
}
.btn:hover { border-color: var(--accent); }
.btn { transition: transform .06s ease, filter .12s ease, background .12s ease; }
.btn:active { transform: translateY(1px) scale(.985); filter: brightness(.9); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.primary:hover { filter: brightness(1.15); }
.btn.success { background: #1f6f2e; border-color: #2ea043; color: #fff; }
.btn.danger  { background: #7d2724; border-color: var(--red); color: #fff; }
.btn.warn    { background: #6b5618; border-color: var(--yellow); color: #fff; }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn.wide { width: 100%; }

input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .5rem .7rem; font-family: inherit; font-size: .95rem;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }

h2.page-title { margin: 0 0 1.1rem; font-size: 1.25rem; }

/* ── Badges ────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .12rem .55rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge.pending      { background: #2c3946; color: var(--muted); }
.badge.in_progress  { background: #1c3a5e; color: var(--accent); }
.badge.transcribed  { background: #3a2e58; color: var(--purple); }
.badge.in_review    { background: #3a2e58; color: var(--purple); }
.badge.approved     { background: #1f4428; color: var(--green); }
.badge.rejected     { background: #542426; color: var(--red); }
.badge.skipped      { background: #4d3800; color: var(--yellow); }
.badge.queued       { background: #2c3946; color: var(--muted); }
.badge.downloading  { background: #1c3a5e; color: var(--accent); }
.badge.processing   { background: #1c3a5e; color: var(--accent); }
.badge.completed    { background: #1f4428; color: var(--green); }
.badge.failed       { background: #542426; color: var(--red); }
.badge.running      { background: #1c3a5e; color: var(--accent); }
.badge.cancelled    { background: #4d3800; color: var(--yellow); }

/* per-episode diarization label (spk0/...); neutral chip next to badges */
.speaker-chip {
  display: inline-block; padding: .12rem .55rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600; white-space: nowrap; direction: ltr;
  background: #233042; color: var(--accent);
}

.term-tab { display: inline-flex; gap: 2px; align-items: center; }

/* ── Workspace ─────────────────────────────────────── */.workspace { display: flex; gap: 1.2rem; align-items: flex-start; }
.clip-sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem; max-height: calc(100vh - 8rem); overflow-y: auto;
  display: flex; flex-direction: column; gap: .6rem;
}
.clip-list { display: flex; flex-direction: column; gap: 2px; }
.clip-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: .4rem .6rem; border-radius: 6px; cursor: pointer; font-size: .85rem;
}
.clip-item:hover { background: var(--bg-3); }
.clip-item.active { background: var(--bg-3); outline: 1px solid var(--accent); }

.editor-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.clip-header {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1.1rem; display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; align-items: center;
}
.clip-header .title { font-weight: 600; }
.clip-header a { color: var(--accent); text-decoration: none; }

.audio-row {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1.1rem; display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.audio-row audio { flex: 1; min-width: 280px; height: 40px; }

.original-caption {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1.1rem; font-size: .95rem; line-height: 1.8;
}
.original-caption summary { cursor: pointer; color: var(--muted); font-size: .85rem; }

.reject-note {
  background: #542426; border: 1px solid var(--red); border-radius: var(--radius);
  padding: .7rem 1.1rem; color: #ffd7d5; font-size: .95rem; line-height: 1.7;
}

#transcript-input {
  width: 100%; min-height: 190px; resize: vertical;
  font-family: var(--font-editor);
  font-size: 1.25rem; line-height: 2.1; direction: rtl;
}

.editor-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
#save-status { font-size: .82rem; }
.kbd-help { font-size: .78rem; color: var(--muted); line-height: 1.9; }
kbd {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 4px;
  padding: 0 .35rem; font-size: .75rem; font-family: inherit;
}

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: right; padding: .6rem .9rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; position: sticky; top: 0; background: var(--bg-2); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-3); }
td a { color: var(--accent); }

/* ── Cards / misc ──────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.card {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.2rem;
}
.card .num { font-size: 1.7rem; font-weight: 700; }
.card .label { color: var(--muted); font-size: .82rem; margin-top: .2rem; }

.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }

.log-panel {
  background: #0a0e12; border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem 1rem; font-family: Consolas, monospace; font-size: .8rem;
  direction: ltr; text-align: left; max-height: 420px; overflow-y: auto; white-space: pre-wrap;
}

.toast {
  position: fixed; bottom: 1.4rem; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--bg-3); border: 1px solid var(--accent);
  border-radius: 8px; padding: .7rem 1.4rem; z-index: 99;
}
.toast.err { border-color: var(--red); }

textarea.urls-input { width: 100%; min-height: 120px; direction: ltr; text-align: left; font-family: Consolas, monospace; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem; width: 420px; max-width: 92vw; display: flex; flex-direction: column; gap: .9rem;
}
.modal h3 { margin: 0; }

#page-terminal .term-wrap { background: #000; border-radius: var(--radius); padding: .5rem; }

/* ── Mobile ────────────────────────────────────────── */

.topbar { display: none; }
.mobile-only { display: none; }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50;
}

/* tables keep a sane width and scroll inside .table-wrap */
.table-wrap table { min-width: 600px; }

@media (max-width: 880px) {
  .mobile-only { display: inline-block; }

  /* top bar replaces the fixed sidebar */
  .topbar {
    display: flex; align-items: center; gap: .8rem;
    position: sticky; top: 0; z-index: 40;
    background: var(--bg-2); border-bottom: 1px solid var(--border);
    padding: .55rem .9rem;
  }
  .topbar #menu-btn {
    background: none; border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: 1.15rem; padding: .3rem .7rem; cursor: pointer;
  }
  .brand-sm { font-weight: 700; }
  #topbar-user { margin-inline-start: auto; font-size: .8rem; }

  /* sidebar becomes an off-canvas drawer sliding from the right (RTL) */
  .shell { display: block; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; right: 0; height: 100dvh;
    width: min(78vw, 300px); z-index: 60;
    transform: translateX(100%); transition: transform .22s ease;
    border-inline-start: 1px solid var(--border); border-inline-end: none;
  }
  .sidebar.open { transform: translateX(0); }

  #main-content { padding: .9rem .8rem; }

  /* workspace stacks; clip list is a collapsible panel */
  .workspace { flex-direction: column; }
  .clip-sidebar { display: none; width: 100%; max-height: 45vh; }
  .clip-sidebar.show { display: flex; }
  .editor-panel { width: 100%; }
  #transcript-input { min-height: 32vh; }

  /* action bar stays reachable under the thumb while the page scrolls */
  .editor-actions {
    position: sticky; bottom: 0; z-index: 10;
    background: var(--bg); border-top: 1px solid var(--border);
    padding: .6rem 0; margin: 0 -0.2rem;
  }
  .kbd-help { display: none; }  /* shortcuts are keyboard-only */

  /* inputs at 16px+ so iOS doesn't auto-zoom on focus */
  input[type=text], input[type=password], input[type=number], select, textarea {
    font-size: 16px;
  }
  .toolbar select { max-width: 72vw; }

  .toast {
    inset-inline: .8rem; transform: none; text-align: center;
  }

  .login-card { width: 100%; max-width: 380px; margin: 0 1rem; padding: 1.8rem; }
}

@media (max-width: 560px) {
  .hide-sm { display: none; }
  .table-wrap table { min-width: 480px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .card { padding: .8rem .9rem; }
  .card .num { font-size: 1.35rem; }
  h2.page-title { font-size: 1.1rem; margin-bottom: .8rem; }
}

/* bigger touch targets on touch devices, any size */
@media (pointer: coarse) {
  .btn { padding: .65rem 1.05rem; }
  .btn.small { padding: .45rem .75rem; }
  .clip-item { padding: .65rem .7rem; }
  #main-nav a { padding: .75rem .9rem; }
}
