:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --chip: #efe9df;
  --line: #e4ded3;
  --ink: #1d201e;
  --ink-2: #545a55;
  --muted: #7d837e;
  --brand: #8a5a2b;
  --brand-ink: #ffffff;
  --brand-soft: #f3e7d9;
  --ok: #2d7a4c;
  --ok-soft: #e1f1e7;
  --warn: #b25e12;
  --warn-soft: #fbeedc;
  --bad: #b83a32;
  --bad-soft: #f9e2df;
  --info: #2a78d6;
  --info-soft: #e1edfb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141614; --surface: #1c1f1d; --surface-2: #222623; --chip: #2a2e2b; --line: #323733;
    --ink: #eceeea; --ink-2: #c3c7c1; --muted: #9aa099;
    --brand: #d09a62; --brand-ink: #1a1a1a; --brand-soft: #3a2d20;
    --ok: #5cc28a; --ok-soft: #1f3528; --warn: #e79a4d; --warn-soft: #3b2c1b;
    --bad: #ef7b72; --bad-soft: #3c2220; --info: #6da7ec; --info-soft: #1d2a3b;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141614; --surface: #1c1f1d; --surface-2: #222623; --chip: #2a2e2b; --line: #323733;
  --ink: #eceeea; --ink-2: #c3c7c1; --muted: #9aa099;
  --brand: #d09a62; --brand-ink: #1a1a1a; --brand-soft: #3a2d20;
  --ok: #5cc28a; --ok-soft: #1f3528; --warn: #e79a4d; --warn-soft: #3b2c1b;
  --bad: #ef7b72; --bad-soft: #3c2220; --info: #6da7ec; --info-soft: #1d2a3b;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  font-family: "IBM Plex Sans Arabic", -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }

/* ───── Layout ───── */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--line);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand img { width: 36px; height: 36px; border-radius: 9px; }
.brand b { font-size: 18px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.nav-group { color: var(--muted); font-size: 12px; padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.nav .count { margin-inline-start: auto; background: var(--brand); color: var(--brand-ink); border-radius: 999px; font-size: 12px; padding: 0 8px; }
.sidebar .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.sidebar .me b { color: var(--ink); display: block; }
.main { padding: 24px 28px 80px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.page-head .spacer { flex: 1; }
.btn.menu-toggle { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 270px; z-index: 30; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: -8px 0 24px rgba(0,0,0,.2); }
  .btn.menu-toggle { display: inline-flex; }
  .main { padding: 16px 16px 80px; }
}

/* ───── Components ───── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; direction: ltr; unicode-bidi: embed; }
.hr { height: 1px; background: var(--line); margin: 14px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 6px 9px; }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--ink); font-weight: 600; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
input[type=range] { accent-color: var(--brand); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 16px; height: 16px; }

.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); padding: 2px 10px; border-radius: 999px; font-size: 12.5px; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.brand { background: var(--brand-soft); color: var(--brand); }

.tabs { display: flex; gap: 4px; background: var(--chip); padding: 4px; border-radius: 12px; width: fit-content; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 9px; cursor: pointer; color: var(--ink-2); }
.tabs button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.empty { text-align: center; color: var(--muted); padding: 50px 10px; }
.notice { background: var(--info-soft); color: var(--ink); border-radius: 12px; padding: 12px 14px; font-size: 14px; border-inline-start: 4px solid var(--info); }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; inset-inline-start: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(-18px); }
[dir=ltr] .switch input:checked + span::before { transform: translateX(18px); }

.stat { padding: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12.5px; }

/* ───── Toasts & modal ───── */
#toasts { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2); font-size: 14px; }
.toast.error { background: var(--bad); color: #fff; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,12,10,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(1200px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head .spacer { flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* ───── Login ───── */
.login { max-width: 400px; margin: 10vh auto; padding: 16px; }
.login .card { padding: 28px; }
.login img { width: 64px; height: 64px; border-radius: 16px; }
.error-text { color: var(--bad); font-size: 14px; min-height: 1.2em; }

/* ───── Exam detail ───── */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 1200px) { .detail-grid { grid-template-columns: minmax(0, 1fr); } }
.detail-grid > *, .layout > *, .with-preview > * { min-width: 0; }
.page-head > div { min-width: 0; }
.player { background: #000; border-radius: 12px; overflow: hidden; position: relative; }
.player video { width: 100%; max-height: 62vh; display: block; background: #000; }
.player .overlay-info { position: absolute; top: 10px; inset-inline-start: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 3px 10px; border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums; direction: ltr; }
.player-tools { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; padding: 12px 0 4px; }
.player-tools .group { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.player-tools .group > span { color: var(--muted); font-size: 12.5px; margin-inline-end: 4px; }
.slider { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.slider input { width: 110px; max-width: 30vw; }
.clips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.clip { border: 2px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; background: var(--surface-2); font-size: 13px; }
.clip.active { border-color: var(--brand); background: var(--brand-soft); }
.clip b { display: block; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photos .ph { position: relative; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: zoom-in; display: block; }
.photos .ph .btn { position: absolute; bottom: 6px; inset-inline-end: 6px; }
.findings { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.findings label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.findings label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.findings label.full { grid-column: 1 / -1; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs .t { position: relative; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumbs .t button { position: absolute; top: -6px; inset-inline-end: -6px; border-radius: 50%; width: 20px; height: 20px; padding: 0; border: 0; background: var(--bad); color: #fff; cursor: pointer; font-size: 12px; line-height: 20px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ───── Annotation editor ───── */
.annot { display: grid; grid-template-columns: 1fr; gap: 10px; }
.annot-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.annot canvas { max-width: 100%; max-height: 70vh; border-radius: 10px; background: #000; cursor: crosshair; touch-action: none; display: block; margin: 0 auto; }
.color-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; }
.color-dot.active { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ───── Chat ───── */
.chat-layout { display: grid; grid-template-columns: 330px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 480px; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; height: auto; } }
.conv-list { overflow-y: auto; padding: 6px; }
.conv { padding: 10px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--brand-soft); }
.conv .top { display: flex; gap: 6px; align-items: center; }
.conv .top .spacer { flex: 1; }
.conv .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); border-radius: 12px; min-height: 260px; }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-start-start-radius: 4px; }
.msg.admin { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-start-end-radius: 4px; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; margin-top: 6px; cursor: zoom-in; }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.composer textarea { min-height: 44px; height: 44px; }
.quick-replies { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ───── Phone preview ───── */
.phone {
  width: 290px; height: 590px; border-radius: 42px; border: 10px solid #111; background: #fff; overflow: hidden;
  position: relative; margin: 0 auto; box-shadow: 0 20px 40px rgba(0,0,0,.2); color: #1d201e; direction: rtl;
}
.phone.ltr { direction: ltr; }
.phone .notch { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 90px; height: 24px; background: #111; border-radius: 14px; z-index: 3; }
.phone .screen { position: absolute; inset: 0; overflow: hidden; display: flex; flex-direction: column; }
.phone .screen img.bg, .phone .screen video.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.phone .p-body { position: relative; padding: 46px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.phone .p-title { font-size: 20px; font-weight: 700; }
.phone .p-sub { font-size: 12.5px; color: #555; }
.phone .p-btn { background: #8a5a2b; color: #fff; border-radius: 14px; padding: 14px; text-align: center; font-weight: 600; font-size: 14px; }
.phone .p-btn.alt { background: #f1ebe2; color: #1d201e; }
.phone .p-card { background: #f6f3ee; border-radius: 12px; padding: 10px; font-size: 12px; }
.phone .p-tabbar { display: flex; justify-content: space-around; border-top: 1px solid #eee; padding: 8px 4px 18px; font-size: 10.5px; color: #777; background: #fff; position: relative; }
.phone .p-tabbar .on { color: #8a5a2b; font-weight: 600; }
.phone .p-header-img { height: 110px; border-radius: 14px; background: #efe7da center/cover; }
.phone .homescreen { background: linear-gradient(160deg, #3b5a7a, #b9895a); position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; padding: 60px 14px; align-content: start; }
.phone .homescreen .app { display: flex; flex-direction: column; align-items: center; gap: 4px; color: #fff; font-size: 10px; }
.phone .homescreen .app i { width: 50px; height: 50px; border-radius: 12px; background: rgba(255,255,255,.35); display: block; }
.phone .homescreen .app img { width: 50px; height: 50px; border-radius: 12px; }

/* ───── Charts ───── */
.chart { position: relative; }
.chart svg { width: 100%; height: 260px; display: block; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; z-index: 5; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 60px; gap: 10px; align-items: center; font-size: 13px; margin: 6px 0; }
.bar-row .track { background: var(--chip); border-radius: 6px; height: 12px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--s1); border-radius: 6px; }

.stars { color: #e3a008; letter-spacing: 2px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.list-item + .list-item { margin-top: 8px; }
.list-item .grow { flex: 1; min-width: 0; }

.with-preview { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .with-preview { grid-template-columns: 1fr; } }
.grid > .card + .card, .stack > .card + .card, .with-preview > .card + .card { margin-top: 0; }
