/* ==========================================================================
   الواجهة — RTL، الجوال أولًا. كل الألوان كمتغيرات على :root.
   الشريط السفلي ثابت على الجوال (< 768px)، وعلى الكمبيوتر الروابط في الشريط العلوي.
   الجداول .rtable بتتحول لبطاقات على الجوال (data-label على كل خلية).
   ========================================================================== */

/* خط Tajawal متضمّن محليًا (SIL OFL، assets/fonts/OFL-Tajawal.txt): العربي واللاتيني كل واحد في ملف. */
@font-face { font-family: "Tajawal"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/tajawal-arabic-400-normal.woff2") format("woff2");
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/tajawal-arabic-700-normal.woff2") format("woff2");
    unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Tajawal"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/tajawal-latin-400-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Tajawal"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/tajawal-latin-700-normal.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --surface-2: #eef2f0;
    --text: #17211e;
    --muted: #5b6863;
    --border: #d5ddd9;
    --primary: #0f5c4d;
    --primary-ink: #ffffff;
    --primary-soft: #e2efeb;
    --accent: #b45309;
    --accent-ink: #ffffff;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --warning-soft: #fff4de;
    --success-soft: #e5f4ea;
    --info-soft: #e8f0fb;
    --debit: #b42318;      /* على العميل */
    --credit: #1d6b3a;     /* لصالح العميل */
    --radius: 12px;
    --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
    --nav-h: 64px;
    --font: "Tajawal", "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
    color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}

body.bare { padding-bottom: 0; }

h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); }
del { color: var(--muted); }

.icon { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.strong { font-weight: 700; }
.muted, .hint, .sub { color: var(--muted); }
.hint { font-size: .875rem; margin: .25rem 0 .5rem; }
.sub { display: block; font-size: .8125rem; font-weight: 400; }
.pre { white-space: pre-line; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.req { color: var(--danger); }
[hidden] { display: none !important; }

/* ── الإطار ── */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
    background: var(--primary); color: var(--primary-ink);
}
.brand { color: inherit; font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.topnav { display: none; gap: 4px; margin-inline-start: 16px; }
.topnav a, .link-button {
    display: inline-flex; align-items: center; gap: 6px;
    color: inherit; text-decoration: none; padding: 6px 10px; border-radius: 8px;
    background: none; border: 0; font: inherit; cursor: pointer;
}
.topnav a[aria-current="page"], .topnav a:hover, .link-button:hover { background: rgb(255 255 255 / 15%); }
.who { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; font-size: .875rem; }
.who-role { opacity: .8; }
.who-users { color: inherit; display: inline-flex; }
.topnav-logout { display: none; }

.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-narrow { max-width: 460px; padding-top: 10vh; }

.bottom-nav {
    position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgb(0 0 0 / 6%);
}
.bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font: inherit; font-size: .75rem;
    background: none; border: 0; cursor: pointer; width: 100%; height: 100%;
}
.bottom-nav form { margin: 0; }
.bottom-nav .icon { width: 24px; height: 24px; }
.bottom-nav a[aria-current="page"] { color: var(--primary); font-weight: 700; }

@media (min-width: 768px) {
    body { padding-bottom: 32px; }
    .bottom-nav { display: none; }
    .topnav, .topnav-logout { display: flex; }
    .who-users { display: none; }
    .page { padding: 24px; }
}

/* ── عناصر عامة ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.crumbs { margin-bottom: 8px; }
.crumbs a { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.section-title { font-size: 1.05rem; margin: 20px 0 10px; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }
.actions { margin-top: 16px; }

.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 8px 14px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.button:hover { border-color: var(--primary); }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible {
    outline: 3px solid #f59e0b; outline-offset: 2px;
}
.button-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.button-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button-danger-outline { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.button-lg { min-height: 52px; font-size: 1.05rem; padding: 10px 18px; }
.button-block { width: 100%; }
.button-icon { min-width: 44px; padding: 8px; }
.button[disabled], .button[aria-busy="true"] { opacity: .6; cursor: progress; }

.alert { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid transparent; }
.alert p:last-child { margin-bottom: 0; }
.alert .button { margin-top: 8px; }
.alert-success { background: var(--success-soft); border-color: #a7d7b5; }
.alert-error { background: var(--danger-soft); border-color: #f1b0a8; }
.alert-warning { background: var(--warning-soft); border-color: #f2cf8a; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
.badge-unpaid, .badge-overdue, .badge-locked { background: var(--danger-soft); color: var(--danger); border-color: #f1b0a8; }
.badge-partial, .badge-due_today { background: var(--warning-soft); color: #8a4b00; border-color: #f2cf8a; }
.badge-paid, .badge-closed, .badge-active { background: var(--success-soft); color: var(--credit); border-color: #a7d7b5; }
.badge-not_due, .badge-rep, .badge-admin { background: var(--info-soft); color: #1d4e89; border-color: #b9cdec; }
.badge-voided, .badge-inactive { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

.is-debit { color: var(--debit); }
.is-credit { color: var(--credit); }
.is-zero { color: var(--muted); }

/* ── النماذج ── */
.form .field { margin-bottom: 18px; border: 0; padding: 0; min-width: 0; }
fieldset.field { border-top: 1px solid var(--border); padding-top: 14px; }
legend { font-weight: 700; padding: 0; margin-bottom: 4px; }
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="search"], input[type="tel"], input[type="url"], input[type="date"], input[type="password"], select, textarea {
    width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; color: var(--text);
    background: var(--surface); border: 1px solid #b9c5c0; border-radius: 10px;
}
textarea { min-height: 90px; resize: vertical; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; }
.field-error { color: var(--danger); font-size: .875rem; font-weight: 600; margin: 4px 0 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; margin-inline-end: 16px; min-height: 44px; }
.check input { width: 20px; height: 20px; }
.radio-row { display: flex; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 600px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.phone-list { display: grid; gap: 8px; margin-bottom: 8px; }
.phone-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.phone-row .field-error { grid-column: 1 / -1; }

.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-pickers { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.photo-pickers label { margin: 0; }
.photo-preview, .photo-current img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--border); }
.photo-current { margin: 0 0 8px; }
.photo-current figcaption { font-size: .875rem; color: var(--muted); }
.due-preview { margin: 6px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--primary-soft); font-size: .9375rem; }
.due-preview:empty { display: none; }

