/* ==========================================================================
   نظام التصميم — أبيض، بسيط، أرقام واضحة
   ========================================================================== */

:root {
  --bg:        #FFFFFF;
  --paper:     #F7F8FA;
  --line:      #E7E9EE;
  --line-soft: #F0F2F5;
  --ink:       #14181F;
  --ink-2:     #3D4653;
  --muted:     #6B7480;

  --brand:     #0F6E5C;
  --brand-2:   #E7F2EF;
  --in:        #0F6E5C;
  --out:       #B3261E;
  --warn:      #A45B00;
  --warn-bg:   #FDF4E7;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-full: 999px;

  --shadow-2: 0 8px 28px rgba(20, 24, 31, .10);

  --sidebar-w: 248px;
  --header-h:  60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Cairo", -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

h1, h2, h3 { margin: 0 0 var(--sp-3); font-weight: 700; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p  { margin: 0 0 var(--sp-3); }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.num   { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: embed; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.in    { color: var(--in); }
.out   { color: var(--out); }

/* ---------- تخطيط ---------- */

.container { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: var(--sp-4); }
.page { padding-block: var(--sp-5) var(--sp-7); }

.page-head {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-5);
}

/* ---------- بطاقات ---------- */

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.grid   { display: grid; gap: var(--sp-3); }
.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)); }

@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .sub   { font-size: 12px; color: var(--muted); }

/* ---------- أزرار ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--paper); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #0C5C4D; }

.btn-danger { color: var(--out); border-color: #F3D6D4; }
.btn-danger:hover { background: #FCF2F1; }

.btn-sm    { min-height: 34px; padding: 0 var(--sp-3); font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- نماذج ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }

.input, .select, .textarea {
  width: 100%; min-height: 46px;
  padding: 10px var(--sp-3);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); color: var(--ink);
  font: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-2);
}
.textarea { min-height: 90px; resize: vertical; }
.field .hint  { font-size: 12px; color: var(--muted); }
.field .error { font-size: 12px; color: var(--out); }

/* ---------- جداول ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; min-width: 620px; }
table.data th, table.data td {
  padding: 12px var(--sp-3); text-align: right;
  border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
table.data th { background: var(--paper); font-size: 13px; font-weight: 600; color: var(--ink-2); }
table.data tbody tr:last-child td { border-bottom: 0; }

/* ---------- شارات وتنبيهات ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 600;
  background: var(--paper); color: var(--ink-2);
}
.badge-completed { background: var(--brand-2); color: var(--brand); }
.badge-partial   { background: var(--warn-bg); color: var(--warn); }
.badge-pending   { background: #F1F3F6; color: var(--muted); }

.alert { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); border: 1px solid var(--line); margin-bottom: var(--sp-4); }
.alert-ok   { background: var(--brand-2); border-color: #CFE6E0; color: #0B5648; }
.alert-warn { background: var(--warn-bg); border-color: #F2E0C4; color: var(--warn); }
.alert-err  { background: #FCF2F1; border-color: #F3D6D4; color: var(--out); }

.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; }

/* ---------- شاشات الدخول والتجهيز ---------- */

.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-4); background: var(--paper); }
.auth-box {
  width: 100%; max-width: 400px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-6) var(--sp-5);
  box-shadow: var(--shadow-2);
}
.auth-box .brand { margin-bottom: var(--sp-5); }
.auth-box .brand h1 { font-size: 20px; margin-bottom: 2px; }
.auth-box .brand p  { color: var(--muted); font-size: 13px; margin: 0; }

.check-list { list-style: none; margin: 0 0 var(--sp-5); padding: 0; }
.check-list li {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--line-soft);
}
.check-list li:last-child { border-bottom: 0; }
.check-list .mark { flex: 0 0 22px; height: 22px; border-radius: var(--r-full); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.check-list .ok  { background: var(--brand-2); color: var(--brand); }
.check-list .bad { background: #FCF2F1; color: var(--out); }
.check-list .body { flex: 1; min-width: 0; }
.check-list .body strong { display: block; font-size: 14px; }
.check-list .body span   { font-size: 13px; color: var(--muted); word-break: break-word; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ==========================================================================
   الهيدر والقائمة الجانبية
   ========================================================================== */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--sp-3);
  padding-inline: var(--sp-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar-brand { font-weight: 700; color: var(--ink); font-size: 16px; }
.topbar-brand:hover { text-decoration: none; }
.topbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-3); }

.icon-btn {
  display: none;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--bg); cursor: pointer;
}
.burger, .burger::before, .burger::after {
  display: block; width: 16px; height: 2px; background: var(--ink); border-radius: 2px;
}
.burger { position: relative; }
.burger::before, .burger::after { content: ''; position: absolute; inset-inline-start: 0; }
.burger::before { top: -5px; }
.burger::after  { top: 5px; }

.layout { display: flex; align-items: flex-start; min-height: calc(100dvh - var(--header-h)); }

