:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #5d6270;
  --line: #e2dfd6;
  --brand: #14161c;
  --red: #c62828;
  --gold: #d4a017;
  --accent: #b3261e;
  --ok: #1e7a46;
  --info: #1c5d99;
  --radius: 14px;
  --font: "Noto Kufi Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, "Geeza Pro", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--font);
}
a { color: var(--info); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: var(--brand); color: #fff;
  border-bottom: 4px solid transparent;
  border-image: linear-gradient(to left, #000 0 33%, var(--red) 33% 66%, var(--gold) 66%) 1;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-sub { font-size: .8rem; opacity: .75; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.logout { margin: 0; }

.container { max-width: 960px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 32px) 64px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(16px, 3vw, 28px); margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 20px 0 4px; }
.muted { color: var(--muted); font-size: .92rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.login-card { max-width: 440px; margin: 8vh auto 0; }

input[type=password], textarea {
  width: 100%; font: inherit; color: inherit;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
input:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(212,160,23,.5); outline-offset: 1px;
}
textarea { min-height: 220px; resize: vertical; line-height: 1.9; font-size: 1.05rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 9px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #951f18; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: rgba(0,0,0,.04); }
.btn-danger { background: #fff; color: var(--red); border-color: #f0c2c2; }
.btn-record { background: #fff; color: var(--red); border: 2px solid var(--red); font-size: 1.05rem; }
.btn-record.recording { background: var(--red); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(198,40,40,.15); } }
@media (prefers-reduced-motion: reduce) { .btn-record.recording { animation: none; } }

.tabs { display: flex; gap: 4px; margin: 16px 0; border-bottom: 1px solid var(--line); }
.tab {
  font: inherit; background: none; border: 0; padding: 8px 14px; cursor: pointer;
  color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.tab-panel[hidden] { display: none; }

.dropzone {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 32px 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--gold); background: #fffbef; }
.dropzone-title { font-weight: 600; }
audio { width: 100%; max-width: 100%; }

.recorder { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.rec-timer { font-variant-numeric: tabular-nums; font-size: 1.1rem; color: var(--muted); }

.progress { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.progress-bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }

.alert { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: .95rem; }
.alert-error { background: #fdecea; color: #8a1c13; border: 1px solid #f5c6c0; }
.alert-ok { background: #e8f5ee; color: var(--ok); border: 1px solid #bfe3cf; }

.jobs-scroll { overflow-x: auto; }
table.jobs { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: .95rem; }
.jobs th, .jobs td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.jobs th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.jobs td a { word-break: break-word; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .82rem; font-weight: 600;
  background: #eceae4; color: var(--muted); white-space: nowrap;
}
.badge.queued { background: #fff4d6; color: #7a5a00; }
.badge.processing { background: #e3eefa; color: var(--info); }
.badge.done { background: #e3f3ea; color: var(--ok); }
.badge.failed { background: #fdecea; color: #8a1c13; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0; font-size: .95rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.raw { margin-top: 16px; }
.raw summary { cursor: pointer; color: var(--muted); }
.raw-text { white-space: pre-wrap; background: #faf9f6; padding: 12px; border-radius: 10px; }

.segments { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.segments li { display: flex; gap: 12px; align-items: baseline; }
.ts {
  font: inherit; font-size: .82rem; font-variant-numeric: tabular-nums; flex-shrink: 0;
  background: #f1efe8; border: 0; border-radius: 6px; padding: 2px 8px; cursor: pointer; color: var(--info);
}
.ts:disabled { cursor: default; color: var(--muted); }

@media (max-width: 640px) {
  .brand-sub { display: none; }
  .jobs thead { display: none; }
  .jobs tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .jobs td { display: inline-block; border: 0; padding: 2px 8px 2px 0; }
  .jobs td:first-child { display: block; font-weight: 600; }
  .meta { grid-template-columns: 1fr; }
  .meta dd { margin-bottom: 6px; }
}

.field { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.field select { font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* Phase 2B: speaking evidence */
.obs-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 10px; }
.obs { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.obs.rejected { opacity: .55; }
.obs .quote { background: #faf9f6; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.obs .interp { color: var(--muted); font-size: .92rem; margin: 4px 0; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; background: #eceae4; color: var(--muted); margin-inline-end: 4px; }
.tag.warn { background: #fff4d6; color: #7a5a00; }
.tag.ok { background: #e3f3ea; color: var(--ok); }
.btn-sm { padding: 3px 12px; font-size: .85rem; }
.text-input { width: 100%; font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .92rem; }
.trait { border-inline-start: 3px solid var(--gold); padding: 4px 12px; margin: 8px 0; }
.dual { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.slot { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fcfbf8; }
.slot h4 { margin: 0 0 6px; font-size: .95rem; }
.slot .de { font-size: 1.05rem; line-height: 1.6; }
.slot .note { font-size: .88rem; color: var(--muted); direction: rtl; text-align: right; margin-top: 8px; }
@media (max-width: 640px) { .dual { grid-template-columns: 1fr; } }
.alert-warn { background: #fff4d6; color: #7a5a00; border: 1px solid #f0dca0; }
.vocab { margin: 4px 0 0; padding-inline-start: 20px; font-size: .88rem; color: var(--muted); direction: rtl; text-align: right; }
.de-term { font-weight: 600; color: inherit; }

/* Phase 2C: dashboard */
.topnav { display: flex; gap: 8px; align-items: center; }
.card.inner { margin-top: 12px; box-shadow: none; }
ul.plain { list-style: none; padding: 0; margin: 8px 0 0; }
td.actions { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 640px) { td.actions { display: flex; } .topnav { flex-wrap: wrap; } }

/* Phase 2C.1: administrator review dashboard */
.container.wide { max-width: 1180px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card .stat-grid { margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; border-inline-start: 4px solid var(--gold); }
.stat-v { font-size: 1.7rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-l { font-weight: 600; font-size: .92rem; }
.stat-h { font-size: .8rem; margin-top: 2px; }
.two-col { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; }
.two-col .card { margin-bottom: 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; margin: 12px 0; }
.fld { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; color: var(--muted); }
.fld select, .fld input { font: inherit; color: var(--ink); padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-width: 140px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }
table.students td:first-child { min-width: 150px; }
table.students td.actions { white-space: nowrap; }
.apanel { display: flex; flex-direction: column; gap: 0; }
.apanel[hidden] { display: none; }
.apanel .card.inner { margin-top: 0; margin-bottom: 16px; box-shadow: none; }
.apanel h3 { margin-top: 16px; }
.chart { width: 100%; }
svg.bars { width: 100%; height: auto; max-height: 230px; display: block; }
svg.bars .axis { stroke: var(--line); stroke-width: 1; }
svg.bars .bar-fill { fill: var(--info); }
svg.bars .bar:hover .bar-fill { fill: #14446f; }
svg.bars text { font: 11px var(--font); fill: var(--muted); }
svg.bars .bar-val { fill: var(--ink); font-weight: 600; }
.quote.src-ar { display: block; padding: 8px 12px; font-weight: 500; }
.audio-box { margin-top: 12px; }
.card .raw-text { margin: 4px 0; }
.apanel .trait { margin: 10px 0; }
/* Tabs wrap instead of scrolling: a scrolling tab bar showed tiny scroll arrows in some browsers. */
#s-tabs { flex-wrap: wrap; overflow: visible; }
#s-tabs .tab { white-space: nowrap; }
#s-tabs .tab[hidden] { display: none; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .filters .fld, .fld select, .fld input { width: 100%; }
  table.students td { white-space: normal; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-v { font-size: 1.35rem; }
}

/* Phase 2C.2: account management, dialogs, layout hardening */
main.container { min-width: 0; }
.card, .meta dd, .jobs td, .stat, .modal { overflow-wrap: anywhere; }
.jobs-scroll { scrollbar-width: thin; max-width: 100%; }
.apanel, .two-col > * { min-width: 0; }
.alert-info { background: #e8f1fa; color: #14446f; border: 1px solid #bcd6ee; }
.layers { padding-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; }
.card .alert-warn, .card .alert-info { margin-bottom: 12px; }
.fld.wide { width: 100%; }
.fld.wide .text-input { width: 100%; }
.btn-warning { background: #fff4d6; color: #6b4e00; border-color: #e0b84f; }
.btn-warning:hover:not(:disabled) { background: #ffe9a8; }
.btn-danger-solid { background: #7a0f0f; color: #fff; border: 2px solid #4a0505; }
.btn-danger-solid:hover:not(:disabled) { background: #5c0a0a; }
.acct-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 12px; }
.acct-group { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 14px; }
.acct-group h3 { margin-top: 10px; }
.acct-group .filters { margin: 8px 0 0; }
.acct-group .fld input { min-width: 0; width: 100%; }
.danger-zone { margin-top: 20px; border: 2px solid #b3261e; background: #fdf0ee; border-radius: 12px; padding: 4px 16px 16px; }
.danger-zone h3 { color: #7a0f0f; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,22,28,.55); display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 540px; max-height: calc(100vh - 24px); overflow-y: auto; padding: 20px 22px; border-top: 6px solid var(--gold); box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.modal.danger { border-top-color: #7a0f0f; }
.modal h2 { margin-bottom: 10px; }
.modal textarea.text-input { min-height: 80px; }
.erase-list { margin: 0; padding-inline-start: 22px; color: #5c0a0a; }
.modal .actions { margin-top: 6px; }
@media (max-width: 640px) {
  .container { padding-inline: 12px; }
  .acct-actions { grid-template-columns: 1fr; }
  .modal { padding: 16px; }
  .modal .actions .btn, .danger-zone .btn, .acct-group .actions .btn { flex: 1 1 100%; }
  table.students td.actions { white-space: normal; }
  .topbar { flex-wrap: wrap; }
  .tab { padding: 8px 10px; }
}

/* Policy dialog + footer (Terms and Privacy). Exactly ONE scroll region (the body); the head and the actions stay put,
   so there are no nested scrollbars or tiny scroll arrows. */
.policy-modal { max-width: 660px; display: flex; flex-direction: column; overflow: hidden; padding: 0; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
.policy-head { padding: 20px 24px 12px; background: linear-gradient(to bottom, #fffbef, var(--surface)); border-bottom: 1px solid var(--line); }
.policy-head h2 { font-size: 1.3rem; margin: 2px 0 6px; }
.policy-step { display: inline-block; font-size: .78rem; font-weight: 700; color: #7a5a00; background: #fff4d6; border-radius: 99px; padding: 1px 12px; }
.policy-lead { margin: 0; color: var(--muted); font-size: .94rem; }
.policy-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px 24px; display: flex; flex-direction: column; gap: 12px; }
.policy-block { border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 12px; background: #fcfbf8; }
.policy-block h3 { margin: 10px 0 4px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.policy-block p { margin: 4px 0; }
.policy-block ul { padding-inline-start: 20px; margin: 4px 0; }
.policy-ico { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; font-size: .8rem; flex-shrink: 0; }
.policy-optional { border-style: dashed; background: #f4f8fc; }
.policy-more { margin: 0; text-align: center; }
.policy-actions { padding: 12px 24px 18px; border-top: 1px solid var(--line); background: var(--surface); }
.site-footer { text-align: center; padding: 8px 16px 28px; font-size: .85rem; }
.site-footer a { color: var(--muted); }
@media (max-width: 640px) {
  .policy-head, .policy-body, .policy-actions { padding-inline: 16px; }
  .policy-actions .actions .btn { flex: 1 1 100%; }
}

/* Phase 2C.3: tabs never scroll (they wrap), tables fit, administrator forms. */
.tabs { flex-wrap: wrap; overflow: visible; row-gap: 0; }
.tab { white-space: nowrap; }
.jobs-scroll { overflow-x: auto; scrollbar-width: thin; }
table.students { table-layout: auto; }
table.students td.actions { display: table-cell; text-align: end; white-space: nowrap; }
table.students td:first-child { min-width: 0; }
.name-link { font-weight: 700; color: var(--ink); text-decoration: none; }
.name-link:hover { text-decoration: underline; }
.container.narrow { max-width: 800px; }
.btn-lg { padding: 12px 26px; font-size: 1.05rem; }
.btn-success { background: #1e7a46; color: #fff; border-color: #14562f; }
.btn-success:hover:not(:disabled) { background: #14562f; }
.btn-act { min-width: 150px; padding: 12px 22px; font-size: 1.05rem; }
.acct-main { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 6px; }
.acct-secondary { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; padding-top: 12px; border-top: 1px dashed var(--line); }
.acct-help p { margin: 4px 0; }
.user-form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 8px 16px 16px; margin: 0 0 16px; min-width: 0; }
.user-form legend { font-weight: 700; padding: 0 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 16px; }
.form-grid .fld input, .form-grid .fld select, .user-form .fld input, .user-form .fld select { width: 100%; }
.fld small { color: var(--muted); font-weight: 400; }
.field-error { color: #8a1c13; font-size: .85rem; }
.field-error[hidden] { display: none; }
.pw-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.pw-row .fld { flex: 1 1 260px; }
.role-select { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-card { display: flex; flex-direction: column; gap: 2px; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; position: relative; }
.role-card[hidden] { display: none; }
.role-card input { position: absolute; inset-inline-end: 12px; top: 12px; }
.role-card:has(input:checked) { border-color: var(--accent); background: #fff6f5; }
.role-title { font-weight: 700; font-size: 1.05rem; }
.perm-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.perm.elevated { background: #fff8e1; border-radius: 8px; padding: 4px 8px; }
.form-actions { margin-top: 8px; }
.handoff { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; }
.handoff-msg { min-height: 120px; line-height: 1.8; background: #faf9f6; }
.team-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.team-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.team-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.team-meta { margin: 4px 0; }
.team-perms { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.dlg-field { display: flex; flex-direction: column; gap: 2px; }
.dlg-field .check { padding: 4px 0; }
.quick { margin-top: -4px; }
.modal .perm-list { max-height: 40vh; overflow-y: auto; }
@media (max-width: 640px) {
  .role-select { grid-template-columns: 1fr; }
  .btn-act { flex: 1 1 100%; }
  .acct-secondary .btn { flex: 1 1 100%; }
  /* the student table becomes a list of cards: no horizontal scrolling at phone width */
  table.students thead { display: none; }
  table.students, table.students tbody, table.students tr, table.students td { display: block; width: 100%; }
  table.students tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; }
  table.students td { border: 0; padding: 3px 0; }
  table.students td.actions { text-align: start; padding-top: 6px; }
  .form-actions .btn { flex: 1 1 100%; }
}

/* Phase 2C.4: "no deadline" control. One compact row (checkbox + its own label) under the date input. The generic
   `.fld input` / `.form-grid .fld input` rules (min-width, width:100%, padding, border) must NOT reach the checkbox:
   they stretched it across the whole field and pushed the text to the far edge. Logical properties keep the row
   anchored to the start edge in RTL (right) and LTR (left) alike. */
.fld .no-expiry { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 8px;
  align-self: flex-start; width: fit-content; max-width: 100%; margin-block-start: 8px; }
.fld .no-expiry > input[type="checkbox"] { flex: 0 0 auto; width: 1.15rem; height: 1.15rem; min-width: 0; margin: 0; padding: 0;
  border: revert; border-radius: revert; background: revert; accent-color: var(--accent); cursor: pointer; }
.fld .no-expiry > label { display: inline-flex; align-items: center; min-height: 32px; font-size: .92rem; color: var(--ink);
  cursor: pointer; user-select: none; }
.fld .no-expiry > input[type="checkbox"]:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }
.fld input[type="date"]:disabled { opacity: .55; cursor: not-allowed; background: #f2f0ea; }
@media (max-width: 640px) {
  .fld .no-expiry { margin-block-start: 6px; }
  .fld .no-expiry > label { min-height: 44px; }
}
