/* =====================================================================
   مجمع الحسام — قسم الطباعة | تطبيق الموبايل
   نظام تصميم: فاخر ونظيف — مساحات واسعة، خطوط كبيرة، ظلال ناعمة
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

:root {
    /* الأسطح */
    --bg:          #f6f7f9;
    --surface:     #ffffff;
    --surface-2:   #fafbfc;
    --line:        #eceef2;
    --line-strong: #e2e5ea;

    /* النص */
    --ink:      #0b1220;
    --ink-2:    #3d4757;
    --muted:    #79839a;
    --muted-2:  #a8b0c0;

    /* الهوية */
    --brand:      #4f46e5;
    --brand-2:    #6366f1;
    --brand-deep: #3730a3;
    --brand-tint: #f0f1fe;

    /* الدلالات */
    --green:      #0d9f6e;
    --green-tint: #e9f9f2;
    --red:        #e5484d;
    --red-tint:   #fdeef0;
    --amber:      #e0900a;
    --amber-tint: #fdf5e6;
    --blue:       #3b82f6;
    --blue-tint:  #eef4ff;
    --violet:     #7c5cf5;
    --violet-tint:#f2effe;

    /* الأنصاف الأقطار */
    --r-xs: 10px;
    --r-sm: 14px;
    --r:    18px;
    --r-lg: 24px;
    --r-xl: 32px;

    /* الظلال — طبقتان ناعمتان بدل الحدود */
    --sh-1: 0 1px 2px rgba(11,18,32,.04), 0 1px 3px rgba(11,18,32,.05);
    --sh-2: 0 2px 6px rgba(11,18,32,.05), 0 8px 20px -6px rgba(11,18,32,.08);
    --sh-3: 0 12px 40px -10px rgba(11,18,32,.16);
    --sh-brand: 0 8px 24px -6px rgba(79,70,229,.42);

    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-h: 68px;

    --ease: cubic-bezier(.32,.72,0,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; padding: 0; height: 100%;
    overscroll-behavior-y: none;
}

