:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f0ede4;
  --ink: #1b2620;
  --ink-2: #4e5b54;
  --ink-3: #7c877f;
  --line: #e2ddd0;
  --brand: #0f3d2e;
  --brand-2: #17573f;
  --brand-ink: #ffffff;
  --gold: #c99a2e;
  --ok: #1f7a4d;
  --ok-bg: #e3f2e9;
  --warn: #9a6200;
  --warn-bg: #fbf0d9;
  --danger: #b3261e;
  --danger-bg: #fbe6e4;
  --info-bg: #e7eef7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 16px rgba(20, 30, 25, .05);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101512; --surface: #171e1a; --surface-2: #1e2722; --ink: #e8ece9; --ink-2: #b2bcb6; --ink-3: #85918a;
    --line: #2a352f; --brand: #2f8a63; --brand-2: #3aa576; --gold: #e0b453;
    --ok: #5cc791; --ok-bg: #173327; --warn: #e9b44c; --warn-bg: #352a12; --danger: #f2867e; --danger-bg: #3a1a18; --info-bg: #1a2533;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #101512; --surface: #171e1a; --surface-2: #1e2722; --ink: #e8ece9; --ink-2: #b2bcb6; --ink-3: #85918a;
  --line: #2a352f; --brand: #2f8a63; --brand-2: #3aa576; --gold: #e0b453;
  --ok: #5cc791; --ok-bg: #173327; --warn: #e9b44c; --warn-bg: #352a12; --danger: #f2867e; --danger-bg: #3a1a18; --info-bg: #1a2533;
  --shadow: none;
}

* { 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.6;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; font-weight: 700; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand-2); }
small, .muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }

/* إقلاع */
.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--ink-3); }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: var(--gold); display: grid; place-items: center; font-weight: 700; font-size: 26px; }

