/* =========================================================================
   المستشار القانوني — هوية رسمية فاخرة بطابع قطري
   عنابي عميق / عاجي / رمادي دافئ مع ذهب هادئ، ونقش هندسي إسلامي خفيف.
   اتجاه RTL كامل، ووضع داكن كامل.
   ========================================================================= */

:root {
  --maroon-950: #3f0917;
  --maroon-900: #55101f;
  --maroon-800: #6d1229;
  --maroon-700: #8a1538;   /* العنابي القطري */
  --maroon-600: #a21c45;
  --maroon-100: #f5e6ec;
  --maroon-050: #fbf4f6;

  --gold-800: #7d6120;
  --gold-700: #9a7b2e;
  --gold-500: #c9a44c;
  --gold-400: #dcbc6a;
  --gold-300: #e9d39a;
  --gold-200: #efe1bd;
  --gold-050: #fbf6ea;

  --ink-900: #1a1618;
  --ink-800: #28232a;
  --ink-700: #3d3740;
  --ink-600: #57515a;
  --ink-500: #736c76;
  --ink-400: #97919a;
  --ink-300: #c7c1c6;
  --ink-200: #e3dfe1;
  --ink-100: #efecec;
  --ink-050: #f7f5f3;
  --ivory: #fbf9f5;
  --white: #ffffff;

  --ok-700: #1f6b45;  --ok-100: #e5f4ec;
  --warn-700: #8a5b00; --warn-100: #fdf2dc;
  --danger-700: #9b1c1c; --danger-100: #fdeaea;
  --info-700: #1d4f8f; --info-100: #e8f0fb;

  --bg: var(--ivory);
  --surface: rgba(255,255,255,.92);
  --surface-solid: #ffffff;
  --surface-2: var(--ink-050);
  --border: rgba(61,55,64,.12);
  --border-strong: rgba(61,55,64,.22);
  --text: var(--ink-900);
  --text-muted: var(--ink-600);
  --brand: var(--maroon-700);
  --brand-contrast: #ffffff;
  --pattern-ink: %238a1538;
  --pattern-alpha: .075;
  --glow: rgba(138,21,56,.10);

  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(40,20,30,.05), 0 2px 6px rgba(40,20,30,.05);
  --shadow-md: 0 8px 24px rgba(40,20,30,.10), 0 2px 6px rgba(40,20,30,.06);
  --shadow-lg: 0 24px 60px rgba(40,10,25,.22);
  --font: "Noto Kufi Arabic", "IBM Plex Sans Arabic", "Dubai", "Segoe UI", "Geeza Pro", "Noto Naskh Arabic", "Tahoma", system-ui, sans-serif;
  --font-display: "Amiri", "Noto Naskh Arabic", "Sakkal Majalla", "Al Bayan", "Geeza Pro", "Traditional Arabic", "Times New Roman", serif;
  --font-serif: var(--font-display);
}

