/* ==========================================================================
   نظام إدارة الحضانة — التنسيقات (عربي RTL)
   ========================================================================== */

:root {
  --primary: #1e3a8a;
  --primary-600: #1d4ed8;
  --primary-400: #4f8cff;
  --primary-50: #eef4ff;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-2: #cbd5e1;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --slate-bg: #f1f5f9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px -12px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 20px 50px -20px rgba(15, 23, 42, 0.35);
  --sidebar-w: 248px;
  --font: "Segoe UI", Tahoma, "Geneva", Verdana, "Noto Naskh Arabic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

a {
  color: var(--primary-600);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5rem;
  font-weight: 700;
  line-height: 1.35;
}
h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.2rem;
}
h3 {
  font-size: 1.05rem;
}

/* ============================== التخطيط ============================== */

.layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 40;
}

.brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 11px;
  align-items: center;
}
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-400), #8b5cf6);
  display: grid;
  place-items: center;
  font-size: 22px;
  flex: 0 0 42px;
}
.brand-name {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  line-height: 1.3;
}
.brand-sub {
  font-size: 0.72rem;
  color: #94a3b8;
}

.nav {
  padding: 12px 10px;
  flex: 1;
}
.nav-group-title {
  font-size: 0.7rem;
  color: #64748b;
  padding: 12px 12px 6px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  cursor: pointer;
  font-size: 0.93rem;
  margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: linear-gradient(90deg, var(--primary-600), var(--primary-400));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px -8px rgba(79, 140, 255, 0.9);
}
.nav-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
}
.nav-badge {
  margin-inline-start: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  padding: 1px 7px;
  font-weight: 700;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: #94a3b8;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}
.topbar .spacer {
  flex: 1;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.85rem;
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-50);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 34px;
}
.role-tag {
  font-size: 0.72rem;
  background: var(--slate-bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 9px;
}

.content {
  padding: 20px;
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.burger {
  display: none;
  font-size: 1.4rem;
  cursor: pointer;
  background: none;
  border: 0;
  color: var(--primary);
}

/* ============================== البطاقات ============================== */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: 1.02rem;
}
.card-head .spacer {
  flex: 1;
}
.card-body {
  padding: 18px;
}
.card-body.tight {
  padding: 0;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

/* ============================== المؤشرات ============================== */

.kpi {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 13px;
  align-items: center;
}
.kpi-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  background: var(--primary-50);
  color: var(--primary);
  flex: 0 0 46px;
}
.kpi-val {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.15;
}
.kpi-lbl {
  font-size: 0.8rem;
  color: var(--muted);
}
.kpi.green .kpi-icon {
  background: var(--success-bg);
  color: var(--success);
}
.kpi.amber .kpi-icon {
  background: var(--warning-bg);
  color: var(--warning);
}
.kpi.red .kpi-icon {
  background: var(--danger-bg);
  color: var(--danger);
}
.kpi.sky .kpi-icon {
  background: var(--info-bg);
  color: var(--info);
}
.kpi.violet .kpi-icon {
  background: var(--purple-bg);
  color: var(--purple);
}

/* ============================== الأزرار ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border-2);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover:not(:disabled) {
  background: var(--slate-bg);
  border-color: var(--border-2);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary-600);
  border-color: var(--primary-600);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #1e40af;
  border-color: #1e40af;
}
.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #15803d;
}
.btn-danger {
  background: #fff;
  border-color: #fca5a5;
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--slate-bg);
  color: var(--text);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 7px;
}
.btn-icon {
  padding: 6px 9px;
  font-size: 0.95rem;
}
.btn-block {
  width: 100%;
}
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ============================== الحقول ============================== */

.field {
  margin-bottom: 14px;
}
.label {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 5px;
}
.label .req {
  color: var(--danger);
}
.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
  transition: border 0.15s, box-shadow 0.15s;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary-400);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.16);
}
.textarea {
  min-height: 74px;
  resize: vertical;
}
.hint {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 4px;
}
.form-grid {
  display: grid;
  gap: 0 16px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.span-2 {
  grid-column: span 2;
}
@media (max-width: 620px) {
  .span-2 {
    grid-column: span 1;
  }
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters .field {
  margin-bottom: 0;
  min-width: 140px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 0.88rem;
}
.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-600);
  cursor: pointer;
}

