/* نظام متابعة الإيجارات — tokens + components. RTL-first, logical properties only.
   Load after fonts.css (self-hosted Cairo). No external resources. */

/* ───────── 1. Tokens ───────── */
:root {
  /* neutrals (warm) */
  --c-bg: #F6F4EF;
  --c-surface: #FFFEFB;
  --c-surface-2: #FBFAF6;      /* expanded rows, quiet panels */
  --c-surface-3: #F1EEE6;      /* table header, neutral chips */
  --c-field: #FFFFFF;
  --c-border: #E4DFD4;
  --c-border-soft: #EFEBE2;    /* row dividers */
  --c-border-strong: #C9C3B6;  /* inputs, secondary buttons */
  --c-text: #1F2421;
  --c-text-2: #3A413C;
  --c-text-muted: #5F665F;     /* 5.6:1 on --c-bg */
  --c-on-solid: #FFFFFF;
  --c-overlay: rgba(31, 36, 33, .5);

  /* brand / primary action */
  --c-accent: #1F5E4B;
  --c-accent-hover: #174A3B;
  --c-accent-soft: #E9F1ED;
  --c-accent-disabled: #8FA89F;

  /* payment states: معلق / محصل بانتظار الفاتورة / مسدد + فاتورة */
  --c-pending-fg: #3A413C;   --c-pending-bg: #F1EEE6;   --c-pending-border: #A9A396;
  --c-collected-fg: #4A3794; --c-collected-bg: #EFEBFA; --c-collected-border: #D2C8F0; --c-collected-solid: #5B45A8; --c-collected-solid-hover: #4A3794;
  --c-paid-fg: #1F6B45;      --c-paid-bg: #E6F2EA;      --c-paid-border: #C5DFCF;      --c-paid-solid: #1F6B45;      --c-paid-solid-hover: #175537;

  /* due states: متأخر / قريباً / نشط */
  --c-overdue-fg: #8F2A1B; --c-overdue-bg: #FBEDE9; --c-overdue-border: #EBCFC8; --c-overdue-solid: #A3301F;
  --c-soon-fg: #7A4F00;    --c-soon-bg: #FBF1D9;    --c-soon-border: #EBDCB0;    --c-soon-solid: #8A5A00;
  --c-active-fg: var(--c-paid-fg); --c-active-bg: var(--c-paid-bg); --c-active-border: var(--c-paid-border);

  /* danger, warning, scanned field */
  --c-danger: #A3301F; --c-danger-hover: #87261A; --c-danger-border: #D9A79E;
  --c-warning-fg: #7A4F00; --c-warning-bg: #FBF1D9; --c-warning-border: #D9BC6A;
  --c-scanned-border: #B8891F; --c-scanned-ring: #F3DFA6;
  --c-toast-bg: #1F2421; --c-toast-success: #5FBF8F; --c-toast-error: #E0705F;

  /* type */
  --font: 'Cairo', system-ui, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;
  --fs-xs: .8125rem;   /* 13 — column captions only */
  --fs-sm: .875rem;    /* 14 — secondary text, labels */
  --fs-md: .9375rem;   /* 15 — body */
  --fs-lg: 1rem;       /* 16 — row titles, inputs on touch */
  --fs-xl: 1.0625rem;  /* 17 — amounts, section titles */
  --fs-2xl: 1.25rem;   /* 20 — dialog title */
  --fs-3xl: 1.625rem;  /* 26 — page title */
  --fs-figure: 1.75rem;/* 28 — summary figure */
  --lh: 1.6; --lh-tight: 1.3;
  --fw-regular: 400; --fw-medium: 600; --fw-bold: 700; --fw-heavy: 800;

  /* spacing (4px base) */
  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem; --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-8: 2rem; --sp-10: 2.5rem;

  /* shape */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;
  --shadow-1: 0 2px 12px rgba(0, 0, 0, .08);
  --shadow-2: 0 12px 40px rgba(0, 0, 0, .25);
  --control-h: 44px;       /* minimum tap target */
  --control-h-sm: 36px;    /* desktop-only dense actions; grows to 44 on touch */
  --sidebar-w: 256px;
}

