/* ===== الأساسيات ===== */
:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --accent: #b45309;
  --danger: #b91c1c;
  --danger-light: #fee2e2;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #14212e;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
  --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); font-size: .85em; }

/* ===== الشريط العلوي ===== */
.topbar {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.brand-mark { font-size: 1.35rem; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: .92rem;
  transition: background .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .14); }
.nav a.active { background: rgba(255, 255, 255, .22); }

/* ===== الحاوية ===== */
.container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 48px;
  flex: 1;
}
.footer {
  text-align: center;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: .82rem;
}

/* ===== رأس الصفحة ===== */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-title { font-size: 1.5rem; font-weight: 700; }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.section-title { font-size: 1.1rem; margin: 24px 0 10px; }
.back-link { color: var(--muted); font-size: .85rem; font-weight: 600; display: inline-block; margin-bottom: 2px; }
.back-link:hover { color: var(--primary); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== الصفحة الرئيسية ===== */
.hero { text-align: center; padding: 28px 0 24px; }
.hero h1 { font-size: 1.85rem; font-weight: 700; }
.hero p { color: var(--muted); margin: 6px 0 0; }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto 28px;
}
.choice {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 32px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.choice:hover, .choice:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}
.choice-warehouse:hover { border-color: var(--primary); }
.choice-pharmacy:hover { border-color: var(--accent); }
.choice-icon { font-size: 2.8rem; line-height: 1; }
.choice-title { font-size: 1.2rem; font-weight: 700; }
.choice-sub { color: var(--muted); font-size: .85rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat-label { display: block; color: var(--muted); font-size: .78rem; }
.stat-value { display: block; font-size: 1.25rem; font-weight: 700; }
.stat-due .stat-value { color: var(--danger); }

/* ===== الأزرار ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #f1f5f9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff5f5; }
.btn-danger:hover { background: var(--danger-light); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #e2e8f0; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: .84rem; }
.btn-xs { min-height: 34px; padding: 4px 10px; font-size: .78rem; border-radius: 8px; }
.btn-icon { min-width: var(--tap); padding: 8px 12px; font-size: 1.2rem; line-height: 1; }

/* ===== الحقول ===== */
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-family: inherit;
  font-size: .92rem;
  color: var(--text);
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
textarea.input { min-height: 64px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: 14px calc(50% - 2px), 19px calc(50% - 2px); background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-left: 34px; }
.input-date { min-width: 150px; }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.toolbar .input { flex: 1 1 180px; max-width: 320px; }
.field-inline { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }

/* ===== البطاقات ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.card-main { padding: 16px; flex: 1; }
.card-main:hover .card-title { color: var(--primary); }
.card-title { font-size: 1.08rem; font-weight: 700; }
.card-meta { margin: 6px 0 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-line { margin: 4px 0 0; font-size: .84rem; color: var(--muted); }
.card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  flex-wrap: wrap;
}
.card-actions form { margin: 0; display: contents; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: .76rem;
  font-weight: 700;
}
.badge-link:hover { background: var(--primary); color: #fff; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 700; }
.pill-credit { background: #fef3c7; color: #92400e; }
.pill-cash { background: #d1fae5; color: #065f46; }

/* ===== شريط التاريخ ===== */
.datebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.datebar-form { margin: 0; }
.filter-input { flex: 1 1 160px; max-width: 260px; margin-right: auto; }

/* ===== الجدول ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  min-width: 900px;
}
.grid-plain { min-width: 760px; }
.grid th, .grid td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}
.grid thead th {
  background: #eef2f5;
  font-weight: 700;
  font-size: .82rem;
  color: #334155;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 2px solid var(--border);
}
.grid tbody tr:hover { background: #f8fafc; }
.grid tbody tr:nth-child(even) { background: #fcfdfe; }
.grid tbody tr:nth-child(even):hover { background: #f8fafc; }

.col-num { width: 46px; color: var(--muted); font-size: .8rem; }
.col-name { text-align: right; min-width: 160px; }
.col-notes { min-width: 150px; }
.col-actions { width: 190px; }
/* جدول المذاخر فيه 4 أزرار — عمود أعرض ليبقى الكل في سطر واحد */
.grid-warehouses { min-width: 1020px; }
.grid-warehouses .col-actions { width: 264px; }
.grid-warehouses .row-actions { flex-wrap: nowrap; }

.col-name .pharmacy-link { font-weight: 700; }
.col-name .pharmacy-link:hover { color: var(--primary); text-decoration: underline; }
.col-name small { display: block; font-weight: 400; }
.pharmacy-link { font-weight: 600; }

.row-actions { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* خانات الإدخال داخل الجدول */
.cell {
  width: 100%;
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f1f5f9;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  transition: border-color .15s, background .15s;
}
.cell:hover { background: #e8eef4; }
.cell:focus {
  outline: none;
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.cell.num { max-width: 78px; margin: 0 auto; }
.cell.money { max-width: 110px; margin: 0 auto; }
.cell.note { text-align: right; font-weight: 400; font-size: .84rem; }
.cell::-webkit-outer-spin-button, .cell::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell[type=number] { -moz-appearance: textfield; }

/* حالات الحفظ */
.cell.saving { border-color: #cbd5e1; background: #fff; }
.cell.saved { border-color: #34d399; background: #ecfdf5; }
.cell.failed { border-color: var(--danger); background: var(--danger-light); }

/* مفتاح آجل/نقد */
.switch { display: inline-flex; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-ui {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #d1fae5;
  color: #065f46;
  font-size: .78rem;
  font-weight: 700;
  transition: background .15s, color .15s;
}
.switch-ui::after { content: attr(data-off); }
.switch input:checked + .switch-ui { background: #fef3c7; color: #92400e; }
.switch input:checked + .switch-ui::after { content: attr(data-on); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--primary-light); }

.remaining { font-weight: 700; color: var(--muted); }
.is-due { color: var(--danger); font-weight: 700; }

/* صف المجاميع */
.totals-row td {
  background: #eef2f5;
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
  position: sticky;
  bottom: 0;
}
.totals-label { text-align: right; }

/* بطاقات المجاميع (للهاتف) */
.totals-cards { display: none; }

/* ===== التقارير ===== */
.report-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  scrollbar-width: none;
}
.report-tabs::-webkit-scrollbar { display: none; }
.report-tabs a {
  padding: 9px 16px;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}
.report-tabs a:hover { background: #f1f5f9; color: var(--text); }
.report-tabs a.on { background: var(--primary); color: #fff; }

.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
}
.preset-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: #e2e8f0; color: var(--text); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input-sm { width: auto; min-width: 130px; font-size: .86rem; }

.report-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.range-label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.report-bar-actions { display: flex; gap: 6px; }

/* المؤشرات */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  display: grid;
  gap: 2px;
  min-width: 0;
}
.kpi span { font-size: .76rem; color: var(--muted); }
.kpi b { font-size: 1.15rem; overflow-wrap: anywhere; }
.kpi-ok b { color: var(--primary); }
.kpi-due { border-color: #fecaca; background: #fff8f8; }
.kpi-due b { color: var(--danger); }

/* شريط النسبة */
.meter {
  display: inline-block;
  width: 78px;
  height: 7px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  vertical-align: middle;
}
.meter-fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* البطاقات المصغّرة */
.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 24px;
}
.mini-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  align-content: start;
}
.mini-title { font-size: .95rem; font-weight: 700; }
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: r; }
.rank li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .87rem;
}
.rank li:last-child { border-bottom: none; }
.rank li::before {
  counter-increment: r;
  content: counter(r);
  flex: 0 0 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: .7rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.rank li a { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank li a:hover { color: var(--primary); }
.rank li b { white-space: nowrap; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }

/* ===== الفراغ / الخطأ ===== */
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  display: grid;
  gap: 12px;
  justify-items: center;
}
.error-page { padding: 60px 20px; }
.error-code { font-size: 3rem; color: var(--primary); }

/* ===== النوافذ المنبثقة ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fade .15s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .3);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-close {
  border: none;
  background: none;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 6px;
}
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 6px; }

/* ===== التنبيه ===== */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translate(-50%, 20px);
  background: #14212e;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: .86rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ===== الهاتف: تحويل الجدول إلى بطاقات ===== */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .container { padding: 16px 12px 40px; }
  .page-title { font-size: 1.28rem; }

  .table-wrap { background: transparent; border: none; box-shadow: none; overflow: visible; }
  .grid, .grid-plain { min-width: 0; display: block; }
  .grid thead { display: none; }
  .grid tbody { display: block; }
  .grid tfoot { display: none; }

  .grid tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    background: var(--surface) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
    margin-bottom: 12px;
  }

  .grid td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
    border: none;
    text-align: left;
    min-width: 0;
  }
  .grid td::before {
    content: attr(data-label);
    font-size: .78rem;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
  }

  /* الاسم يمتد على العرض الكامل ويعمل كعنوان للبطاقة */
  .grid td.col-name {
    grid-column: 1 / -1;
    order: -2;
    display: block;
    text-align: right;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    font-size: 1.02rem;
  }
  .grid td.col-name::before { display: none; }

  .grid td.col-num {
    grid-column: 1 / -1;
    order: -3;
    justify-content: flex-start;
    color: var(--muted);
    font-size: .75rem;
    padding: 0;
  }
  .grid td.col-num::before { content: 'سطر ' attr(data-label); display: none; }

  .grid td.col-notes, .grid td.col-actions {
    grid-column: 1 / -1;
  }
  .grid td.col-actions {
    display: block;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 6px;
  }
  .grid td.col-actions::before { display: none; }
  .row-actions { justify-content: stretch; }
  .row-actions > * { flex: 1; }
  .row-actions .btn { width: 100%; }

  .cell.num, .cell.money { max-width: 120px; margin: 0; }
  .cell { min-height: var(--tap); }
  .cell.note { max-width: none; }

  /* عرض بطاقات المجاميع بدل صف المجاميع */
  .totals-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 7px 0 calc(7px + env(safe-area-inset-bottom));
    margin-top: 4px;
    z-index: 20;
    border-top: 1px solid var(--border);
  }
  .tcard {
    background: var(--primary);
    color: #fff;
    border-radius: 9px;
    padding: 6px 3px;
    text-align: center;
    display: grid;
    gap: 1px;
    min-width: 0;
  }
  .tcard span { font-size: .64rem; opacity: .85; line-height: 1.3; }
  .tcard b { font-size: .8rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; }

  .card-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi b { font-size: 1.05rem; }
  .filter-row .input-sm, .filter-row .field-inline { flex: 1 1 140px; min-width: 0; }
  .filter-row .field-inline .input { min-width: 0; width: 100%; }
  .filter-row .btn { flex: 1 1 100px; }
  .report-bar { justify-content: space-between; }
  .report-bar-actions .btn { flex: 1; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  .toolbar .input { max-width: none; }
  .filter-input { max-width: none; margin-right: 0; width: 100%; }
  .datebar { gap: 6px; }
  .datebar-form { flex: 1; }
  .datebar-form .input { width: 100%; }
}

@media (max-width: 420px) {
  .choice-grid { gap: 10px; }
  .choice { padding: 22px 10px; }
  .choice-icon { font-size: 2.2rem; }
  .choice-title { font-size: 1.02rem; }
  .nav a { padding: 8px 10px; font-size: .86rem; }
  .brand-text { display: none; }
}

/* ===== الطباعة ===== */
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .no-print, .topbar, .footer, .toast { display: none !important; }
  .print-only { display: block; }
  .print-head { text-align: center; margin-bottom: 10px; }
  .print-head h2 { font-size: 16px; }
  .container { padding: 0; max-width: none; }
  .table-wrap { border: none; box-shadow: none; overflow: visible; }
  .grid { min-width: 0; font-size: 10px; }
  .grid th, .grid td { border: 1px solid #94a3b8; padding: 4px 5px; }
  .grid thead th { background: #e2e8f0 !important; position: static; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .totals-row td { position: static; background: #e2e8f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cell { border: none; background: transparent !important; font-size: 10px; padding: 0; }
  .switch-ui { background: transparent !important; color: #000 !important; min-width: 0; padding: 0; }
  .stat-row, .totals-cards, .report-tabs, .filters, .report-bar, .mini-grid, .pager { display: none !important; }
  .kpi-grid { display: grid !important; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 8px; }
  .kpi { border: 1px solid #94a3b8; box-shadow: none; padding: 4px; }
  .kpi b { font-size: 11px; }
  .kpi span { font-size: 8px; }
  tr { page-break-inside: avoid; }
}

/* ===== تسجيل الدخول ===== */
.centered-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(160deg, #0f766e 0%, #115e59 55%, #0b3b37 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .28);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}
.login-head { text-align: center; margin-bottom: 20px; }
.login-mark { font-size: 2.6rem; display: block; line-height: 1; }
.login-head h1 { font-size: 1.25rem; margin-top: 8px; }
.login-head p { margin: 4px 0 0; color: var(--muted); font-size: .85rem; }
.btn-block { width: 100%; margin-top: 4px; }

/* ===== التنبيهات ===== */
.alert {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: .87rem;
  font-weight: 600;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-light); color: var(--danger); border-color: #fecaca; }
.alert-ok { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.alert-info { background: #e0f2fe; color: #075985; border-color: #bae6fd; }

/* ===== قائمة المستخدم ===== */
.usermenu { position: relative; flex: 0 0 auto; }
.usermenu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .14);
  border: none;
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  color: #fff;
  font-family: inherit;
  font-size: .86rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
}
.usermenu-btn:hover { background: rgba(255, 255, 255, .24); }
.avatar {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  color: var(--primary-dark);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .9rem;
  flex: 0 0 auto;
}
.usermenu-pop {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, .22);
  padding: 6px;
  z-index: 60;
  display: grid;
  gap: 2px;
}
.usermenu-pop[hidden] { display: none; }
.usermenu-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: grid; gap: 2px; }
.usermenu-head strong { font-size: .92rem; color: var(--text); }
.usermenu-head small { color: var(--muted); font-size: .76rem; }
.usermenu-pop a, .usermenu-out {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: .87rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}
.usermenu-pop a:hover { background: #f1f5f9; }
.usermenu-out { color: var(--danger); }
.usermenu-out:hover { background: var(--danger-light); }

/* ===== متفرقات ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  max-width: 460px;
}
.pill-off { background: #e2e8f0; color: #475569; }
.paid-amount { color: var(--primary); }
.btn-excel { border-color: #86efac; background: #f0fdf4; color: #166534; }
.btn-excel:hover { background: #dcfce7; }

@media (max-width: 900px) {
  .usermenu-name { display: none; }
  .usermenu-btn { padding: 5px; }
  .topbar-inner { gap: 8px; }
  .nav a { padding: 8px 10px; font-size: .84rem; }
  .panel { max-width: none; }
}
@media print {
  .usermenu, .alert { display: none !important; }
}
