/* ═══ CRM Level Up — نظام التصميم ═══════════════════════ */

:root {
  --accent: #1040b0;
  --accent-rgb: 16, 64, 176;
  --on-accent: #fff;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #0d1b34;
  --ink-2: #5a6b85;
  --ink-3: #8a99b0;
  --border: #e2e8f2;
  --shadow: 0 1px 2px rgba(13, 27, 52, .06), 0 8px 24px rgba(13, 27, 52, .06);
  --shadow-lg: 0 12px 40px rgba(13, 27, 52, .14);

  --good: #0f9d58;
  --good-bg: #e7f6ee;
  --warn: #c77700;
  --warn-bg: #fdf3e2;
  --bad: #d13c3c;
  --bad-bg: #fdeaea;
  --info: #1040b0;
  --info-bg: #e8eefb;
  --wa: #25d366;

  --r: 12px;
  --r-lg: 18px;
  --sp: 16px;
}

html[data-theme="dark"] {
  --accent: #4a7fe0;
  --accent-rgb: 74, 127, 224;
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #182238;
  --ink: #eef3fb;
  --ink-2: #a3b1c8;
  --ink-3: #6f7f99;
  --border: #24314a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);

  --good: #4ecb8b;  --good-bg: #122c20;
  --warn: #e6a532;  --warn-bg: #2e2413;
  --bad:  #f2706e;  --bad-bg:  #2e1717;
  --info: #7aa5f0;  --info-bg: #16233d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 800; line-height: 1.35; }
p { margin: 0 0 .6em; }
a { color: var(--accent); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; }

/* ═══ الهيكل ════════════════════════════════════════════ */

/* الهيكل: قائمة جانبية ثابتة على اليمين (أول عنصر في RTL) + المحتوى */
.shell {
  --side-w: 248px;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

.main { min-width: 0; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px var(--sp) 80px;
}

/* القائمة كحلي ثابت في الوضعين (هوية Level Up — levelup website/BRAND.md) */
.sidebar {
  --side-ink: rgba(255, 255, 255, .72);
  --side-hover: rgba(255, 255, 255, .07);
  --side-line: rgba(255, 255, 255, .09);
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px 12px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  color: #fff;
  background:
    radial-gradient(120% 50% at 100% 0%, rgba(16, 64, 176, .38), transparent 60%),
    linear-gradient(180deg, #0A1E47 0%, #0D1117 100%);
  border-inline-end: 1px solid var(--side-line);
  z-index: 50;
}

.brandmark {
  display: flex; align-items: center;
  padding: 2px 10px 14px; flex: none;
  text-decoration: none;
  border-block-end: 1px solid var(--side-line);
}
.brandmark img { display: block; width: 152px; height: auto; }
.mobilebar .brandmark--sm { border: 0; padding: 0; }
.brandmark--sm img { width: 112px; }

/* القائمة على مقاس الشاشة دائمًا بلا scroll: التابات تتقاسم الارتفاع المتاح
   (حتى 44px للواحد) وتصغر وحدها في الشاشات القصيرة. الـ overflow بلا شريط
   شبكة أمان فقط للشاشات القصيرة جدًا. */
.tabs {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--side-ink);
  font-size: clamp(13.5px, 2vh, 15px); line-height: 1.3;
  flex: 1 1 0; min-height: 34px; max-height: 44px;
  padding: 0 12px; border-radius: 10px; white-space: nowrap;
  display: flex; align-items: center; gap: 11px; width: 100%;
  text-align: start;
  transition: background .15s, color .15s;
}
.tab > span:first-of-type { flex: 1; }
.tab:hover { background: var(--side-hover); color: #fff; }
.tab:focus-visible { outline: 2px solid #4A7FE0; outline-offset: -2px; }
.tab.is-active { background: #1040B0; color: #fff; box-shadow: 0 6px 18px rgba(16, 64, 176, .45); }
.tab__badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 20px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.tab.is-active .tab__badge { background: rgba(255,255,255,.28); }

.sidebar > .sync { padding: 0 12px; color: var(--side-ink); }

.sidebar__foot {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0 0; flex: none;
  border-block-start: 1px solid var(--side-line);
}
.side-btn {
  flex: 1; height: 40px; padding: 0 12px; border-radius: 10px;
  display: flex; align-items: center; gap: 10px;
  font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  color: var(--side-ink); background: transparent;
  border: 1px solid var(--side-line);
  transition: background .15s, color .15s;
}
.side-btn:hover { background: var(--side-hover); color: #fff; }

/* شريط الموبايل: يظهر فقط حين تتحوّل القائمة إلى درج */
.mobilebar { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    width: min(280px, 84vw);
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
    z-index: 80;
  }
  .shell.is-menu-open .sidebar { transform: none; }
  .shell.is-menu-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 70;
    background: rgba(6, 12, 24, .45);
  }
  .mobilebar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 40;
    padding: 10px var(--sp);
    padding-top: max(10px, env(safe-area-inset-top));
    background: linear-gradient(90deg, #0A1E47, #0D1117);
    border-block-end: 1px solid rgba(255, 255, 255, .08);
  }
  .mobilebar .icon-btn { background: transparent; border-color: rgba(255,255,255,.16); color: #fff; }
  .app { padding-top: 18px; }
}

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }

/* ═══ عناصر عامة ════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.section-head h2 { font-size: 20px; }
.section-head p { color: var(--ink-2); font-size: 13.5px; margin: 2px 0 0; }

.muted { color: var(--ink-2); }
.tiny { font-size: 12.5px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); cursor: pointer;
  padding: 9px 15px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: filter .15s, background .15s, border-color .15s;
  text-decoration: none;
}
.btn:hover { filter: brightness(.97); border-color: var(--ink-3); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--wa { background: var(--wa); border-color: var(--wa); color: #06301a; }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.input, .select, .textarea {
  font: inherit; font-size: 14px; width: 100%;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .15);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.75; }
.field { display: grid; gap: 5px; }
.field > label { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 460px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-2);
}
.chip--good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.chip--warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip--bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.chip--info { background: var(--info-bg); color: var(--info); border-color: transparent; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.brand-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 3px 9px;
  border-radius: 20px; white-space: nowrap;
  background: color-mix(in srgb, var(--bc) 14%, transparent);
  color: var(--bc);
}
html[data-theme="dark"] .brand-tag { background: color-mix(in srgb, var(--bc) 22%, transparent); filter: brightness(1.25); }

.empty {
  text-align: center; padding: 48px 20px; color: var(--ink-2);
}
.empty__icon {
  width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-3);
  border: 1px solid var(--border);
}

/* الأيقونات: SVG خطي بلون النص. WhatsApp مملوء بلونه الرسمي، إلا جوه زرار ملوّن */
.ic { flex: none; vertical-align: -0.18em; }
.ic-wa { color: var(--wa); }
.btn--wa .ic-wa, .btn--primary .ic-wa { color: inherit; }
h1 > .ic, h2 > .ic, h3 > .ic { vertical-align: -0.14em; margin-inline-end: 6px; }
.tl-type { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }

/* ═══ إحصائيات ══════════════════════════════════════════ */

.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 16px;
}
/* الكروت القابلة للضغط أزرار — من غير ده لون الرقم بيرجع أسود في الوضع الداكن */
button.stat { font: inherit; color: var(--ink); }
.stat__num { font-size: 26px; font-weight: 800; line-height: 1.2; }
.stat__lbl { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }

/* ═══ قائمة العملاء ═════════════════════════════════════ */

.client {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 14px; border-radius: var(--r);
  border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, transform .12s;
}
.client:hover { border-color: var(--accent); }
.client__av {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
  background: color-mix(in srgb, var(--bc) 16%, transparent); color: var(--bc);
}
html[data-theme="dark"] .client__av { filter: brightness(1.3); }
.client__body { flex: 1; min-width: 0; }
.client__name { font-weight: 700; font-size: 15px; }
.client__meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.client__acts { display: flex; gap: 6px; flex: none; }
.client.is-due { border-inline-start: 3px solid var(--warn); }
.client.is-late { border-inline-start: 3px solid var(--bad); }

/* ═══ حملة التواصل ══════════════════════════════════════ */

.queue-card {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); padding: 20px; box-shadow: var(--shadow);
}
.queue-progress {
  height: 7px; border-radius: 20px; background: var(--surface-2);
  overflow: hidden; margin-bottom: 16px;
}
.queue-progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.msg-preview {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px 16px;
  white-space: pre-wrap; word-break: break-word;
  font-size: 14px; line-height: 1.8; max-height: 260px; overflow: auto;
}

/* ═══ نافذة ═════════════════════════════════════════════ */

.modal-bg {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(6, 12, 24, .55); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px;
  animation: fade .15s;
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  width: min(640px, 100%); max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-block-end: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal__head h3 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.modal__head h3 > .ic { color: var(--accent); margin: 0; }
.modal__body { padding: 18px; }
.modal__foot {
  padding: 14px 18px; border-block-start: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-start;
  position: sticky; bottom: 0; background: var(--surface);
}

/* ═══ تنبيهات ═══════════════════════════════════════════ */

.toast-box {
  position: fixed; inset-block-end: 20px; inset-inline-start: 50%;
  transform: translateX(50%); z-index: 200;
  display: grid; gap: 8px; justify-items: center; pointer-events: none;
}
.toast {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--bg);
  padding: 9px 18px; border-radius: 20px;
  font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow-lg);
  animation: rise .2s;
}
.toast--ok > svg { color: var(--good); }
.toast--bad { background: var(--bad); color: #fff; }
.toast.is-out { opacity: 0; transition: opacity .4s; }
@keyframes rise { from { transform: translateY(10px); opacity: 0 } }

/* ═══ التاريخ ═══════════════════════════════════════════ */

.timeline { display: grid; gap: 10px; }
.tl-item {
  display: flex; gap: 10px; font-size: 13px;
  padding-inline-start: 4px;
}
.tl-item__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-top: 8px; flex: none; }
.tl-item__txt { flex: 1; }
.tl-item time { color: var(--ink-3); font-size: 11.5px; display: block; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .input, .filters .select { width: auto; min-width: 130px; }
.filters .grow { min-width: 180px; }

kbd {
  font-family: inherit; font-size: 11px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 6px; color: var(--ink-2);
}

/* ═══ تقويم المحتوى ═════════════════════════════════════ */

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal__head {
  text-align: center; font-size: 12px; font-weight: 700;
  color: var(--ink-2); padding: 6px 0;
}

.cal__cell {
  position: relative;
  min-height: 104px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 6px 4px;
  overflow: hidden;
}
.cal__cell--out { background: transparent; border-color: transparent; min-height: 0; }
.cal__cell.is-today { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(var(--accent-rgb), .18); }

.cal__num { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; }
.cal__cell.is-today .cal__num { color: var(--accent); }

.cal__posts { display: grid; gap: 3px; }

.cal__post {
  display: flex; align-items: center; gap: 4px;
  width: 100%; border: 0; cursor: pointer; font: inherit;
  font-size: 11px; font-weight: 600; text-align: start;
  padding: 3px 5px; border-radius: 6px;
  background: color-mix(in srgb, var(--bc) 12%, transparent);
  color: var(--ink);
}
html[data-theme="dark"] .cal__post { background: color-mix(in srgb, var(--bc) 26%, transparent); }
.cal__post:hover { filter: brightness(1.08); }
.cal__post-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cal__add {
  position: absolute; inset-block-end: 4px; inset-inline-end: 5px;
  width: 20px; height: 20px; border-radius: 6px;
  border: 1px dashed var(--border); background: transparent;
  color: var(--ink-3); cursor: pointer; font-size: 13px; line-height: 1;
  opacity: 0; transition: opacity .12s;
}
.cal__cell:hover .cal__add { opacity: 1; }
.cal__add:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 700px) {
  .cal { gap: 4px; }
  .cal__cell { min-height: 78px; padding: 4px; }
  .cal__head { font-size: 10.5px; }
  .cal__post { font-size: 10px; padding: 2px 4px; }
}

/* ═══ عروض الأسعار ══════════════════════════════════════ */

.quote-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 1000px) { .quote-split { grid-template-columns: 1fr; } }

