/* ==========================================================
   سند بوت — أنماط لوحات التحكم والصفحات المشتركة
   ========================================================== */

@font-face {
  font-family: "Cairo";
  src: url("../fonts/Cairo.ttf") format("truetype");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  --brand: #0E6E55;
  --brand-ink: color-mix(in srgb, var(--brand) 78%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #fff);
  --brand-line: color-mix(in srgb, var(--brand) 22%, #fff);
  --accent: #E3A23A;
  --accent-soft: #FCF1DE;
  --deep: #0F2E28;
  --deep-2: #143A33;

  --bg: #F2F5F3;
  --surface: #FFFFFF;
  --surface-2: #F7FAF8;
  --line: #E0E8E4;
  --line-strong: #CBD7D2;
  --text: #13302A;
  --muted: #5D716B;
  --faint: #8A9C96;

  --ok: #13804F;   --ok-soft: #E3F4EA;
  --warn: #A86A0C; --warn-soft: #FBF0D9;
  --bad: #BB3426;  --bad-soft: #FBE7E4;
  --info: #1F5FBF; --info-soft: #E5EEFB;

  --r-sm: 8px;
  --r: 11px;
  --r-lg: 16px;
  --shadow-1: 0 1px 2px rgba(15, 46, 40, .06);
  --shadow-2: 0 1px 2px rgba(15, 46, 40, .05), 0 10px 28px -14px rgba(15, 46, 40, .18);
  --shadow-3: 0 24px 60px -20px rgba(15, 46, 40, .35);
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent);
  --sidebar-w: 264px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: color-mix(in srgb, var(--brand) 20%, #12201D);
    --brand-line: color-mix(in srgb, var(--brand) 40%, #12201D);
    --accent-soft: #3A2D16;
    --bg: #0C1614;
    --surface: #12201D;
    --surface-2: #172824;
    --line: #22362F;
    --line-strong: #2E463E;
    --text: #E3EEEA;
    --muted: #97ABA4;
    --faint: #6D827B;
    --ok-soft: #12352A; --warn-soft: #3A2D12; --bad-soft: #3D1A16; --info-soft: #14263F;
    --ok: #4ACB8C; --warn: #E8B04F; --bad: #F07B6C; --info: #7AA7F0;
    --shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-soft: color-mix(in srgb, var(--brand) 20%, #12201D);
  --brand-line: color-mix(in srgb, var(--brand) 40%, #12201D);
  --accent-soft: #3A2D16;
  --bg: #0C1614;
  --surface: #12201D;
  --surface-2: #172824;
  --line: #22362F;
  --line-strong: #2E463E;
  --text: #E3EEEA;
  --muted: #97ABA4;
  --faint: #6D827B;
  --ok-soft: #12352A; --warn-soft: #3A2D12; --bad-soft: #3D1A16; --info-soft: #14263F;
  --ok: #4ACB8C; --warn: #E8B04F; --bad: #F07B6C; --info: #7AA7F0;
  --shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 10px 28px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---------- الأساسيات ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.35; font-weight: 750; letter-spacing: -.005em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; direction: ltr; unicode-bidi: embed; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .05em .4em; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ltr { direction: ltr; unicode-bidi: embed; text-align: left; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

.i { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-lg { width: 1.5em; height: 1.5em; }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 40px; padding: .45em 1.05em;
  border: 1px solid transparent; border-radius: var(--r);
  font: inherit; font-weight: 650; font-size: .95rem; line-height: 1.2;
  cursor: pointer; text-decoration: none !important; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, var(--shadow-1); }
.btn-primary:hover { background: var(--brand-ink); }
.btn-accent { background: var(--accent); color: #2A1A00; }
.btn-accent:hover { background: color-mix(in srgb, var(--accent) 85%, #000); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-light:hover { border-color: var(--brand-line); background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-sm { min-height: 32px; padding: .3em .75em; font-size: .86rem; border-radius: var(--r-sm); }
.btn-lg { min-height: 50px; padding: .6em 1.5em; font-size: 1.05rem; border-radius: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; min-height: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; min-height: 32px; }

/* ---------- نماذج ---------- */
.field { margin-bottom: 1.05rem; }
.field > label, .label { display: block; font-weight: 650; font-size: .92rem; margin-bottom: .35rem; }
.hint { display: block; color: var(--muted); font-size: .83rem; margin-top: .3rem; line-height: 1.55; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: .5em .8em;
  font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input[dir="ltr"] { text-align: left; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235D716B' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: left .8em center; padding-left: 2.2em; }
.input-group { display: flex; gap: .5rem; align-items: stretch; }
.input-group .input { flex: 1; }
.input-affix { position: relative; }
.input-affix .affix { position: absolute; inset-inline-start: .8em; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input-affix .input { padding-inline-start: 2.4em; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.form-actions.sticky { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); padding: .8rem 0; border-top: 1px solid var(--line); margin-top: 1rem; z-index: 5; }

.check { display: flex; gap: .65rem; align-items: flex-start; cursor: pointer; padding: .2rem 0; }
.check input { margin-top: .35em; accent-color: var(--brand); width: 17px; height: 17px; flex: none; }
.check b { display: block; font-weight: 650; }
.check span { color: var(--muted); font-size: .86rem; }

/* مفتاح تشغيل */
.switch { position: relative; display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--line-strong); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: .6rem; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; }
.choice .choice-box { display: block; height: 100%; padding: .75rem .9rem; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); transition: border-color .15s, background .15s; }
.choice .choice-box b { display: block; font-size: .93rem; }
.choice .choice-box small { color: var(--muted); line-height: 1.5; display: block; }
.choice input:checked + .choice-box { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.choice input:focus-visible + .choice-box { box-shadow: var(--focus); }

/* ---------- تنبيهات وشارات ---------- */
.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; border-radius: var(--r); border: 1px solid; margin-bottom: 1rem; font-size: .93rem; }
.alert .i { margin-top: .2em; }
.alert-success { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 25%, transparent); color: var(--ok); }
.alert-error { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, transparent); color: var(--bad); }
.alert-warning { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 22%, transparent); color: var(--info); }
.alert > div { color: var(--text); }
.alert > div b { color: inherit; }
.alert .alert-close { margin-inline-start: auto; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; opacity: .7; }

.badge { display: inline-flex; align-items: center; gap: .3em; padding: .12em .62em; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; line-height: 1.6; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-green { background: var(--ok-soft); color: var(--ok); }
.badge-amber { background: var(--warn-soft); color: var(--warn); }
.badge-red { background: var(--bad-soft); color: var(--bad); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.badge-gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill { display: inline-block; padding: .1em .6em; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.tag { display: inline-block; padding: 0 .55em; border-radius: 6px; background: var(--brand-soft); color: var(--brand); font-size: .78rem; font-weight: 700; margin: 0 0 .2rem .2rem; }

/* ---------- بطاقات ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: 1.02rem; }
.card-head .sub { color: var(--muted); font-size: .85rem; margin: 0; }
.card-body { padding: 1.25rem; }
.card-foot { padding: .9rem 1.25rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.card + .card { margin-top: 1.25rem; }
.grid > .card, .grid > .stack > .card:first-child { margin-top: 0; }
.card.flush .card-body { padding: 0; }

.grid { display: grid; gap: 1.25rem; }
.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)); }
.grid-main { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 1.25rem; }

/* مؤشرات */
.kpi { padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .2rem; position: relative; overflow: hidden; }
.kpi .kpi-label { color: var(--muted); font-size: .86rem; font-weight: 600; display: flex; align-items: center; gap: .45rem; }
.kpi .kpi-label .i { color: var(--brand); }
.kpi .kpi-value { font-size: 1.85rem; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .kpi-value small { font-size: .9rem; font-weight: 600; color: var(--muted); }
.kpi .kpi-foot { font-size: .82rem; color: var(--muted); }
.meter { height: 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin-top: .4rem; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.meter.is-warn > span { background: var(--accent); }
.meter.is-full > span { background: var(--bad); }

/* ---------- جداول ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: start; font-weight: 700; color: var(--muted); font-size: .8rem; padding: .7rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.table .actions { display: flex; gap: .35rem; justify-content: flex-end; white-space: nowrap; }
.table .t-title { font-weight: 700; color: var(--text); }
.table .t-sub { color: var(--muted); font-size: .82rem; }
.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 2.5rem 1.5rem; color: var(--muted); }
.empty .empty-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto .8rem; }
.empty .empty-icon .i { width: 26px; height: 26px; }
.empty h3 { color: var(--text); margin-bottom: .3rem; }
.empty p { max-width: 420px; margin: 0 auto 1rem; }

.pager { display: flex; gap: .3rem; align-items: center; padding: .9rem 1rem; flex-wrap: wrap; }
.pager-link { min-width: 34px; height: 34px; padding: 0 .6rem; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--line); color: var(--text); font-size: .88rem; text-decoration: none !important; }
.pager-link.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager-link.is-disabled { color: var(--faint); }
.pager-info { margin-inline-start: auto; color: var(--muted); font-size: .85rem; }

/* شريط الأدوات فوق الجداول */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; padding: .9rem 1.25rem; border-bottom: 1px solid var(--line); }
.toolbar .input, .toolbar .select { min-height: 38px; width: auto; }
.toolbar .search { flex: 1; min-width: 200px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); padding: 0 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs a, .tabs button { padding: .8rem .85rem; color: var(--muted); font-weight: 650; font-size: .92rem; border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; cursor: pointer; font-family: inherit; text-decoration: none !important; display: inline-flex; gap: .4rem; align-items: center; }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs .is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs .count { background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; padding: 0 .45em; font-size: .75rem; }

/* قوائم تعريفية */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.2rem; margin: 0; font-size: .93rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; word-break: break-word; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; gap: .8rem; align-items: center; padding: .8rem 1.25rem; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list code { word-break: break-all; }
.list .title { font-weight: 700; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { color: var(--muted); font-size: .84rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; flex: none; font-size: .95rem; }
.avatar.sm { width: 30px; height: 30px; font-size: .8rem; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.2rem; }

.copy-box { display: flex; align-items: center; gap: .5rem; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--r); padding: .45rem .5rem .45rem .8rem; }
.copy-box code { flex: 1; min-width: 0; background: none; border: 0; padding: 0; overflow-x: auto; white-space: nowrap; font-size: .85rem; }

/* مخططات */
.chart-wrap { width: 100%; }
.chart { width: 100%; height: 220px; display: block; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--faint); font-size: 11px; font-family: inherit; }
.bar-a { fill: var(--brand); }
.bar-b { fill: var(--accent); }
.bar-c { fill: var(--info); }
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .4rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-legend i.bar-a { background: var(--brand); }
.chart-legend i.bar-b { background: var(--accent); }
.chart-legend i.bar-c { background: var(--info); }
.chart-legend .chart-max { margin-inline-start: auto; }

/* ==========================================================
   هيكل لوحة التحكم
   ========================================================== */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--deep); color: #CFE1DA;
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: #2B4C44 transparent;
}
.sidebar-brand { display: flex; align-items: center; gap: .65rem; padding: 1.15rem 1.25rem; color: #fff; text-decoration: none !important; }
.sidebar-brand img { width: 36px; height: 36px; border-radius: 10px; }
.sidebar-brand b { font-size: 1.12rem; font-weight: 800; display: block; line-height: 1.2; }
.sidebar-brand small { color: #8FB1A6; font-size: .76rem; }
.sidebar-biz { margin: 0 .9rem .6rem; padding: .7rem .8rem; background: var(--deep-2); border-radius: 12px; display: flex; gap: .6rem; align-items: center; }
.sidebar-biz .avatar { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-biz b { color: #fff; font-size: .9rem; display: block; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-biz small { font-size: .76rem; color: #8FB1A6; }
.sidebar-biz .dot { width: 8px; height: 8px; border-radius: 50%; background: #6B8A81; display: inline-block; margin-inline-end: .3rem; }
.sidebar-biz .dot.on { background: #44D49A; box-shadow: 0 0 0 3px rgba(68,212,154,.18); }
.nav { padding: .3rem .7rem 1rem; flex: 1; }
.nav-label { font-size: .74rem; color: #7FA195; padding: .9rem .6rem .3rem; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 10px; color: #CFE1DA; font-weight: 600; font-size: .93rem; text-decoration: none !important; margin-bottom: 2px; transition: background .15s, color .15s; }
.nav a .i { color: #86AA9E; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.is-active { background: rgba(255,255,255,.1); color: #fff; box-shadow: inset -3px 0 0 var(--accent); }
.nav a.is-active .i { color: var(--accent); }
.nav a .count { margin-inline-start: auto; background: var(--accent); color: #2A1A00; font-size: .72rem; font-weight: 800; border-radius: 99px; padding: 0 .5em; min-width: 20px; text-align: center; }
.sidebar-foot { padding: .9rem 1rem 1.1rem; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-usage { font-size: .8rem; color: #A9C4BB; }
.sidebar-usage .meter { background: rgba(255,255,255,.08); border-color: transparent; }
.sidebar-usage .meter > span { background: var(--accent); }
.sidebar-usage b { color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .8rem; padding: .7rem 1.6rem; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); min-height: 64px; }
.topbar .menu-btn { display: none; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 1.18rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .crumb { color: var(--muted); font-size: .8rem; display: block; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: .4rem; }
.user-menu { position: relative; }
.user-menu > button { display: flex; align-items: center; gap: .5rem; background: none; border: 1px solid transparent; border-radius: 99px; padding: .2rem .25rem .2rem .7rem; cursor: pointer; font: inherit; color: var(--text); }
.user-menu > button:hover { border-color: var(--line); background: var(--surface); }
.dropdown { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-3); padding: .4rem; display: none; z-index: 40; }
.dropdown.is-open { display: block; }
.dropdown a, .dropdown button { display: flex; gap: .6rem; align-items: center; width: 100%; padding: .55rem .7rem; border-radius: 8px; color: var(--text); font: inherit; font-size: .92rem; background: none; border: 0; cursor: pointer; text-decoration: none !important; text-align: start; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }
.dropdown .sep { height: 1px; background: var(--line); margin: .3rem 0; }
.dropdown .head { padding: .5rem .7rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; }
.dropdown .head b { display: block; }
.dropdown .head small { color: var(--muted); }

.content { padding: 1.6rem; flex: 1; width: 100%; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.impersonate-bar { background: var(--accent); color: #2A1A00; padding: .5rem 1.6rem; display: flex; align-items: center; gap: .8rem; font-weight: 700; font-size: .9rem; flex-wrap: wrap; }
.impersonate-bar form { margin-inline-start: auto; }
.announce { display: flex; gap: .7rem; align-items: flex-start; padding: .75rem 1.6rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
.announce.info { background: var(--info-soft); }
.announce.warning { background: var(--warn-soft); }
.announce.success { background: var(--ok-soft); }
.announce b { display: block; }

.backdrop { display: none; }

@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(86vw, 300px); z-index: 60; transform: translateX(105%); transition: transform .25s ease; box-shadow: var(--shadow-3); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 20, 17, .45); z-index: 55; }
  .topbar { padding: .6rem 1rem; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .impersonate-bar, .announce { padding-inline: 1rem; }
  .user-menu .user-name { display: none; }
}

/* ==========================================================
   صندوق المحادثات
   ========================================================== */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 64px - 3.2rem); min-height: 520px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.inbox-list { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.inbox-list .toolbar { padding: .7rem; }
.inbox-filters { display: flex; gap: .3rem; padding: .5rem .7rem; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.inbox-filters a { padding: .25rem .7rem; border-radius: 99px; font-size: .82rem; font-weight: 650; color: var(--muted); border: 1px solid var(--line); white-space: nowrap; text-decoration: none !important; }
.inbox-filters a.is-active { background: var(--deep); color: #fff; border-color: var(--deep); }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: .7rem; padding: .8rem .9rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none !important; position: relative; }
.conv:hover { background: var(--surface-2); }
.conv.is-active { background: var(--brand-soft); }
.conv.is-active::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--brand); }
.conv .grow { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: .5rem; }
.conv .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { color: var(--faint); font-size: .75rem; white-space: nowrap; }
.conv .preview { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.conv .meta { display: flex; gap: .3rem; align-items: center; margin-top: .15rem; }
.conv .unread { background: var(--brand); color: #fff; border-radius: 99px; font-size: .72rem; font-weight: 800; min-width: 20px; height: 20px; display: inline-grid; place-items: center; padding: 0 .35em; }
.conv .flag { color: var(--warn); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-head .grow { flex: 1; min-width: 140px; }
.chat-head b { display: block; line-height: 1.3; }
.chat-head small { color: var(--muted); }
.chat-head .actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.chat-body { flex: 1; overflow-y: auto; padding: 1.2rem 1.2rem .6rem; background-color: var(--surface-2); background-image: radial-gradient(color-mix(in srgb, var(--brand) 7%, transparent) 1px, transparent 1px); background-size: 18px 18px; }
.day-sep { text-align: center; margin: .8rem 0; }
.day-sep span { background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: .75rem; border-radius: 99px; padding: .15rem .7rem; }
.msg { display: flex; margin-bottom: .45rem; }
.msg .bubble { max-width: min(78%, 560px); padding: .5rem .8rem .35rem; border-radius: 14px; font-size: .93rem; line-height: 1.65; box-shadow: var(--shadow-1); word-wrap: break-word; overflow-wrap: anywhere; }
.msg .bubble a { color: inherit; text-decoration: underline; }
.msg .bubble-meta { display: flex; gap: .35rem; align-items: center; justify-content: flex-end; font-size: .7rem; opacity: .7; margin-top: .1rem; }
.msg .bubble-meta .i { width: 1.1em; height: 1.1em; }
.msg.in { justify-content: flex-start; }
.msg.in .bubble { background: var(--surface); border: 1px solid var(--line); border-start-start-radius: 4px; }
.msg.out { justify-content: flex-end; }
.msg.out .bubble { background: #D9F2E6; color: #0E2E25; border-start-end-radius: 4px; }
.msg.out.agent .bubble { background: #FFF1D6; color: #3A2804; }
.msg.out.failed .bubble { background: var(--bad-soft); color: var(--bad); }
:root[data-theme="dark"] .msg.out .bubble { background: #134034; color: #DDF3EA; }
:root[data-theme="dark"] .msg.out.agent .bubble { background: #3D2E12; color: #F6E6C6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .msg.out .bubble { background: #134034; color: #DDF3EA; }
  :root:not([data-theme="light"]) .msg.out.agent .bubble { background: #3D2E12; color: #F6E6C6; }
}
.msg .who { font-size: .72rem; font-weight: 800; opacity: .7; display: block; }
.msg.system { justify-content: center; }
.msg.system .bubble { background: var(--info-soft); color: var(--info); font-size: .82rem; box-shadow: none; padding: .3rem .8rem; border-radius: 99px; max-width: 90%; text-align: center; }
.chat-compose { border-top: 1px solid var(--line); padding: .7rem; display: flex; gap: .5rem; align-items: flex-end; background: var(--surface); }
.chat-compose .textarea { min-height: 44px; max-height: 160px; resize: none; }
.chat-note { padding: .5rem 1rem; font-size: .82rem; background: var(--warn-soft); color: var(--warn); border-top: 1px solid var(--line); display: flex; gap: .5rem; align-items: center; }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 2rem; }
.typing { display: inline-flex; gap: 3px; padding: .2rem 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

@media (max-width: 860px) {
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .inbox.has-chat .inbox-list { display: none; }
  .inbox:not(.has-chat) .chat { display: none; }
  .conv-list { max-height: none; }
  .chat { height: calc(100vh - 64px - 2rem); }
  .chat-back { display: inline-flex !important; }
}
.chat-back { display: none !important; }

/* ==========================================================
   صفحات الدخول والتثبيت والأخطاء
   ========================================================== */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
.auth-panel { background: var(--deep); color: #D3E5DE; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-panel::after { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; border: 1px solid rgba(255,255,255,.06); left: -180px; bottom: -220px; box-shadow: 0 0 0 60px rgba(255,255,255,.02), 0 0 0 130px rgba(255,255,255,.015); }
.auth-panel .brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 800; font-size: 1.2rem; text-decoration: none !important; position: relative; z-index: 1; }
.auth-panel .brand img { width: 40px; height: 40px; border-radius: 11px; }
.auth-panel h2 { color: #fff; font-size: 1.9rem; line-height: 1.45; max-width: 440px; position: relative; z-index: 1; }
.auth-panel ul { list-style: none; padding: 0; margin: 1.5rem 0 0; position: relative; z-index: 1; }
.auth-panel li { display: flex; gap: .6rem; align-items: center; margin-bottom: .7rem; }
.auth-panel li .i { color: var(--accent); }
.auth-panel .foot { font-size: .85rem; color: #84A79B; position: relative; z-index: 1; }
.auth-form { display: grid; place-items: center; padding: 2.5rem 1.5rem; background: var(--surface); }
.auth-box { width: 100%; max-width: 420px; }
.auth-box h1 { font-size: 1.65rem; }
.auth-box .lead { color: var(--muted); margin-bottom: 1.6rem; }
.auth-box .switch-link { text-align: center; margin-top: 1.4rem; color: var(--muted); font-size: .93rem; }
.auth-mobile-brand { display: none; }
@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-panel { display: none; }
  .auth-mobile-brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; color: var(--text); margin-bottom: 1.6rem; text-decoration: none !important; }
  .auth-mobile-brand img { width: 34px; height: 34px; border-radius: 9px; }
}

.install { min-height: 100vh; padding: 2.5rem 1rem; display: flex; flex-direction: column; align-items: center; }
.install-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.6rem; font-weight: 800; font-size: 1.2rem; }
.install-head img { width: 38px; height: 38px; border-radius: 10px; }
.install .card { width: 100%; max-width: 640px; }
.steps { display: flex; gap: .4rem; margin-bottom: 1.4rem; width: 100%; max-width: 640px; }
.steps .step { flex: 1; text-align: center; font-size: .82rem; color: var(--muted); font-weight: 650; }
.steps .step::before { content: ""; display: block; height: 4px; border-radius: 99px; background: var(--line-strong); margin-bottom: .45rem; }
.steps .step.done::before, .steps .step.current::before { background: var(--brand); }
.steps .step.current { color: var(--brand); }
.req { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.req:last-child { border-bottom: 0; }
.req .grow { flex: 1; }
.req small { color: var(--muted); display: block; }
.req .ok { color: var(--ok); }
.req .bad { color: var(--bad); }
.req .warn { color: var(--warn); }

.error-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.error-box { text-align: center; max-width: 440px; }
.error-code { font-size: 4.5rem; font-weight: 900; color: var(--brand); line-height: 1; margin-bottom: .6rem; letter-spacing: -.02em; }
.error-box p { color: var(--muted); }

/* ---------- نوافذ منبثقة ---------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); }
dialog.modal::backdrop { background: rgba(8, 20, 17, .5); }
dialog.modal .card-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
dialog.modal .modal-close { background: none; border: 0; cursor: pointer; color: var(--muted); padding: .2rem; }

/* ---------- قائمة الإعداد الأولي ---------- */
.setup { counter-reset: s; }
.setup-item { display: flex; gap: .8rem; align-items: center; padding: .8rem 1.25rem; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none !important; }
.setup-item:last-child { border-bottom: 0; }
.setup-item:hover { background: var(--surface-2); }
.setup-item .num { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; font-size: .8rem; font-weight: 800; color: var(--muted); flex: none; }
.setup-item.done .num { background: var(--brand); border-color: var(--brand); color: #fff; }
.setup-item.done .t { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.setup-item .t { flex: 1; font-weight: 650; }
.setup-item .t small { display: block; color: var(--muted); font-weight: 500; text-decoration: none; }

/* خطوات الشرح */
.guide { counter-reset: g; list-style: none; padding: 0; margin: 0; }
.guide li { counter-increment: g; position: relative; padding: 0 2.6rem 1.1rem 0; }
.guide li::before { content: counter(g); position: absolute; right: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.guide li::after { content: ""; position: absolute; right: 13px; top: 32px; bottom: 4px; width: 2px; background: var(--line); }
.guide li:last-child::after { display: none; }
.guide li b { display: block; margin-bottom: .15rem; }
.guide li p { margin: 0; color: var(--muted); font-size: .9rem; }

/* أيام العمل */
.hours { display: grid; gap: .45rem; }
.hours-row { display: grid; grid-template-columns: 110px auto 1fr; gap: .7rem; align-items: center; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.hours-row .times { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.hours-row .times .input { width: 120px; min-height: 36px; padding: .3em .5em; }
.hours-row.is-off .times { opacity: .35; pointer-events: none; }
@media (max-width: 560px) { .hours-row { grid-template-columns: 1fr auto; } .hours-row .times { grid-column: 1 / -1; } }

/* ساحة التجربة */
.playground { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; }
.playground .chat { height: calc(100vh - 64px - 9rem); min-height: 480px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
@media (max-width: 980px) { .playground { grid-template-columns: minmax(0, 1fr); } }

/* بطاقة الباقة في لوحة العميل */
.plan-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.plan-card { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.2rem; background: var(--surface); display: flex; flex-direction: column; gap: .6rem; }
.plan-card.is-current { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.plan-card .price { font-size: 1.7rem; font-weight: 800; }
.plan-card .price small { font-size: .85rem; color: var(--muted); font-weight: 600; }
.plan-card ul { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.plan-card li { display: flex; gap: .45rem; align-items: center; padding: .2rem 0; }
.plan-card li .i { color: var(--brand); }
.plan-card li.off { color: var(--faint); }
.plan-card li.off .i { color: var(--faint); }
.plan-card .btn { margin-top: auto; }

.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--deep); color: #fff; padding: .6rem 1.1rem; border-radius: 99px; font-size: .9rem; font-weight: 650; box-shadow: var(--shadow-3); opacity: 0; transition: opacity .2s, transform .2s; z-index: 100; pointer-events: none; }
.toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

.mt-0 { margin-top: 0 !important; } .mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.text-end { text-align: end; }
.center { text-align: center; }
.hide-sm { }
@media (max-width: 760px) { .hide-sm { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- التقارير ---------- */
.delta { display: inline-flex; align-items: center; gap: .2rem; font-size: .78rem; font-weight: 700; padding: .1rem .45rem; border-radius: 99px; vertical-align: middle; letter-spacing: 0; }
.delta .i { width: 14px; height: 14px; }
.delta.up { background: var(--ok-soft); color: var(--ok); }
.delta.down { background: var(--bad-soft); color: var(--bad); }
.bar-row { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr) auto; gap: .8rem; align-items: center; padding: .45rem 0; }
.bar-label { font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: .4rem; }
.bar-label .i { color: var(--brand); }
.bar-track { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.bar-fill.fill-green { background: var(--ok); } .bar-fill.fill-amber { background: var(--warn); } .bar-fill.fill-red { background: var(--bad); }
.bar-num { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .92rem; white-space: nowrap; }
.bar-num small { color: var(--muted); font-weight: 500; }

/* ---------- الردود الجاهزة ---------- */
.qr-pop { position: absolute; bottom: calc(100% + 6px); inset-inline: .75rem; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r); box-shadow: var(--shadow-lg, 0 18px 40px -16px rgba(0,0,0,.35)); z-index: 20; padding: .3rem; }
.qr-pop button { all: unset; box-sizing: border-box; display: block; width: 100%; padding: .55rem .7rem; border-radius: 8px; cursor: pointer; }
.qr-pop button:hover, .qr-pop button.is-active { background: var(--brand-soft); }
.qr-pop b { display: block; font-size: .9rem; }
.qr-pop small { display: block; color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-pop .qr-empty { padding: .7rem; color: var(--muted); font-size: .88rem; }

@media print {
  .sidebar, .topbar, .tabs, .page-head .actions, .impersonate-bar, .announce, [data-sanadbot] { display: none !important; }
  .shell, .main, .content { display: block !important; margin: 0 !important; padding: 0 !important; }
  .card { break-inside: avoid; box-shadow: none !important; }
  body { background: #fff !important; }
}
.chat-compose { position: relative; }
kbd { font-family: ui-monospace, monospace; font-size: .85em; padding: .05em .4em; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); }
@media (max-width: 640px) {
  .grid.kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi-grid .kpi { padding: .85rem .9rem; }
  .kpi-grid .kpi-value { font-size: 1.4rem; }
  .kpi-grid .kpi-label { font-size: .8rem; }
  .kpi-grid .delta { display: inline-flex; font-size: .7rem; }
}
