:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --tint: #f4f1ec;
  --ink: #1f1f1f;
  --ink-2: #4a4a4a;
  --muted: #7a756d;
  --line: #e2ddd4;
  --line-2: #d6cfc4;
  --red: #d8312b;
  --red-ink: #b8231e;
  --red-soft: #fbeceb;
  --lvl-a: #d8312b;
  --lvl-b: #8f6232;
  --lvl-c: #1f1f1f;
  --ok: #2e7d4f;
  --warn: #a8660b;
  --warn-soft: #fdf3e2;
  --bar: #3a3632;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 31, 31, .05), 0 4px 16px rgba(31, 31, 31, .04);
  --font: "Noto Sans Arabic", "IBM Plex Sans Arabic", Tahoma, "Segoe UI", Arial, sans-serif;
  --font-head: "Noto Kufi Arabic", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red-ink); }
[hidden] { display: none !important; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(245, 242, 236, .94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1320px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 14px; margin-inline-end: auto; }
.brand-logo { font-family: Arial, sans-serif; font-weight: 800; font-size: 26px; color: var(--red); letter-spacing: .5px; line-height: 1; }
.brand-title { font-family: var(--font-head); font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 13px; }

.agent-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; color: var(--ink-2); max-width: 100%;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--red); }

/* ---------------------------------------------------------------- layout */
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
}
.card h2 { font-family: var(--font-head); font-size: 18px; margin: 0 0 4px; }
.card .lead { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.eyebrow { color: var(--red); font-weight: 700; font-size: 12px; letter-spacing: .3px; margin-bottom: 2px; }

.grid-2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- upload */
.drop {
  border: 2px dashed var(--line-2); border-radius: var(--radius); background: var(--surface-2);
  min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--red); background: var(--red-soft); }
.drop:focus-visible { outline: 3px solid rgba(216, 49, 43, .35); outline-offset: 2px; }
.drop-icon { width: 46px; height: 46px; color: var(--red); margin-bottom: 8px; }
.drop strong { font-size: 16px; }
.drop .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.file-pill {
  margin-top: 14px; display: inline-flex; align-items: center; gap: 10px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; max-width: 100%;
}
.file-pill .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.file-pill .size { color: var(--muted); font-size: 12px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field .opt { color: var(--muted); font-weight: 400; font-size: 12px; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface);
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.7; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(216, 49, 43, .12); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row-2 { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--ink-2); margin: 6px 0 18px; }
.check input { margin-top: 6px; accent-color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 8px;
  padding: 8px 16px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-ink); border-color: var(--red-ink); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #000; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--tint); border-color: var(--tint); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- progress */
.prog-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.prog-bar { height: 8px; background: var(--tint); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.prog-fill { height: 100%; width: 0; background: var(--red); border-radius: 99px; transition: width .4s ease; }
.prog-fill.indet { width: 30%; animation: indet 1.4s ease-in-out infinite; }
@keyframes indet { 0% { margin-inline-start: -30%; } 100% { margin-inline-start: 100%; } }
.prog-meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.log { margin: 14px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); max-height: 180px; overflow: auto; }
.log li { padding: 3px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; }
.log li::before { content: "•"; color: var(--muted); }
.log li.ok::before { content: "✓"; color: var(--ok); }
.log li.err::before { content: "!"; color: var(--red); font-weight: 700; }
.log li.warn::before { content: "!"; color: var(--warn); font-weight: 700; }