/* Dark theme: same names, other values. Opt in with <html data-theme="dark">. */
[data-theme="dark"] {
  --c-bg: #141815; --c-surface: #1C211E; --c-surface-2: #212723; --c-surface-3: #272E29; --c-field: #171B18;
  --c-border: #333B35; --c-border-soft: #2A312C; --c-border-strong: #4A544D;
  --c-text: #ECEFEA; --c-text-2: #CDD3CC; --c-text-muted: #A2ABA3; --c-overlay: rgba(0, 0, 0, .65);
  --c-accent: #3F9C80; --c-accent-hover: #4DAE91; --c-accent-soft: #1F2F29; --c-accent-disabled: #3A4A44; --c-on-solid: #0E1210;
  --c-pending-fg: #CDD3CC; --c-pending-bg: #272E29; --c-pending-border: #5C665F;
  --c-collected-fg: #C2B5F5; --c-collected-bg: #2A2540; --c-collected-border: #463D70; --c-collected-solid: #A593EE; --c-collected-solid-hover: #B8A9F3;
  --c-paid-fg: #8FD3AE; --c-paid-bg: #1B2E24; --c-paid-border: #2F4D3D; --c-paid-solid: #5FBF8F; --c-paid-solid-hover: #74CB9F;
  --c-overdue-fg: #F0A598; --c-overdue-bg: #351F1B; --c-overdue-border: #5A322B; --c-overdue-solid: #E0705F;
  --c-soon-fg: #E8C773; --c-soon-bg: #322A15; --c-soon-border: #55461F; --c-soon-solid: #D9B14A;
  --c-danger: #E0705F; --c-danger-hover: #E98777; --c-danger-border: #6B3A32;
  --c-warning-fg: #E8C773; --c-warning-bg: #322A15; --c-warning-border: #6B5A26;
  --c-scanned-border: #D9B14A; --c-scanned-ring: #4A3E1A;
  --c-toast-bg: #ECEFEA;
}

