/* نظام إدارة المكتب المحاسبي — الطابع: كحلي داكن مع أزرق، بطاقات مستديرة */
:root, :root[data-theme="dark"] {
  --bg: #12132A;
  --frame: #1B1C33;
  --card: #25263D;
  --card-2: #2E3050;
  --card-3: #36395E;
  --spark-bg: #1E1F36;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .15);
  --text: #F4F5FB;
  --muted: #A3A6C2;
  --faint: #7C7F9E;
  --primary: #4264E6;
  --primary-h: #5475F0;
  --primary-soft: rgba(95, 127, 245, .18);
  --on-primary: #FFFFFF;
  --on-primary-muted: rgba(255, 255, 255, .78);
  --track: rgba(255, 255, 255, .1);
  --ring-a: #F272C1;
  --ring-b: #F7A072;
  --chart-1: #5F7FF5;
  --chart-2: #CF7A3F;
  --chart-3: #0F9D8E;
  --chart-4: #B765D6;
  --good: #3FD9A9; --good-bg: rgba(63, 217, 169, .14);
  --warn: #F5BC63; --warn-bg: rgba(245, 188, 99, .14);
  --bad: #FF8A95; --bad-bg: rgba(255, 106, 122, .15);
  --info: #94ADFF; --info-bg: rgba(126, 155, 255, .16);
  --violet: #C9A2F5; --violet-bg: rgba(185, 140, 240, .16);
  --neutral: #B3B6CE; --neutral-bg: rgba(255, 255, 255, .08);
  --danger: #E5485D;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #DFE3F2;
  --frame: #F2F4FB;
  --card: #FFFFFF;
  --card-2: #EEF1FA;
  --card-3: #E2E6F5;
  --spark-bg: #F1F3FB;
  --line: rgba(27, 30, 60, .09);
  --line-2: rgba(27, 30, 60, .18);
  --text: #1B1D35;
  --muted: #5C6080;
  --faint: #767A99;
  --primary: #3F62E0;
  --primary-h: #3253CB;
  --primary-soft: rgba(63, 98, 224, .11);
  --track: rgba(27, 30, 60, .1);
  --ring-a: #D23C9B;
  --ring-b: #E47B3E;
  --chart-1: #3F62E0;
  --chart-2: #C8622A;
  --chart-3: #0B8F80;
  --chart-4: #A945C8;
  --good: #067A5B; --good-bg: rgba(6, 122, 91, .1);
  --warn: #8F5A00; --warn-bg: rgba(200, 130, 10, .13);
  --bad: #C42339; --bad-bg: rgba(196, 35, 57, .09);
  --info: #2F50C8; --info-bg: rgba(63, 98, 224, .1);
  --violet: #7C3AB5; --violet-bg: rgba(124, 58, 181, .1);
  --neutral: #565A78; --neutral-bg: rgba(27, 30, 60, .07);
  --danger: #D32F45;
  --shadow: 0 18px 50px rgba(40, 50, 100, .18);
  color-scheme: light;
}