/* ── الرئيسية والبحث ── */
.home-head { display: grid; gap: 12px; margin-bottom: 8px; }
.search-form { display: flex; gap: 8px; }
.search-form input { min-height: 52px; font-size: 1.05rem; }
.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hide-sm { display: none; }
@media (min-width: 600px) { .hide-sm { display: inline; } .home-actions { display: flex; } }

.customer-cards, .overdue-cards, .user-cards, .plain-list, .alloc-list { list-style: none; margin: 0; padding: 0; }
.customer-cards { display: grid; gap: 10px; }
@media (min-width: 768px) { .customer-cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .customer-cards { grid-template-columns: repeat(3, 1fr); } }
.customer-card {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline;
    padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); text-decoration: none; box-shadow: var(--shadow); min-height: 84px;
}
.customer-card:hover { border-color: var(--primary); }
.cc-name { font-weight: 700; font-size: 1.05rem; }
.cc-code { color: var(--muted); font-size: .875rem; }
.cc-balance { grid-column: 1 / -1; font-weight: 700; }
.cc-overdue { grid-column: 1 / -1; color: var(--danger); font-size: .9rem; font-weight: 600; }
.pager { display: flex; justify-content: center; gap: 10px; margin: 16px 0; }

/* ── ملف العميل ── */
.profile-head {
    position: sticky; top: 52px; z-index: 10;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px 14px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.ph-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ph-photo img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; }