/* ============================== الجداول ============================== */

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  min-width: 560px;
}
table.tbl th {
  background: #f8fafc;
  color: #334155;
  text-align: right;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
table.tbl tbody tr:hover {
  background: #f8fafc;
}
table.tbl tbody tr:last-child td {
  border-bottom: 0;
}
table.tbl.compact td,
table.tbl.compact th {
  padding: 6px 8px;
  font-size: 0.8rem;
}
.tbl .num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.right {
  text-align: right;
}
.center {
  text-align: center;
}
.nowrap {
  white-space: nowrap;
}
.small {
  font-size: 0.78rem;
}
.muted {
  color: var(--muted);
}
.bold {
  font-weight: 700;
}
.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.82rem;
  direction: ltr;
  display: inline-block;
}
.link-btn {
  background: none;
  border: 0;
  color: var(--primary-600);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  padding: 2px 4px;
  font-weight: 600;
}
.link-btn:hover {
  text-decoration: underline;
}
.link-btn.danger {
  color: var(--danger);
}

/* ============================== الشارات ============================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}
.chip-present,
.chip-active {
  background: var(--success-bg);
  color: #15803d;
}
.chip-late,
.chip-suspended {
  background: var(--warning-bg);
  color: #b45309;
}
.chip-absent,
.chip-left {
  background: var(--danger-bg);
  color: #b91c1c;
}
.chip-excused {
  background: var(--purple-bg);
  color: #6d28d9;
}
.chip-holiday {
  background: var(--slate-bg);
  color: #475569;
}
.chip-early_leave {
  background: var(--info-bg);
  color: #0369a1;
}
.chip-paid,
.chip-cash,
.chip-transfer,
.chip-card,
.chip-wallet,
.chip-cheque,
.chip-device {
  background: var(--success-bg);
  color: #15803d;
}
.chip-partial {
  background: var(--warning-bg);
  color: #b45309;
}
.chip-unpaid {
  background: var(--danger-bg);
  color: #b91c1c;
}
.chip-gray {
  background: var(--slate-bg);
  color: var(--muted);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-on {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
}
.dot-off {
  background: #cbd5e1;
}
.pin-badge {
  background: var(--primary-50);
  color: var(--primary);
  border: 1px solid #dbeafe;
  border-radius: 7px;
  padding: 1px 8px;
  font-weight: 700;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  direction: ltr;
  display: inline-block;
}

/* ============================== النافذة المنبثقة ============================== */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 18px;
  animation: fade 0.15s ease;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease;
}
@keyframes pop {
  from {
    transform: translateY(10px) scale(0.98);
    opacity: 0;
  }
}
.modal.wide {
  max-width: 900px;
}
.modal.narrow {
  max-width: 440px;
}
.modal-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}
.modal-head .spacer {
  flex: 1;
}
.modal-close {
  background: none;
  border: 0;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
}
.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 9px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

/* ============================== التنبيهات ============================== */

.toasts {
  position: fixed;
  bottom: 20px;
  inset-inline-start: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: 380px;
}
.toast {
  background: #fff;
  border-radius: 11px;
  padding: 12px 15px;
  box-shadow: var(--shadow-lg);
  border-inline-start: 4px solid var(--primary-400);
  font-size: 0.88rem;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn {
  from {
    transform: translateX(-24px);
    opacity: 0;
  }
}
.toast.ok {
  border-color: var(--success);
}
.toast.err {
  border-color: var(--danger);
}
.toast.warn {
  border-color: var(--warning);
}
.toast .ico {
  font-size: 1.05rem;
  line-height: 1.3;
}

/* ============================== عناصر متنوعة ============================== */

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  margin-bottom: 14px;
  font-size: 0.87rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid transparent;
}
.alert-info {
  background: var(--info-bg);
  border-color: #bae6fd;
  color: #075985;
}
.alert-warn {
  background: var(--warning-bg);
  border-color: #fde68a;
  color: #92400e;
}
.alert-danger {
  background: var(--danger-bg);
  border-color: #fecaca;
  color: #991b1b;
}
.alert-ok {
  background: var(--success-bg);
  border-color: #bbf7d0;
  color: #166534;
}