[data-theme="dark"] {
  --bg: #121014;
  --surface: rgba(28,24,29,.92);
  --surface-solid: #1c181d;
  --surface-2: #241f26;
  --border: rgba(255,255,255,.09);
  --border-strong: rgba(255,255,255,.18);
  --text: #f1ecee;
  --text-muted: #b1a8ad;
  --brand: #d24a75;
  --maroon-100: #33161f;
  --maroon-050: #241419;
  --gold-050: #26201a;
  --gold-200: #4a3d24;
  --gold-300: #6a5630;
  --ink-100: #2a2529;
  --ink-200: #352f34;
  --ink-300: #4a4349;
  --ink-050: #1f1b20;
  --ivory: #121014;
  --white: #1c181d;
  --pattern-ink: %23c9a44c;
  --pattern-alpha: .06;
  --glow: rgba(201,164,76,.08);
  --ok-100: #10291d; --warn-100: #2b2109; --danger-100: #2d1414; --info-100: #101f33;
  --ok-700: #6fce9f; --warn-700: #e0b256; --danger-700: #ef8b8b; --info-700: #8fb8ef;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.45);
  --shadow-md: 0 8px 24px rgba(0,0,0,.5);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15.5px; line-height: 1.75; direction: rtl;
  padding-bottom: env(safe-area-inset-bottom);
  position: relative; min-height: 100vh;
}
/* خلفية ثابتة أثناء التصفح: توهّج عنابي علوي + نقش هندسي إسلامي خفيف
   (عنصر ثابت بدل background-attachment لأن iOS لا يدعم الأخير) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--glow), transparent 62%),
    radial-gradient(900px 600px at 100% 100%, rgba(201,164,76,.07), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%238a1538' stroke-opacity='.075' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3Cpath d='M0 48h6M90 48h6M48 0v6M48 90v6'/%3E%3Ccircle cx='48' cy='48' r='4'/%3E%3Ccircle cx='0' cy='0' r='6'/%3E%3Ccircle cx='96' cy='0' r='6'/%3E%3Ccircle cx='0' cy='96' r='6'/%3E%3Ccircle cx='96' cy='96' r='6'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--bg), var(--bg));
  background-size: auto, auto, 96px 96px, auto;
}
[data-theme="dark"] body::before {
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--glow), transparent 62%),
    radial-gradient(900px 600px at 100% 100%, rgba(138,21,56,.12), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23c9a44c' stroke-opacity='.06' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3Cpath d='M0 48h6M90 48h6M48 0v6M48 90v6'/%3E%3Ccircle cx='48' cy='48' r='4'/%3E%3Ccircle cx='0' cy='0' r='6'/%3E%3Ccircle cx='96' cy='0' r='6'/%3E%3Ccircle cx='0' cy='96' r='6'/%3E%3Ccircle cx='96' cy='96' r='6'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--bg), var(--bg));
  background-size: auto, auto, 96px 96px, auto;
}
h1, h2, h3, h4 { line-height: 1.45; margin: 0 0 .5rem; font-weight: 700; letter-spacing: 0; }
h1 { font-family: var(--font-display); font-size: 1.85rem; font-weight: 700; }
h2 { font-size: 1.22rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--gold-500); outline-offset: 2px; border-radius: 4px; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
::selection { background: var(--gold-300); color: var(--ink-900); }

/* ------------------------------ الترويسة ------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 40; color: #fff;
  background: linear-gradient(120deg, var(--maroon-950) 0%, var(--maroon-800) 45%, var(--maroon-700) 100%);
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 6px 24px rgba(40,5,18,.28);
  isolation: isolate;
}
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: .5; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23e9d39a' stroke-opacity='.16' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3Ccircle cx='48' cy='48' r='4'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 96px 96px;
  mask-image: linear-gradient(90deg, transparent, #000 35%, #000 65%, transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 35%, #000 65%, transparent);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--gold-800), var(--gold-400) 30%, var(--gold-300) 50%, var(--gold-400) 70%, var(--gold-800));
}
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .7rem 1rem .8rem; }
.brand { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.brand-mark {
  width: 48px; height: 48px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,.35));
}
.brand-mark svg { width: 48px; height: 48px; display: block; }
.brand-text { min-width: 0; }
.brand-title {
  font-family: var(--font-display); font-weight: 700; font-size: 1.28rem; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.brand-sub { font-size: .72rem; color: var(--gold-300); letter-spacing: .06em; opacity: .95; }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .45rem; }
.icon-btn {
  background: rgba(255,255,255,.08); border: 1px solid rgba(233,211,154,.35); color: #fff;
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.16); border-color: var(--gold-400); transform: translateY(-1px); }
.user-chip {
  display: flex; align-items: center; gap: .55rem; background: rgba(255,255,255,.08);
  border: 1px solid rgba(233,211,154,.35); border-radius: 999px; padding: .25rem .8rem .25rem .3rem;
  font-size: .86rem; color: #fff; transition: background .15s, border-color .15s;
}
.user-chip:hover { background: rgba(255,255,255,.16); border-color: var(--gold-400); text-decoration: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; color: #3a2c07; display: grid; place-items: center; font-weight: 700; font-size: .8rem;
  background: linear-gradient(145deg, var(--gold-300), var(--gold-500) 60%, var(--gold-700));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}

/* ------------------------------ التخطيط ------------------------------ */
.shell { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: 262px minmax(0, 1fr); gap: 1.4rem; padding: 1.4rem 1rem 3rem; }
.sidebar { position: sticky; top: 84px; align-self: start; min-width: 0; }
.nav-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); overflow: hidden;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.nav-group-title {
  font-size: .7rem; color: var(--gold-700); padding: .95rem 1rem .3rem; letter-spacing: .1em; font-weight: 700;
  display: flex; align-items: center; gap: .5rem;
}
.nav-group-title::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--gold-300), transparent); }
[data-theme="dark"] .nav-group-title { color: var(--gold-400); }
.nav a {
  display: flex; align-items: center; gap: .65rem; padding: .62rem 1rem; color: var(--text);
  border-right: 3px solid transparent; font-size: .92rem; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--maroon-050); color: var(--brand); border-right-color: var(--gold-500); font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .75; }