.sidebar {
  flex: 0 0 var(--sidebar-w);
  position: sticky; top: var(--header-h);
  height: calc(100dvh - var(--header-h));
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3);
  border-inline-start: 1px solid var(--line);
  background: var(--bg);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.sidebar a, .nav-soon {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px var(--sp-3); border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600; font-size: 14px;
}
.sidebar a:hover { background: var(--paper); text-decoration: none; }
.sidebar a.active { background: var(--brand-2); color: var(--brand); }
.nav-soon { color: #A6ADB8; cursor: default; }
.nav-soon em { font-style: normal; font-size: 11px; font-weight: 600; color: #A6ADB8; }

.content { flex: 1; min-width: 0; padding-block: var(--sp-5) var(--sp-7); }
.content .container { padding-inline: var(--sp-5); }

.scrim { display: none; }

@media (max-width: 900px) {
  .icon-btn { display: inline-flex; }
  .hide-sm  { display: none; }

  .sidebar {
    position: fixed; inset-block: var(--header-h) 0; inset-inline-end: 0;
    width: 260px; height: auto; z-index: 40;
    transform: translateX(100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-2);
  }
  body.drawer-open .sidebar { transform: translateX(0); }

  .scrim {
    display: block; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(20, 24, 31, .35); z-index: 35;
  }
  .scrim[hidden] { display: none; }

  .content .container { padding-inline: var(--sp-4); }
}

/* ==========================================================================
   الإضافة السريعة
   ========================================================================== */

.seg {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 4px; margin-bottom: var(--sp-4);
  background: var(--paper); border-radius: var(--r-sm);
}
.seg-btn {
  flex: 1 1 auto; min-width: 76px; min-height: 38px;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--ink-2);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.seg-btn.active { background: var(--bg); color: var(--brand); box-shadow: 0 1px 2px rgba(20,24,31,.08); }
.seg-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.quick-add .grid-2 { align-items: start; }
.quick-add .field  { margin-bottom: 0; }
.quick-add .field[hidden] { display: none; }
.quick-add .span-2 { grid-column: 1 / -1; }

.quick-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-4);
}

@media (max-width: 620px) {
  .quick-add .grid-2 { grid-template-columns: 1fr; }
  .quick-actions .btn { width: 100%; }
}

/* ==========================================================================
   كروت الأماكن والأشخاص
   ========================================================================== */

.place-card { display: flex; flex-direction: column; gap: 6px; color: inherit; }
.place-card .place-name {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  font-weight: 700; font-size: 15px;
}
.place-card .value { font-size: 20px; font-weight: 700; }
.place-card .place-rows {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  font-size: 13px; color: var(--muted);
  padding-top: 6px; border-top: 1px solid var(--line-soft);
}
.place-card .sub { font-size: 12px; color: var(--muted); }

/* ==========================================================================
   المودالات
   ========================================================================== */

body.modal-open { overflow: hidden; }

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: var(--sp-4); }
.modal[hidden] { display: none; }

.modal-scrim { position: absolute; inset: 0; background: rgba(20, 24, 31, .45); }

.modal-box {
  position: relative;
  width: 100%; max-width: 520px; max-height: 90dvh; overflow-y: auto;
  background: var(--bg); border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-2);
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.modal-head h2 { margin: 0; }
.modal-head .icon-btn { display: inline-flex; font-size: 22px; line-height: 1; color: var(--muted); }

@media (max-width: 620px) {
  .modal { align-items: end; padding: 0; }
  .modal-box { max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; }
}

/* ==========================================================================
   الفلاتر وأدوات الصفحة
   ========================================================================== */

.filters { margin-bottom: var(--sp-4); }
.filters .field { margin-bottom: 0; }
.filters .span-2 { grid-column: span 2; }

.filters-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.head-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions form.inline { display: inline; margin: 0; }

.row-form {
  display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end;
  margin-bottom: var(--sp-2);
}
.row-form .field { margin-bottom: 0; flex: 1 1 200px; }

.check { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.check[hidden] { display: none; }

.input-sm { min-height: 38px; padding: 6px 10px; font-size: 14px; }

.input-suffix { position: relative; }
.input-suffix span {
  position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.input-suffix .input { padding-inline-end: 32px; }

.pager {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: var(--sp-3); margin-top: var(--sp-4);
}

table.data tfoot th {
  background: var(--paper); border-top: 2px solid var(--line);
  padding: 12px var(--sp-3); text-align: right; font-size: 14px;
}

@media (max-width: 620px) {
  .filters .grid-3, .filters .grid-4 { grid-template-columns: 1fr; }
  .filters .span-2 { grid-column: span 1; }
  .head-actions .btn { flex: 1 1 auto; }
}

/* ==========================================================================
   الطباعة
   ========================================================================== */

@media print {
  .topbar, .sidebar, .scrim, .filters, .no-print, .head-actions, .pager { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; }
  .content .container { max-width: none; padding: 0; }
  .card { break-inside: avoid; }
  .table-wrap { overflow: visible; border: 0; }
  table.data { min-width: 0; font-size: 12px; }
  a { color: inherit; text-decoration: none; }
  body { font-size: 12px; }
}
