/*
 * نظام تصميم سيليا ووركس — مرجعه قسم «نظام التصميم» في المخطط المعتمد.
 *
 * القواعد:
 * - كل لون يأتي من متغير هنا، ولا يُكتب لون مباشرة في أي شاشة.
 * - لوحة واحدة لكل الأقسام: عاجي وكحلي، والذهبي للتمييز فقط.
 * - المسافات من مقياس واحد مضاعفات ٤.
 * - التباين بين كل نص وخلفيته ٤٫٥ إلى ١ على الأقل، ويفحصه اختبار آلي.
 */

@font-face { font-family: "Plex Arabic"; src: url("fonts/IBMPlexSansArabic-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/IBMPlexSansArabic-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url("fonts/IBMPlexSansArabic-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Amiri"; src: url("fonts/Amiri-Bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

/* ---------- الألوان: النهاري ---------- */
:root, [data-theme="light"] {
  --page: #F6F1E8;
  --card: #FFFCF7;
  --card-muted: #FAF5EC;
  --line: #E4D9C6;
  --ink: #1F2B3B;
  --ink-soft: #5B6573;
  --gold: #A8844A;
  --gold-ink: #7A5E2E;
  --on-ink: #F6F1E8;

  --ok: #4E7656;      --ok-bg: #EDF3EE;
  --warn: #8A6224;    --warn-bg: #F6ECD9;
  --danger: #A34A3E;  --danger-bg: #F5E4E1;
  --info: #3E6283;    --info-bg: #E3EAF1;

  --focus: 0 0 0 3px rgba(168, 132, 74, .35);
  --shadow: 0 1px 2px rgba(31, 43, 59, .06), 0 4px 16px rgba(31, 43, 59, .05);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 12px; --radius-sm: 8px;
  --touch: 44px;
  --font: "Plex Arabic", "Segoe UI", Tahoma, sans-serif;
  --display: "Amiri", "Plex Arabic", serif;

  --sidebar: 248px;
  --bottom-nav: 64px;
  color-scheme: light;
}

/* ---------- الألوان: الليلي ---------- */
[data-theme="dark"] {
  --page: #111821;
  --card: #1A2331;
  --card-muted: #162030;
  --line: #2C3747;
  --ink: #EFE8DB;
  --ink-soft: #A59D90;
  --gold: #C9A66B;
  --gold-ink: #D8BC8A;
  --on-ink: #111821;

  --ok: #8DBB96;      --ok-bg: #1D2E25;
  --warn: #D9AE6C;    --warn-bg: #33291A;
  --danger: #E0978C;  --danger-bg: #3A2220;
  --info: #9AB8D6;    --info-bg: #1C2A3A;

  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ---------- الأساس ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  direction: rtl;
}
a { color: var(--gold-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
h1 { font-family: var(--display); font-size: 28px; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0 0 var(--s3); }
small, .muted { color: var(--ink-soft); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
[x-cloak] { display: none !important; }

/* ---------- هيكل التطبيق ---------- */
.shell { min-height: 100vh; display: flex; }
.sidebar {
  width: var(--sidebar);
  flex: none;
  background: var(--card);
  border-inline-start: 1px solid var(--line);
  padding: var(--s5) var(--s4);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); }
.sidebar .brand img { width: 40px; height: 40px; }
.sidebar .brand strong { font-family: var(--display); font-size: 20px; }
.nav-group { margin-bottom: var(--s4); }
.nav-group > span { display: block; font-size: 13px; color: var(--ink-soft); margin: 0 var(--s3) var(--s1); }
.nav-link {
  display: flex; align-items: center; gap: var(--s3);
  min-height: var(--touch); padding: 0 var(--s3);
  border-radius: var(--radius-sm);
  color: var(--ink); font-weight: 500;
}
.nav-link:hover { background: var(--card-muted); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--card-muted); box-shadow: inset -3px 0 0 var(--gold); }
.nav-link svg { width: 20px; height: 20px; flex: none; color: var(--ink-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s5);
  padding-top: calc(var(--s3) + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.icon-btn {
  position: relative;
  width: var(--touch); height: var(--touch);
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .dot { position: absolute; top: 8px; left: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.content { padding: var(--s5); max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; }

/* الشريط السفلي للهاتف: يختفي تلقائيًا عند فتح لوحة المفاتيح. */
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .content { padding: var(--s4); padding-bottom: calc(var(--bottom-nav) + var(--s5) + env(safe-area-inset-bottom, 0px)); }
  .topbar { padding-inline: var(--s4); }
  .bottom-nav {
    display: flex; position: fixed; z-index: 30;
    inset-inline: var(--s3); bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
    height: var(--bottom-nav);
    background: var(--card); border: 1px solid var(--line); border-radius: 18px;
    box-shadow: var(--shadow);
    transition: transform .2s ease, opacity .2s ease;
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--ink-soft); font-size: 12px; font-weight: 500;
  }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--ink); }
  .bottom-nav a[aria-current="page"] svg { color: var(--gold); }
  html.keyboard-open .bottom-nav { transform: translateY(150%); opacity: 0; pointer-events: none; }
  html.keyboard-open .sticky-actions { bottom: 0; }
  h1 { font-size: 24px; }
}

/* ---------- رأس الصفحة ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); margin-bottom: var(--s5); }
.page-head .titles { flex: 1; min-width: 220px; }
.page-head p { margin: var(--s1) 0 0; color: var(--ink-soft); }
.page-head .actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ---------- البطاقات ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s5); box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--s4); }
.card-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: var(--s1); }
.stat .value { font-size: 26px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .label { color: var(--ink-soft); font-size: 14px; }
.stat.accent { border-top: 3px solid var(--gold); }
@media (max-width: 900px) { .card { padding: var(--s4); } }

/* بطاقة ترحيب بالشعار المائي: الشعار بشفافية ٦٪ ولا يقع خلف الأرقام. */
.hero {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s5); padding-inline-end: 160px;
}
.hero::after {
  content: ""; position: absolute; inset-inline-end: -10px; top: 50%; transform: translateY(-50%);
  width: 170px; height: 170px; background: url("monogram.png") center / contain no-repeat; opacity: .06;
}
.hero h1 { margin-bottom: var(--s1); }
@media (max-width: 600px) { .hero { padding-inline-end: var(--s5); } .hero::after { width: 120px; height: 120px; inset-inline-end: -30px; top: auto; bottom: -30px; transform: none; } }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--touch); padding: 0 var(--s4);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 15px; line-height: 1;
  cursor: pointer; text-decoration: none !important; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover { filter: brightness(1.12); }
.btn-secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--card-muted); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--card-muted); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* أزرار الإجراء الرئيسي ثابتة أسفل النموذج على الهاتف. */
.sticky-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s5); }
@media (max-width: 900px) {
  .sticky-actions {
    position: sticky; bottom: calc(var(--bottom-nav) + var(--s4) + env(safe-area-inset-bottom, 0px)); z-index: 10;
    margin-inline: calc(var(--s4) * -1); padding: var(--s3) var(--s4);
    background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
  }
  .sticky-actions .btn { flex: 1; }
}