/* ───────── 2. Base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh); color: var(--c-text); background: var(--c-bg); font-variant-numeric: tabular-nums; }
a { color: var(--c-accent); }
a:hover { color: var(--c-accent-hover); }
:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--c-text-muted); }
.ltr { direction: ltr; unicode-bidi: isolate; text-align: end; } /* IDs, phones, invoice numbers, e-mail */
.num { white-space: nowrap; }
.icon { inline-size: 1.25em; block-size: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ───────── 3. Shell ───────── */
.app { display: flex; min-block-size: 100vh; }
.sidebar { inline-size: var(--sidebar-w); flex: none; display: flex; flex-direction: column; gap: var(--sp-5); padding: var(--sp-5) .875rem; background: var(--c-surface); border-inline-end: 1px solid var(--c-border); position: sticky; inset-block-start: 0; block-size: 100vh; }
.main { flex: 1; min-inline-size: 0; max-inline-size: 1240px; padding: 1.75rem 2.25rem 3.5rem; display: flex; flex-direction: column; gap: var(--sp-6); }
.topbar { display: none; align-items: center; gap: var(--sp-3); }
.topbar__title { flex: 1; min-inline-size: 0; font-weight: var(--fw-heavy); font-size: var(--fs-xl); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-backdrop { display: none; position: fixed; inset: 0; background: var(--c-overlay); z-index: 35; }

.wordmark { display: flex; align-items: center; gap: .625rem; padding: var(--sp-1) var(--sp-2); }
.wordmark__mark { inline-size: 36px; block-size: 36px; border-radius: var(--r-md); background: var(--c-accent); display: flex; align-items: center; justify-content: center; gap: 3px; }
.wordmark__mark i { inline-size: 4px; background: var(--c-on-solid); border-radius: 1px; }
.wordmark__mark i:nth-child(1) { block-size: 10px; } .wordmark__mark i:nth-child(2) { block-size: 16px; } .wordmark__mark i:nth-child(3) { block-size: 13px; }
.wordmark__pre { font-size: .75rem; color: var(--c-text-muted); line-height: 1.2; }
.wordmark__name { font-weight: var(--fw-heavy); font-size: var(--fs-xl); line-height: var(--lh-tight); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item { display: flex; align-items: center; gap: var(--sp-3); min-block-size: var(--control-h); padding-inline: var(--sp-3); border-radius: var(--r-md); color: var(--c-text-2); font-weight: var(--fw-medium); text-decoration: none; }
.nav__item:hover { background: var(--c-surface-2); color: var(--c-text); }
.nav__item[aria-current="page"] { background: var(--c-accent-soft); color: var(--c-accent); font-weight: var(--fw-bold); }
.nav__label { flex: 1; }
.count-badge { min-inline-size: 24px; block-size: 24px; padding-inline: 6px; border-radius: var(--r-pill); background: var(--c-collected-solid); color: var(--c-on-solid); font-size: var(--fs-xs); font-weight: var(--fw-bold); display: inline-flex; align-items: center; justify-content: center; }
.user-box { margin-block-start: auto; border-block-start: 1px solid var(--c-border); padding: .875rem var(--sp-2) 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.user-box__links { display: flex; gap: var(--sp-4); font-size: var(--fs-sm); }
.user-box__links a { color: var(--c-text-2); }
.user-box__links a.is-danger { color: var(--c-danger); font-weight: var(--fw-medium); }

.page-title { font-size: var(--fs-3xl); font-weight: var(--fw-heavy); line-height: var(--lh-tight); margin: 0; }
.page-sub { color: var(--c-text-muted); margin: 0; }
.toolbar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.toolbar__title { margin-inline-end: auto; }

/* ───────── 4. Buttons ───────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-block-size: var(--control-h); padding-inline: 1.125rem; border: 1px solid transparent; border-radius: var(--r-md); font: inherit; font-weight: var(--fw-bold); line-height: 1.2; cursor: pointer; text-decoration: none; white-space: nowrap; background: var(--c-accent); color: var(--c-on-solid); }
.btn:hover { background: var(--c-accent-hover); color: var(--c-on-solid); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong); }
.btn--secondary:hover { background: var(--c-surface-3); color: var(--c-text); }
.btn--collect { background: var(--c-paid-solid); }               /* تحصيل / تأكيد التحصيل */
.btn--collect:hover { background: var(--c-paid-solid-hover); }
.btn--invoice { background: var(--c-collected-solid); }          /* فاتورة / إصدار الفاتورة */
.btn--invoice:hover { background: var(--c-collected-solid-hover); }
.btn--danger { background: var(--c-danger); }                    /* confirm button of a destructive dialog */
.btn--danger:hover { background: var(--c-danger-hover); }
.btn--danger-outline { background: var(--c-surface); color: var(--c-danger); border-color: var(--c-danger-border); } /* حذف in lists */
.btn--danger-outline:hover { background: var(--c-overdue-bg); color: var(--c-danger); }
.btn--link { background: none; border: 0; padding-inline: var(--sp-2); color: var(--c-text-2); text-decoration: underline; font-weight: var(--fw-medium); }
.btn--link:hover { background: none; color: var(--c-text); }
.btn--link.is-danger { color: var(--c-danger); }                 /* إلغاء التحصيل: kept apart from collect/invoice */
.btn--sm { min-block-size: var(--control-h-sm); padding-inline: var(--sp-3); font-size: var(--fs-sm); border-radius: 6px; }
.btn--block { inline-size: 100%; }
.btn--icon { inline-size: var(--control-h); padding: 0; }        /* icon-only: always give aria-label */
.btn:disabled, .btn[aria-disabled="true"] { background: var(--c-accent-disabled); border-color: transparent; color: var(--c-on-solid); cursor: not-allowed; }
.btn--secondary:disabled { background: var(--c-surface-3); color: var(--c-text-muted); border-color: var(--c-border); }
.btn.is-loading::before { content: ""; inline-size: 16px; block-size: 16px; border: 2px solid rgba(255, 255, 255, .5); border-block-start-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@media (pointer: coarse) { .btn--sm { min-block-size: var(--control-h); } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { inline-size: 40px; block-size: 40px; border: 3px solid var(--c-border); border-block-start-color: var(--c-accent); border-radius: 50%; animation: spin .8s linear infinite; }

/* ───────── 5. Form controls (native, styled) ───────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { display: flex; align-items: center; gap: var(--sp-2); min-block-size: 22px; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.input, .select, .file { inline-size: 100%; min-block-size: var(--control-h); padding-inline: var(--sp-3); border: 1px solid var(--c-border-strong); border-radius: var(--r-md); background: var(--c-field); color: var(--c-text); font: inherit; }
.input::placeholder { color: var(--c-text-muted); }
.input:focus, .select:focus, .file:focus { outline: 3px solid var(--c-accent-soft); border-color: var(--c-accent); }
.file { padding: var(--sp-2) .625rem; border-style: dashed; border-color: var(--c-pending-border); font-size: var(--fs-sm); }
.file::file-selector-button { font: inherit; font-weight: var(--fw-bold); margin-inline-end: var(--sp-3); padding: 2px var(--sp-3); border: 1px solid var(--c-border-strong); border-radius: 6px; background: var(--c-surface); color: var(--c-text); cursor: pointer; }
.field__hint { font-size: var(--fs-sm); color: var(--c-text-muted); }
.field__error { display: none; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--c-danger); }
.field--error .input, .field--error .select { border: 2px solid var(--c-danger); }
.field--error .field__error { display: block; }
/* scan result: class stays on the field until the user edits the value */
.field--scanned .input, .field--scanned .select { border: 2px solid var(--c-scanned-border); }
.field--scanned .input:focus, .field--scanned .select:focus { outline: 4px solid var(--c-scanned-ring); }
.tag-scanned { font-size: .75rem; font-weight: var(--fw-bold); color: var(--c-warning-fg); background: var(--c-warning-bg); border: 1px solid var(--c-warning-border); border-radius: var(--r-sm); padding-inline: 6px; }
.scan-src > summary { inline-size: fit-content; padding-block: var(--sp-1); font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--c-warning-fg); text-decoration: underline; cursor: pointer; list-style: none; }
.scan-src > summary::-webkit-details-marker { display: none; }
.scan-src__text { margin: 0; padding: 6px .625rem; font-size: var(--fs-sm); color: var(--c-text-2); background: var(--c-surface-2); border-inline-start: 3px solid var(--c-warning-border); overflow-wrap: anywhere; }
.form-section { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: var(--sp-5); padding-block: .875rem; border-block-end: 1px solid var(--c-border-soft); }
.form-section__title { margin: 0; padding-block-start: 26px; font-size: var(--fs-lg); font-weight: var(--fw-heavy); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .875rem; align-items: start; }
.form-grid .is-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: .625rem; flex-wrap: wrap; padding-block-start: 1.125rem; }

/* ───────── 6. Badges ───────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px .625rem; border: 1px solid; border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: var(--fw-bold); white-space: nowrap; }
.badge .icon { inline-size: 15px; block-size: 15px; stroke-width: 2; }
/* payment state: icon + text + shape (dashed outline = nothing received yet) */
.badge--pending { color: var(--c-pending-fg); background: var(--c-pending-bg); border: 1px dashed var(--c-pending-border); }
.badge--collected { color: var(--c-collected-fg); background: var(--c-collected-bg); border-color: var(--c-collected-border); }
.badge--paid { color: var(--c-paid-fg); background: var(--c-paid-bg); border-color: var(--c-paid-border); }
/* contract / due state */
.badge--overdue { color: var(--c-overdue-fg); background: var(--c-overdue-bg); border-color: var(--c-overdue-border); }
.badge--soon { color: var(--c-soon-fg); background: var(--c-soon-bg); border-color: var(--c-soon-border); }
.badge--active { color: var(--c-active-fg); background: var(--c-active-bg); border-color: var(--c-active-border); }
.role-badge { display: inline-block; padding-inline: var(--sp-2); border: 1px solid var(--c-text); border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: var(--fw-bold); }

/* ───────── 7. Cards, figures, groups ───────── */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.card--pad { padding: 1.125rem var(--sp-5); }
.card__title { margin: 0 0 var(--sp-3); font-size: var(--fs-xl); font-weight: var(--fw-heavy); }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); }
.figure { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: .875rem 1.125rem; }
.figure__label { display: flex; align-items: center; flex-wrap: wrap; gap: 0 var(--sp-2); font-weight: var(--fw-bold); color: var(--c-text-muted); }
.figure__value { font-size: var(--fs-figure); font-weight: var(--fw-heavy); line-height: 1.4; }
.figure__value small { font-size: var(--fs-lg); font-weight: var(--fw-medium); }
.figure__alt { font-size: var(--fs-xl); font-weight: var(--fw-bold); color: var(--c-text-2); } /* USD line: never summed with EGP */
.figure--overdue { border-block-start: 4px solid var(--c-overdue-solid); } .figure--overdue .figure__label { color: var(--c-overdue-solid); }
.figure--soon { border-block-start: 4px solid var(--c-soon-solid); } .figure--soon .figure__label { color: var(--c-soon-fg); }
.due-group__head { display: flex; align-items: center; flex-wrap: wrap; gap: .625rem; padding: var(--sp-3) var(--sp-5); font-size: var(--fs-xl); font-weight: var(--fw-heavy); background: var(--c-surface-3); }
.due-group__count { font-size: var(--fs-md); font-weight: var(--fw-medium); }
.due-group__totals { margin-inline-start: auto; display: flex; gap: var(--sp-4); font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--c-text); }
.due-group--overdue .due-group__head { background: var(--c-overdue-bg); color: var(--c-overdue-fg); }
.due-group--soon .due-group__head { background: var(--c-soon-bg); color: var(--c-soon-fg); }
.due-group--overdue .due-rel { color: var(--c-overdue-fg); } .due-group--soon .due-rel { color: var(--c-soon-fg); }
.due-rel { font-weight: var(--fw-bold); white-space: nowrap; }

/* ───────── 8. Table ───────── */
.table-wrap { overflow-x: auto; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.table { inline-size: 100%; border-collapse: collapse; }
.table th { padding: .625rem var(--sp-4); background: var(--c-surface-3); color: var(--c-text-2); font-size: var(--fs-sm); font-weight: var(--fw-bold); text-align: start; white-space: nowrap; }
.table td { padding: var(--sp-3) var(--sp-4); border-block-start: 1px solid var(--c-border-soft); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-inline-start: var(--sp-5); }
.table th:last-child, .table td:last-child { padding-inline-end: var(--sp-5); }
.table .is-end { text-align: end; }
.table .cell-title { font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.table .cell-sub { font-size: var(--fs-sm); color: var(--c-text-muted); }
.table .cell-amount { font-size: var(--fs-xl); font-weight: var(--fw-heavy); text-align: end; white-space: nowrap; }
.table .cell-actions { white-space: nowrap; text-align: end; }
.table .cell-actions > * + * { margin-inline-start: 6px; }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover td { background: var(--c-surface-2); }
.table tr.row-detail td { background: var(--c-surface-2); border-block-start: 1px dashed var(--c-border); padding-block: var(--sp-2) var(--sp-5); }
.table tfoot td { border-block-start: 2px solid var(--c-text); background: var(--c-surface-2); font-weight: var(--fw-heavy); vertical-align: top; }
.chevron { transition: transform .15s; } [aria-expanded="true"] .chevron { transform: rotate(180deg); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr); gap: var(--sp-1) var(--sp-10); }
.detail-grid__full { grid-column: 1 / -1; }
.detail-caption { margin: 0; padding-block: .625rem 6px; font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--c-text-muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .625rem var(--sp-6); margin: 0; }
.facts dt { font-size: var(--fs-xs); color: var(--c-text-muted); } .facts dd { margin: 0; font-weight: var(--fw-medium); }
.list-row { display: flex; align-items: center; gap: var(--sp-3); min-block-size: 48px; border-block-end: 1px solid var(--c-border-soft); }
.list-row__grow { margin-inline-end: auto; }

/* ───────── 9. Dialog, toast, notices, empty ───────── */
.dialog-backdrop { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; padding: var(--sp-4); background: var(--c-overlay); }
.dialog-backdrop.open { display: flex; }
.dialog { inline-size: 100%; max-inline-size: 480px; max-block-size: 90vh; overflow: auto; display: flex; flex-direction: column; gap: .875rem; padding: 1.375rem var(--sp-6); background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2); }
.dialog--wide { max-inline-size: 920px; }
.dialog__title { margin: 0; display: flex; align-items: center; gap: .625rem; font-size: var(--fs-2xl); font-weight: var(--fw-heavy); }
.dialog__sub { margin: 0; color: var(--c-text-muted); }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .625rem; margin-block-start: var(--sp-1); }
/* confirmations: coloured top bar + icon in the title; the confirm button takes the same colour */
.dialog--danger { max-inline-size: 420px; border-block-start: 6px solid var(--c-danger); }
.dialog--danger .dialog__title { color: var(--c-danger); }
.dialog--caution { max-inline-size: 420px; border-block-start: 6px solid var(--c-soon-solid); }
.dialog--caution .dialog__title { color: var(--c-soon-fg); }
.summary-box { padding: var(--sp-3) .875rem; border: 1px solid var(--c-border); border-radius: var(--r-md); }
.summary-box--collect { background: var(--c-paid-bg); border-color: var(--c-paid-border); }
.summary-box--invoice { background: var(--c-collected-bg); border-color: var(--c-collected-border); }
.summary-box__amount { font-size: 1.5rem; font-weight: var(--fw-heavy); line-height: 1.4; }
.secret { direction: ltr; padding: .875rem; border: 2px solid var(--c-text); border-radius: var(--r-md); background: var(--c-field); font-family: var(--font-mono); font-size: 1.5rem; font-weight: var(--fw-bold); letter-spacing: 2px; text-align: center; user-select: all; }