.nav a.active svg { opacity: 1; color: var(--gold-700); }
[data-theme="dark"] .nav a.active svg { color: var(--gold-400); }
.nav-badge { margin-inline-start: auto; background: var(--maroon-100); color: var(--maroon-700); font-size: .72rem; padding: 0 .45rem; border-radius: 999px; font-weight: 700; }
[data-theme="dark"] .nav-badge { color: var(--gold-300); }
.main { min-width: 0; }

/* ------------------------------ البطاقات ------------------------------ */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); margin-bottom: 1.15rem; overflow: hidden;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.card-head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(201,164,76,.05), transparent); }
.card-head h2, .card-head h3 { margin: 0; display: flex; align-items: center; gap: .55rem; }
.card-head h2::before, .card-head h3::before { content: ""; width: 4px; height: 1.05em; border-radius: 2px;
  background: linear-gradient(180deg, var(--gold-400), var(--gold-700)); flex: none; }
.card-head .spacer { flex: 1; }
.card-body { padding: 1.2rem; }
.card-accent::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--maroon-700), var(--gold-500) 55%, var(--maroon-700)); }
.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.15rem; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.tiny { font-size: .78rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; direction: ltr; unicode-bidi: embed; }

/* ------------------------------ الشبكات ------------------------------ */
.grid { display: grid; gap: 1rem; }
.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)); }
.stat {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem .9rem; box-shadow: var(--shadow-sm); overflow: hidden;
}
.stat::after { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--gold-400), var(--gold-700)); }
.stat-label { font-size: .8rem; color: var(--text-muted); }
.stat-value { font-family: var(--font-display); font-size: 2.1rem; font-weight: 700; color: var(--brand); line-height: 1.25; }
.stat-note { font-size: .75rem; color: var(--text-muted); }

/* ------------------------------ النماذج ------------------------------ */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; }
.hint { font-weight: 400; color: var(--text-muted); font-size: .8rem; margin-bottom: .35rem; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-solid); color: var(--text); font-family: inherit; font-size: .95rem; line-height: 1.6;
  transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold-500); outline: none; box-shadow: 0 0 0 3px rgba(201,164,76,.22); }
.field { margin-bottom: 1rem; }
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
.field-row-3 { display: grid; gap: 1rem; grid-template-columns: repeat(3, minmax(0,1fr)); }
.facts-box { min-height: 190px; font-size: 1.02rem; line-height: 1.9; }
.checkline { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkline input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .62rem 1.2rem; border-radius: var(--radius); border: 1px solid rgba(0,0,0,.08);
  background: linear-gradient(180deg, var(--maroon-600), var(--maroon-700) 55%, var(--maroon-800));
  color: #fff; font-family: inherit; font-size: .94rem; font-weight: 600;
  cursor: pointer; min-height: 44px; text-decoration: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.14), 0 2px 6px rgba(90,10,35,.22);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.14), 0 6px 16px rgba(90,10,35,.28), 0 0 0 1px var(--gold-500); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-lg { font-size: 1.05rem; padding: .85rem 1.6rem; }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--border-strong); box-shadow: none; }
