/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
html[lang="ar"] body { font-family: var(--font-ar); }
html[lang="ar"] [lang="en"] { font-family: var(--font); }   /* English question content keeps Manrope */
h1, h2, h3, h4 { margin: 0 0 var(--s-3); line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--s-4); }
a { color: var(--cobalt); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); }
.eyebrow {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: var(--tracking-wide);
  text-transform: uppercase; color: var(--ink-3);
}
html[lang="ar"] .eyebrow { letter-spacing: 0; }
.accent-bar { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--lime); margin: var(--s-3) 0; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  font: inherit; font-weight: 700; font-size: var(--fs-sm);
  border-radius: var(--r-sm); border: 1.5px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--cobalt); color: var(--white); }
.btn-primary:hover { background: var(--cobalt-600); }
.btn-dark { background: var(--navy); color: var(--white); }
.btn-dark:hover { background: var(--navy-700); }
.btn-outline { background: transparent; color: var(--navy); border-color: var(--line-strong); }
.btn-outline:hover { border-color: var(--navy); }
.btn-ghost { background: transparent; color: var(--ink-2); padding: 0 var(--s-3); }
.btn-ghost:hover { background: rgba(16, 29, 53, .06); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #F8D7D4; }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-block { width: 100%; }
html[dir="rtl"] .icon-flip { transform: scaleX(-1); }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--s-4); }
.field label { display: block; font-size: var(--fs-sm); font-weight: 700; margin-bottom: var(--s-1); color: var(--ink-2); }
.input, .field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="tel"], .field select, .field textarea {
  width: 100%; min-height: 46px; padding: var(--s-2) var(--s-3);
  font: inherit; color: var(--ink); background: var(--white);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--cobalt); box-shadow: var(--focus); }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-sm); margin-top: var(--s-1); }
.field-check { display: flex; align-items: center; gap: var(--s-2); }
.field-check label { margin: 0; font-weight: 600; }
.field-check input { width: 18px; height: 18px; accent-color: var(--cobalt); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-2); }

/* ---------- Flash messages ---------- */
.flashes { display: grid; gap: var(--s-2); margin-bottom: var(--s-5); }
.flash {
  display: flex; gap: var(--s-3); align-items: flex-start;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 600; background: var(--info-bg); color: var(--navy);
  border-inline-start: 4px solid var(--cobalt);
}
.flash-success { background: var(--success-bg); border-color: var(--success); }
.flash-error { background: var(--danger-bg); border-color: var(--danger); color: #7A1F18; }

/* ---------- Cards, badges, tables ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); box-shadow: var(--shadow-sm); }
.card + .card { margin-top: var(--s-5); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.card-header h2, .card-header h3 { margin: 0; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700;
  background: var(--cobalt-50); color: var(--cobalt-600); white-space: nowrap;
}
.badge-navy { background: var(--navy); color: var(--white); }
.badge-lime { background: var(--lime); color: var(--navy); }
.badge-muted { background: #EDEBE4; color: var(--ink-3); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: start; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em; padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line); background: #FBFAF6; white-space: nowrap;
}
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #FBFAF6; }
.table .cell-user { display: flex; align-items: center; gap: var(--s-3); min-width: 220px; }
.table .cell-user strong { display: block; }
.table .cell-user span { color: var(--ink-3); font-size: var(--fs-xs); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: var(--fs-sm);
  background: var(--cobalt-50); color: var(--cobalt-600);
}
.avatar-lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.empty { text-align: center; padding: var(--s-7) var(--s-5); color: var(--ink-3); }
.empty .icon { width: 36px; height: 36px; color: var(--line-strong); margin-bottom: var(--s-2); }

.pagination { display: flex; gap: var(--s-2); justify-content: center; margin-top: var(--s-5); }

/* ---------- Brand lockup ---------- */
.brand { display: inline-flex; align-items: center; gap: var(--s-3); color: inherit; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand img { height: 34px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.62rem; font-weight: 600; letter-spacing: .16em; opacity: .75; margin-top: 3px; }

/* ---------- Language switch ---------- */
.lang-switch { display: inline-flex; border: 1.5px solid currentColor; border-radius: var(--r-pill); overflow: hidden; font-size: var(--fs-xs); font-weight: 700; opacity: .9; }
.lang-switch a { padding: 4px 10px; color: inherit; text-decoration: none; }
.lang-switch a[aria-current="true"] { background: var(--navy); color: var(--white); }
.on-dark .lang-switch a[aria-current="true"] { background: var(--lime); color: var(--navy); }

/* ---------- Public layout ---------- */
.public-header { background: var(--white); border-bottom: 1px solid var(--line); }
.public-header .inner { max-width: 1180px; margin: 0 auto; padding: var(--s-4); display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.public-header nav { display: flex; align-items: center; gap: var(--s-3); }

.hero { background: var(--navy); color: var(--white); position: relative; overflow: hidden; }
.hero .inner { max-width: 1180px; margin: 0 auto; padding: var(--s-8) var(--s-4); position: relative; z-index: 1; }
.hero h1 { font-size: var(--fs-3xl); letter-spacing: -0.035em; margin-bottom: var(--s-4); }
.hero h1 .line { display: block; }
.hero h1 .lime { color: var(--lime); }
.hero p.lead { font-size: var(--fs-lg); color: rgba(255,255,255,.78); max-width: 46ch; }
.hero .eyebrow { color: rgba(255,255,255,.7); }
.hero-actions { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-5); }
.hero .btn-outline { color: var(--white); border-color: rgba(255,255,255,.4); }
.hero .btn-outline:hover { border-color: var(--white); }
.hero-pattern { position: absolute; inset-inline-end: -60px; top: 50%; transform: translateY(-50%); width: min(620px, 70vw); opacity: .9; pointer-events: none; }
html[dir="rtl"] .hero-pattern { transform: translateY(-50%) scaleX(-1); }

.features { max-width: 1180px; margin: 0 auto; padding: var(--s-8) var(--s-4); display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-5); }
.feature { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); }
.feature .num { font-size: var(--fs-xs); font-weight: 800; color: var(--cobalt); letter-spacing: var(--tracking-wide); }
.feature h3 { margin-top: var(--s-2); }
.feature p { color: var(--ink-2); margin: 0; font-size: var(--fs-sm); }