/* ---------- النماذج ---------- */
.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.field { display: flex; flex-direction: column; gap: var(--s1); }
.field.full { grid-column: 1 / -1; }
.field label, .label { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--ink-soft); }
.field .error { font-size: 13px; color: var(--danger); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: var(--touch);
  padding: var(--s2) var(--s3);
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: inherit; font-size: 16px;
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--gold); box-shadow: var(--focus); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input.code { letter-spacing: 8px; text-align: center; font-size: 22px; font-weight: 600; direction: ltr; }
.input-affix { position: relative; }
.input-affix .input { padding-inline-start: 48px; }
.input-affix .affix { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-size: 14px; }

/* مفتاح تشغيل وإيقاف بنص واضح بجانبه دائمًا. */
.switch { display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer; min-height: var(--touch); padding-top: var(--s2); }
.switch input { appearance: none; flex: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked { background: var(--ink); }
.switch input:checked::after { transform: translateX(-18px); }
.switch input:focus-visible { box-shadow: var(--focus); }
.switch .text strong { display: block; font-weight: 600; font-size: 15px; }
.switch .text span { display: block; font-size: 13px; color: var(--ink-soft); }

.check { display: flex; align-items: center; gap: var(--s2); min-height: 36px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }

/* اختيار من بطاقات، مثل طريقة رمز التحقق. */
.choice { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choice label { display: flex; gap: var(--s3); padding: var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); cursor: pointer; }
.choice input { margin-top: 5px; accent-color: var(--ink); }
.choice label:has(input:checked) { border-color: var(--gold); box-shadow: var(--focus); }
.choice label.disabled { opacity: .55; cursor: not-allowed; }

/* ---------- الشارات ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: var(--card-muted); color: var(--ink-soft); border: 1px solid var(--line);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.badge.plain::before { display: none; }

/* ---------- التنبيهات ---------- */
.alert { display: flex; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius-sm); margin-bottom: var(--s4); font-weight: 500; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.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(--info); }
.alert ul { margin: 0; padding-inline-start: var(--s4); }