.empty {
  text-align: center;
  padding: 42px 20px;
  color: var(--muted);
}
.empty .ico {
  font-size: 2.6rem;
  display: block;
  margin-bottom: 8px;
  opacity: 0.5;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 24px auto;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.loading-row {
  text-align: center;
  padding: 30px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.tab {
  padding: 9px 15px;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1px;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-600);
}

.progress {
  height: 7px;
  background: var(--slate-bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary-600), var(--primary-400));
  border-radius: 999px;
  transition: width 0.4s;
}

.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 130px;
  padding-top: 8px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(180deg, var(--primary-400), var(--primary-600));
  border-radius: 6px 6px 0 0;
  min-height: 3px;
  transition: height 0.4s;
}
.bar-lbl {
  font-size: 0.66rem;
  color: var(--muted);
  white-space: nowrap;
}
.bar-val {
  font-size: 0.7rem;
  font-weight: 700;
  color: #334155;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.pill {
  background: var(--slate-bg);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ============================== صفحة الدخول ============================== */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #4f8cff 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 34px 30px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  width: 66px;
  height: 66px;
  border-radius: 19px;
  background: linear-gradient(135deg, var(--primary-400), #8b5cf6);
  display: grid;
  place-items: center;
  font-size: 33px;
  margin: 0 auto 14px;
}
.login-card h1 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 3px;
}
.login-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 24px;
}
.login-card .input {
  padding: 11px 13px;
  font-size: 0.95rem;
}

/* ============================== الاستجابة والموبايل ============================== */

/* خلفية معتمة عند فتح القائمة الجانبية على الموبايل */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 35;
  backdrop-filter: blur(2px);
}
.backdrop.show {
  display: block;
}