.quote-preview-wrap { position: sticky; top: 78px; }
/* معاينة العقد / طلب الدفع / الفاتورة: صفحة A4 كاملة في iframe متصغّرة على عرض العمود (js/documents.js) */
.doc-frame { position: relative; overflow: hidden; border-radius: 12px; }
.doc-frame iframe { position: absolute; top: 0; right: 0; width: 860px; border: 0; transform-origin: top right; background: #E9ECF2; }

.qitem {
  display: flex; gap: 6px; align-items: flex-start;
  padding: 8px 0; border-block-end: 1px solid var(--border);
}
.qitem:last-child { border-block-end: 0; }
.qitem__main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.qitem .input { padding: 6px 9px; font-size: 13px; }
.qitem .input.tiny { font-size: 12px; color: var(--ink-2); }

/* ختم حالة الفاتورة (مدفوعة / ملغاة / مسودة) */
.invoice-stamp {
  position: absolute; inset-block-start: 22px; inset-inline-start: 50%; transform: translateX(50%) rotate(-8deg);
  border: 3px solid currentColor; border-radius: 8px; padding: 4px 16px;
  font-size: 20px; font-weight: 800; opacity: .75; pointer-events: none;
}
.invoice-stamp--paid { color: #0f9d58; }
.invoice-stamp--cancelled { color: #d13c3c; }
.invoice-stamp--draft { color: #8a99b0; }

/* المستند نفسه — ألوانه ثابتة (ورق أبيض) في اللايت والدارك */
.quote-doc {
  position: relative;
  background: #fff; color: #16202e;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 26px 26px 20px;
  font-size: 13px; line-height: 1.7;
  box-shadow: var(--shadow);
}

.quote-doc__head {
  display: flex; justify-content: space-between; gap: 16px;
  padding-block-end: 14px; margin-block-end: 16px;
  border-block-end: 3px solid var(--bc);
}
.quote-doc__brand { font-size: 21px; font-weight: 800; color: var(--bc); }
.quote-doc__sub { font-size: 12px; color: #6b7a90; }
.quote-doc__meta { text-align: end; font-size: 12px; color: #4a5a72; }
.quote-doc__title { font-size: 16px; font-weight: 800; color: #16202e; margin-bottom: 3px; }

.quote-doc__to {
  background: #f5f7fb; border-radius: 8px; padding: 9px 13px;
  margin-block-end: 16px; display: flex; gap: 10px; align-items: baseline;
}
.quote-doc__to span { font-size: 11.5px; color: #6b7a90; }
.quote-doc__to strong { font-size: 15px; }

.quote-doc__table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.quote-doc__table th {
  background: var(--bc); color: #fff; font-weight: 700;
  padding: 8px 10px; text-align: start; font-size: 12px;
}
.quote-doc__table th:first-child { border-start-start-radius: 7px; }
.quote-doc__table th:last-child { border-start-end-radius: 7px; }
.quote-doc__table td { padding: 9px 10px; border-block-end: 1px solid #e8edf5; vertical-align: top; }
.quote-doc__desc { font-size: 11.5px; color: #6b7a90; margin-top: 2px; }

.quote-doc__totals {
  margin-block-start: 14px; margin-inline-start: auto;
  width: min(280px, 100%); display: grid; gap: 5px;
}
.quote-doc__totals > div { display: flex; justify-content: space-between; font-size: 13px; }
.quote-doc__totals .is-grand {
  border-block-start: 2px solid var(--bc); margin-block-start: 5px; padding-block-start: 7px;
  font-size: 16px; font-weight: 800; color: var(--bc);
}
.quote-doc__totals .tiny { font-size: 11.5px; color: #6b7a90; }

.quote-doc__notes {
  margin-block-start: 18px; padding: 11px 13px;
  background: #f5f7fb; border-radius: 8px;
  font-size: 11.5px; color: #4a5a72; white-space: pre-wrap;
}

.quote-doc__foot {
  margin-block-start: 18px; padding-block-start: 11px;
  border-block-start: 1px solid #e8edf5;
  display: flex; justify-content: space-between;
  font-size: 11.5px; color: #6b7a90;
}

/* ═══ حقل باسورد قابل للإظهار ═══════════════════════════ */

.pw-field { position: relative; }
.pw-field .input { padding-inline-end: 38px; }
.pw-toggle {
  position: absolute; inset-inline-end: 6px; inset-block-start: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px; border: 0; background: transparent;
  color: var(--ink-3); cursor: pointer; display: grid; place-items: center;
  border-radius: 7px;
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }

details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

/* ═══ التقارير ══════════════════════════════════════════ */

.report__sec { margin-top: 22px; break-inside: avoid; }
.report__sec h3 { font-size: 16px; margin: 0 0 4px; }
.report__sec > p { margin: 0 0 8px; }
.rtable-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.rtable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.rtable th, .rtable td { padding: 8px 12px; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rtable th { background: var(--surface-2); font-weight: 700; color: var(--ink-2); font-size: 12.5px; }
.rtable td.n { font-variant-numeric: tabular-nums; }
.rtable tbody tr:last-child td { border-bottom: 0; }
.rtable tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 700; }
.print-only { display: none; }
.report__head h1 { font-size: 20px; margin: 0 0 4px; }
.report__head p { margin: 0 0 14px; color: #555; }

/* ═══ الطباعة — المستند فقط ══════════════════════════════ */

@media print {
  .sidebar, .mobilebar, .scrim, .no-print, .toast-box, .modal-bg, .auth-split { display: none !important; }
  /* الورقة بيضا دايمًا: ألوان الوضع الفاتح حتى لو الشاشة داكنة */
  html[data-theme="dark"] {
    --accent: #1040b0; --bg: #fff; --surface: #fff; --surface-2: #f7f9fc;
    --ink: #0d1b34; --ink-2: #5a6b85; --ink-3: #8a99b0; --border: #e2e8f2;
    --good: #0f9d58; --warn: #c77700; --bad: #d13c3c; --info: #1040b0;
  }
  .shell { display: block; }
  body { background: #fff; }
  .app { max-width: none; padding: 0; }
  .quote-split { display: block; }
  .quote-form { display: none !important; }
  .quote-preview-wrap { position: static; }
  .quote-doc { border: 0; border-radius: 0; box-shadow: none; padding: 0; }
  .print-only { display: block; }
  .report .stat, .rtable-wrap { border-color: #ccc; background: #fff; box-shadow: none; }
  .report .stat__num { font-size: 20px; }
  .rtable th { background: #f2f2f2; color: #333; }
  .rtable td, .rtable th { white-space: normal; }
  .report .grid-4 { grid-template-columns: repeat(4, 1fr); }
  @page { margin: 14mm; }
}

/* ═══ مبدّل الأقسام داخل التبويب (المفكرة) ══════════════ */

.seg {
  display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.seg > button {
  border: 0; background: transparent; cursor: pointer; font: inherit;
  font-weight: 600; color: var(--ink-2); padding: 7px 16px; border-radius: 9px;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.seg > button:hover { color: var(--ink); }
.seg > button.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.seg--page { display: flex; width: fit-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg--page::-webkit-scrollbar { display: none; }

.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); }
@media (max-width: 460px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.sec-title { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.sec-title > span { display: inline-grid; }
.due-fold > summary { cursor: pointer; }
.due-fold > summary::after {
  content: ""; width: 7px; height: 7px; margin-inline-start: auto;
  border-inline-end: 2px solid var(--ink-3); border-block-end: 2px solid var(--ink-3);
  transform: rotate(45deg); transition: transform .15s;
}
.due-fold[open] > summary::after { transform: rotate(-135deg); }

.acct { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.acct__who { display: flex; align-items: center; gap: 12px; }
.acct__av {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--info-bg); color: var(--info);
}

/* ═══ إضافة سريعة ═══════════════════════════════════════ */

.quick-add { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.quick-add .input { min-width: 160px; }

/* ═══ مربع الإنجاز ══════════════════════════════════════ */

.check-box {
  width: 22px; height: 22px; flex: none; margin-top: 2px;
  border: 2px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--on-accent);
  cursor: pointer; display: grid; place-items: center; padding: 0;
  transition: background .15s, border-color .15s;
}
.check-box:hover { border-color: var(--accent); }
.check-box.is-on { background: var(--good); border-color: var(--good); }

.client__name.is-done,
.deliv__txt.is-done { text-decoration: line-through; color: var(--ink-3); font-weight: 600; }

/* ═══ شريط التقدّم ══════════════════════════════════════ */

.bar { height: 7px; border-radius: 20px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ═══ بنود التسليم وقوائم المشروع ═══════════════════════ */

.deliv {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.deliv:last-child { border-bottom: 0; }
.deliv__txt { flex: 1; min-width: 0; font-size: 14px; line-height: 1.6; }
.deliv__txt a { color: var(--accent); text-decoration: none; }
.deliv__txt a:hover { text-decoration: underline; }
.deliv > svg { flex: none; margin-top: 3px; color: var(--ink-3); }

/* ═══ حافظة الروابط ═════════════════════════════════════ */

.link-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.link-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border-radius: var(--r);
  border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s;
}
.link-card:hover { border-color: var(--accent); }
.link-card.is-pinned { border-inline-start: 3px solid var(--accent); }
.link-card__top { display: flex; gap: 8px; align-items: flex-start; }
.link-card__title {
  font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-card__url {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--accent); text-decoration: none;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-card__url:hover { text-decoration: underline; }
.link-card__note {
  margin: 0; font-size: 13px; line-height: 1.7; color: var(--ink-2);
  white-space: pre-wrap; word-break: break-word;
}
.link-card__meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.link-card__acts { display: flex; gap: 6px; margin-top: auto; padding-top: 4px; }

/* ═══ تسجيل الدخول ══════════════════════════════════════ */
/* نصّين زي نظام صلة: النموذج بلون الثيم، واللوحة كحلي ثابت بهوية Level Up.
   ثابتة فوق كل حاجة (القائمة والشريط) لحد ما الدخول يخلص. */

.auth-split {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: stretch;
  background: var(--bg); overflow: auto;
}
.auth-main {
  position: relative; flex: 1 1 50%; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 48px 28px;
}
.auth-theme { position: absolute; inset-block-start: 18px; inset-inline-end: 18px; }
.auth-form { width: 100%; max-width: 400px; }
.auth-title { font-size: 30px; font-weight: 800; line-height: 1.3; margin: 0; }
.auth-sub { margin: 6px 0 26px; color: var(--ink-2); font-size: 15px; line-height: 1.8; }
.auth-foot { margin: 22px 0 0; text-align: center; font-size: 13px; color: var(--ink-2); }
.input--lg { padding: 12px 14px; font-size: 15px; border-radius: 12px; }
.btn--lg { padding: 12px 18px; font-size: 15px; border-radius: 12px; margin-top: 6px; }
.auth-wait { display: grid; justify-items: center; text-align: center; gap: 14px; }
.auth-wait .auth-sub { margin: 0 0 6px; }
.auth-ring {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(var(--accent-rgb), .18); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-side {
  position: relative; flex: 1 1 50%; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between; gap: 32px;
  padding: 52px 60px 36px;
  color: #fff;
  background:
    radial-gradient(70% 55% at 0% 100%, rgba(16, 64, 176, .55), transparent 65%),
    radial-gradient(60% 50% at 100% 0%, rgba(74, 127, 224, .22), transparent 60%),
    linear-gradient(160deg, #0A1E47 0%, #0D1117 100%);
  border-inline-start: 1px solid rgba(74, 127, 224, .22);
}
/* نقش نقط خفيف */
.auth-side::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, .9) 1px, transparent 1.4px);
  background-size: 26px 26px; opacity: .06;
}
.auth-side > * { position: relative; }
.auth-logo { display: block; width: 190px; height: auto; }
.auth-hero { max-width: 34rem; }
.auth-hero h1 { margin: 0; font-weight: 800; line-height: 1.4; font-size: clamp(28px, 3vw, 44px); }
.auth-hero h1 em {
  font-style: normal;
  background: linear-gradient(135deg, #4A7FE0, #fff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.auth-lead { margin: 16px 0 0; font-size: 16.5px; line-height: 1.9; color: rgba(255, 255, 255, .74); }
.auth-ticks { list-style: none; margin: 26px 0 0; padding: 0; display: grid; gap: 13px; }
.auth-ticks li { display: flex; align-items: flex-start; gap: 12px; font-size: 15px; line-height: 1.7; color: rgba(255, 255, 255, .9); }
.auth-ticks li::before {
  content: ""; flex: none; width: 12px; height: 7px; margin-top: .6em;
  border-left: 2px solid #4A7FE0; border-bottom: 2px solid #4A7FE0; transform: rotate(-45deg);
}
.auth-quote {
  margin: 30px 0 0; padding: 14px 18px; border-radius: 14px;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .09);
  border-inline-start: 3px solid #1040B0;
}
.auth-quote figcaption { font-size: 12px; font-weight: 700; letter-spacing: .02em; color: #4A7FE0; }
.auth-quote blockquote { margin: 4px 0 0; font-size: 16px; font-weight: 700; line-height: 1.7; }
.auth-copy { font-size: 12.5px; color: rgba(255, 255, 255, .5); }

@media (max-width: 860px) {
  .auth-split { flex-direction: column; }
  .auth-side { order: -1; flex: none; gap: 14px; padding: 22px 22px 24px;
    border-inline-start: 0; border-block-end: 1px solid rgba(74, 127, 224, .22); }
  .auth-logo { width: 130px; }
  .auth-hero h1 { font-size: 22px; }
  .auth-lead, .auth-ticks, .auth-quote, .auth-copy { display: none; }
  .auth-main { flex: 1 0 auto; align-items: flex-start; padding: 30px 20px 40px; }
  .auth-theme { inset-block-start: 12px; inset-inline-end: 12px; }
  .auth-title { font-size: 25px; }
}

/* بطاقات الدخول القديمة — لسه بيستخدمها قفل PIN الوصية (pin-lock.js) */
.auth { min-height: 60vh; display: grid; place-items: center; padding: 24px 0; }
.auth__card { width: min(400px, 100%); }
.auth__card h2 { margin: 6px 0 4px; font-size: 22px; }
.auth__logo {
  width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 50%;
  display: grid; place-items: center; color: var(--accent);
  background: rgba(var(--accent-rgb), .1);
}
.auth__mark { display: block; margin: 0 auto 4px; border-radius: 14px; }

/* ═══ حالة الحفظ أونلاين ════════════════════════════════ */

.sync {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.sync > i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.sync.is-saved > i { background: var(--good); }
.sync.is-saving > i { background: var(--warn); animation: syncPulse 1s ease-in-out infinite; }
.sync.is-error { color: var(--bad); }
.sync.is-error > i { background: var(--bad); }
@keyframes syncPulse { 50% { opacity: .35; } }

/* ═══ نموذج العميل الموسّع ══════════════════════════════ */

.form-sec {
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 10px 14px; margin-top: 10px; background: var(--surface-2);
}
.form-sec > summary {
  font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px;
}
.form-sec > summary::before {
  content: ""; width: 7px; height: 7px; flex: none;
  border-inline-end: 2px solid var(--ink-3); border-block-end: 2px solid var(--ink-3);
  transform: rotate(135deg); transition: transform .15s;
}
.form-sec[open] > summary::before { transform: rotate(45deg); }
.form-sec[open] { padding-bottom: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-toggle {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  padding: 4px 11px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2);
}
.chip-toggle.is-on { background: var(--info-bg); color: var(--info); border-color: var(--accent); }

.check-line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.check-line input { width: 17px; height: 17px; accent-color: var(--accent); }

.auto-info {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  padding: 10px 12px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--r);
  font-size: 13px; font-weight: 700;
}
.auto-info small { display: block; font-size: 11px; font-weight: 600; color: var(--ink-3); }

.imp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; font-weight: 600; }

.pay-add { display: grid; grid-template-columns: 140px 110px 130px 130px 1fr auto; gap: 8px; align-items: center; }
@media (max-width: 760px) { .pay-add { grid-template-columns: 1fr 1fr; } }

/* ═══ الموظفين — تنبيهات الملكية في نموذج العميل ═══════════ */
.notice {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; margin-bottom: 14px; border-radius: var(--r);
  background: var(--info-bg); color: var(--info);
  font-size: 13.5px; font-weight: 600;
}
.notice svg { flex: none; }
.notice--warn { background: var(--warn-bg); color: var(--warn); }

/* ═══ تراخيص صلة ═════════════════════════════════════════ */
.lic { padding: 16px; }
.lic.is-dim { opacity: .7; }
.lic.is-busy { opacity: .6; pointer-events: none; }
.lic__top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px; }
.lic__name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lic__name strong { font-size: 16px; }
.lic__name > div { flex-basis: 100%; }
.lic__facts { display: flex; flex-wrap: wrap; gap: 8px 22px; font-weight: 700; }
.lic__facts small { display: block; font-size: 11px; font-weight: 600; color: var(--ink-3); }
.lic .stepper { display: inline-flex; align-items: center; gap: 8px; }
.lic .stepper .icon-btn { width: 28px; height: 28px; font-weight: 800; }
.lic .stepper .icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.lic__foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.lic code { font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.lic__login {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--r);
}
.lic__creds { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: 13px; font-weight: 600; }
.lic__creds small { display: block; font-size: 11px; color: var(--ink-3); }
.lic-group { margin-bottom: 26px; }
.lic-group__head { display: flex; align-items: center; gap: 8px; }
.lic-group__head h3 { margin: 0; font-size: 17px; }
.lic-group > .tiny { margin: 4px 0 10px; }
.lic-group__empty { padding: 14px; border: 1px dashed var(--border); border-radius: var(--r); margin: 0; }

/* ═══ قفل PIN الوصية ═════════════════════════════════════ */
.pin-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; margin-bottom: 16px;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--r);
}
.pin-bar svg { vertical-align: -2px; }
.pin-input { text-align: center; letter-spacing: .5em; font-size: 20px; font-weight: 800; }