/* الهيكل */
.shell { min-height: 100vh; display: grid; grid-template-columns: 1fr; padding-bottom: 76px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--brand); color: var(--brand-ink);
}
.topbar .logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: inherit; text-decoration: none; }
.topbar .logo .brand-mark { width: 32px; height: 32px; font-size: 17px; border-radius: 9px; background: rgba(255,255,255,.12); }
.topbar .org { font-size: .85rem; opacity: .8; margin-inline-start: auto; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-pill { background: var(--gold); color: #2a1f00; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
main { padding: 16px; max-width: 980px; width: 100%; margin: 0 auto; }

.nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav a { display: grid; justify-items: center; gap: 2px; padding: 8px 2px 9px; font-size: .72rem; color: var(--ink-3); text-decoration: none; }
.nav a svg { width: 22px; height: 22px; }
.nav a.active { color: var(--brand-2); font-weight: 600; }
@media (min-width: 900px) {
  .shell { grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .nav {
    position: sticky; top: 52px; align-self: start; height: calc(100vh - 52px); display: flex; flex-direction: column; gap: 2px;
    border-top: 0; border-inline-end: 1px solid var(--line); padding: 14px 10px; background: transparent;
  }
  .nav a { display: flex; gap: 10px; align-items: center; justify-items: start; font-size: .92rem; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--surface); box-shadow: var(--shadow); }
  main { padding: 24px; }
}

/* عناصر */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head p { color: var(--ink-2); margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid.kpis { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid.kpis { grid-template-columns: repeat(4, 1fr); } .grid.two { grid-template-columns: 1fr 1fr; } }
.kpi { padding: 14px; }
.kpi .label { font-size: .8rem; color: var(--ink-2); }
.kpi .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.kpi .sub { font-size: .76rem; color: var(--ink-3); }
.kpi.danger .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px;
  background: var(--brand); color: var(--brand-ink);
}
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.google { background: var(--surface); color: var(--ink); border-color: var(--line); }
.link-btn { background: none; border: 0; color: var(--brand-2); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); }

.alert { border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); color: var(--ink); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert p { margin: 0; color: var(--ink); }
.alert strong { color: inherit; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .meta { font-size: .8rem; color: var(--ink-3); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.bar.warn > span { background: var(--warn); }
.bar.danger > span { background: var(--danger); }
.week { display: flex; gap: 4px; }
.week i { width: 16px; height: 16px; border-radius: 4px; background: var(--surface-2); display: inline-block; }
.week i.ok { background: var(--ok); } .week i.warn { background: var(--gold); } .week i.danger { background: var(--danger); }

/* نماذج */
form .field { display: grid; gap: 5px; margin-bottom: 12px; }
label { font-weight: 600; font-size: .88rem; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.hint { font-size: .78rem; color: var(--ink-3); font-weight: 400; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
.checks { display: flex; gap: 8px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 500; background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.checks input { width: auto; min-height: 0; }

/* قائمة الفحص */
.cat-title { font-size: .82rem; font-weight: 700; color: var(--ink-2); margin: 18px 0 6px; letter-spacing: 0; }
.check-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
.check-item.fail { border-color: var(--danger); background: var(--danger-bg); }
.check-item.ok { border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.check-item .q { font-weight: 600; }
.check-item .meta { font-size: .76rem; color: var(--ink-3); margin-top: 2px; }
.check-item textarea { margin-top: 8px; min-height: 40px; font-size: .9rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-top: 8px; background: var(--surface); }
.seg button { font: inherit; border: 0; background: transparent; padding: 8px 14px; min-height: 40px; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button[aria-pressed="true"][data-v="ok"] { background: var(--ok); color: #fff; }
.seg button[aria-pressed="true"][data-v="fail"] { background: var(--danger); color: #fff; }
.seg button[aria-pressed="true"][data-v="na"] { background: var(--ink-3); color: #fff; }
.sticky-foot {
  position: sticky; bottom: 76px; z-index: 10; margin-top: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}
@media (min-width: 900px) { .sticky-foot { bottom: 12px; } }
.sticky-foot .grow { flex: 1; font-size: .85rem; }

/* جدول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: start; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--ink-2); font-weight: 600; }

/* الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 420px; padding: 24px; }
.auth .hero { text-align: center; margin-bottom: 18px; }
.auth .hero .brand-mark { margin: 0 auto 10px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: .8rem; margin: 14px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; font: inherit; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--ink-2); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* التقرير */
.report-total { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .report-total { grid-template-columns: 1fr 1fr 1fr; } }
.fine { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-3); }
.empty .btn { margin-top: 10px; }

#toast {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .25s;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; pointer-events: none; max-width: 90vw; font-size: .9rem;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast[data-tone="danger"] { background: var(--danger); color: #fff; }

.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 12, .45); z-index: 60; display: grid; place-items: end center; }
@media (min-width: 700px) { .modal-back { place-items: center; } }
.modal { background: var(--surface); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px; }
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--ink-2); font-size: 1.4rem; line-height: 1; padding: 4px 8px; min-height: 40px; }

@media print {
  .topbar, .nav, .no-print, .sticky-foot { display: none !important; }
  body { background: #fff; }
  .shell { display: block; padding: 0; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* الشعار: العين اليقظة */
.brand-mark { background: none !important; overflow: hidden; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.topbar .logo { font-family: 'Reem Kufi', var(--font); font-size: 1.3rem; }
.topbar .logo .brand-mark { box-shadow: 0 0 0 1px rgba(255,255,255,.2); }
.auth .hero h1 { font-family: 'Reem Kufi', var(--font); font-size: 2rem; }

[hidden] { display: none !important; }

/* الاشتراك */
.sub-link { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; margin-bottom: 12px; }
.sub-link .grow { flex: 1; }
.sub-link > span[aria-hidden] { color: var(--ink-3); font-size: 1.4rem; }
.sub-status { display: flex; gap: 12px; border-inline-start: 4px solid var(--line); }
.sub-status.ok { border-inline-start-color: var(--ok); }
.sub-status.warn { border-inline-start-color: var(--warn); }
.sub-status.danger { border-inline-start-color: var(--danger); }
.sub-status .grow { flex: 1; }
.founders-check { display: flex; gap: 8px; align-items: center; font-weight: 500; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; }
.founders-check input { width: auto; min-height: 0; }
.total-row { font-size: 1.05rem; }
.total-row strong { color: var(--brand-2); font-size: 1.25rem; }
.alert .grow { flex: 1; }

.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.stepper button { width: 46px; min-height: 46px; border: 0; background: var(--surface-2); color: var(--ink); font: inherit; font-size: 1.3rem; cursor: pointer; }
.stepper button:hover { background: var(--line); }
.stepper input { width: 64px; min-height: 46px; border: 0; border-radius: 0; text-align: center; font-weight: 700; font-size: 1.1rem; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.usage { margin-top: 12px; }
.usage-top { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 6px; }

.admin-link { border-color: var(--brand-2); }