@media (max-width: 980px) {
  .layout {
    display: block;
  }
  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    transform: translateX(100%);
    transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 30px rgba(15, 23, 42, 0.35);
    width: 270px;
    flex-basis: 270px;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .burger {
    display: block;
    padding: 6px 10px;
    border-radius: 9px;
    line-height: 1;
  }
  .burger:active {
    background: var(--slate-bg);
  }
  .content {
    padding: 14px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }
  .topbar {
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .topbar h1 {
    font-size: 1rem;
  }
}

/* ---------- شاشات الموبايل الصغيرة ---------- */
@media (max-width: 720px) {
  body {
    font-size: 15px;
  }

  /* منع تكبير الصفحة تلقائياً في iPhone عند الكتابة */
  .input,
  .select,
  .textarea,
  select,
  input,
  textarea {
    font-size: 16px;
  }

  /* أزرار أسهل للمس */
  .btn {
    min-height: 40px;
    padding: 9px 14px;
  }
  .btn-sm {
    min-height: 34px;
    padding: 6px 11px;
  }
  .btn-icon {
    min-width: 40px;
  }
  .link-btn {
    padding: 6px 4px;
  }

  .content {
    padding: 12px;
  }

  /* البطاقات والمؤشرات */
  .card {
    border-radius: 12px;
    margin-bottom: 14px;
  }
  .card-head {
    padding: 12px 14px;
  }
  .card-body {
    padding: 14px;
  }
  .card-body.tight {
    padding: 0;
  }
  .grid {
    gap: 12px;
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi {
    padding: 12px;
    gap: 10px;
    border-radius: 12px;
    flex-direction: column;
    align-items: flex-start;
  }
  .kpi-icon {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 1.15rem;
    border-radius: 11px;
  }
  .kpi-val {
    font-size: 1.25rem;
  }
  .kpi-lbl {
    font-size: 0.74rem;
    line-height: 1.35;
  }

  /* الفلاتر تصبح عمودية بعرض كامل */
  .filters {
    display: block;
  }
  .filters .field {
    min-width: 0;
    margin-bottom: 10px;
  }
  .filters .btn {
    width: 100%;
    margin-bottom: 8px;
  }
  /* إخفاء عناصر التوسيط الفارغة عند الترتيب العمودي */
  .filters > div:empty,
  .btn-row > div:empty {
    display: none;
  }
  .filters > div:has(> .switch) {
    margin-bottom: 10px;
  }

  /* التبويبات قابلة للتمرير أفقياً */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-inline: -12px;
    padding-inline: 12px;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tab {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 10px 13px;
    font-size: 0.86rem;
  }

  /* النوافذ المنبثقة تصبح شاشة كاملة */
  .modal-back {
    padding: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
  }
  .modal,
  .modal.wide,
  .modal.narrow {
    max-width: none;
    width: 100%;
    /* ارتفاع ثابت بارتفاع الشاشة حتى يتمرّر المحتوى داخلياً */
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    animation: none;
  }
  .modal-head {
    padding: 14px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    flex: 0 0 auto;
  }
  .modal-body {
    padding: 14px;
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .modal-foot {
    padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    flex: 0 0 auto;
  }
  .modal-foot .btn {
    flex: 1 1 auto;
  }

  /* الجداول تتحول إلى بطاقات مرتبة */
  table.tbl.stack {
    min-width: 0;
  }
  table.tbl.stack thead {
    display: none;
  }
  table.tbl.stack,
  table.tbl.stack tbody,
  table.tbl.stack tr,
  table.tbl.stack td {
    display: block;
    width: 100%;
  }
  table.tbl.stack tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin: 0 10px 10px;
    padding: 4px 0;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
  }
  table.tbl.stack tbody tr:last-child {
    margin-bottom: 10px;
  }
  table.tbl.stack td {
    border: 0;
    border-bottom: 1px dashed #eef2f7;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: right;
    white-space: normal;
  }
  table.tbl.stack tr:hover {
    background: #fff;
  }
  table.tbl.stack td:last-child {
    border-bottom: 0;
  }
  table.tbl.stack td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 38%;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--muted);
    text-align: right;
    line-height: 1.4;
  }
  table.tbl.stack td > * {
    min-width: 0;
  }
  table.tbl.stack td .btn-row {
    justify-content: flex-start !important;
    width: 100%;
  }
  table.tbl.stack td .btn-row .btn {
    flex: 1 1 auto;
  }
  table.tbl.stack td .table-wrap {
    padding: 0;
  }

  /* جداول عريضة (المصفوفة الشهرية) تبقى قابلة للتمرير مع تثبيت عمود الاسم */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }
  table.tbl:not(.stack) th:first-child,
  table.tbl:not(.stack) td:first-child {
    position: sticky;
    inset-inline-start: 0;
    background: #fff;
    z-index: 1;
    box-shadow: -3px 0 8px rgba(15, 23, 42, 0.06);
  }
  table.tbl:not(.stack) th:first-child {
    background: #f8fafc;
    z-index: 2;
  }

  /* الرسم البياني */
  .bars {
    height: 108px;
    gap: 3px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .bar-col {
    min-width: 20px;
  }
  .bar-val {
    font-size: 0.62rem;
  }
  .bar-lbl {
    font-size: 0.58rem;
  }

  /* التنبيهات */
  .toasts {
    inset-inline: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
  .toast {
    font-size: 0.86rem;
  }

  /* صفحة الدخول */
  .login-page {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    align-items: start;
  }
  .login-card {
    padding: 26px 20px;
    border-radius: 18px;
    margin-top: 6vh;
  }
  .login-card .input {
    padding: 12px 13px;
  }

  .avatar {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    font-size: 0.8rem;
  }
  .topbar-user > div:not(.avatar) {
    display: none;
  }

  .empty {
    padding: 30px 16px;
  }
  h1 {
    font-size: 1.25rem;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
}

/* ---------- شاشات صغيرة جداً ---------- */
@media (max-width: 380px) {
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .kpi {
    flex-direction: row;
    align-items: center;
  }
  .kpi-icon {
    flex: 0 0 38px;
  }
  table.tbl.stack td[data-label]::before {
    flex-basis: 42%;
    font-size: 0.7rem;
  }
}

/* ---------- الأجهزة اللوحية ---------- */
@media (min-width: 721px) and (max-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
  .content {
    padding: 16px;
  }
}

/* ---------- الطباعة ---------- */
@media print {
  .sidebar,
  .topbar,
  .btn,
  .toasts,
  .no-print,
  .tabs,
  .burger,
  .backdrop {
    display: none !important;
  }
  .content {
    padding: 0;
  }
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
    break-inside: avoid;
  }
  table.tbl {
    font-size: 10px;
  }
  table.tbl th,
  table.tbl td {
    padding: 4px 6px;
  }
  a[href]::after {
    content: "";
  }
}

