:root {
  --navy: #14284b;
  --navy-2: #1f3a66;
  --gold: #b8924a;
  --gold-soft: #f4ead6;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #5d6676;
  --line: #e3dfd5;
  --ok: #1f7a4d;
  --ok-bg: #e7f4ec;
  --warn: #9a6400;
  --warn-bg: #fff4dc;
  --err: #b42318;
  --err-bg: #fdecea;
  --info-bg: #eaf0fa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 40, 75, .06), 0 4px 16px rgba(20, 40, 75, .05);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --display: "Amiri", "IBM Plex Sans Arabic", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1522;
    --surface: #172033;
    --text: #e7e9ee;
    --muted: #a3abba;
    --line: #2a3550;
    --gold-soft: #2c2616;
    --ok-bg: #12301f;
    --warn-bg: #33270c;
    --err-bg: #3a1714;
    --info-bg: #17243c;
    --navy-2: #8fb0e8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.75 var(--font);
  color: var(--text);
  background: var(--bg);
}
a { color: var(--navy-2); }
h1, h2, h3, h4, h5 { line-height: 1.4; margin: 0 0 .5rem; }
h1 { font-family: var(--display); font-size: 1.9rem; color: var(--text); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.pre { white-space: pre-wrap; }
bdi { unicode-bidi: isolate; }

/* ---------- top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700; }
.brand span { font-family: var(--display); font-size: 1.3rem; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.nav a { color: #d8dfec; text-decoration: none; padding: .35rem .75rem; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a[aria-current="page"] { background: rgba(212, 178, 106, .18); color: #f3dfb0; }
.logout { margin: 0; }
.topbar .btn-ghost { color: #d8dfec; border-color: rgba(255, 255, 255, .25); }

.container { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.footer { max-width: 1180px; margin: 0 auto; padding: 1rem 1rem 2rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }

/* ---------- building blocks ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { max-width: 70ch; }
.eyebrow { color: var(--gold); font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem;
}
.stack > * + * { margin-top: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid-2.align-start { align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; border-radius: 10px; padding: .55rem 1.1rem;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-primary[disabled] { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--err); color: #fff; }
.btn-sm { padding: .3rem .8rem; min-height: 36px; font-size: .9rem; }
.btn-block { width: 100%; }

.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; min-height: 44px;
}
textarea.input { resize: vertical; line-height: 1.7; }
.input:focus, .btn:focus-visible, summary:focus-visible, .cite:focus-visible {
  outline: 3px solid rgba(184, 146, 74, .45); outline-offset: 1px; border-color: var(--gold);
}
.hint { font-size: .86rem; color: var(--muted); margin: .4rem 0 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin: 0; }
legend { font-weight: 700; padding: 0 .4rem; }
.privacy { background: var(--gold-soft); border-color: transparent; }
.check { display: flex; gap: .55rem; align-items: flex-start; cursor: pointer; }
.check input { margin-top: .45rem; width: 18px; height: 18px; flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.flash { border-radius: 10px; padding: .75rem 1rem; margin-bottom: 1rem; display: flex; gap: 1rem; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.flash form { margin: 0; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--err-bg); color: var(--err); }
.flash-info { background: var(--info-bg); color: var(--text); }
.error-text { color: var(--err); }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .6rem; border-radius: 999px; background: var(--line); color: var(--text); white-space: nowrap; }
.badge-running, .badge-step-running { background: var(--info-bg); color: var(--navy-2); }
.badge-done, .badge-step-done { background: var(--ok-bg); color: var(--ok); }
.badge-failed, .badge-step-failed { background: var(--err-bg); color: var(--err); }
.badge-step-pending { background: var(--line); color: var(--muted); }
.chip { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
.table, .md-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td, .md-table th, .md-table td { text-align: start; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th, .md-table th { color: var(--muted); font-weight: 600; font-size: .85rem; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; display: flex; flex-direction: column; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--navy-2); }
.stat-label { color: var(--muted); font-size: .9rem; }

/* ---------- case page ---------- */
.working { display: flex; gap: 1rem; align-items: flex-start; background: var(--info-bg); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin 1s linear infinite; flex: none; margin-top: .2rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.report { border-top: 4px solid var(--gold); }
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.verify { border-radius: 10px; padding: .7rem 1rem; margin: .5rem 0 1rem; font-size: .92rem; }
.verify-ok { background: var(--ok-bg); }
.verify-warn { background: var(--warn-bg); }

.prose { max-width: 80ch; }
.prose h3, .prose h4, .prose h5 { margin-top: 1.1rem; color: var(--navy-2); }
.prose ul, .prose ol { padding-inline-start: 1.4rem; margin: 0 0 .75rem; }
.prose blockquote { border-inline-start: 3px solid var(--gold); margin: .5rem 0; padding: .25rem .9rem; color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.prose code { background: var(--bg); padding: 0 .3rem; border-radius: 4px; }

.cite {
  display: inline-block; background: var(--gold-soft); color: var(--text); border: 1px solid rgba(184, 146, 74, .45);
  border-radius: 6px; padding: 0 .4rem; font-size: .85em; cursor: help;
}
.cite-warn { background: var(--warn-bg); border-color: var(--warn); }
.cite-bad { background: var(--err-bg); border-color: var(--err); color: var(--err); }

.timeline { list-style: none; margin: 0; padding: 0; }
.tl-stage { position: relative; padding-inline-start: 2rem; padding-bottom: 1.1rem; }
.tl-stage::before { content: ""; position: absolute; inset-inline-start: .55rem; top: 1.4rem; bottom: 0; width: 2px; background: var(--line); }
.tl-stage:last-child::before { display: none; }
.tl-dot { position: absolute; inset-inline-start: .2rem; top: .45rem; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--line); }
.tl-done .tl-dot { background: var(--ok); border-color: var(--ok); }
.tl-active .tl-dot { border-color: var(--gold); }
.tl-future h3, .tl-skipped h3 { color: var(--muted); font-weight: 500; }
.step { border: 1px solid var(--line); border-radius: 10px; margin: .5rem 0; background: var(--surface); }
.step > summary { list-style: none; cursor: pointer; padding: .6rem .9rem; display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; align-items: center; }
.step > summary::-webkit-details-marker { display: none; }
.step > summary::before { content: "◂"; color: var(--muted); transition: transform .15s; }
.step[open] > summary::before { transform: rotate(-90deg); }
.step-who { display: flex; flex-direction: column; flex: 1; min-width: 200px; }
.step-who .muted { font-size: .85rem; }
.step-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.step-content { padding: 0 1rem 1rem; border-top: 1px solid var(--line); padding-top: .75rem; }
.step-running { border-color: var(--gold); }
.step-failed { border-color: var(--err); }
.step-question { background: var(--bg); padding: .5rem .75rem; border-radius: 8px; }
.step-foot { margin-top: .5rem; }

.followup { border-bottom: 1px solid var(--line); padding-bottom: 1rem; margin-bottom: 1rem; }
.followup .q { background: var(--bg); padding: .5rem .75rem; border-radius: 8px; }
.case-file > summary { cursor: pointer; list-style: none; }
.case-file > summary h2 { display: inline; }

/* ---------- library / firm ---------- */
.suggest dt { font-weight: 700; margin-top: .75rem; color: var(--navy-2); }
.suggest dd { margin: 0; padding-inline-start: 1rem; }
.law-article { border-bottom: 1px solid var(--line); padding: .75rem 0; }
.law-article:last-child { border-bottom: 0; }

.flow { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; counter-reset: f; }
.flow li { counter-increment: f; background: var(--bg); border-radius: 10px; padding: .75rem; display: flex; flex-direction: column; gap: .2rem; position: relative; }
.flow li::before { content: counter(f); position: absolute; inset-inline-end: .6rem; top: .4rem; color: var(--gold); font-weight: 700; }
.flow span { font-size: .88rem; color: var(--muted); }
.flow em { font-style: normal; font-size: .78rem; color: var(--gold); font-weight: 600; }
.manager-card { border-top: 4px solid var(--gold); }
.dept-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.dept-grid .card { margin: 0; }
.dept ul { padding-inline-start: 1.2rem; margin: 0 0 .5rem; font-size: .93rem; }
.dept h3 { margin-top: .75rem; color: var(--navy-2); font-size: .95rem; }
.note { background: var(--gold-soft); border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }

/* ---------- auth ---------- */
.page-auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top, #1f3a66, #0c1730); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 2rem 1.5rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); text-align: start; }
.auth-logo { display: block; margin: 0 auto .75rem; }
.auth-title { text-align: center; }
.auth-sub { text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--gold); margin: 0; }

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; }
  .topbar-inner { gap: .5rem; }
  .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
  .card { padding: 1rem; }
}

@media print {
  .topbar, .footer, .nav, #timeline, .case-file, #followups, .btn, .working, .flash { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}