.toast { position: fixed; inset-block-end: var(--sp-6); inset-inline-start: 50%; transform: translateX(50%); z-index: 60; max-inline-size: 90vw; padding: var(--sp-3) 1.125rem; border-radius: var(--r-md); border-inline-start: 6px solid var(--c-toast-success); background: var(--c-toast-bg); color: var(--c-bg); font-weight: var(--fw-bold); box-shadow: var(--shadow-2); opacity: 0; pointer-events: none; transition: opacity .3s; }
[dir="ltr"] .toast { transform: translateX(-50%); }
.toast.show { opacity: 1; }
.toast.e { border-inline-start-color: var(--c-toast-error); }

.notice { display: flex; gap: var(--sp-3); padding: .875rem 1.125rem; border: 1px solid var(--c-border); border-radius: var(--r-md); background: var(--c-surface); }
.notice > .icon { margin-block-start: 2px; inline-size: 22px; block-size: 22px; }
.notice__body { display: flex; flex-direction: column; gap: var(--sp-1); }
.notice__body > :first-child { font-weight: var(--fw-bold); }
.notice--warning { background: var(--c-warning-bg); border-color: var(--c-warning-border); } .notice--warning > .icon { color: var(--c-warning-fg); }
.notice--danger { background: var(--c-overdue-bg); border-color: var(--c-overdue-border); color: var(--c-overdue-fg); }
.empty { padding: 3rem var(--sp-5); text-align: center; background: var(--c-surface); border: 1px dashed var(--c-border-strong); border-radius: var(--r-md); font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.loading-screen { min-block-size: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-4); }
.auth-card { inline-size: 100%; max-inline-size: 400px; display: flex; flex-direction: column; gap: var(--sp-4); padding: 2rem 1.75rem; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); }