:root[data-theme="light"] .topbar .search-input,
:root[data-theme="light"] .topbar .branch-select,
:root[data-theme="light"] .topbar .branch-chip,
:root[data-theme="light"] .topbar .icon-btn { background: var(--card); }
:root[data-theme="light"] .topbar .icon-btn:hover { background: var(--card-2); }
:root[data-theme="light"] .topbar .role-switch,
:root[data-theme="light"] .topbar .theme-switch { background: var(--card); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 2px solid var(--primary-h); outline-offset: 2px; }
.ic { flex: none; display: block; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; display: inline-block; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.money small { font-size: .72em; color: var(--muted); font-weight: 500; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ===== الإطار العام ===== */
.app {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  background: var(--frame);
  padding: 16px;
}
.rail {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  background: var(--primary);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 18px 8px 12px;
  color: var(--on-primary);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail-logo { display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; font-size: 13px; line-height: 1.2; text-align: center; margin-bottom: 18px; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.rail-item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 7px;
  border-radius: 13px;
  color: var(--on-primary-muted);
  font-size: 11.5px; font-weight: 500;
  border: 0; background: none; width: 100%;
  transition: background .15s, color .15s;
}
.rail-item:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.rail-item.active { background: rgba(255, 255, 255, .22); color: #fff; }
.rail-item .badge { position: absolute; top: 4px; left: 16px; }
.rail-foot { margin-top: 10px; }
.badge { min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px; background: #F0566C; color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }

.shell { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; min-width: 0; }
.shell.has-side { grid-template-columns: minmax(0, 1fr) 318px; }
.center { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* الشريط العلوي */
.topbar { display: flex; align-items: center; gap: 10px; }
.global-search { position: relative; flex: 1; max-width: 560px; }
.search-input { display: flex; align-items: center; gap: 8px; background: var(--card-2); border-radius: 12px; padding: 0 12px; height: 42px; color: var(--muted); border: 1px solid transparent; }
.search-input:focus-within { border-color: var(--primary-h); }
.search-input input { background: none; border: 0; outline: 0; flex: 1; min-width: 0; height: 100%; color: var(--text); }
.search-input input::placeholder { color: var(--muted); }
.search-input input::-webkit-search-cancel-button { display: none; }
.topbar-end { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.branch-select { background: var(--card-2); border: 1px solid transparent; border-radius: 12px; height: 42px; padding: 0 12px; max-width: 220px; }
.branch-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card-2); border-radius: 12px; height: 42px; padding: 0 12px; color: var(--muted); white-space: nowrap; }
.icon-btn {
  position: relative;
  width: 42px; height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--card-2);
  border: 0; color: var(--text);
  transition: background .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--card-3); }
.icon-btn.ghost { background: none; width: 34px; height: 34px; color: var(--muted); }
.icon-btn.ghost:hover:not(:disabled) { background: var(--neutral-bg); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn .badge { position: absolute; top: -4px; left: -4px; }
.me-link { display: flex; }

/* اختيار المظهر: نفس الشكل خارج السستم وداخله */
.theme-switch { display: inline-flex; gap: 2px; background: var(--card-2); border-radius: 12px; padding: 3px; height: 42px; flex: none; }
.theme-switch button { display: inline-flex; align-items: center; gap: 5px; height: 100%; padding: 0 10px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* تبديل الصلاحية داخل السستم */
.role-switch { display: inline-flex; align-items: center; gap: 6px; height: 42px; padding-inline-start: 12px; background: var(--card-2); border-radius: 12px; color: var(--info); flex: none; }
.role-switch select { background: none; border: 0; min-height: 0; height: 100%; width: auto; max-width: 165px; padding: 0 4px 0 8px; color: var(--text); text-overflow: ellipsis; }

.popover {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0;
  width: 370px; max-width: calc(100vw - 32px); max-height: 460px; overflow: auto;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 16px;
  box-shadow: var(--shadow); z-index: 40; padding: 8px;
}
.global-search .popover { inset-inline: 0; width: auto; }
.popover-title { padding: 8px 10px; font-weight: 600; }
.pop-group { padding: 8px 10px 2px; font-size: 12px; color: var(--muted); }
.pop-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border-radius: 10px; }
.pop-item:hover, .pop-item:focus-visible { background: var(--card-2); }
.pop-item > .ic { margin-top: 2px; color: var(--muted); }
.pop-item.danger > .ic { color: var(--bad); }
.pop-item.warning > .ic { color: var(--warn); }
.pop-item.info > .ic { color: var(--info); }
.pop-item div { min-width: 0; }
.pop-item strong { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-item span { display: block; font-size: 12px; color: var(--muted); }

/* شريط الصفحة والتنقل الفرعي */
.pagebar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pagebar h1 { font-size: 21px; font-weight: 700; }
.subnav { display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 12px; overflow-x: auto; scrollbar-width: none; }
.subnav a { padding: 6px 14px; border-radius: 9px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.subnav a:hover { color: var(--text); background: var(--neutral-bg); }
.subnav a.active { background: var(--primary); color: #fff; }
.view-page { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ===== البطاقات ===== */
.card { background: var(--card); border-radius: 16px; padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.card-title.strong { color: var(--text); font-size: 15px; }
.grid { display: grid; gap: 16px; }
.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)); }
.span-all { grid-column: 1 / -1; }

/* البانر الترحيبي */
.hero {
  position: relative; overflow: hidden;
  background: var(--primary);
  color: #fff;
  border-radius: 18px;
  min-height: 186px;
  padding: 22px 28px;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.hero-art { position: absolute; inset-block: 0; left: 0; width: 66%; height: 100%; pointer-events: none; }
.hero > *:not(.hero-art) { position: relative; z-index: 1; }
.hero-date { align-self: flex-start; display: inline-flex; align-items: center; gap: 7px; background: rgba(255, 255, 255, .17); border-radius: 9px; padding: 5px 11px; font-size: 12.5px; margin-bottom: 14px; }
.hero h2 { font-size: 27px; font-weight: 700; line-height: 1.25; }
.hero p { color: rgba(255, 255, 255, .85); }

/* بطاقات المؤشرات */
.kpi { display: flex; flex-direction: column; gap: 12px; transition: transform .15s, background .15s; }
a.kpi:hover { background: var(--card-2); }
.kpi-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-body { display: flex; gap: 14px; align-items: stretch; }
.kpi-spark { flex: 0 0 96px; height: 80px; background: var(--spark-bg); border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--chart-1); }
.kpi-values { min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; flex: 1; }
.kpi-value { font-size: 22px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-label { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.delta { align-self: flex-start; display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; padding: 2px 7px; border-radius: 7px; margin-top: 4px; }
.delta.good { background: var(--good-bg); color: var(--good); }
.delta.bad { background: var(--bad-bg); color: var(--bad); }

/* الحلقة */
.donut { position: relative; flex: none; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-center strong { font-size: 32px; font-weight: 700; line-height: 1.1; }
.donut-center small { font-size: 15px; font-weight: 500; }
.donut-center span { font-size: 11.5px; color: var(--muted); }
.donut-row { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; justify-content: center; }
.mini-stats { flex: 1; min-width: 150px; background: var(--card-2); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.mini-stats div { display: flex; flex-direction: column; }
.mini-stats strong { font-size: 19px; font-weight: 700; line-height: 1.2; }
.mini-stats span { font-size: 12px; color: var(--muted); }
.select-pill { background: var(--primary); color: #fff; border-radius: 9px; padding: 4px 12px; font-size: 12.5px; font-weight: 500; white-space: nowrap; }

/* أشرطة الخطة */
.plan { display: flex; flex-direction: column; gap: 16px; }
.plan-row-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.plan-track { height: 5px; background: var(--track); border-radius: 4px; overflow: hidden; }
.plan-fill { display: block; height: 100%; border-radius: 4px; }
.dashed-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; padding: 11px; border: 1px dashed var(--line-2); border-radius: 12px; background: none; color: var(--info); font-weight: 500; }
.dashed-btn:hover { background: var(--primary-soft); }

/* الملف الشخصي */
.head-card { background: var(--card); border-radius: 16px; overflow: hidden; }
.head-card-top { background: var(--primary); color: #fff; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 54px; }
.head-card-top h3 { font-size: 13px; font-weight: 600; }
.head-card-top .icon-btn { background: rgba(255, 255, 255, .2); color: #fff; }
.head-card-top .icon-btn:hover { background: rgba(255, 255, 255, .3); }
.head-card-top select { background: rgba(255, 255, 255, .2); color: #fff; border: 0; border-radius: 9px; padding: 5px 8px; font-size: 13px; }
.head-card-top select option { color: #1B1D35; background: #fff; }
.profile-main { display: flex; gap: 14px; align-items: center; padding: 16px; }
.profile-main h4 { font-size: 16px; font-weight: 700; line-height: 1.3; }
.profile-main .role { font-size: 12.5px; color: var(--muted); }
.profile-main .loc { display: flex; gap: 4px; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.profile-main .loc .ic { color: var(--info); }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); padding: 12px 8px; text-align: center; }
.profile-stats div { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 0 4px; }
.profile-stats div + div { border-inline-start: 1px solid var(--line); }
.profile-stats span { font-size: 11px; color: var(--muted); }
.profile-stats strong { font-size: 12.5px; font-weight: 600; }
.profile-actions { display: flex; gap: 8px; padding: 0 16px 16px; }
.profile-actions .btn { flex: 1; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--info); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; font-size: 13px; word-spacing: -2px; }
.avatar.lg { width: 76px; height: 76px; font-size: 22px; background: linear-gradient(145deg, #7E9BFF, #4264E6); color: #fff; box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--primary-h); }
.avatar.sm { width: 26px; height: 26px; font-size: 10px; }
.person { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }

/* التقويم الجانبي */
.week { display: grid; grid-template-columns: 24px repeat(7, 1fr) 24px; gap: 1px; padding: 0 6px 12px; background: var(--primary); color: #fff; }
.week-nav { background: none; border: 0; color: rgba(255, 255, 255, .8); padding: 0; display: flex; align-items: center; justify-content: center; }
.week-nav:hover { color: #fff; }
.week-day { background: none; border: 0; color: rgba(255, 255, 255, .78); border-radius: 11px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.500px; min-width: 0; }
.week-day b { font-size: 14px; font-weight: 600; color: #fff; }
.week-day:hover { background: rgba(255, 255, 255, .12); }
.week-day.active { background: rgba(255, 255, 255, .26); color: #fff; }
.week-day.today:not(.active) b { text-decoration: underline; text-underline-offset: 3px; }
.day-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.day-list { padding: 0 8px 10px; max-height: 330px; overflow-y: auto; }
.day-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; font-size: 13px; width: 100%; background: none; border: 0; text-align: start; }
button.day-item:hover, a.day-item:hover { background: var(--card-2); }
.day-time { flex: 0 0 56px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.meeting { background: var(--ring-a); }
.dot.visit { background: var(--chart-1); }
.dot.deadline { background: var(--bad); }
.dot.consultation { background: var(--good); }
.dot.other { background: var(--neutral); }
.dot.task { background: var(--warn); }
.day-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== الأزرار والنماذج ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  background: var(--card-2); border: 0; font-weight: 500; white-space: nowrap;
  transition: background .15s;
}
.btn:hover:not(:disabled) { background: var(--card-3); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-h); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn.good { background: var(--good-bg); color: var(--good); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }

input:not([type=checkbox]):not([type=file]), select, textarea {
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 11px;
  min-height: 38px;
  width: 100%;
  outline: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary-h); }
.search-input input { min-height: 0; border: 0; padding: 0; }
select { cursor: pointer; }
select option { background: var(--card); color: var(--text); }
input[type=date], input[type=month], input[type=time] { direction: ltr; text-align: right; }
input[type=number] { direction: ltr; text-align: right; }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field.span-2, .form-section.span-2 { grid-column: 1 / -1; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; }
.req { color: var(--bad); }
.input-suffix { position: relative; }
.input-suffix input { padding-inline-start: 44px; }
.input-suffix span { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
.form-section { font-size: 13px; font-weight: 600; color: var(--info); border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-top: 6px; }
.form-error { margin-top: 12px; background: var(--bad-bg); color: var(--bad); padding: 9px 12px; border-radius: 10px; font-size: 13px; }
.form-intro { color: var(--muted); margin-bottom: 14px; }

/* النوافذ */
dialog.modal {
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--text);
  border-radius: 18px;
  padding: 0;
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  box-shadow: var(--shadow);
}
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal.sm { width: min(430px, calc(100vw - 24px)); }
dialog.modal.lg { width: min(860px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(8, 9, 24, .62); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); }
.confirm-msg { line-height: 1.8; }

/* التنبيهات */
#toasts { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 2147483000; max-width: calc(100vw - 40px); }
.toast { display: flex; align-items: center; gap: 8px; background: var(--card-3); color: var(--text); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); max-width: 420px; animation: toast-in .2s ease; border-inline-start: 3px solid var(--good); }
.toast.bad { border-inline-start-color: var(--bad); }
.toast.out { opacity: 0; transition: opacity .25s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ===== الجداول ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .search-input { width: 240px; height: 38px; border-radius: 10px; }
.toolbar select { width: auto; max-width: 180px; }
.toolbar-end { display: flex; gap: 8px; margin-inline-start: auto; flex-wrap: wrap; }
.filter-date { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.filter-date input { width: 140px; }
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: 12px; font-weight: 600; color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--card); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; border-top: 1px solid var(--line-2); border-bottom: 0; }
.table .n { text-align: end; white-space: nowrap; }
.link-row { cursor: pointer; }
.link-row:hover td, .table tbody tr:hover td { background: rgba(127, 135, 200, .07); }
.th-sort { background: none; border: 0; padding: 0; color: inherit; font-weight: inherit; font-size: inherit; display: inline-flex; align-items: center; gap: 3px; }
.th-sort:hover { color: var(--text); }
.cell-main { font-weight: 500; display: block; }
.cell-sub { font-size: 12px; color: var(--muted); display: block; }
.table td a.cell-link:hover { color: var(--info); text-decoration: underline; }
.pager { display: flex; justify-content: space-between; align-items: center; min-height: 32px; font-size: 13px; }
.pager-btns { display: inline-flex; align-items: center; gap: 8px; }
.pager .icon-btn { width: 32px; height: 32px; border-radius: 9px; }
.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 8px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.violet { background: var(--violet-bg); color: var(--violet); }
.pill.neutral { background: var(--neutral-bg); color: var(--neutral); }
.is-bad { color: var(--bad); }
.is-good { color: var(--good); }
.is-warn { color: var(--warn); }

/* المظهر الفاتح: حدود واضحة للحقول والأزرار على الخلفية الفاتحة */
:root[data-theme="light"] input:not([type=checkbox]):not([type=file]),
:root[data-theme="light"] select,
:root[data-theme="light"] textarea { border-color: var(--line-2); background: var(--card); }
:root[data-theme="light"] .search-input { border-color: var(--line-2); background: var(--card); }
:root[data-theme="light"] .search-input input { border: 0; }
:root[data-theme="light"] .btn:not(.primary):not(.danger):not(.good) { background: var(--card); box-shadow: inset 0 0 0 1px var(--line-2); }
:root[data-theme="light"] .btn:not(.primary):not(.danger):not(.good):hover:not(:disabled) { background: var(--card-2); }
:root[data-theme="light"] .role-switch select,
:root[data-theme="light"] .head-card-top select { border: 0; background: none; }
:root[data-theme="light"] .head-card-top select { background: rgba(255, 255, 255, .2); }
:root[data-theme="light"] .input-suffix input { background: var(--card); }
:root[data-theme="light"] input:focus, :root[data-theme="light"] select:focus, :root[data-theme="light"] textarea:focus { border-color: var(--primary-h); }

/* إحصاءات */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 19px; font-weight: 700; line-height: 1.35; }
.stat.inset { background: var(--card-2); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 40px 16px; color: var(--muted); text-align: center; }
.empty strong { color: var(--text); font-weight: 600; }
.empty.compact { padding: 22px 12px; }
.empty.bad .ic { color: var(--bad); }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--track); border-top-color: var(--primary-h); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* التبويبات */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: none; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--info); border-bottom-color: var(--primary-h); }
.tab-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* صفحة التفاصيل */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; align-self: flex-start; }
.back-link:hover { color: var(--text); }
.back-link .ic { transform: scaleX(-1); }
.entity-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.entity-head h2 { font-size: 21px; font-weight: 700; line-height: 1.3; }
.entity-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 13px; margin-top: 4px; align-items: center; }
.entity-meta span { display: inline-flex; gap: 4px; align-items: center; }
.entity-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 18px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: 12px; color: var(--muted); }
.dl dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }

/* الملاحظات */
.note-form { display: flex; gap: 8px; align-items: flex-start; }
.note-form textarea { flex: 1; }
.notes { display: flex; flex-direction: column; gap: 10px; }
.note { background: var(--card-2); border-radius: 12px; padding: 10px 14px; }
.note p { white-space: pre-wrap; overflow-wrap: anywhere; }
.note small { color: var(--muted); display: block; margin-top: 4px; }

/* لوحة المهام */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; align-items: start; padding-bottom: 6px; }
.board-col { background: var(--card); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 240px; transition: background .12s; }
.board-col.drag-over { background: var(--card-3); }
.board-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; padding: 2px 4px 6px; }
.board-count { background: var(--neutral-bg); color: var(--muted); border-radius: 8px; padding: 0 8px; font-size: 12px; }
.task-card { background: var(--card-2); border-radius: 12px; padding: 10px 12px; cursor: grab; display: flex; flex-direction: column; gap: 6px; border: 0; text-align: start; width: 100%; }
.task-card:hover { background: var(--card-3); }
.task-card.dragging { opacity: .45; }
.task-card .t { font-weight: 500; line-height: 1.4; }
.task-card .c { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-card .f { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; }
.segmented { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { background: none; border: 0; border-radius: 8px; height: 32px; padding: 0 11px; display: inline-flex; gap: 5px; align-items: center; color: var(--muted); }
.segmented button.active { background: var(--primary); color: #fff; }

/* تقويم الشهر */
.cal-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cal-head h2 { font-size: 17px; font-weight: 700; min-width: 140px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(92px, 1fr)); gap: 4px; overflow-x: auto; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-cell { background: var(--card-2); border: 0; border-radius: 10px; min-height: 104px; padding: 6px 7px; display: flex; flex-direction: column; gap: 3px; text-align: start; min-width: 0; color: var(--text); }
.cal-cell:hover { background: var(--card-3); }
.cal-cell.other { opacity: .42; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--primary-h); }
.cal-num { font-weight: 600; font-size: 13px; }
.cal-ev { display: flex; align-items: center; gap: 4px; font-size: 11.500px; overflow: hidden; white-space: nowrap; min-width: 0; }
.cal-ev span:last-child { overflow: hidden; text-overflow: ellipsis; }
.cal-more { font-size: 11px; color: var(--muted); }

/* فروع */
.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.branch-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.branch-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; background: var(--card-2); border-radius: 12px; padding: 10px 4px; }
.branch-stats strong { display: block; font-size: 17px; font-weight: 700; line-height: 1.3; }
.branch-stats span { font-size: 11px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.kv span:first-child { color: var(--muted); }

/* الرسوم */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 12px; height: 3px; border-radius: 2px; display: block; }
.line-chart { display: block; overflow: visible; }
.line-chart .grid { stroke: var(--line); stroke-width: 1; }
.line-chart .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.cross-line { stroke: var(--line-2); stroke-width: 1; }
.chart-tip { position: fixed; z-index: 2147483000; background: var(--card-3); color: var(--text); border: 1px solid var(--line-2); padding: 6px 10px; border-radius: 9px; font-size: 12px; pointer-events: none; box-shadow: var(--shadow); max-width: 280px; }
.tip-title { font-weight: 600; margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row i { width: 8px; height: 8px; border-radius: 50%; display: block; flex: none; }
.tip-row b { margin-inline-start: auto; padding-inline-start: 14px; direction: ltr; unicode-bidi: isolate; }
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-track { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-value { min-width: 62px; text-align: end; }

/* تسجيل الدخول */
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); background: var(--frame); }
.login-side { position: relative; display: flex; align-items: center; justify-content: center; padding: 72px 20px 32px; }
.login-theme { position: absolute; top: 20px; inset-inline-start: 20px; }
.login-box { width: min(500px, 100%); display: flex; flex-direction: column; gap: 18px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.role-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.role-card { display: flex; align-items: center; gap: 11px; padding: 11px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; text-align: start; min-width: 0; transition: background .15s, border-color .15s; }
.role-card:hover:not(:disabled) { background: var(--card-2); border-color: var(--primary-h); }
.role-card i { width: 38px; height: 38px; flex: none; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--info); }
.role-text { display: flex; flex-direction: column; min-width: 0; }
.role-text strong { font-size: 13.5px; font-weight: 600; line-height: 1.35; }
.role-text small { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.login-box h1 { font-size: 24px; font-weight: 700; }
.login-art { position: relative; overflow: hidden; background: var(--primary); color: #fff; margin: 16px; margin-inline-start: 0; border-radius: 22px; display: flex; flex-direction: column; justify-content: flex-start; padding: 34px; min-height: 340px; }
.login-art svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.login-art > div { position: relative; }
.login-art h2 { font-size: 24px; font-weight: 700; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.login-brand i { width: 42px; height: 42px; border-radius: 12px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; }

/* وثيقة قابلة للطباعة */
.doc { background: #fff; color: #1B1D35; border-radius: 16px; padding: 32px; max-width: 860px; width: 100%; margin-inline: auto; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; border-bottom: 2px solid #3F62E0; padding-bottom: 16px; margin-bottom: 18px; }
.doc h2 { font-size: 20px; font-weight: 700; color: #3F62E0; }
.doc .label { color: #5C6080; font-size: 12px; }
.doc-title { font-size: 22px; font-weight: 700; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.doc table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.doc th { background: #EEF1FA; text-align: start; padding: 8px 10px; font-size: 12.5px; }
.doc td { padding: 8px 10px; border-bottom: 1px solid #E2E6F5; }
.doc .n { text-align: end; white-space: nowrap; }
.doc .money small { color: #5C6080; }
.doc-totals { margin-inline-start: auto; width: min(320px, 100%); display: flex; flex-direction: column; gap: 5px; }
.doc-totals div { display: flex; justify-content: space-between; }
.doc-totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid #3F62E0; padding-top: 7px; margin-top: 3px; }
.doc-foot { margin-top: 26px; color: #5C6080; font-size: 12.5px; text-align: center; border-top: 1px solid #E2E6F5; padding-top: 12px; }
.doc .pill.good { background: #DDF5EC; color: #067A5B; } .doc .pill.bad { background: #FBE2E6; color: #C42339; }
.doc .pill.warn { background: #FBEFD8; color: #8F5A00; } .doc .pill.info { background: #E4EAFD; color: #2F50C8; }
.doc .pill.neutral { background: #ECEEF6; color: #565A78; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* محرر الفاتورة */
.items-table input, .items-table select { min-width: 74px; }
.items-table td { padding: 6px; border: 0; }
.items-table th { padding: 6px; }
.totals-box { background: var(--card-2); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.totals-box > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.totals-box .grand { font-size: 17px; font-weight: 700; border-top: 1px solid var(--line-2); padding-top: 9px; }
.totals-box input { width: 110px; min-height: 32px; padding: 4px 8px; background: var(--card); flex: none; }
.totals-box label { font-size: 13px; white-space: nowrap; }
.totals-box .field-error { flex-basis: 100%; }
.totals-box > div[data-field] { flex-wrap: wrap; }
tr.voided td { opacity: .55; }

/* مؤشر كلمة المرور المؤقتة */
.secret { display: flex; justify-content: space-between; gap: 10px; align-items: center; background: var(--card-2); border-radius: 10px; padding: 10px 14px; font-size: 18px; font-weight: 600; letter-spacing: .5px; }
.notice { display: flex; gap: 8px; align-items: flex-start; padding: 10px 13px; border-radius: 11px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }

/* ===== الاستجابة للشاشات ===== */
@media (max-width: 1240px) {
  .shell.has-side { grid-template-columns: minmax(0, 1fr); }
  .side { flex-direction: row; flex-wrap: wrap; }
  .side > * { flex: 1 1 300px; }
}
@media (max-width: 1040px) {
  .grid-3.kpis { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .login-page { grid-template-columns: minmax(0, 1fr); }
  .login-art { display: none; }
  .hero-art { width: 52%; opacity: .55; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); padding: 12px 12px 88px; gap: 12px; }
  .rail {
    position: fixed; top: auto; bottom: 0; inset-inline: 0;
    height: auto; flex-direction: row; border-radius: 16px 16px 0 0;
    padding: 6px 6px; z-index: 30; overflow-x: auto;
  }
  .rail-logo { display: none; }
  .rail-nav { flex-direction: row; gap: 2px; }
  .rail-item { flex: 0 0 66px; padding: 6px 2px; font-size: 10.500px; }
  .rail-foot { margin: 0; flex: none; }
  .rail-foot .rail-item { flex-basis: 56px; }
  .topbar { flex-wrap: wrap; }
  .global-search { order: 5; flex-basis: 100%; max-width: none; }
  .topbar-end { margin-inline-start: 0; width: 100%; flex-wrap: wrap; }
  .role-switch { flex: 1 1 100%; }
  .role-switch select { flex: 1; max-width: none; width: 100%; }
  .theme-switch button span { display: none; }
  .login-theme .theme-switch button span { display: inline; }
  .branch-select { flex: 1; max-width: none; min-width: 0; }
  .branch-chip { flex: 1; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field.span-2, .field.span-1 { grid-column: auto; }
  .toolbar .search-input { width: 100%; }
  .toolbar select { flex: 1; max-width: none; min-width: 120px; }
  .toolbar-end { margin-inline-start: 0; width: 100%; }
  .toolbar-end .btn { flex: 1; }
  .hero { padding: 18px; }
  .hero h2 { font-size: 22px; }
  .doc { padding: 18px; }
  .doc-parties { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .table-card { padding: 0; }
  .entity-actions { margin-inline-start: 0; width: 100%; }
  .entity-actions .btn { flex: 1; }
  #toasts { left: 12px; right: 12px; bottom: 84px; }
  /* الجداول تتحول لبطاقات بدلاً من التمرير الأفقي */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr { display: block; width: 100%; }
  .table.stack tr { padding: 8px 0; border-bottom: 1px solid var(--line); }
  .table.stack tbody tr:last-child { border-bottom: 0; }
  .table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 14px; border: 0; text-align: start; min-width: 0; }
  .table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; flex: none; max-width: 40%; }
  .table.stack td:first-child { font-size: 15px; }
  .table.stack td:first-child::before { display: none; }
  .table.stack td > :not(.pill):not(.money) { min-width: 0; }
}

/* ===== الطباعة: الوثيقة أو الجدول فقط ===== */
@media print {
  :root { --card: #fff; --card-2: #fff; --text: #000; --muted: #444; --line: #ccc; --line-2: #999; --frame: #fff; --bg: #fff; color-scheme: light; }
  body { background: #fff; color: #000; font-size: 12px; }
  .app { display: block; padding: 0; background: #fff; }
  .role-switch, .theme-switch, .rail, .topbar, .pagebar, .toolbar, .pager, .no-print, .doc-actions, .back-link, .tabs, .btn, .icon-btn, #toasts { display: none !important; }
  .card, .doc, .stat { border-radius: 0; padding: 0; box-shadow: none; }
  .table th, .table td { padding: 5px 7px; border-bottom: 1px solid #ccc; color: #000; background: #fff; }
  .table-wrap { overflow: visible; }
  .pill { background: none !important; color: #000 !important; padding: 0; }
}

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