body {
    font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.55;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body.no-scroll { overflow: hidden; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
input, select, textarea { -webkit-appearance: none; appearance: none; }

/* الأرقام: تباعد مضبوط وعرض ثابت حتى لا ترقص أثناء التحديث */
.num, .value, .li-amount, .stat .value, .hero-figure, .summary-row .v {
    font-variant-numeric: tabular-nums;
    letter-spacing: -.02em;
}

/* ===================== تسجيل الدخول ===================== */

#login-screen {
    position: fixed; inset: 0; z-index: 900;
    display: flex; align-items: center; justify-content: center;
    padding: 28px 22px;
    background:
        radial-gradient(90% 60% at 50% -10%, #eef0ff 0%, transparent 62%),
        linear-gradient(180deg, #ffffff 0%, #f6f7f9 100%);
}

.login-card {
    width: 100%; max-width: 380px;
    text-align: center;
}

.login-logo {
    width: 84px; height: 84px; margin: 0 auto 20px;
    border-radius: 26px; overflow: hidden;
    background: #fff;
    box-shadow: var(--sh-2);
    padding: 8px;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }

.login-card h1 {
    margin: 0 0 4px;
    font-size: 1.72rem; font-weight: 700;
    letter-spacing: -.03em;
}
.login-card .sub {
    margin: 0 0 30px;
    color: var(--muted); font-size: .9rem; font-weight: 500;
}

#login-form {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 22px 20px 20px;
    box-shadow: var(--sh-2);
    text-align: right;
}

/* ===================== الحقول ===================== */

.field { margin-bottom: 16px; text-align: right; }
.field > label {
    display: block; margin-bottom: 8px;
    font-size: .8rem; font-weight: 600; color: var(--ink-2);
}

.input,
input[type=text], input[type=password], input[type=number],
input[type=search], input[type=date], input[type=tel],
select, textarea {
    width: 100%;
    min-height: 52px;
    padding: 13px 16px;
    border: 1.5px solid transparent;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--line);
    font-weight: 500; font-size: .95rem;
    color: var(--ink);
    outline: none;
    transition: box-shadow .2s var(--ease), background .2s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.7; }

.input:focus, input:focus, select:focus, textarea:focus {
    background: var(--surface);
    box-shadow: inset 0 0 0 1.5px var(--brand), 0 0 0 4px rgba(79,70,229,.1);
}

input::placeholder, textarea::placeholder { color: var(--muted-2); font-weight: 400; }

input[readonly], input:disabled, select:disabled, textarea:disabled {
    background: #f2f4f7; color: var(--muted); box-shadow: none;
}

select {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2379839a' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: left 15px center;
    padding-left: 44px;
}

input[type=date] { text-align: right; }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.field-row { display: flex; gap: 12px; }
/* min-width:0 يمنع حقول التاريخ من تجاوز عرض الصف */
.field-row > .field { flex: 1 1 0; min-width: 0; }
.field-row input[type=date] { padding-right: 12px; padding-left: 8px; font-size: .9rem; }

.field-error {
    display: none;
    background: var(--red-tint); color: #b42328;
    padding: 12px 14px; border-radius: var(--r-sm);
    font-size: .83rem; font-weight: 600; margin-bottom: 14px;
    white-space: pre-line; text-align: center; line-height: 1.65;
}
.field-error.in { display: block; }

/* ===================== الأزرار ===================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    min-height: 52px; padding: 0 22px;
    border-radius: var(--r-sm);
    font-weight: 600; font-size: .95rem;
    letter-spacing: -.01em;
    transition: transform .16s var(--ease), box-shadow .2s, background .2s, opacity .2s;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn svg { width: 19px; height: 19px; flex: none; }

.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--sh-brand); }
.btn-primary:active { background: var(--brand-deep); }
.btn-success { background: var(--green); color: #fff; box-shadow: 0 8px 24px -6px rgba(13,159,110,.42); }
.btn-danger  { background: var(--red); color: #fff; box-shadow: 0 8px 24px -6px rgba(229,72,77,.4); }
.btn-warning { background: var(--amber); color: #fff; box-shadow: 0 8px 24px -6px rgba(224,144,10,.4); }
.btn-ghost   { background: #eef0f4; color: var(--ink-2); }
.btn-soft    { background: var(--brand-tint); color: var(--brand); }
.btn-outline { background: var(--surface); color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.btn-block   { display: flex; width: 100%; }
.btn-sm      { min-height: 40px; padding: 0 15px; font-size: .84rem; border-radius: 11px; }

/* ===================== الهيكل ===================== */

#app { display: none; min-height: 100%; flex-direction: column; }
#app.in { display: flex; }

.app-header {
    position: sticky; top: 0; z-index: 60;
    padding: calc(var(--safe-top) + 14px) 18px 14px;
    background: rgba(255,255,255,.86);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 13px;
}

.hdr-back {
    width: 40px; height: 40px; flex: none;
    display: none; align-items: center; justify-content: center;
    border-radius: 13px; background: #f1f3f6; color: var(--ink-2);
    transition: transform .16s var(--ease), background .2s;
}
.hdr-back.in { display: flex; }
.hdr-back:active { transform: scale(.9); background: #e7eaef; }
.hdr-back svg { width: 19px; height: 19px; }

.hdr-logo {
    width: 40px; height: 40px; flex: none;
    border-radius: 13px; overflow: hidden;
    background: #fff; padding: 3px;
    box-shadow: var(--sh-1);
}
.hdr-logo img { width: 100%; height: 100%; object-fit: contain; }

.hdr-titles { flex: 1; min-width: 0; }
.hdr-titles h1 {
    margin: 0; font-size: 1.06rem; font-weight: 700;
    letter-spacing: -.025em; color: var(--ink);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hdr-titles span {
    display: block; font-size: .76rem; font-weight: 500; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.hdr-status {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: .7rem; font-weight: 600;
    padding: 7px 11px; border-radius: 999px;
    background: var(--green-tint); color: #087a54;
    flex: none;
}
.hdr-status .dot {
    width: 6px; height: 6px; border-radius: 50%; background: var(--green);
    box-shadow: 0 0 0 3px rgba(13,159,110,.16);
}
.hdr-status.offline { background: var(--amber-tint); color: #9a6206; }
.hdr-status.offline .dot { background: var(--amber); box-shadow: 0 0 0 3px rgba(224,144,10,.16); }

main {
    flex: 1;
    padding: 20px 18px calc(var(--nav-h) + var(--safe-bottom) + 28px);
    max-width: 680px; width: 100%; margin: 0 auto;
}

/* ===================== شريط التنقل ===================== */

.bottom-nav {
    position: fixed; bottom: 0; right: 0; left: 0; z-index: 70;
    display: flex; gap: 2px;
    padding: 8px 10px calc(var(--safe-bottom) + 10px);
    background: rgba(255,255,255,.9);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--line);
    max-width: 680px; margin: 0 auto;
}

.nav-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 7px 2px 6px;
    color: var(--muted-2);
    font-size: .67rem; font-weight: 600;
    border-radius: 14px;
    transition: color .2s, background .2s;
}
.nav-btn svg { width: 23px; height: 23px; stroke-width: 1.9; transition: stroke-width .2s; }
.nav-btn.active { color: var(--brand); background: var(--brand-tint); }
.nav-btn.active svg { stroke-width: 2.3; }

/* ===================== البطاقات ===================== */

.card {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--sh-1);
    padding: 20px;
    margin-bottom: 14px;
}

.section-title {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: 12px; margin: 26px 4px 14px;
}
.section-title h2 {
    margin: 0; font-size: 1.02rem; font-weight: 700;
    letter-spacing: -.025em; color: var(--ink);
}
.section-title .hint { font-size: .78rem; color: var(--muted); font-weight: 500; }
.section-title .hint[id] { color: var(--brand); font-weight: 600; cursor: pointer; }

/* ===================== البطاقة البطلة (الرئيسية) ===================== */

.hero {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-2);
    padding: 24px 22px 20px;
    margin-bottom: 14px;
    position: relative; overflow: hidden;
}
.hero-label {
    font-size: .8rem; font-weight: 600; color: var(--muted);
    display: block; margin-bottom: 10px;
}
.hero-figure {
    font-size: 2.6rem; font-weight: 700; line-height: 1.05;
    letter-spacing: -.045em; color: var(--ink);
    display: flex; align-items: baseline; gap: 8px;
}
.hero-figure .cur {
    font-size: .92rem; font-weight: 600; color: var(--muted);
    letter-spacing: 0;
}
.hero-delta {
    display: inline-flex; align-items: center; gap: 5px;
    margin-top: 12px;
    font-size: .8rem; font-weight: 600;
    padding: 6px 11px; border-radius: 999px;
}
.hero-delta.up   { background: var(--green-tint); color: #087a54; }
.hero-delta.down { background: var(--red-tint);   color: #b42328; }
.hero-delta.flat { background: #f1f3f6;           color: var(--muted); }

.spark { display: block; width: 100%; height: 56px; margin-top: 18px; }

/* إجراءات سريعة */
.quick-row { display: flex; gap: 12px; margin-bottom: 6px; }
.quick {
    flex: 1;
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--sh-1);
    padding: 16px 12px;
    display: flex; flex-direction: column; align-items: center; gap: 9px;
    transition: transform .16s var(--ease), box-shadow .22s;
}
.quick:active { transform: scale(.96); box-shadow: var(--sh-2); }
.quick-ico {
    width: 46px; height: 46px; border-radius: 15px;
    display: flex; align-items: center; justify-content: center;
}
.quick-ico svg { width: 22px; height: 22px; stroke-width: 2.1; }
.quick span { font-size: .8rem; font-weight: 600; color: var(--ink-2); }

/* ===================== الإحصائيات ===================== */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.stat {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--sh-1);
    padding: 16px 17px;
    position: relative;
}
.stat .label {
    font-size: .76rem; font-weight: 600; color: var(--muted);
    display: flex; align-items: center; gap: 7px; margin-bottom: 8px;
}
.stat .label::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent, var(--brand)); flex: none;
}
.stat .value {
    font-size: 1.32rem; font-weight: 700; color: var(--ink);
    display: block; line-height: 1.2;
}
.stat .unit {
    font-size: .7rem; font-weight: 500; color: var(--muted-2);
    margin-right: 4px; letter-spacing: 0;
}