/* ───────── 10. Responsive ───────── */
@media (max-width: 1099px) {
  .sidebar { display: none; position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .app.drawer-open .sidebar { display: flex; }
  .app.drawer-open .drawer-backdrop { display: block; }
  .topbar { display: flex; }
  .main { padding: var(--sp-4) var(--sp-4) 3rem; }
}
@media (max-width: 899px) {
  .form-section { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .form-section__title { padding-block-start: 0; }
}
@media (max-width: 699px) {
  .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .625rem; }
  .figure__value { font-size: 1.1875rem; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .input, .select { font-size: var(--fs-lg); } /* 16px: no zoom on focus in iOS */
  /* .table--stack: each row becomes a block; give cells data-label where the header is needed */
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tfoot, .table--stack tr, .table--stack td { display: block; inline-size: 100%; }
  .table--stack tr { padding: var(--sp-3) var(--sp-4); border-block-start: 1px solid var(--c-border-soft); }
  .table--stack td { padding: 1px 0; border: 0; text-align: start; }
  .table--stack td:first-child, .table--stack td:last-child { padding-inline: 0; }
  .table--stack td[data-label]::before { content: attr(data-label) ": "; color: var(--c-text-muted); font-size: var(--fs-sm); }
  .table--stack .cell-amount { text-align: start; }
  .table--stack .cell-actions { padding-block-start: var(--sp-2); text-align: start; white-space: normal; }
  .table--stack .cell-actions .btn { min-block-size: var(--control-h); }
  .table--stack tr.row-detail { background: var(--c-surface-2); }
}

/* ───────── 11. Print (reports, A4) ───────── */
.print-area { display: none; }
/* Wide reports (إجمالي, كل الدفعات: 8 columns) print landscape; the 5-column شهري تفصيلي prints portrait.
   Add .print-area--portrait to #print-area when the monthly report is the one being printed. */
@page { size: A4 landscape; margin: 12mm; }
@page portrait { size: A4 portrait; margin: 14mm; }
.print-area--portrait { page: portrait; }
@media print {
  .no-print, .sidebar, .topbar, .toast, .dialog-backdrop { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .print-area { display: block; }
  .print-head { text-align: center; border-block-end: 2px solid #000; padding-block-end: 8pt; margin-block-end: 12pt; }
  .print-head h1 { margin: 0; font-size: 18pt; }
  .print-figures { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid #000; margin-block-end: 12pt; }
  .print-figures > div { padding: 6pt 10pt; border-inline-end: 1px solid #000; }
  .print-figures strong { display: block; font-size: 15pt; }
  .print-area .table th { background: none; color: #000; border-block: 2px solid #000; font-size: 12pt; white-space: normal; }
  .print-area .table td { border-block-start: 0; border-block-end: 1px solid #777; color: #000; vertical-align: top; }
  .print-area .table tr { break-inside: avoid; }
  .print-area .table tfoot td { background: none; border-block: 2px solid #000; }
  .print-area .badge { border: 0; background: none; color: #000; padding: 0; } /* state stays readable as icon + text */
}

/* ───────── 12. App additions ───────── */
.page { display: none; }
.page.active { display: flex; flex-direction: column; gap: var(--sp-5); }
.btn--caution { background: var(--c-soon-solid); }
.btn--caution:hover { background: var(--c-soon-fg); }
.auth-screen { min-block-size: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--sp-4); }
.auth-error { display: none; align-items: center; gap: var(--sp-2); color: var(--c-danger); font-weight: var(--fw-medium); font-size: var(--fs-sm); }
.auth-error:not(:empty) { display: flex; }
.topbar__inv { display: inline-flex; align-items: center; gap: 6px; min-block-size: var(--control-h); padding-inline: var(--sp-3); flex: none; white-space: nowrap; border-radius: var(--r-md); background: var(--c-collected-bg); color: var(--c-collected-fg); font-weight: var(--fw-bold); font-size: var(--fs-sm); text-decoration: none; }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); }
.page-head .page-title { margin-inline-end: auto; }
.role-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); color: var(--c-text-2); }
.form-grid .form-grid__action { align-self: end; }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-4); }

/* ───────── 13. Dashboard, invoices, contracts ───────── */
.sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.figure__count { font-weight: var(--fw-medium); white-space: nowrap; }
.due-group__head.is-toggle { cursor: pointer; }
.due-group__head .btn { font-size: var(--fs-sm); }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.row-actions .btn { font-size: var(--fs-sm); padding-inline: .875rem; }
.row-actions .btn--link { margin-inline-start: auto; padding-inline: var(--sp-2); }   /* إلغاء التحصيل: far end of the row */
.row-toggle { display: inline-flex; align-items: center; justify-content: center; inline-size: var(--control-h); block-size: var(--control-h); padding: 0; border: 0; border-radius: var(--r-md); background: none; color: var(--c-text-2); cursor: pointer; }
.row-toggle:hover { background: var(--c-surface-3); }
.toolbar__search { flex: 1 1 200px; max-inline-size: 280px; }
.toolbar__select { inline-size: 220px; }
.table--contracts .c-toggle { inline-size: 1%; padding-inline: 0 var(--sp-3); }
.pay-line { display: grid; grid-template-columns: 100px minmax(150px, 1fr) auto 90px; gap: var(--sp-4); align-items: center; min-block-size: 52px; border-block-end: 1px solid var(--c-border-soft); }
.pay-line__act { display: flex; justify-content: flex-end; }
.detail-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-block-start: .875rem; }
.detail-actions .btn--danger-outline { margin-inline-start: auto; }
.import-cols { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--c-text-2); }
.import-cols > span { flex: 1 1 280px; }
.figures.import-figures { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .625rem; }
.import-figures .figure { padding: var(--sp-2) .875rem; }
.import-figures .figure__label { color: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.import-figures .figure__value { font-size: 1.375rem; }
.figure--added { background: var(--c-paid-bg); border-color: var(--c-paid-border); }
.figure--skipped { background: var(--c-surface-3); }
.figure--rejected { background: var(--c-overdue-bg); border-color: var(--c-overdue-border); color: var(--c-overdue-fg); }
.import-result { font-weight: var(--fw-bold); white-space: nowrap; }
.import-result .icon { inline-size: 1em; block-size: 1em; margin-inline-end: var(--sp-1); vertical-align: -.125em; stroke-width: 2.25; }
.table--import .is-added .import-result { color: var(--c-paid-fg); }
.table--import .is-skipped .import-result { color: var(--c-text-muted); }
.table--import tr.is-rejected td { background: var(--c-overdue-bg); }
.table--import .is-rejected .import-result { color: var(--c-overdue-fg); }
.import-line { margin: 0; font-size: var(--fs-sm); }
.import-line--ignored { color: var(--c-warning-fg); font-weight: var(--fw-medium); }
#payImportPreview:empty { display: none; }
@media (min-width: 700px) {
  /* the three due groups are separate tables: fixed columns keep them aligned */
  .table--due { table-layout: fixed; min-inline-size: 848px; }
  .table--due .due-rel { inline-size: 150px; }
  .table--due .d-owner { inline-size: 22%; }
  .table--due .d-date { inline-size: 124px; }
  .table--due .cell-amount { inline-size: 150px; }
  .table--due .cell-actions { inline-size: 156px; }
  .table--due .cell-actions .btn { inline-size: 100%; }
}
@media (max-width: 699px) {
  .figure__count { flex-basis: 100%; }
  .toolbar__search, .toolbar__select { flex: 1 1 100%; max-inline-size: none; inline-size: 100%; }
  .table--stack tr > td { min-inline-size: 0; }
  /* dashboard row: tenant + amount / owner / when, date, تحصيل */
  .table--due tr { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px var(--sp-3); align-items: center; }
  .table--due .d-tenant { grid-area: 1 / 1 / 2 / 3; }
  .table--due .cell-amount { grid-area: 1 / 3; align-self: start; }
  .table--due .d-owner { grid-area: 2 / 1 / 3 / -1; }
  .table--due .due-rel { grid-area: 3 / 1; }
  .table--due .d-date { grid-area: 3 / 2; font-size: var(--fs-sm); }
  .table--due .cell-actions { grid-area: 3 / 3; padding-block-start: 0; }
  .table--due tr > td, .table--contracts tr.contract-row > td, .table--inv tr > td, .table--pays tr > td { inline-size: auto; }
  /* pending invoice: tenant + amount on the first line, full-width button */
  .table--inv tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--sp-3); }
  .table--inv td { grid-column: 1 / -1; }
  .table--inv td:first-child { grid-column: 1; }
  .table--inv .cell-amount { grid-area: 1 / 2; }
  .table--inv .i-collected { color: var(--c-collected-fg); font-weight: var(--fw-medium); }
  .table--inv .cell-actions .btn { inline-size: 100%; }
  /* contract row: tenant, state, chevron / number / owner / rent + next payment */
  .table--contracts tr.contract-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2px var(--sp-3); align-items: center; padding-inline-end: var(--sp-2); }
  .table--contracts .c-tenant { grid-area: 1 / 1; }
  .table--contracts .c-state { grid-area: 1 / 2; }
  .table--contracts .c-toggle { grid-area: 1 / 3 / 3 / 4; padding: 0; }
  .table--contracts .c-id { grid-area: 2 / 1 / 3 / 3; font-size: var(--fs-sm); color: var(--c-text-muted); }
  .table--contracts .c-id::before { content: "عقد رقم "; }
  .table--contracts .c-owner { grid-area: 3 / 1 / 4 / -1; }
  .table--contracts .c-rent { grid-area: 4 / 1; }
  .table--contracts .c-next { grid-area: 4 / 2 / 5 / -1; font-size: var(--fs-sm); text-align: end; }
  .table--contracts .c-remain { display: none; }
  .table--contracts tr.is-clickable:hover td { background: none; } /* grid row: tint the row, not the cells */
  .table--contracts tr.is-clickable:hover { background: var(--c-surface-2); }
  .pay-line { grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-1) var(--sp-3); padding-block: var(--sp-2); }
  .pay-line > strong, .pay-line__act { justify-self: end; }
  .detail-actions .btn { flex: 1 1 auto; }
  /* payments dialog: date + amount / invoice + state / actions */
  .table--pays tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-1) var(--sp-3); align-items: center; }
  .table--pays tr > td:nth-child(2) { justify-self: end; }
  .table--pays tr > td:nth-child(5) { grid-column: 1 / -1; }
  .import-figures .figure__value { font-size: 1.1875rem; }
}