.sample-q { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); max-width: 440px; }
.sample-q .choice { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; font-size: var(--fs-sm); color: var(--ink-2); }
.choice-letter { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-weight: 800; font-size: var(--fs-xs); color: var(--cobalt); flex: none; }

.public-footer { border-top: 1px solid var(--line); padding: var(--s-5) var(--s-4); text-align: center; font-size: var(--fs-sm); color: var(--ink-3); }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.auth-brand { background: var(--navy); color: var(--white); padding: var(--s-7); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-brand h2 { font-size: clamp(1.75rem, 3vw, 2.6rem); letter-spacing: -0.03em; margin-top: var(--s-8); position: relative; z-index: 1; }
.auth-brand h2 .lime { color: var(--lime); display: block; }
.auth-brand .byline { color: rgba(255,255,255,.7); font-size: var(--fs-sm); position: relative; z-index: 1; }
.auth-brand .hero-pattern { width: 440px; top: auto; bottom: -70px; inset-inline-end: -150px; transform: none; opacity: .4; }
html[dir="rtl"] .auth-brand .hero-pattern { transform: scaleX(-1); }
.auth-main { display: flex; flex-direction: column; padding: var(--s-5); }
.auth-top { display: flex; justify-content: flex-end; color: var(--navy); }
.auth-card { width: 100%; max-width: 420px; margin: auto; padding: var(--s-6) 0; }
.auth-card h1 { margin-bottom: var(--s-1); }
.auth-card .sub { color: var(--ink-3); margin-bottom: var(--s-5); }
.auth-alt { margin-top: var(--s-5); font-size: var(--fs-sm); color: var(--ink-3); text-align: center; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--navy); color: var(--white); display: flex; flex-direction: column; padding: var(--s-5) var(--s-4); position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 0 var(--s-2) var(--s-5); }
.side-nav { display: grid; gap: 2px; margin-top: var(--s-3); }
.side-nav a {
  display: flex; align-items: center; gap: var(--s-3); padding: 10px var(--s-3);
  border-radius: var(--r-sm); color: rgba(255,255,255,.72); font-weight: 600; font-size: var(--fs-sm);
  text-decoration: none; position: relative;
}
.side-nav a:hover { background: rgba(255,255,255,.06); color: var(--white); }
.side-nav a[aria-current="page"] { background: var(--navy-700); color: var(--white); }
.side-nav a[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: -16px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--lime);
}
html[dir="rtl"] .side-nav a[aria-current="page"]::before { border-radius: 4px 0 0 4px; }
.sidebar-foot { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid rgba(255,255,255,.1); display: grid; gap: var(--s-3); }
.me { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.me .avatar { background: var(--cobalt); color: var(--white); }
.me-text { min-width: 0; }
.me-text strong { display: block; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text span { font-size: var(--fs-xs); color: rgba(255,255,255,.6); }
.sidebar .btn-ghost { color: rgba(255,255,255,.75); justify-content: flex-start; padding: 0 var(--s-3); min-height: 38px; }
.sidebar .btn-ghost:hover { background: rgba(255,255,255,.06); color: var(--white); }
.sidebar-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }

.main { padding: var(--s-6) var(--s-6) var(--s-8); max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .eyebrow { margin-bottom: var(--s-1); }

.mobile-bar { display: none; }

/* ---------- Dashboard pieces ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--s-4); margin-bottom: var(--s-5); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4) var(--s-5); }
.stat .label { font-size: var(--fs-xs); font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin-top: var(--s-1); }
.stat.feature-stat { background: var(--navy); color: var(--white); border-color: var(--navy); }
.stat.feature-stat .label { color: rgba(255,255,255,.65); }
.stat.feature-stat .value { color: var(--lime); }

.welcome { background: var(--navy); color: var(--white); border-radius: var(--r-lg); padding: var(--s-6); position: relative; overflow: hidden; margin-bottom: var(--s-5); }
.welcome h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); position: relative; z-index: 1; }
.welcome h1 .lime { color: var(--lime); }
.welcome p { color: rgba(255,255,255,.75); max-width: 52ch; position: relative; z-index: 1; margin: 0; }
.welcome .hero-pattern { width: 380px; inset-inline-end: -80px; opacity: .5; }
.code-chip { display: inline-flex; align-items: center; gap: var(--s-2); background: var(--lime); color: var(--navy); border-radius: var(--r-sm); padding: var(--s-2) var(--s-3); font-weight: 800; font-size: var(--fs-lg); letter-spacing: .2em; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.filters { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.filters .input { min-height: 40px; width: auto; }
.filters .search { flex: 1 1 240px; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: var(--fs-sm); }
.timeline li { padding: var(--s-2) 0; border-bottom: 1px dashed var(--line); display: flex; justify-content: space-between; gap: var(--s-3); }
.timeline li:last-child { border: 0; }
code.diff { font-size: var(--fs-xs); color: var(--ink-3); word-break: break-word; }

/* ---------- Error pages ---------- */
.error-page { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: var(--s-5); }
.error-page .code { font-size: 6rem; font-weight: 800; color: var(--cobalt); letter-spacing: -0.05em; line-height: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .features { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: var(--s-5); min-height: 0; }
  .auth-brand h2 { margin-top: var(--s-5); font-size: 1.6rem; }
  .auth-brand .byline, .auth-brand .hero-pattern { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(16,29,53,.45); z-index: 20; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; background: var(--navy); color: var(--white); padding: var(--s-3) var(--s-4); position: sticky; top: 0; z-index: 10; }
  .mobile-bar .btn-ghost { color: var(--white); }
  .main { padding: var(--s-5) var(--s-4) var(--s-7); }
  .form-grid { grid-template-columns: 1fr; }
  .hero .inner { padding: var(--s-7) var(--s-4); }
  .hero-pattern { opacity: .25; }
  .public-header .btn-outline { display: none; }
}

.sidebar .brand-sub { letter-spacing: .08em; white-space: nowrap; font-size: .58rem; }

/* ---------- Badges in navigation ---------- */
.side-nav a .nav-badge { margin-inline-start: auto; }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--lime); color: var(--navy); font-size: 11px; font-weight: 800;
  display: inline-grid; place-items: center; line-height: 1;
}
.bell { position: relative; margin-inline-start: auto; color: rgba(255,255,255,.75); display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); }
.bell:hover { background: rgba(255,255,255,.08); color: var(--white); }
.bell .nav-badge { position: absolute; top: -2px; inset-inline-end: -4px; }
.mobile-bar .bell { margin-inline-start: auto; margin-inline-end: var(--s-2); }
.stat-link { color: inherit; text-decoration: none; }
.stat-link:hover { text-decoration: none; border-color: var(--cobalt); }
.link-child { margin-top: var(--s-5); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.link-child label { font-weight: 700; font-size: var(--fs-sm); display: block; margin-bottom: var(--s-2); }
.link-row { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.code-input { max-width: 180px; text-transform: uppercase; letter-spacing: .25em; font-weight: 800; }
.login-row { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); margin-bottom: var(--s-4); font-size: var(--fs-sm); }
.login-row .field { margin: 0; }
.section-title { margin: var(--s-6) 0 var(--s-4); }
.danger-card { border-color: #F2C3BF; }
.legal-links { text-align: center; font-size: var(--fs-xs); color: var(--ink-3); margin: var(--s-4) 0 0; }
.legal { max-width: 760px; margin: 0 auto; padding: var(--s-7) var(--s-4); }
.legal h1 { font-size: var(--fs-2xl); }
.legal h2 { font-size: var(--fs-lg); margin-top: var(--s-6); }
.legal p, .legal li { color: var(--ink-2); }
.legal .updated { color: var(--ink-3); font-size: var(--fs-sm); }

/* trademark notice (footers, auth pages, bottom of every app page) */
.trademark-note { margin: var(--s-2) auto 0; max-width: 60ch; font-size: 12px; line-height: 1.5; color: var(--ink-3); text-align: center; }
.app-footer { margin-top: var(--s-8); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.app-footer .trademark-note { margin-top: 0; }
.auth-main > .trademark-note { margin-top: var(--s-2); }
@media print { .app-footer { display: none; } }
