/* ================================================================
   Shipping Cash Control — واجهة موبايل أولاً
   كل المسافات بخصائص منطقية (inline-start/end) عشان التبديل بين
   العربي والإنجليزي يقلب الاتجاه من غير أي CSS مكرر.
   ================================================================ */

:root {
  --bg: #0f1419;
  --surface: #171e26;
  --surface-2: #1f2933;
  --border: #2b3947;
  --text: #e8edf2;
  --text-dim: #93a4b5;
  --primary: #2f81f7;
  --primary-ink: #ffffff;
  --ok: #2ea043;
  --warn: #d29922;
  --bad: #e5534b;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px; /* أقل مقاس زرار يتضغط بالإصبع بسهولة */
  --shadow: 0 6px 24px rgba(0, 0, 0, .28);
  --chart-bar: #3987e5;
  --font: "Segoe UI", "Noto Naskh Arabic", "Tahoma", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f6;
    --border: #d9e1ea;
    --text: #131a22;
    --text-dim: #5d6e80;
    --shadow: 0 4px 18px rgba(16, 32, 50, .09);
    --chart-bar: #2a78d6;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
a { color: var(--primary); }

/* أرقام بعرض ثابت — الأعمدة المالية لازم تتقرا مترصّة */
.num, .kv-value, .table td, .balance-value, .input-money { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Layout */
.app { max-width: 720px; margin-inline: auto; padding: 0 14px; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; font-weight: 700; font-size: 1rem; }
.topbar-user { font-size: .8rem; color: var(--text-dim); }

.view { padding: 14px 0 24px; }
.stack > * + * { margin-top: 12px; }

/* -------------------------------------------------------------- Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: .95rem; font-weight: 700; margin-bottom: 10px; }

/* --------------------------------------------------- Balance hero */
.balance {
  background: linear-gradient(135deg, var(--primary), #1c5fbf);
  color: #fff; border: 0; text-align: center; padding: 22px 14px;
}
.balance-label { font-size: .85rem; opacity: .9; }
.balance-value { font-size: 2.3rem; font-weight: 800; letter-spacing: -.5px; margin: 6px 0 2px; }
.balance-currency { font-size: 1rem; opacity: .9; }
.balance-note { font-size: .75rem; opacity: .82; margin-top: 8px; }
.balance.is-negative { background: linear-gradient(135deg, var(--bad), #a4342d); }

/* ------------------------------------------------------- Key/value */
.kv {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.kv:last-child { border-bottom: 0; }
.kv-label { color: var(--text-dim); font-size: .88rem; }
.kv-value { font-weight: 600; text-align: end; }
.kv-ok { color: var(--ok); }
.kv-warn { color: var(--warn); }
.kv-bad { color: var(--bad); }

/* سطر رقم + شرح تحته */
.kv-explained { display: block; }
.kv-explained-main { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.kv-explained-sub { font-size: .72rem; color: var(--text-dim); margin-top: 3px; line-height: 1.35; }

/* ------------------------------------------------------------ Forms */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: .85rem; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field-hint { display: block; font-size: .75rem; color: var(--text-dim); margin-top: 5px; }

.input {
  width: 100%; min-height: var(--tap);
  padding: 11px 13px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* أقل من كده iOS بيزوّم لوحده عند الكتابة */
  font-family: inherit;
}
.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
.input-money { font-size: 1.35rem; font-weight: 700; text-align: center; letter-spacing: .5px; }
textarea.input { min-height: 84px; resize: vertical; }
select.input { appearance: none; background-image: none; }
input[type="file"].input { padding: 10px; font-size: .85rem; }

/* --------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 11px 16px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600; font-family: inherit;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn-danger { background: var(--bad); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 11px; font-size: .82rem; }
.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 18px; height: 18px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: #fff; animation: spin .7s linear infinite;
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------- Badges */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--text-dim);
}
.badge-ok { background: rgba(46, 160, 67, .16); color: var(--ok); }
.badge-warn { background: rgba(210, 153, 34, .16); color: var(--warn); }
.badge-bad { background: rgba(229, 83, 75, .16); color: var(--bad); }

/* ---------------------------------------------------------- Alerts */
.alert-item {
  display: flex; gap: 10px; padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: 0; }
.alert-bar { width: 4px; border-radius: 2px; flex: 0 0 4px; background: var(--text-dim); }
.alert-critical .alert-bar { background: var(--bad); }
.alert-high .alert-bar { background: var(--bad); opacity: .7; }
.alert-medium .alert-bar { background: var(--warn); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; font-size: .92rem; }
.alert-meta { font-size: .76rem; color: var(--text-dim); margin-top: 3px; }
.alert-detail { font-size: .8rem; color: var(--text-dim); margin-top: 5px; word-break: break-word; }

/* --------------------------------------------------- Result panel */
.result { border-radius: var(--radius); padding: 15px; text-align: center; margin-bottom: 12px; }
.result-ok { background: rgba(46, 160, 67, .13); border: 1px solid rgba(46, 160, 67, .35); }
.result-bad { background: rgba(229, 83, 75, .13); border: 1px solid rgba(229, 83, 75, .38); }
.result-warn { background: rgba(210, 153, 34, .13); border: 1px solid rgba(210, 153, 34, .38); }
.result-headline { font-size: 1.5rem; font-weight: 800; margin: 6px 0; }
.result-sub { font-size: .85rem; opacity: .85; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-inline: -14px; padding-inline: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: .85rem; white-space: nowrap; }
.table th, .table td { padding: 9px 10px; text-align: start; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-dim); font-weight: 600; font-size: .78rem; }

/* ------------------------------------------------------- List item */
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 600; font-size: .92rem; }
.list-sub { font-size: .78rem; color: var(--text-dim); margin-top: 2px; }
.list-end { text-align: end; flex-shrink: 0; }

.selectable {
  width: 100%; text-align: start; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; margin-bottom: 8px; cursor: pointer; color: inherit; font-family: inherit;
}
.selectable.is-selected { border-color: var(--primary); background: rgba(47, 129, 247, .1); }

/* ---------------------------------------------------------- Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .58);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; overflow-y: auto;
}
.modal-card {
  width: 100%; max-width: 560px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  max-height: 92vh; overflow-y: auto;
  animation: slideUp .2s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } }
.modal-title { font-size: 1.05rem; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.modal-error {
  background: rgba(229, 83, 75, .14); border: 1px solid rgba(229, 83, 75, .4);
  color: var(--bad); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: .87rem; font-weight: 600; margin: 10px 0 0;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal-card { border-radius: var(--radius); }
}

/* ---------------------------------------------------------- Toasts */
.toasts {
  position: fixed; z-index: 200;
  inset-block-start: calc(12px + env(safe-area-inset-top));
  inset-inline: 12px;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  max-width: 520px; width: 100%;
  padding: 12px 15px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: .89rem; font-weight: 600;
  animation: slideDown .2s ease-out;
}
@keyframes slideDown { from { transform: translateY(-12px); opacity: 0; } }
.toast-ok { background: var(--ok); color: #fff; border-color: transparent; }
.toast-error { background: var(--bad); color: #fff; border-color: transparent; }
.toast-warn { background: var(--warn); color: #201a05; border-color: transparent; }
.toast-out { opacity: 0; transition: opacity .25s; }

/* ------------------------------------------------------- Bottom nav */
.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 40;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-item {
  flex: 1; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--text-dim);
  font-size: .7rem; font-weight: 600; font-family: inherit;
  cursor: pointer; padding: 6px 2px; position: relative;
}
.tabbar-item.is-active { color: var(--primary); }
.tabbar-icon { font-size: 1.2rem; line-height: 1; }
.tabbar-badge {
  position: absolute; inset-block-start: 6px; inset-inline-end: 22%;
  min-width: 17px; height: 17px; padding: 0 4px;
  background: var(--bad); color: #fff; border-radius: 9px;
  font-size: .64rem; line-height: 17px; text-align: center;
}

/* ------------------------------------------------------- اللوجو */
/* نسختين من اللوجو: ملونة للخلفية الفاتحة، وبيضا للغامقة.
   الاتنين بنفس المقاس بالظبط (512x443) عشان ما يتزحزحش الشكل
   وانت بتبدّل الثيم. */
.logo {
  display: block;
  aspect-ratio: 512 / 443;
  background: url('/icons/logo-white.png') center / contain no-repeat;
}
@media (prefers-color-scheme: light) {
  .logo { background-image: url('/icons/logo-color.png'); }
}
.logo-login { width: 150px; margin: 0 auto 14px; }
.logo-bar { height: 32px; width: 37px; flex: 0 0 auto; }
.logo-print { width: 130px; margin-bottom: 10px; }

/* ---------------------------------------------------------- Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; }
.login-title { text-align: center; margin-bottom: 20px; }

/* ----------------------------------------------------------- Misc */
.empty { color: var(--text-dim); text-align: center; padding: 22px 10px; font-size: .88rem; }
.spinner {
  width: 26px; height: 26px; margin: 26px auto;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.muted { color: var(--text-dim); font-size: .82rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.proof-thumb {
  width: 100%; max-height: 320px; object-fit: contain;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2);
}
.chip-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip {
  flex-shrink: 0; padding: 7px 13px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: .8rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.chip.is-active { background: var(--primary); color: #fff; border-color: transparent; }

.warn-box {
  background: rgba(210, 153, 34, .12); border: 1px solid rgba(210, 153, 34, .35);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: .85rem; margin-bottom: 12px;
}

/* ------------------------------------------- الرصيد بالسالب */
.danger-card {
  background: linear-gradient(135deg, var(--bad), #a4342d);
  border: 0; color: #fff; text-align: center; padding: 20px 14px;
}
.danger-label { font-size: .9rem; font-weight: 700; opacity: .95; }
.danger-value { font-size: 2.1rem; font-weight: 800; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.danger-currency { font-size: .95rem; opacity: .9; }
.danger-hint { font-size: .78rem; opacity: .88; margin-top: 8px; }
.danger-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.danger-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 9px 12px;
  background: rgba(0, 0, 0, .22); border: 0; border-radius: var(--radius-sm);
  color: #fff; font-family: inherit; font-size: .88rem; font-weight: 600;
  cursor: pointer; text-align: start;
}
.danger-item .num { font-variant-numeric: tabular-nums; }

/* --------------------------------------- مصروفات إضافية (بنود) */
.section-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin: 18px 0 4px; font-size: .9rem; font-weight: 700;
}
.extras { display: flex; flex-direction: column; gap: 8px; }
.extra-row { display: flex; gap: 6px; align-items: start; }
.extra-fields { flex: 1; display: grid; grid-template-columns: 1fr 108px; gap: 6px; }
.extra-remove { flex: 0 0 auto; min-height: 44px; padding: 0 10px; color: var(--bad); }
.input-money-sm { font-size: 1rem; font-weight: 600; }

.total-box {
  display: flex; justify-content: space-between; align-items: center;
  margin: 14px 0; padding: 13px 15px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-weight: 700;
}
.total-box.has-extras { border-color: var(--primary); }
.total-label { font-size: .88rem; color: var(--text-dim); }
.total-value { font-size: 1.45rem; font-variant-numeric: tabular-nums; }

.thumb-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.thumb {
  width: 66px; height: 66px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.proof-stack { display: flex; flex-direction: column; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; font-size: .9rem; }
.check-row input { width: 20px; height: 20px; }

.list-extras { margin-top: 5px; padding-inline-start: 10px; border-inline-start: 2px solid var(--border); }
.list-extra { font-size: .76rem; color: var(--text-dim); }
.list-button {
  width: 100%; background: none; border: 0; border-bottom: 1px solid var(--border);
  color: inherit; font-family: inherit; cursor: pointer; text-align: start;
}
.row-actions { display: flex; gap: 5px; margin-top: 6px; justify-content: flex-end; }
.sum-line {
  display: flex; justify-content: space-between; padding: 9px 0 12px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: .9rem;
}
.btn-lg { min-height: 54px; font-size: 1rem; }

/* ------------------------------------------------------- الشارت */
/* لون واحد مقصود: اسم النوع مكتوب جنب كل عمود، فاللون ما بيحملش
   أي معلومة زيادة. اللونين اتفحصوا للتباين في الوضعين. */
.chart { display: flex; flex-direction: column; gap: 14px; }
.chart-row { display: flex; flex-direction: column; gap: 5px; }
.chart-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.chart-name { font-size: .88rem; font-weight: 600; }
.chart-value { font-size: .88rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart-track { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.chart-bar {
  height: 100%; background: var(--chart-bar);
  border-radius: 0 6px 6px 0; min-width: 4px;
}
html[dir="ltr"] .chart-bar { border-radius: 0 6px 6px 0; }
html[dir="rtl"] .chart-bar { border-radius: 6px 0 0 6px; }
.chart-meta { font-size: .73rem; color: var(--text-dim); }

/* ------------------------------------------ شاشة العهد */
.custody-hero {
  background: linear-gradient(135deg, #1c5fbf, var(--primary));
  color: #fff; border: 0; text-align: center; padding: 20px 14px;
}
.custody-hero-label { font-size: .85rem; opacity: .92; }
.custody-hero-value {
  font-size: 2.1rem; font-weight: 800; margin: 5px 0 2px;
  font-variant-numeric: tabular-nums;
}
.custody-hero-cur { font-size: .95rem; opacity: .9; }
.custody-hero-warn {
  margin-top: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .25); font-size: .8rem; font-weight: 600;
}

.custody-emp { padding: 12px 0; border-bottom: 1px solid var(--border); }
.custody-emp:last-child { border-bottom: 0; }
.custody-emp-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
}
.custody-emp-name {
  flex: 1; min-width: 0; text-align: start;
  background: none; border: 0; padding: 0; color: inherit;
  font-family: inherit; font-size: .95rem; font-weight: 700; cursor: pointer;
}
.custody-emp-balance { text-align: end; flex-shrink: 0; }
.custody-emp-num { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.custody-emp-cap { font-size: .7rem; color: var(--text-dim); }

.custody-emp-breakdown {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 9px;
}
.mini-stat {
  background: var(--surface-2); border-radius: 8px; padding: 7px 8px; text-align: center;
}
.mini-stat-label { font-size: .67rem; color: var(--text-dim); font-weight: 600; }
.mini-stat-value {
  font-size: .85rem; font-weight: 700;
  font-variant-numeric: tabular-nums; margin-top: 2px;
}

/* فاصل واضح بين الوضع الحالي وسجل الحركات — الاتنين بيجاوبوا
   على سؤالين مختلفين، فما ينفعش يبانوا كأنهم قائمة واحدة */
.section-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 22px 0 12px; font-size: .88rem; font-weight: 700; color: var(--text-dim);
}
.section-divider::before, .section-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ------------------------------------------- أرقام سريعة */

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px;
}
.stat-label { font-size: .74rem; color: var(--text-dim); font-weight: 600; }
.stat-value {
  font-size: 1.28rem; font-weight: 800; margin-top: 5px;
  font-variant-numeric: tabular-nums; line-height: 1.25;
  overflow-wrap: anywhere;
}
.stat-sub { font-size: .73rem; color: var(--text-dim); margin-top: 3px; }

/* ------------------------------ المصروف على مدار الفترة */
.trend-bars {
  display: flex; align-items: flex-end; gap: 3px;
  height: 110px; overflow-x: auto; padding-bottom: 2px;
}
.trend-col { flex: 1 0 14px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.trend-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.trend-bar { width: 100%; background: var(--chart-bar); border-radius: 3px 3px 0 0; min-height: 2px; }
.trend-tick { font-size: .6rem; color: var(--text-dim); margin-top: 4px; font-variant-numeric: tabular-nums; }
.trend-range {
  display: flex; justify-content: space-between;
  font-size: .7rem; color: var(--text-dim); margin-top: 8px;
  padding-top: 8px; border-top: 1px solid var(--border);
}
.list-invoice { font-variant-numeric: tabular-nums; opacity: .75; }

/* ------------------------------- اختيار فترة محددة بتاريخين */
.period-custom:not(:empty) {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px 0;
  margin-bottom: 12px;
}
.period-custom .field { margin-bottom: 12px; }
.period-custom .grid-2 { gap: 10px; }
/* حقل التاريخ على iOS بيطلع صغير من غير الارتفاع ده */
.period-custom input[type=date] { min-height: var(--tap); }

/* ============================================================
   تقرير الطباعة / PDF

   مصمم للورق مش للشاشة. المبادئ:
   - مقاسات بالنقاط (pt) مش rem — الورق مقاسه ثابت
   - رأس الجدول بيتكرر في كل صفحة (table-header-group)
   - الصف ما ينقسمش على صفحتين
   - أعمدة بعرض محدد عشان البيان ما يتزنقش
   - أرقام بعرض ثابت ومحاذاة لليسار عشان تتقرا مترصّة
   - خطوط أفقية خفيفة بدل شبكة كاملة تقيلة
   ============================================================ */

.print-sheet {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
}

/* ---------- الرأس ---------- */
.print-header {
  display: flex; align-items: flex-start; gap: 16px;
  padding-bottom: 14px; margin-bottom: 18px;
  border-bottom: 2px solid var(--text);
}
.print-header .logo-print { width: 92px; margin: 0; flex: 0 0 auto; }
.print-titles { flex: 1; min-width: 0; }
.print-titles h1 { font-size: 1.25rem; margin: 0 0 4px; }
.print-period { font-size: .95rem; font-weight: 700; }
.print-meta { font-size: .78rem; color: var(--text-dim); margin-top: 4px; }

/* ---------- ملخص الأرقام ---------- */
.print-summary {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 20px;
}
.print-fig {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
.print-fig-label { font-size: .72rem; color: var(--text-dim); font-weight: 600; }
.print-fig-value {
  font-size: 1.1rem; font-weight: 800; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.print-fig-strong { border-color: var(--text); border-width: 2px; }
.print-fig-sub {
  font-size: .68rem; color: var(--text-dim);
  margin-top: 4px; line-height: 1.35;
}

/* الرصيد الحقيقي لوحده في صندوق منفصل — عشان ما يتلخبطش مع
   فرق الفترة اللي فوقه */
.print-balance-note {
  border: 2px solid var(--text); border-radius: 8px;
  padding: 11px 13px; margin-bottom: 20px;
}
.print-balance-note .print-fig-value { font-size: 1.25rem; }


/* ---------- الأقسام ---------- */
.print-section { margin-bottom: 22px; }
.print-section > h2 {
  font-size: .98rem; margin: 0 0 8px;
  padding-bottom: 5px; border-bottom: 1px solid var(--border);
}

/* ---------- الجداول ---------- */
.print-table {
  width: 100%; border-collapse: collapse;
  font-size: .82rem; table-layout: fixed;
}
.print-table th, .print-table td {
  padding: 7px 8px; text-align: start; vertical-align: top;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.print-table th {
  font-size: .75rem; font-weight: 700; line-height: 1.25;
  background: var(--surface-2);
  border-bottom: 1.5px solid var(--text);
  /* ممنوع nowrap هنا: العنوان الطويل في عمود ضيق بيطفح برّه الخلية
     ويركب على اللي جنبه — الجدول ثابت العرض فمفيش حاجة بتزقّه. */
}
.print-table tbody tr:nth-child(even) { background: rgba(127, 127, 127, .06); }
.print-table .num {
  text-align: end; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.print-table tfoot td {
  font-weight: 800; background: var(--surface-2);
  border-top: 2px solid var(--text); border-bottom: 0;
}
.print-table .muted-cell { color: var(--text-dim); font-size: .76rem; }

/* أعمدة جدول المصروفات — محددة عشان البيان ياخد مساحته */
/* العرض محسوب على أعرض محتوى ممكن يحصل:
   التاريخ 2026-09-22 · الفاتورة EM-2026-00079 · مبلغ 999,999.00 */
.col-date { width: 11%; }
.col-inv { width: 13.5%; }
.col-emp { width: 11%; }
.col-cat { width: 11%; }
.col-desc { width: 19%; }
.col-money { width: 11.5%; }

/* التاريخ ورقم الفاتورة ما ينقسموش على سطرين — بيبوّظ شكل الجدول */
.print-table .col-date, .print-table td:first-child { white-space: nowrap; }
.print-table .nowrap { white-space: nowrap; }
/* شبكة أمان: مستحيل أي خلية تركب على اللي جنبها مهما كان المحتوى */
.print-table th, .print-table td { overflow: hidden; text-overflow: ellipsis; }

.print-footer {
  margin-top: 18px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: .72rem; color: var(--text-dim);
  display: flex; justify-content: space-between; gap: 10px;
}

@media (max-width: 640px) {
  .print-summary { grid-template-columns: 1fr 1fr; }
  .print-sheet { padding: 12px; }
}

/* ============================================================
   الطباعة الفعلية
   ============================================================ */
@media print {
  /* الورق أبيض والحبر أسود مهما كان ثيم الشاشة */
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #f0f0f0;
    --border: #b0b0b0; --text: #000; --text-dim: #555;
  }

  html, body {
    background: #fff !important; color: #000 !important;
    padding: 0 !important; margin: 0 !important;
    font-size: 10pt;
  }

  /* كل حاجة مش جزء من التقرير تختفي */
  .topbar, .tabbar, .no-print, .toasts, .btn,
  .chip-row, .period-custom, .stat-row { display: none !important; }

  .app { max-width: none !important; padding: 0 !important; }
  .view { padding: 0 !important; }

  .print-sheet {
    padding: 0 !important; border-radius: 0 !important;
    background: #fff !important;
  }

  /* الورق أبيض، فالنسخة الملونة من اللوجو هي الصح */
  .logo { background-image: url('/icons/logo-color.png') !important; }
  .print-header .logo-print { width: 26mm; }

  .print-header { border-bottom: 1.5pt solid #000; margin-bottom: 8mm; }
  .print-titles h1 { font-size: 16pt; }
  .print-period { font-size: 11pt; }
  .print-meta { font-size: 8pt; }

  .print-summary { gap: 4mm; margin-bottom: 8mm; }
  .print-fig { border: 0.5pt solid #999; padding: 2.5mm 3mm; }
  .print-fig-strong { border: 1.2pt solid #000; }
  .print-fig-label { font-size: 7.5pt; }
  .print-fig-value { font-size: 12pt; }
  .print-fig-sub { font-size: 7pt; line-height: 1.3; }
  .print-balance-note { border: 1.2pt solid #000; padding: 3mm; margin-bottom: 7mm; break-inside: avoid; }

  .print-section { margin-bottom: 7mm; }
  .print-section > h2 { font-size: 11pt; margin-bottom: 2mm; }

  .print-table { font-size: 8.5pt; }
  .print-table th, .print-table td { padding: 1.6mm 2mm; }
  .print-table th {
    background: #e8e8e8 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    border-bottom: 1pt solid #000;
  }
  .print-table tbody tr:nth-child(even) {
    background: #f6f6f6 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .print-table tfoot td {
    background: #e8e8e8 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    border-top: 1.2pt solid #000;
  }

  /* رأس الجدول يتكرر في كل صفحة، والصف ما ينقسمش */
  .print-table thead { display: table-header-group; }
  .print-table tfoot { display: table-footer-group; }
  .print-table tr { break-inside: avoid; page-break-inside: avoid; }
  .print-section > h2 { break-after: avoid; page-break-after: avoid; }

  /* العنوان ما يفضلش لوحده في آخر الصفحة */
  h1, h2, h3 { break-after: avoid; orphans: 3; widows: 3; }
  p { orphans: 3; widows: 3; }

  .print-footer { border-top: 0.5pt solid #999; font-size: 7.5pt; }

  @page {
    size: A4;
    margin: 14mm 12mm;
  }
}

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