/* ───────── 14. Form, owners, users, reports ───────── */
/* contract form */
.contract-form { padding: 6px var(--sp-5) var(--sp-5); }
#scan-slot:empty, #scan-warnings:empty { display: none; }
.tag-scanned { white-space: nowrap; }
.scan-actions { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); margin-block-start: .875rem; }
.field__hint:empty { display: none; }
.yearly { display: flex; flex-direction: column; gap: .875rem; }
.yearly > .btn { align-self: flex-start; }
#f-docs:empty { display: none; }
#f-docs .docs-list { display: contents; }   /* caption → section title column, rows → field column */
#f-docs .detail-caption { margin: 0; padding-block-start: var(--sp-3); font-size: var(--fs-lg); font-weight: var(--fw-heavy); color: var(--c-text); }
.docs-list .list-row { flex-wrap: wrap; gap: .625rem; min-block-size: 56px; }
.docs-list .list-row__grow { font-weight: var(--fw-medium); }
.doc-open { font-weight: var(--fw-bold); padding: .625rem var(--sp-1); }

/* owners, users */
.table-wrap__title { margin: 0; padding: var(--sp-3) var(--sp-5); font-size: var(--fs-xl); font-weight: var(--fw-heavy); }
.users-table__perm { color: var(--c-text-2); }
.users-table__owner { display: flex; align-items: center; gap: 6px; font-weight: var(--fw-medium); }
input.secret { inline-size: 100%; color: var(--c-text); }