.btn-ghost:hover { background: var(--maroon-050); }
.btn-neutral { background: var(--surface-2); color: var(--text); border-color: var(--border); box-shadow: none; }
.btn-neutral:hover { background: var(--ink-100); }
.btn-danger { background: linear-gradient(180deg, #b32424, var(--danger-700)); }
.btn-gold { background: linear-gradient(180deg, var(--gold-300), var(--gold-500) 60%, var(--gold-700)); color: #2e2306; border-color: rgba(120,90,20,.25); }
.btn-gold:hover { color: #1f1804; }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; min-height: 34px; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

/* ------------------------------ الشارات ------------------------------ */
.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .76rem; font-weight: 700;
  padding: .15rem .55rem; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.badge-ok { background: var(--ok-100); color: var(--ok-700); }
.badge-warn { background: var(--warn-100); color: var(--warn-700); }
.badge-danger { background: var(--danger-100); color: var(--danger-700); }
.badge-info { background: var(--info-100); color: var(--info-700); }
.badge-neutral { background: var(--ink-100); color: var(--ink-600); }
.badge-brand { background: var(--maroon-100); color: var(--maroon-700); }
.badge-gold { background: var(--gold-050); color: var(--gold-700); border-color: var(--gold-200); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ------------------------------ الجداول ------------------------------ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .6rem .7rem; text-align: right; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; font-size: .8rem; color: var(--gold-800); letter-spacing: .03em; white-space: nowrap; }
[data-theme="dark"] th { color: var(--gold-400); }
tbody tr:hover { background: var(--maroon-050); }
.table-clickable tbody tr { cursor: pointer; }
td.num { text-align: center; white-space: nowrap; }

/* ------------------------------ التنبيهات ------------------------------ */
.alert { border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; border: 1px solid; font-size: .92rem; }
.alert-info { background: var(--info-100); border-color: color-mix(in srgb, var(--info-700) 25%, transparent); color: var(--info-700); }
.alert-warn { background: var(--warn-100); border-color: color-mix(in srgb, var(--warn-700) 25%, transparent); color: var(--warn-700); }
.alert-danger { background: var(--danger-100); border-color: color-mix(in srgb, var(--danger-700) 25%, transparent); color: var(--danger-700); }
.alert-ok { background: var(--ok-100); border-color: color-mix(in srgb, var(--ok-700) 25%, transparent); color: var(--ok-700); }
.alert strong { display: block; margin-bottom: .2rem; }

/* ------------------------------ المذكرة القانونية ------------------------------ */
.memo { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.memo-header { position: relative; background: linear-gradient(120deg, var(--maroon-950), var(--maroon-800) 50%, var(--maroon-700)); color: #fff; padding: 1.3rem 1.5rem; border-bottom: 3px solid var(--gold-500); overflow: hidden; }
.memo-header::before { content: ""; position: absolute; inset: 0; opacity: .35; pointer-events: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23e9d39a' stroke-opacity='.18' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3C/g%3E%3C/svg%3E"); background-size: 96px 96px; }
.memo-header > * { position: relative; }
.memo-header h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
.memo-meta { display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: .82rem; opacity: .92; }
.memo-section { border-bottom: 1px solid var(--border); padding: 1.15rem 1.4rem; }
.memo-section:last-child { border-bottom: none; }
.memo-section > h2 {
  font-size: 1.02rem; color: var(--maroon-700); display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem;
}
.memo-section > h2::before { content: ""; width: 5px; height: 18px; background: var(--gold-500); border-radius: 3px; }
[data-theme="dark"] .memo-section > h2 { color: var(--gold-500); }

.quote-box {
  background: var(--maroon-050); border: 1px solid var(--maroon-100); border-right: 4px solid var(--maroon-700);
  border-radius: 8px; padding: .8rem 1rem; font-family: var(--font-serif); font-size: 1.06rem; line-height: 2;
}
.explain-box { background: var(--info-100); border: 1px solid color-mix(in srgb, var(--info-700) 22%, transparent); border-right: 4px solid var(--info-700); border-radius: 8px; padding: .8rem 1rem; }
.apply-box { background: var(--gold-050); border: 1px solid var(--gold-200); border-right: 4px solid var(--gold-500); border-radius: 8px; padding: .8rem 1rem; }
.opinion-box { background: var(--ok-100); border: 1px solid color-mix(in srgb, var(--ok-700) 22%, transparent); border-right: 4px solid var(--ok-700); border-radius: 8px; padding: .9rem 1.1rem; }
.box-label { font-size: .74rem; font-weight: 700; letter-spacing: .03em; opacity: .8; margin-bottom: .25rem; display: block; }

.citation-link { display: inline-flex; align-items: center; gap: .25rem; background: var(--maroon-100); color: var(--maroon-700);
  border-radius: 6px; padding: .05rem .4rem; font-size: .78rem; font-weight: 700; border: 1px solid transparent; }
.citation-link:hover { background: var(--maroon-700); color: #fff; text-decoration: none; }

.numbered { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.numbered > li { counter-increment: step; position: relative; padding-inline-start: 2.2rem; margin-bottom: .7rem; }
.numbered > li::before {
  content: counter(step); position: absolute; inset-inline-start: 0; top: .12rem; width: 1.6rem; height: 1.6rem;
  background: var(--maroon-700); color: #fff; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; font-weight: 700;
}
.plain-list { padding-inline-start: 1.2rem; margin: 0; }
.plain-list li { margin-bottom: .35rem; }

/* ------------------------------ عارض المستندات ------------------------------ */
.viewer { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.viewer-pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.viewer-toolbar { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
#pdf-canvas-wrap { max-height: 74vh; overflow: auto; background: var(--ink-100); display: grid; place-items: start center; padding: .6rem; }
#pdf-canvas { box-shadow: var(--shadow-md); background: #fff; max-width: 100%; }
.extracted-text { max-height: 74vh; overflow: auto; padding: 1rem; white-space: pre-wrap; line-height: 2; font-size: .95rem; }
mark.hl { background: var(--gold-200); color: inherit; padding: 0 .1rem; border-radius: 3px; }

.select-filter { margin-bottom: .4rem; }
select { max-width: 100%; }
.select-compact { max-width: 100%; text-overflow: ellipsis; }
input[type=search] { width: 100%; padding: .65rem .8rem; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-solid); color: var(--text); font-family: inherit; font-size: .95rem; -webkit-appearance: none; appearance: none; }
input[type=search]:focus { border-color: var(--gold-500); outline: none; box-shadow: 0 0 0 3px rgba(201,164,76,.22); }

/* ------------------------------ الحوارات ------------------------------ */
dialog.dialog { border: none; border-radius: var(--radius-lg); padding: 0; background: var(--surface-solid); color: var(--text);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(201,164,76,.35); width: min(92vw, 460px); direction: rtl; }
dialog.dialog::backdrop { background: rgba(40,10,25,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dialog-body { padding: 1.4rem 1.4rem 1.2rem; }
.dialog-body h3 { display: flex; align-items: center; gap: .55rem; margin-bottom: 1rem; font-size: 1.15rem; }
.dialog-body h3::before { content: ""; width: 4px; height: 1.05em; border-radius: 2px; background: linear-gradient(180deg, var(--gold-400), var(--gold-700)); }
.dialog-body .checkline { font-weight: 500; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .45rem; cursor: pointer; }
.dialog-body .checkline:has(input:checked) { border-color: var(--gold-500); background: var(--gold-050); }
tr[data-href] { cursor: pointer; }
tr[data-href]:focus-visible { outline: 2px solid var(--gold-500); outline-offset: -2px; }

/* ------------------------------ متفرقات ------------------------------ */
.progress { height: 8px; background: var(--ink-200); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); }
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; opacity: .35; margin-bottom: .6rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .9rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding-inline-start: 1.3rem; padding-bottom: .85rem; border-inline-start: 2px solid var(--border); margin-inline-start: .4rem; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -6px; top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.footer-note { text-align: center; color: var(--text-muted); font-size: .8rem; padding: 1.5rem 1rem 0; }
.print-only { display: none; }

/* ------------------------------ تسجيل الدخول ------------------------------ */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; position: relative; isolation: isolate;
  background: linear-gradient(160deg, var(--maroon-950) 0%, var(--maroon-800) 45%, #2e0711 100%);
}
.login-wrap::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(700px 420px at 50% 0%, rgba(201,164,76,.22), transparent 65%),
    radial-gradient(600px 400px at 100% 100%, rgba(255,255,255,.06), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23e9d39a' stroke-opacity='.13' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3Cpath d='M0 48h6M90 48h6M48 0v6M48 90v6'/%3E%3Ccircle cx='48' cy='48' r='4'/%3E%3C/g%3E%3C/svg%3E");
  background-size: auto, auto, 96px 96px;
}
.login-card {
  width: 100%; max-width: 440px; background: var(--surface-solid); border-radius: 22px; overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(201,164,76,.45), 0 0 0 6px rgba(201,164,76,.08);
}
.login-head {
  position: relative; background: linear-gradient(120deg, var(--maroon-950), var(--maroon-800) 55%, var(--maroon-700));
  color: #fff; padding: 1.9rem 1.5rem 1.5rem; text-align: center; border-bottom: 3px solid var(--gold-500); overflow: hidden;
}
.login-head::before { content: ""; position: absolute; inset: 0; opacity: .4; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23e9d39a' stroke-opacity='.2' stroke-width='1'%3E%3Cpath d='M48 6l11.6 30.4L90 48 59.6 59.6 48 90 36.4 59.6 6 48l30.4-11.6z'/%3E%3Cpath d='M48 20l8 20 20 8-20 8-8 20-8-20-20-8 20-8z'/%3E%3C/g%3E%3C/svg%3E"); background-size: 96px 96px; }
.login-head > * { position: relative; }
.login-head .brand-mark { margin: 0 auto .8rem; width: 84px; height: 84px; }
.login-head .brand-mark svg { width: 84px; height: 84px; }
.login-head h1 { font-family: var(--font-display); font-size: 1.45rem !important; margin: 0 !important; text-shadow: 0 1px 2px rgba(0,0,0,.3); }
.login-head .small { color: var(--gold-300) !important; letter-spacing: .08em; font-size: .78rem; opacity: 1 !important; margin-top: .25rem; }
.login-body { padding: 1.6rem 1.5rem 1.5rem; }
.login-body .btn { width: 100%; }

/* ------------------------------ الاستجابة ------------------------------ */
@media (max-width: 1024px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 1rem; }
  .sidebar { position: static; }
  .nav-card { border-radius: 999px; padding: .3rem; }
  .nav { display: flex; overflow-x: auto; gap: .2rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { border-right: none; border-radius: 999px; padding: .45rem .85rem; white-space: nowrap; font-size: .88rem; }
  .nav a.active { background: linear-gradient(180deg, var(--maroon-600), var(--maroon-800)); color: #fff; box-shadow: 0 2px 8px rgba(90,10,35,.25); }
  .nav a.active svg { color: var(--gold-300); }
  .nav-badge { background: var(--gold-400); color: #2e2306; }
  .nav-group-title { display: none; }
  .viewer { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 680px) {
  body { font-size: 15px; }
  h1 { font-size: 1.5rem; }
  .shell { padding: .85rem .8rem 4.5rem; }
  .topbar-inner { padding: .55rem .8rem .65rem; gap: .6rem; }
  .brand-mark, .brand-mark svg { width: 40px; height: 40px; }
  .brand-title { font-size: .98rem; white-space: normal; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .user-chip span:last-child { display: none; }
  .user-chip { padding: .2rem .3rem; }
  .stat-value { font-size: 1.8rem; }
  .login-head .brand-mark, .login-head .brand-mark svg { width: 72px; height: 72px; }
  .field-row, .field-row-3, .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .card-body, .memo-section { padding: .95rem; }
  .brand-sub { display: none; }
  table { font-size: .85rem; }
  .btn { min-height: 46px; }
  .sheet-toggle { display: inline-flex; }
}
@media print {
  .topbar, .sidebar, .btn, .no-print { display: none !important; }
  .shell { display: block; padding: 0; }
  .print-only { display: block; }
  .card, .memo { border: none; box-shadow: none; }
  body { background: #fff; font-size: 12pt; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