/* ===================== الأقسام (البلاطات) ===================== */

.tile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tile {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--sh-1);
    padding: 18px 16px;
    display: flex; flex-direction: column; align-items: flex-start; gap: 11px;
    text-align: right;
    transition: transform .16s var(--ease), box-shadow .22s;
}
.tile:active { transform: scale(.965); box-shadow: var(--sh-2); }
.tile-ico {
    width: 46px; height: 46px; border-radius: 15px;
    display: flex; align-items: center; justify-content: center;
}
.tile-ico svg { width: 22px; height: 22px; stroke-width: 2.1; }
.tile .t-title { font-size: .95rem; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
.tile .t-desc  { font-size: .75rem; font-weight: 500; color: var(--muted); line-height: 1.55; }

/* ===================== القوائم ===================== */

.list-item {
    display: flex; align-items: center; gap: 14px;
    width: 100%;
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--sh-1);
    padding: 15px 17px; margin-bottom: 10px;
    text-align: right;
    transition: transform .14s var(--ease), box-shadow .2s;
}
.list-item:active { transform: scale(.99); box-shadow: var(--sh-2); }

.li-main { flex: 1; min-width: 0; }
.li-title {
    display: block; font-weight: 600; font-size: .95rem; color: var(--ink);
    letter-spacing: -.015em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.li-sub {
    display: block; font-size: .78rem; color: var(--muted);
    font-weight: 500; margin-top: 3px;
}
.li-end { text-align: left; flex: none; }
.li-amount { display: block; font-weight: 700; font-size: 1rem; }
.li-meta { display: block; font-size: .7rem; color: var(--muted-2); font-weight: 500; margin-top: 1px; }

.li-actions { display: flex; gap: 7px; flex: none; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: #f1f3f6; color: var(--muted);
    transition: transform .14s var(--ease);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.edit { background: var(--amber-tint); color: var(--amber); }
.icon-btn.del  { background: var(--red-tint);   color: var(--red); }
.icon-btn.view { background: var(--blue-tint);  color: var(--blue); }
.icon-btn:active { transform: scale(.88); }

/* ===================== الشارات ===================== */

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 999px;
    font-size: .69rem; font-weight: 600;
}
.badge-green { background: var(--green-tint); color: #087a54; }
.badge-red   { background: var(--red-tint);   color: #b42328; }
.badge-amber { background: var(--amber-tint); color: #9a6206; }
.badge-blue  { background: var(--blue-tint);  color: #1d4ed8; }
.badge-gray  { background: #f1f3f6;           color: var(--muted); }

.money-pos { color: var(--green); }
.money-neg { color: var(--red); }

/* ===================== البحث ===================== */

.search-wrap { position: relative; margin-bottom: 14px; }
.search-wrap svg {
    position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    width: 18px; height: 18px; color: var(--muted-2); pointer-events: none;
}
.search-wrap input { padding-right: 46px; }

/* ===================== الحالة الفارغة ===================== */

.empty-state {
    text-align: center; padding: 52px 22px;
    color: var(--muted); font-weight: 500; font-size: .9rem; line-height: 1.7;
}
.empty-state.small { padding: 32px 18px; font-size: .85rem; }
.empty-state svg { width: 44px; height: 44px; color: var(--line-strong); margin-bottom: 14px; stroke-width: 1.5; }

/* ===================== النوافذ السفلية ===================== */

.sheet-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(11,18,32,.44);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: flex-end; justify-content: center;
    opacity: 0; transition: opacity .28s var(--ease);
}
.sheet-overlay.in { opacity: 1; }

.sheet {
    width: 100%; max-width: 680px; max-height: 93vh;
    background: var(--bg);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    display: flex; flex-direction: column;
    transform: translateY(100%);
    transition: transform .38s var(--ease);
    overflow: hidden;
}
.sheet-overlay.in .sheet { transform: translateY(0); }
.sheet-full { height: 93vh; }

.sheet-head {
    position: relative; flex: none;
    padding: 18px 20px 15px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 12px;
}
.sheet-grip {
    position: absolute; top: 8px; right: 50%; transform: translateX(50%);
    width: 40px; height: 4px; border-radius: 99px; background: var(--line-strong);
}
.sheet-head h3 {
    margin: 5px 0 0; flex: 1;
    font-size: 1.06rem; font-weight: 700; letter-spacing: -.025em;
}
.sheet-close {
    width: 36px; height: 36px; border-radius: 12px;
    background: #f1f3f6; color: var(--muted);
    display: flex; align-items: center; justify-content: center;
    transition: transform .14s var(--ease);
}
.sheet-close:active { transform: scale(.9); }
.sheet-close svg { width: 16px; height: 16px; }

.sheet-body {
    flex: 1; overflow-y: auto;
    padding: 20px 18px calc(var(--safe-bottom) + 26px);
    -webkit-overflow-scrolling: touch;
}

.sheet-actions {
    display: flex; gap: 12px;
    padding-top: 10px; padding-bottom: 4px;
    position: sticky; bottom: -1px;
    background: linear-gradient(to top, var(--bg) 74%, transparent);
}
.sheet-actions .btn { flex: 1; }

/* ===================== نافذة التأكيد ===================== */

.dialog-overlay {
    position: fixed; inset: 0; z-index: 300;
    background: rgba(11,18,32,.5);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 26px;
    opacity: 0; transition: opacity .22s var(--ease);
}
.dialog-overlay.in { opacity: 1; }

.dialog-box {
    width: 100%; max-width: 340px;
    background: var(--surface); border-radius: var(--r-lg);
    padding: 30px 24px 22px; text-align: center;
    box-shadow: var(--sh-3);
    transform: scale(.9); transition: transform .28s var(--ease);
}
.dialog-overlay.in .dialog-box { transform: scale(1); }

.dialog-icon {
    width: 60px; height: 60px; margin: 0 auto 16px;
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
}
.dialog-icon svg { width: 27px; height: 27px; stroke-width: 2.1; }
.dialog-icon.danger { background: var(--red-tint); color: var(--red); }
.dialog-icon.warn   { background: var(--amber-tint); color: var(--amber); }

.dialog-box h3 { margin: 0 0 9px; font-size: 1.1rem; font-weight: 700; letter-spacing: -.025em; }
.dialog-box p {
    margin: 0 0 24px; font-size: .89rem; color: var(--muted);
    font-weight: 500; line-height: 1.7; white-space: pre-line;
}
.dialog-actions { display: flex; gap: 11px; }
.dialog-actions .btn { flex: 1; }

/* ===================== قائمة الاختيار ===================== */

.picker { display: flex; flex-direction: column; height: 100%; }
.picker-add { margin-bottom: 14px; }
.picker-list { flex: 1; }

.picker-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%; text-align: right;
    background: var(--surface);
    border-radius: var(--r-sm);
    box-shadow: var(--sh-1);
    padding: 15px 17px; margin-bottom: 9px;
    transition: transform .14s var(--ease), box-shadow .2s;
}
.picker-item:active { transform: scale(.985); box-shadow: inset 0 0 0 1.5px var(--brand); }
.picker-item-main { flex: 1; min-width: 0; }
.picker-item-title { display: block; font-weight: 600; font-size: .93rem; }
.picker-item-sub { display: block; font-size: .77rem; color: var(--muted); font-weight: 500; margin-top: 2px; }
.picker-item-meta { font-size: .8rem; font-weight: 700; color: var(--brand); flex: none; }

/* ===================== التنبيهات ===================== */

#toast-host {
    position: fixed; top: calc(var(--safe-top) + 14px); right: 14px; left: 14px;
    z-index: 400; display: flex; flex-direction: column; gap: 10px;
    pointer-events: none;
}

.toast {
    display: flex; align-items: center; gap: 12px;
    padding: 15px 17px;
    border-radius: var(--r-sm);
    background: var(--surface);
    box-shadow: var(--sh-3);
    font-weight: 500; font-size: .87rem; line-height: 1.6;
    color: var(--ink-2);
    transform: translateY(-20px) scale(.96); opacity: 0;
    transition: transform .34s var(--ease), opacity .3s;
    white-space: pre-line;
}
.toast.in { transform: translateY(0) scale(1); opacity: 1; }
.toast svg { width: 21px; height: 21px; flex: none; padding: 4px; border-radius: 8px; box-sizing: content-box; }
.toast-success svg { color: var(--green); background: var(--green-tint); }
.toast-danger  svg { color: var(--red);   background: var(--red-tint); }
.toast-warning svg { color: var(--amber); background: var(--amber-tint); }
.toast-info    svg { color: var(--blue);  background: var(--blue-tint); }

/* ===================== الانتظار ===================== */

#busy-overlay {
    position: fixed; inset: 0; z-index: 500;
    background: rgba(246,247,249,.72);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center;
}
#busy-overlay.in { display: flex; }

.spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(79,70,229,.16);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .68s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== صفوف الفاتورة ===================== */

.inv-row {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--sh-1);
    padding: 16px; margin-bottom: 12px;
}
.inv-row-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.inv-row-no {
    width: 28px; height: 28px; flex: none;
    border-radius: 10px; background: var(--brand-tint); color: var(--brand);
    display: flex; align-items: center; justify-content: center;
    font-size: .78rem; font-weight: 700;
}
.inv-row-head .name {
    flex: 1; font-weight: 600; font-size: .9rem; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inv-row-total-badge {
    background: var(--green-tint); color: #087a54;
    padding: 5px 11px; border-radius: 999px;
    font-size: .79rem; font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.inv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.inv-grid .field { margin: 0; }
.inv-grid .field > label { font-size: .73rem; margin-bottom: 5px; }
.inv-grid input { min-height: 46px; padding: 10px 13px; font-size: .9rem; }
.inv-grid .full { grid-column: 1 / -1; }

/* الملخّص */
.summary-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 0; font-size: .9rem; font-weight: 500;
    border-bottom: 1px solid var(--line);
}
.summary-row:last-child { border-bottom: none; }
.summary-row .k { color: var(--muted); }
.summary-row .v { font-weight: 700; color: var(--ink); }
.summary-row.total { padding-top: 16px; }
.summary-row.total .k { color: var(--ink-2); font-weight: 600; font-size: .95rem; }
.summary-row.total .v { color: var(--brand); font-size: 1.35rem; }

/* ===================== الجداول ===================== */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: .82rem; min-width: 440px; }
table.data th {
    background: var(--surface-2); color: var(--muted);
    font-size: .73rem; font-weight: 600; text-align: right;
    padding: 11px 12px; border-bottom: 1px solid var(--line);
    white-space: nowrap; position: sticky; top: 0;
}
table.data td { padding: 12px; border-bottom: 1px solid var(--line); font-weight: 500; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }

/* ===================== التبويبات ===================== */

.tabs {
    display: flex; gap: 3px; padding: 4px;
    background: #eaecf0; border-radius: 15px;
    margin-bottom: 16px;
}
.tab {
    flex: 1; padding: 11px 6px;
    border-radius: 11px;
    font-size: .84rem; font-weight: 600; color: var(--muted);
    transition: background .22s var(--ease), color .22s, box-shadow .22s;
}
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }

/* ===================== مربّع الاختيار ===================== */

.check-row {
    display: flex; align-items: center; gap: 13px;
    padding: 14px 16px; background: var(--surface);
    border-radius: var(--r-sm); box-shadow: var(--sh-1);
    margin-bottom: 9px;
}
.check-row input[type=checkbox] {
    width: 23px; height: 23px; flex: none; margin: 0;
    border-radius: 8px; background: #eef0f4;
    box-shadow: inset 0 0 0 1.5px var(--line-strong);
    position: relative; transition: background .18s, box-shadow .18s;
}
.check-row input[type=checkbox]:checked {
    background: var(--brand); box-shadow: none;
}
.check-row input[type=checkbox]:checked::after {
    content: ''; position: absolute; inset: 0;
    background: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center/14px no-repeat;
}
.check-row label { flex: 1; font-weight: 500; font-size: .9rem; }
.check-row label .li-meta { display: block; }

/* ===================== الزر العائم ===================== */

.fab {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px);
    left: 18px; z-index: 65;
    width: 58px; height: 58px; border-radius: 20px;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--sh-brand);
    transition: transform .18s var(--ease);
}
.fab:active { transform: scale(.88); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }

/* ===================== مساعدات ===================== */

.divider { height: 1px; background: var(--line); margin: 20px 0; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 12px; } .mb-1 { margin-bottom: 12px; }
.mt-2 { margin-top: 22px; } .mb-2 { margin-bottom: 22px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap-gap { display: flex; flex-wrap: wrap; gap: 9px; }

/* ظهور ناعم عند تبديل الشاشات */
main > * { animation: rise .38s var(--ease) both; }
@keyframes rise {
    from { opacity: 0; transform: translateY(9px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    main > * { animation: none; }
    * { transition-duration: .01ms !important; }
}

@media (min-width: 540px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .tile-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ===================== الطباعة ===================== */

#print-holder { display: none; }

@media print {
    body > *:not(#print-holder) { display: none !important; }
    #print-holder { display: block !important; }

    @page { size: A4; margin: 12mm; }

    #print-area { font-family: 'Tahoma', sans-serif; color: #000; direction: rtl; }
    .p-head { text-align: center; border-bottom: 2.5px solid #000; padding-bottom: 8px; margin-bottom: 14px; }
    .p-head h1 { margin: 0; font-size: 20pt; font-weight: 900; }
    .p-head h2 { margin: 2px 0; font-size: 12pt; font-weight: 700; }
    .p-head h3 { margin: 6px 0 0; font-size: 13pt; font-weight: 800; }

    .p-meta { width: 100%; margin-bottom: 12px; font-size: 10pt; }
    .p-meta td { padding: 3px 0; }

    .p-items { width: 100%; border-collapse: collapse; font-size: 10pt; margin-bottom: 14px; }
    .p-items th, .p-items td { border: 1px solid #444; padding: 6px 5px; text-align: center; }
    .p-items th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-weight: 800; }
    .p-items small { font-size: 8pt; color: #444; }

    .p-sum { width: 55%; margin-right: auto; border-collapse: collapse; font-size: 10.5pt; }
    .p-sum td { border: 1px solid #444; padding: 6px 9px; }
    .p-sum td:last-child { text-align: left; font-weight: 800; }
    .p-sum .grand td { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 12pt; font-weight: 900; }

    .p-foot { display: flex; justify-content: space-between; margin-top: 34px; font-size: 10pt; font-weight: 700; }
}