.ph-title { flex: 1 1 140px; min-width: 0; }
.ph-title h1 { font-size: 1.2rem; margin: 0; overflow-wrap: anywhere; }
.ph-code { color: var(--muted); font-size: .875rem; }
.ph-balance { text-align: end; }
.ph-balance strong { display: block; font-size: 1.45rem; line-height: 1.2; }
.ph-label { font-size: .8125rem; color: var(--muted); }
.ph-facts { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.ph-facts div { flex: 1 1 0; background: var(--surface-2); border-radius: 8px; padding: 4px 10px; min-width: 120px; }
.ph-facts div.is-alert { background: var(--danger-soft); color: var(--danger); }
.ph-facts dt { font-size: .75rem; color: var(--muted); }
.ph-facts .is-alert dt { color: inherit; }
.ph-facts dd { margin: 0; font-weight: 700; }
.ph-main-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.action-row .button { flex: none; }
.mini-facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.mini-facts div { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; }
.mini-facts dt { font-size: .75rem; color: var(--muted); }
.mini-facts dd { margin: 0; font-weight: 700; }
@media (min-width: 768px) { .profile-head { top: 60px; } }

.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
.section > summary { cursor: pointer; padding: 14px 16px; list-style: none; display: flex; align-items: center; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary::after { content: "▾"; margin-inline-start: auto; color: var(--muted); transition: transform .15s; }
.section:not([open]) > summary::after { transform: rotate(90deg); }
.section > summary h2 { margin: 0; display: flex; align-items: baseline; gap: 8px; }
.count { font-size: .8125rem; font-weight: 400; color: var(--muted); }
.section-body { padding: 0 16px 16px; }
.section-body > .button { margin-bottom: 12px; }
.sub-title { margin-top: 20px; }
.plain-list li { padding: 8px 0; border-top: 1px solid var(--border); }
.is-voided { color: var(--muted); }
.alloc-list li { font-size: .9rem; }

.void-box summary { list-style: none; min-height: 36px; padding: 4px 10px; font-size: .875rem; }
.void-box summary::-webkit-details-marker { display: none; }
.void-box { margin-top: 6px; }
.inline-delete { display: inline-flex; margin: 0; }
.action-row .inline-delete { flex: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.void-box[open] summary { margin-bottom: 8px; }
.void-box .form { display: grid; gap: 6px; min-width: 220px; }

/* جداول بتبقى بطاقات على الجوال */
.rtable { width: 100%; border-collapse: collapse; }
.rtable th, .rtable td { text-align: start; vertical-align: top; }
@media screen and (max-width: 767px) {
    .rtable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .rtable, .rtable tbody, .rtable tfoot, .rtable tr { display: block; }
    .rtable tr { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
    .rtable tr.is-closed { background: var(--surface-2); }
    .rtable th, .rtable td { display: grid; grid-template-columns: 7.5em 1fr; gap: 8px; padding: 3px 0; }
    .rtable th[scope="row"] { display: block; font-size: 1.05rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 4px; }
    .rtable td::before { content: attr(data-label); color: var(--muted); font-size: .8125rem; font-weight: 400; }
    .rtable tfoot th { display: block; font-weight: 700; }
}
@media print, (min-width: 768px) {
    .rtable { font-size: .9375rem; }
    .rtable th, .rtable td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
    .rtable thead th { background: var(--surface-2); font-size: .8125rem; color: var(--muted); }
    .rtable tr.is-closed { color: var(--muted); }
    .rtable tfoot th, .rtable tfoot td { font-weight: 700; border-bottom: 0; }
}
.rtable tr.is-info td, .rtable tr.is-info th { color: var(--muted); font-style: italic; }

/* ── المتأخرات والمستخدمين ── */
.overdue-cards, .user-cards { display: grid; gap: 10px; }
@media (min-width: 768px) { .overdue-cards { grid-template-columns: repeat(2, 1fr); } }
.overdue-card { margin: 0; }
.oc-customer { text-decoration: none; color: var(--text); display: block; margin-bottom: 6px; }
.oc-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0 0 10px; }
.oc-facts dt { font-size: .75rem; color: var(--muted); }
.oc-facts dd { margin: 0; }
.oc-actions, .uc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.uc-actions form { margin: 0; }
.uc-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.user-card { margin: 0; }
.user-card.is-inactive { opacity: .75; }
.inline-form summary { list-style: none; }
.inline-form summary::-webkit-details-marker { display: none; }
.inline-form[open] { flex-basis: 100%; }
.inline-form .form { display: grid; gap: 6px; margin-top: 8px; max-width: 360px; }

.login-card { padding: 24px; }
.login-title { color: var(--primary); }
.error-card h1 { color: var(--danger); }

/* ── المرحلة ٣: التحصيل والمراجعة والتسوية ── */
.alert-info { background: var(--info-soft); border-color: #b9cdec; }
.button-small { min-height: 36px; padding: 4px 10px; font-size: .875rem; margin-top: 6px; }
.badge-opening { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.pay-head { display: grid; gap: 6px; grid-template-columns: 1fr auto; align-items: center; }
.pay-name { font-size: 1.1rem; }
.pay-balance { text-align: end; }
.pay-balance strong { display: block; font-size: 1.25rem; }
.pay-head > p, .pay-credit { grid-column: 1 / -1; margin: 0; }

.alloc-box > .button { margin-bottom: 10px; }
.alloc-input { max-width: 11em; }
.rtable tr.has-error { outline: 2px solid var(--danger); outline-offset: -2px; background: #fffafa; }
@media (max-width: 767px) {
    .alloc-table td:last-child { grid-template-columns: 1fr; }
    .alloc-table td:last-child::before { display: none; }
    .alloc-input { max-width: none; }
}

.pay-counter { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 12px; }
.pay-counter div { background: var(--primary-soft); border-radius: 10px; padding: 6px 10px; text-align: center; }
.pay-counter span { display: block; font-size: .75rem; color: var(--muted); }
.pay-counter strong { font-variant-numeric: tabular-nums; }
.pay-counter.is-over div:last-child { background: var(--danger-soft); color: var(--danger); }

.sticky-actions {
    position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 5;
    background: var(--surface); border-top: 1px solid var(--border); padding: 10px 0; margin: 0;
}
@media (min-width: 768px) { .sticky-actions { bottom: 0; } }
.sticky-actions .button { flex: 1 1 auto; }

.review-card h2 { margin-top: 16px; }
.review-facts { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 0; }
@media (min-width: 600px) { .review-facts { grid-template-columns: 1fr 1fr; } }
.review-facts div { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.review-facts dt { font-size: .8125rem; color: var(--muted); }
.review-facts dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.review-amount { grid-column: 1 / -1; }
.review-amount dd { font-size: 1.8rem; line-height: 1.2; }
.review-advance { margin-top: 12px; padding: 8px 12px; border-radius: 10px; background: var(--warning-soft); }
.review-net { margin-top: 12px; font-size: 1.05rem; }
.review-net strong { font-size: 1.2rem; }

.receipt-card { text-align: start; }
.receipt-label { margin: 0; color: var(--muted); }
.receipt-no { font-size: 2rem; font-weight: 800; margin: 0 0 8px; letter-spacing: .02em; overflow-wrap: anywhere; }
.receipt-card.is-voided .receipt-no { text-decoration: line-through; color: var(--muted); }
.not-cash { display: inline-block; margin: 0 0 12px; padding: 6px 12px; border-radius: 8px; background: var(--warning-soft); border: 1px solid #f2cf8a; font-weight: 700; color: #7a4100; }

.option-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; font-weight: 400; cursor: pointer; }
.option-card input { width: 20px; height: 20px; margin-top: 3px; flex: none; }
.option-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.option-card.is-disabled { opacity: .55; cursor: not-allowed; }
.oc-body { display: grid; gap: 2px; }

.void-section h2 { color: var(--danger); }
.blocker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.blocker-list li { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; }

/* ── الإيصال المطبوع ── */
.print-page { background: #fff; padding: 16px; }
.print-toolbar { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.slip { max-width: 80mm; margin: 0 auto; font-size: 14px; color: #000; }
.slip-head { display: flex; flex-direction: column; align-items: center; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 8px; }
.slip-head strong { font-size: 18px; }
.slip-void { border: 2px solid #000; text-align: center; font-weight: 800; padding: 4px; }
.slip-rows { margin: 0; }
.slip-rows div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted #999; }
.slip-rows dt { color: #333; }
.slip-rows dd { margin: 0; font-weight: 700; text-align: end; }
.slip-amount dd { font-size: 18px; }
.slip-title { font-size: 14px; margin: 10px 0 4px; }
.slip-list { list-style: none; margin: 0; padding: 0; }
.slip-list li { display: flex; justify-content: space-between; padding: 2px 0; }
.slip-balance { margin-top: 10px; font-weight: 700; }
.slip-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; font-size: 12px; }

@media print {
    .topbar, .bottom-nav, .no-print, .crumbs { display: none !important; }
    body { padding: 0; background: #fff; }
    .print-page { padding: 0; }
    @page { margin: 8mm; }
}

/* الأكواد والأرقام المرجعية (C-00001، RC-2026-00001) ما تتقسمش عند الشرطة */
bdi { white-space: nowrap; }

/* ── صفحة المتأخرات ── */
.overdue-head { text-align: center; }
.oh-label { margin: 0; color: var(--muted); }
.oh-total { font-size: 2rem; font-weight: 800; color: var(--debit); margin: 0; }
.overdue-search { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.chip {
    flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600;
}
.chip[aria-current="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip-count { font-size: .8125rem; opacity: .8; }
.chip-clear { color: var(--danger); }

/* ── الإدخال بالصوت: زرار ميكروفون جنب الحقل (app.js بيضيفه لو المتصفح بيدعم) ── */
.voice-wrap { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; width: 100%; min-width: 0; }
.voice-wrap > input, .voice-wrap > textarea { flex: 1 1 0; min-width: 0; width: auto; }
.voice-wrap-area { align-items: flex-start; }
.voice-button {
    flex: none; width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--primary); cursor: pointer;
}
.voice-button:hover { border-color: var(--primary); }
.voice-button.is-listening { background: var(--danger); border-color: var(--danger); color: #fff; animation: voice-pulse 1.2s ease-in-out infinite; }
@keyframes voice-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgb(180 35 24 / 45%); } 50% { box-shadow: 0 0 0 6px rgb(180 35 24 / 0%); } }
@media (prefers-reduced-motion: reduce) { .voice-button.is-listening { animation: none; } }
.voice-status { flex-basis: 100%; font-size: .875rem; color: var(--muted); }
.search-form .voice-wrap { flex: 1 1 auto; }
.search-form .voice-wrap > input { min-height: 52px; }
.alloc-table .voice-wrap { max-width: 14em; }
@media print { .voice-button, .voice-status { display: none !important; } }

/* ── تقرير العميل (شاشة) ── */
.print-only, .print-footer { display: none; }
.print-frame, .print-frame > tbody, .print-frame > tbody > tr, .print-frame > tbody > tr > td { display: block; }
.print-frame > tfoot { display: none; }
.nowrap { white-space: nowrap; }
.report { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; border-bottom: 2px solid var(--primary); padding-bottom: 10px; margin-bottom: 12px; }
.report-head h1 { margin: 0 0 4px; }
.report-meta { margin: 0; color: var(--muted); }
.report-period { margin: 0; display: grid; gap: 4px; }
.report-period dt { font-size: .75rem; color: var(--muted); }
.report-period dd { margin: 0; font-weight: 700; }
.report-quick { display: grid; gap: 10px; margin-bottom: 16px; }
.rq-balance { padding: 12px; border-radius: 10px; background: var(--surface-2); }
.rq-balance span { display: block; font-size: .875rem; color: var(--muted); }
.rq-balance strong { font-size: 1.8rem; line-height: 1.2; }
.rq-facts { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 0; }
@media (min-width: 600px) { .rq-facts { grid-template-columns: 1fr 1fr; } .report-quick { grid-template-columns: 1fr 2fr; } }
.rq-facts div { border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.rq-facts div.is-alert { border-color: var(--danger); color: var(--danger); }
.rq-facts dt { font-size: .75rem; color: var(--muted); }
.rq-facts dd { margin: 0; font-weight: 700; }
.report-section { margin-top: 18px; }
.report-section h2 { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.kv-table { width: 100%; border-collapse: collapse; max-width: 560px; }
.kv-table th, .kv-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: start; }
.kv-table th { font-weight: 400; color: var(--muted); }
.kv-table tr.strong th, .kv-table tr.strong td { font-weight: 800; color: var(--text); }
.rtable tr.is-edge th, .rtable tr.is-edge td { background: var(--surface-2); font-weight: 700; }

/* ── طباعة التقرير: A4، RTL، هوامش ١٥ ملم ── */
@media print {
    @page { size: A4 portrait; margin: 15mm; }
    html, body { background: #fff !important; color: #000; font-size: 10pt; line-height: 1.45; }
    body { padding: 0 !important; }
    .page { max-width: none; padding: 0; }
    .no-print, .topbar, .bottom-nav, .alert, .period-form, button, .button, form { display: none !important; }
    a { color: #000; text-decoration: none; }
    .print-only { display: inline; }
    .report { border: 0; padding: 0; border-radius: 0; }
    .report-head { border-bottom: 2px solid #000; }
    .report-head h1 { font-size: 16pt; }
    .report-quick { grid-template-columns: 1fr 2fr; }
    .rq-facts { grid-template-columns: 1fr 1fr; }
    .rq-balance, .rq-facts div, .rtable tr.is-edge th, .rtable tr.is-edge td { background: none !important; border: 1px solid #000; }
    .rq-balance strong { font-size: 18pt; }
    .is-debit, .is-credit, .is-zero, .rq-facts div.is-alert { color: #000 !important; }
    .rq-facts div.is-alert { border: 2px solid #000; }
    .report-section { break-inside: auto; }
    .report-section h2 { font-size: 12pt; border-bottom: 1px solid #000; break-after: avoid; }
    h3 { break-after: avoid; }

    /* الجداول: عناوين بتتكرر في كل صفحة، والصف ما يتقسمش */
    .rtable, .kv-table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
    .rtable thead { display: table-header-group; }
    .rtable tfoot { display: table-footer-group; }
    .rtable tr, .kv-table tr { break-inside: avoid; page-break-inside: avoid; }
    .rtable th, .rtable td, .kv-table th, .kv-table td { border: 1px solid #555; padding: 3px 4px; background: none !important; color: #000 !important; }
    .rtable thead th { font-weight: 700; color: #000; }
    .rtable tr.is-closed, .rtable tr.is-voided, .rtable tr.is-info td, .rtable tr.is-info th { color: #000; }

    /* الحالات بالكلام: الشارة من غير لون، بإطار */
    .badge { background: none !important; color: #000 !important; border: 1px solid #000 !important; font-weight: 700; padding: 0 4px; }
    del { color: #000; }

    /* إطار الصفحة: tfoot بيحجز مكان في آخر كل صفحة، والتذييل الثابت بيتطبع فيه */
    .print-frame { display: table; width: 100%; border-collapse: collapse; }
    .print-frame > tbody { display: table-row-group; }
    .print-frame > tfoot { display: table-footer-group; }
    .print-frame > tbody > tr, .print-frame > tfoot > tr { display: table-row; }
    .print-frame > tbody > tr > td, .print-frame > tfoot > tr > td { display: table-cell; padding: 0; border: 0; }
    .print-footer-space { height: 9mm; }
    .print-footer { display: block; position: fixed; bottom: 0; inset-inline: 0; height: 7mm; margin: 0; padding-top: 2mm; border-top: 1px solid #000; font-size: 8pt; text-align: center; background: #fff; }
}
