:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2740;
  --border: #2a3550;
  --text: #e8ecf5;
  --muted: #8b96ad;
  --accent: #4f8cff;
  --accent-2: #7aa5ff;
  --green: #34c98e;
  --amber: #f5b942;
  --red: #f0616d;
  --purple: #a78bfa;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Kufi Arabic", "Noto Sans Arabic", sans-serif;
}
button {
  font: inherit; color: inherit; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover { background: #253254; border-color: #3a4a73; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--red); border-color: #5a2f38; }
button.small { padding: 4px 10px; font-size: 13px; border-radius: 6px; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
a { color: var(--accent-2); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* ---------- login ---------- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 34px;
}
.login-card h1 { text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card button { margin-top: 8px; padding: 10px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: .3px; }
.sidebar .brand span { color: var(--accent); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar .whoami { border-top: 1px solid var(--border); padding: 12px 10px 2px; font-size: 13px; }
.sidebar .whoami .name { font-weight: 600; }
.sidebar .whoami .role { color: var(--muted); }
.sidebar .whoami button { width: 100%; margin-top: 10px; }
.main { flex: 1; padding: 26px 32px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards / tables ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.card .big { font-size: 26px; font-weight: 700; margin-top: 4px; }
.card .label { color: var(--muted); font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }
.table-scroll { overflow-x: auto; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.chip.pending { background: #3a3f4d; color: #b8c0d0; }
.chip.transcribing, .chip.downloading { background: #4b3d1e; color: var(--amber); }
.chip.ready { background: #1e3b56; color: #6cb8ff; }
.chip.in_review, .chip.in_progress, .chip.assigned { background: #3a2f5b; color: var(--purple); }
.chip.submitted { background: #4b3d1e; color: var(--amber); }
.chip.completed, .chip.approved { background: #17402f; color: var(--green); }
.chip.failed { background: #4d2229; color: var(--red); }

.progress { background: var(--panel-2); border-radius: 20px; height: 8px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 20px; }
.progress.green > div { background: var(--green); }

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- modal / toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(5,8,15,.65);
  display: grid; place-items: center; z-index: 50;
}
.modal {
  width: 420px; max-width: 94vw; background: var(--panel);
  border: 1px solid var(--border); border-radius: 14px; padding: 24px;
  max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; }
.modal form { display: flex; flex-direction: column; gap: 11px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 20px; border-radius: 10px; z-index: 100; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 80vw;
}
#toast.error { border-color: var(--red); }
#toast.hidden { display: none; }

/* ---------- editor ---------- */
.editor-top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg); padding: 14px 0 10px;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.editor-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.editor-title h1 { font-size: 17px; }
.player {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px;
}
.player .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 110px; }
.seekwrap { flex: 1; min-width: 200px; position: relative; height: 22px; cursor: pointer; }
.seekbar, .coverbar { position: absolute; left: 0; right: 0; border-radius: 6px; }
.coverbar { top: 4px; height: 5px; background: var(--panel-2); }
.coverbar span { position: absolute; top: 0; height: 100%; background: rgba(52,201,142,.55); border-radius: 4px; }
.seekbar { bottom: 4px; height: 5px; background: var(--panel-2); }
.seekbar > div { height: 100%; background: var(--accent); border-radius: 6px; }
.editor-stats { display: flex; gap: 18px; margin-top: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.editor-stats b { color: var(--text); }
.conf-legend { display: inline-flex; align-items: center; gap: 6px; }
.conf-swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; }
.conf-swatch.low { background: rgba(240, 97, 109, .55); }
.conf-swatch.med { background: rgba(245, 185, 66, .5); }
.savestate.dirty { color: var(--amber); }
.savestate.saved { color: var(--green); }

.transcript { max-width: 980px; margin: 0 auto; padding-bottom: 120px; }
.segment {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 14px; overflow: hidden;
}
.seg-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--panel-2); font-size: 13px;
}
.seg-head .spk { font-weight: 700; }
.seg-head .tc { color: var(--muted); font-variant-numeric: tabular-nums; }
.seg-head select { padding: 3px 8px; font-size: 12.5px; border-radius: 6px; }
.seg-words { padding: 14px 18px; direction: rtl; text-align: right; line-height: 2.35; font-size: 19px; }
.w {
  display: inline-block; padding: 1px 5px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; margin: 0 1px;
}
.w:hover { background: var(--panel-2); }
/* ASR confidence tints — declared before .playing/.sel so those still win */
.conf-on .w.conf-low { background: rgba(240, 97, 109, .22); box-shadow: inset 0 -2px 0 var(--red); }
.conf-on .w.conf-med { background: rgba(245, 185, 66, .16); box-shadow: inset 0 -2px 0 var(--amber); }
.w.playing { background: #2a4370; }
.w.sel { border-color: var(--accent); background: #223458; }
.w.edited { color: #ffd479; }
.w.inserted { color: #7ee2b8; }
.w.deleted { text-decoration: line-through; opacity: .4; }
.w[contenteditable="true"] {
  background: #223458; border-color: var(--accent); outline: none; min-width: 30px;
}
.wordbar {
  position: fixed; bottom: 0; left: 220px; right: 0; z-index: 20;
  background: var(--panel); border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 10px 24px; flex-wrap: wrap;
}
.wordbar .info { color: var(--muted); font-size: 13px; margin-right: 6px; direction: rtl; }
.speaker-colors-0 .spk { color: #6cb8ff; }
.kbd {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px;
  font-size: 11.5px; padding: 1px 6px; color: var(--muted);
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .wordbar { left: 0; }
  .main { padding: 16px; }
}