/* reports */
.table .cell-strong { font-weight: var(--fw-bold); }
.report-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .875rem; }
.report-filters .field { flex: 0 1 200px; }
.report-filters .report-filters__year { flex-basis: 110px; }
.report-filters .report-filters__type { flex-basis: 180px; }
#report-output { display: flex; flex-direction: column; gap: var(--sp-5); }
#report-output .figures { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.report-table td { font-size: var(--fs-sm); }
.report-table td.cell-strong { font-size: var(--fs-md); }

@media (max-width: 699px) {
  .contract-form { padding-inline: var(--sp-4); }
  .report-filters .field, .report-filters .report-filters__year, .report-filters .report-filters__type { flex: 1 1 140px; }
  .report-filters .btn { flex: 1 1 auto; }
  #report-output .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table--stack td.is-end { text-align: start; }
  .table--stack td.is-empty { display: none; }
  .table--stack .cell-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .table--stack .cell-actions > * + * { margin-inline-start: 0; }
  .table--stack tfoot tr { background: var(--c-surface-2); border-block-start: 2px solid var(--c-text); }
  .table--stack tfoot td { border: 0; background: none; }
}

/* print: only the report sheet, never the screen page behind it */
@media print {
  body:has(> .print-area:not(:empty)) > .app { display: none !important; }
  .print-head p { margin: 2pt 0 0; }
  .print-figures { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
  .print-figures > div:last-child { border-inline-end: 0; }
  .print-area .table th, .print-area .table td { padding: 4pt 6pt; font-size: 12pt; }
  .print-area .table tfoot { display: table-row-group; } /* totals once, at the end — not repeated on every page */
}