.facts { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 14px; margin-top: 6px; }
.facts b { font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 1px 8px;
  font-size: 12px; font-weight: 700; line-height: 1.6; border: 1px solid transparent; white-space: nowrap;
}
.q-good { background: #e7f3ec; color: var(--ok); }
.q-mid { background: var(--warn-soft); color: var(--warn); }
.q-bad { background: var(--red-soft); color: var(--red-ink); }

.alert { border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-top: 12px; }
.alert-warn { background: var(--warn-soft); color: #6d4208; border: 1px solid #f1dcb5; }
.alert-err { background: var(--red-soft); color: var(--red-ink); border: 1px solid #f3c9c6; }
.alert-ok { background: #e7f3ec; color: #1f5a38; border: 1px solid #c9e4d3; }
.alert ul { margin: 4px 0 0; padding-inline-start: 18px; }

details.preview { margin-top: 14px; }
details.preview summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
details.preview pre {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; max-height: 320px; overflow: auto; font-family: var(--font); font-size: 13px; margin: 8px 0 0;
}

/* ---------------------------------------------------------------- KPIs */
.kpis { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } .kpi.hero { grid-column: 1 / -1; } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-family: var(--font); font-weight: 700; font-size: 30px; line-height: 1.25; margin-top: 2px; }
.kpi.hero .kpi-value { font-size: 48px; }
.kpi-sub { color: var(--muted); font-size: 13px; }
.lvl-row { display: flex; gap: 14px; margin-top: 6px; flex-wrap: wrap; }
.lvl-row span { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.lvl-row b { font-size: 20px; }

.lvl { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; border-radius: 4px; color: #fff; font-weight: 700; font-size: 12px; font-family: Arial, sans-serif; padding: 0 5px; }
.lvl-A { background: var(--lvl-a); }
.lvl-B { background: var(--lvl-b); }
.lvl-C { background: var(--lvl-c); }
.lvl-none { background: #b9b2a7; }

/* distribution bars */
.dist { display: grid; gap: 10px; }
.dist-row { display: grid; grid-template-columns: minmax(150px, 220px) 1fr 36px; gap: 12px; align-items: center; font-size: 14px; }
.dist-track { height: 12px; position: relative; }
.dist-fill { height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.dist-row .n { font-variant-numeric: tabular-nums; color: var(--ink-2); text-align: start; }
.dist-row.zero { color: var(--muted); }
.dist-row.zero .dist-fill { background: var(--line); }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  position: sticky; top: 62px; z-index: 10; background: var(--bg); padding: 10px 0; margin-bottom: 12px;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line);
}
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.chip-toggle { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 3px 10px 3px 6px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.chip-toggle.off { opacity: .45; }
.toolbar .select, .toolbar .input { width: auto; padding: 5px 10px; font-size: 13px; }
.toolbar .search { min-width: 180px; }
.toolbar .spacer { margin-inline-start: auto; }
.save-state { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- side panels */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .panels { grid-template-columns: 1fr; } }
.plist { margin: 0; padding: 0; list-style: none; }
.plist li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.plist li:last-child { border-bottom: 0; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--tint); border-radius: 4px; padding: 0 6px; direction: ltr; unicode-bidi: isolate; }

/* ---------------------------------------------------------------- scenes table */
.scene { margin-bottom: 26px; }
.scene-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
.scene-head h3 { font-family: var(--font-head); font-size: 17px; margin: 0; }
.scene-head .sh-sub { color: var(--muted); font-size: 14px; }
.shots { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; table-layout: fixed; }
.shots th { background: var(--ink); color: #fff; font-weight: 600; font-size: 13px; text-align: start; padding: 8px 12px; }
.shots th.ai-col { background: var(--red); }
.shots td { vertical-align: top; padding: 12px; border-top: 1px solid var(--line); font-size: 14px; }
.shots td.no { font-weight: 700; width: 64px; }
.shots td.dia { color: var(--ink-2); }
.shots td.ai { background: var(--tint); }
.shots col.c-no { width: 70px; }
.shots col.c-act { width: 32%; }
.shots col.c-dia { width: 22%; }
.shots tr.practical td { color: var(--muted); }
.shots tr.practical td.ai { background: var(--surface-2); }
.dia-name { font-weight: 700; color: var(--ink); display: block; }
.dia-line { display: block; margin-bottom: 4px; }

.req { padding: 8px 0 10px; border-bottom: 1px dashed var(--line-2); }
.req:last-of-type { border-bottom: 0; }
.req-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.req-name { font-weight: 700; }
.req-code { color: var(--red-ink); font-weight: 700; font-size: 13px; }
.req-why { color: var(--muted); font-size: 13px; margin-top: 2px; }
.req-edit { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.req-edit .select { width: auto; padding: 3px 8px; font-size: 13px; max-width: 100%; }
.x-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.x-btn:hover { background: var(--red-soft); color: var(--red); }
.nec { font-size: 12px; font-weight: 700; padding: 0 8px; border-radius: 6px; }
.nec-must { background: var(--red-soft); color: var(--red-ink); }
.nec-opt { background: #ece8e1; color: var(--ink-2); }
.shot-level { display: flex; gap: 8px; align-items: center; margin: 2px 0 6px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.intent-label { font-weight: 700; margin-top: 8px; font-size: 13px; }
.intent-text { border-radius: 6px; padding: 2px 4px; margin-inline-start: -4px; }
.intent-text[contenteditable="true"]:hover { background: #fff; outline: 1px dashed var(--line-2); }
.intent-text[contenteditable="true"]:focus { background: #fff; outline: 2px solid rgba(216, 49, 43, .3); }
.kv { font-size: 13px; margin-top: 2px; }
.kv b { font-weight: 700; }
.kv.muted { color: var(--muted); }
.esc { margin-top: 6px; font-size: 13px; background: var(--warn-soft); color: #6d4208; border-radius: 6px; padding: 4px 8px; }
.cont { margin-top: 6px; font-size: 13px; background: #ecebf6; color: #3b3a6b; border-radius: 6px; padding: 4px 8px; }
.edited-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line-2); border-radius: 4px; padding: 0 5px; }

@media (max-width: 860px) {
  .shots, .shots tbody, .shots tr, .shots td { display: block; width: 100%; }
  .shots thead, .shots colgroup { display: none; }
  .shots tr { border-top: 1px solid var(--line); }
  .shots td { border-top: 0; padding: 8px 14px; }
  .shots td.no::before { content: "اللقطة "; font-weight: 400; color: var(--muted); }
  .shots td.dia:not(:empty)::before { content: "الحوار والصوت"; display: block; font-size: 12px; color: var(--muted); }
}

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 40px; }

/* ---------------------------------------------------------------- login */
.login { max-width: 380px; margin: 12vh auto; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; border-radius: 8px; padding: 10px 16px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18); z-index: 50; max-width: calc(100% - 32px);
}

@media print {
  .topbar, .toolbar, #uploadCard, #progressCard, .req-edit, .x-btn, .no-print { display: none !important; }
  body { background: #fff; }
  .card, .kpi, .shots { box-shadow: none; }
  .scene { break-inside: auto; }
  .shots tr { break-inside: avoid; }
}
@media (max-width: 640px) {
  .wrap { padding: 16px; }
  .topbar-in { padding: 10px 16px; }
  .card { padding: 18px; }
  .brand-sub { display: none; }
  .toolbar { top: 0; position: static; }
  .dist-row { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 28px; gap: 8px; }
}