/* ---------- الجداول: على الهاتف تتحول إلى بطاقات ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th { text-align: start; font-size: 13px; font-weight: 600; color: var(--ink-soft); background: var(--card-muted); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { font-variant-numeric: tabular-nums; text-align: end; }
.table .actions { text-align: end; white-space: nowrap; }
@media (max-width: 700px) {
  .table-wrap.cards { border: 0; background: none; overflow: visible; }
  .table.cards thead { display: none; }
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2) var(--s4); margin-bottom: var(--s3); box-shadow: var(--shadow); }
  .table.cards td { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s2) 0; border-bottom: 1px dashed var(--line); text-align: start; }
  .table.cards td:last-child { border-bottom: 0; }
  .table.cards td::before { content: attr(data-label); color: var(--ink-soft); font-size: 13px; font-weight: 600; flex: none; }
  .table.cards td.primary { font-weight: 700; font-size: 16px; }
  .table.cards td.primary::before { display: none; }
  .table.cards td.actions { justify-content: flex-end; }
  .table.cards td.actions::before { display: none; }
}

/* ---------- عام ---------- */
.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--ink-soft); }
.empty img { width: 56px; opacity: .25; margin-bottom: var(--s3); }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s4); }
.toolbar .input, .toolbar .select { width: auto; flex: 1; min-width: 160px; }
.divider { height: 1px; background: var(--line); margin: var(--s5) 0; border: 0; }
.stack > * + * { margin-top: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.kbd { font-family: ui-monospace, monospace; background: var(--card-muted); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; direction: ltr; display: inline-block; word-break: break-all; }
.pagination { display: flex; gap: var(--s2); justify-content: center; margin-top: var(--s4); flex-wrap: wrap; }
.pagination a, .pagination span { min-width: var(--touch); min-height: var(--touch); display: inline-grid; place-items: center; padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--card); color: var(--ink); }
.pagination [aria-current] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.pagination .disabled { opacity: .45; }
details.diff summary { cursor: pointer; color: var(--gold-ink); font-weight: 600; }
details.diff pre { white-space: pre-wrap; word-break: break-word; background: var(--card-muted); border-radius: var(--radius-sm); padding: var(--s3); font-size: 13px; direction: ltr; text-align: left; }

/* ---------- صفحات الدخول ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .logo { display: block; width: 180px; margin: 0 auto var(--s5); }
.auth-card .card { padding: var(--s6) var(--s5); }
.auth-card h1 { font-size: 24px; text-align: center; margin-bottom: var(--s1); }
.auth-card .lead { text-align: center; color: var(--ink-soft); margin-bottom: var(--s5); }
.auth-wide { max-width: 640px; }
.qr { background: #fff; padding: var(--s3); border-radius: var(--radius-sm); width: 200px; margin: 0 auto var(--s3); }

/* ---------- معاينة التصميم ---------- */
.swatches { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.swatch { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--card); }
.swatch .chip { height: 64px; border-bottom: 1px solid var(--line); }
.swatch .meta { padding: var(--s2) var(--s3); font-size: 13px; }
.swatch .meta strong { display: block; font-size: 14px; }
.phone-frame { max-width: 390px; border: 10px solid #0E141C; border-radius: 40px; overflow: hidden; margin: 0 auto; background: var(--page); }

/* القائمة الجانبية على الهاتف تُفتح كدرج من زر القائمة. */
.drawer-backdrop { display: none; }
@media (max-width: 900px) {
  .sidebar.open { display: block; position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50; height: 100%; padding-top: calc(var(--s5) + env(safe-area-inset-top, 0px)); box-shadow: var(--shadow); }
  .drawer-backdrop.open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(17, 24, 33, .45); }
}
@media (min-width: 901px) { .only-mobile { display: none !important; } }

.theme-sample { background: var(--page); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); }
