/* =====================================================
   إدارة الشيكات والكمبيالات - التنسيقات
   خلفية بيضاء + أزرار بلون أزرق سماوي (بلو سيل) + RTL
   ===================================================== */

:root {
    --sky:        #2BA9E0;   /* الأزرق السماوي الرئيسي للأزرار */
    --sky-dark:   #1E90C8;   /* عند التمرير */
    --sky-darker: #157AAE;
    --sky-tint:   #E8F5FC;   /* خلفية فاتحة جداً للأزرق */
    --sky-tint-2: #F2F9FD;

    --bg:         #F2F8FC;   /* خلفية الصفحة الخارجية (أبيض مائل لأزرق فاتح جداً) */
    --surface:    #FFFFFF;   /* سطح التطبيق والبطاقات: أبيض */
    --border:     #E2EAF0;
    --border-soft:#EEF3F7;

    --text:       #17242E;
    --muted:      #6B7C8A;
    --muted-2:    #97A6B2;

    --green:  #1F9D55;
    --green-bg:#E7F6EE;
    --orange: #D9820B;
    --orange-bg:#FCF1E2;
    --red:    #D63031;
    --red-bg: #FBEAEA;
    --gray:   #7A8894;
    --gray-bg:#EEF1F4;
    --blue:   #2B7DE0;
    --blue-bg:#E7F0FC;
    --purple: #7C4DD6;
    --purple-bg:#F0EAFB;

    --shadow:   0 2px 10px rgba(23, 60, 90, 0.06);
    --shadow-md:0 6px 22px rgba(23, 60, 90, 0.10);
    --radius:   16px;
    --radius-sm:12px;

    --maxw: 540px;
    --topbar-h: 60px;
    --nav-h: 66px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
}

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: var(--maxw);
    margin: 0 auto;
    min-height: 100%;
    background: var(--surface);
    position: relative;
    box-shadow: 0 0 40px rgba(23, 60, 90, 0.06);
    display: flex;
    flex-direction: column;
}

/* ---------- الشريط العلوي ---------- */
#topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    background: linear-gradient(135deg, var(--sky) 0%, var(--sky-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    box-shadow: 0 2px 12px rgba(43, 169, 224, 0.30);
}

#topbarTitle {
    font-size: 19px;
    font-weight: 700;
    flex: 1;
    text-align: center;
}

.topbar-spacer { width: 40px; }

.topbar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topbar-btn:active { background: rgba(255, 255, 255, 0.30); }
.topbar-btn svg { width: 22px; height: 22px; }

/* ---------- منطقة المحتوى ---------- */
#content {
    flex: 1;
    padding: 16px 16px calc(var(--nav-h) + 20px);
    overflow-y: auto;
}

.state-msg {
    text-align: center;
    color: var(--muted);
    padding: 48px 16px;
    font-size: 15px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 22px 4px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title:first-child { margin-top: 4px; }
.section-title .bar {
    width: 4px;
    height: 18px;
    background: var(--sky);
    border-radius: 4px;
}

/* ---------- البطاقات الإحصائية ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 16px 14px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-card .stat-icon svg { width: 22px; height: 22px; }

.stat-card .stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.stat-card.amount .stat-value { font-size: 18px; }

.stat-card .stat-label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

/* ألوان أيقونات البطاقات */
.ic-blue   { background: var(--blue-bg);   color: var(--blue); }
.ic-green  { background: var(--green-bg);  color: var(--green); }
.ic-orange { background: var(--orange-bg); color: var(--orange); }
.ic-red    { background: var(--red-bg);    color: var(--red); }
.ic-purple { background: var(--purple-bg); color: var(--purple); }
.ic-sky    { background: var(--sky-tint);  color: var(--sky); }

/* ---------- شريط الأدوات (بحث + فلترة + إضافة) ---------- */
.toolbar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box svg {
    position: absolute;
    right: 14px;
    width: 20px;
    height: 20px;
    color: var(--muted-2);
    pointer-events: none;
}
.search-box input {
    width: 100%;
    padding: 13px 44px 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
}
.search-box input:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-tint);
}

.filter-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.filter-chip {
    flex: 0 0 auto;
    padding: 8px 16px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    border-radius: 999px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.filter-chip.active {
    background: var(--sky);
    border-color: var(--sky);
    color: #fff;
}

/* ---------- الأزرار (بلون أزرق سماوي) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, transform .05s;
    text-align: center;
}
.btn:active { transform: scale(0.985); }
.btn svg { width: 20px; height: 20px; }

.btn-primary {
    background: var(--sky);
    color: #fff;
    box-shadow: 0 4px 14px rgba(43, 169, 224, 0.35);
}
.btn-primary:hover { background: var(--sky-dark); }

.btn-block { width: 100%; }

.btn-outline {
    background: var(--surface);
    color: var(--sky-darker);
    border: 1.5px solid var(--sky);
}
.btn-outline:hover { background: var(--sky-tint); }

.btn-danger {
    background: var(--surface);
    color: var(--red);
    border: 1.5px solid var(--red);
}
.btn-danger:hover { background: var(--red-bg); }

.btn-ghost {
    background: var(--gray-bg);
    color: var(--muted);
}

/* ---------- بطاقة عنصر (شيك / كمبيالة) ---------- */
.item-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

.item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.item-number {
    font-size: 17px;
    font-weight: 700;
    color: var(--sky-darker);
}

.item-rows { display: flex; flex-direction: column; gap: 8px; }
.item-row {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 14.5px;
    color: var(--text);
}
.item-row svg { width: 18px; height: 18px; color: var(--muted-2); flex: 0 0 auto; }
.item-row .lbl { color: var(--muted); }
.item-row.amount { font-weight: 700; color: var(--green); font-size: 16px; }

.item-notes {
    margin-top: 10px;
    padding: 9px 11px;
    background: var(--sky-tint-2);
    border-radius: 10px;
    font-size: 13.5px;
    color: var(--muted);
}

.item-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    border-top: 1px solid var(--border-soft);
    padding-top: 12px;
}
.item-actions .btn { flex: 1; padding: 10px; font-size: 14.5px; }

/* ---------- شرائح الحالة ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}
.chip-green  { background: var(--green-bg);  color: var(--green); }
.chip-orange { background: var(--orange-bg); color: var(--orange); }
.chip-red    { background: var(--red-bg);    color: var(--red); }
.chip-gray   { background: var(--gray-bg);   color: var(--gray); }
.chip-blue   { background: var(--blue-bg);   color: var(--blue); }

.type-tag {
    font-size: 12.5px;
    color: var(--muted);
    background: var(--gray-bg);
    padding: 3px 10px;
    border-radius: 8px;
}

/* ---------- الحالة الفارغة ---------- */
.empty {
    text-align: center;
    padding: 56px 24px;
    color: var(--muted);
}
.empty .empty-icon {
    width: 84px;
    height: 84px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: var(--sky-tint);
    color: var(--sky);
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty .empty-icon svg { width: 40px; height: 40px; }
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 14px; }

/* ---------- النماذج ---------- */
.form { display: flex; flex-direction: column; gap: 4px; }

.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 14.5px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 7px;
}
.field label .req { color: var(--red); }

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--sky);
    box-shadow: 0 0 0 3px var(--sky-tint);
}
.field input[readonly],
.field textarea[readonly] {
    background: var(--sky-tint-2);
    color: var(--muted);
}
.field input.error,
.field select.error {
    border-color: var(--red);
    box-shadow: 0 0 0 3px var(--red-bg);
}
.field .hint { font-size: 12.5px; color: var(--muted-2); margin-top: 5px; }
.field .err-text { font-size: 13px; color: var(--red); margin-top: 5px; display: none; }
.field .err-text.show { display: block; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    margin-bottom: 8px;
}
.form-actions .btn { flex: 1; }

/* ---------- بطاقة بسيطة / إعدادات / تقارير ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 16px;
    margin-bottom: 14px;
}
.card-title {
    font-size: 15.5px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
}

/* مفتاح التبديل */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
}
.switch-row .switch-label { font-size: 15px; font-weight: 500; }
.switch {
    position: relative;
    width: 52px;
    height: 30px;
    flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    inset: 0;
    background: #C9D4DC;
    border-radius: 999px;
    transition: .2s;
    cursor: pointer;
}
.slider::before {
    content: "";
    position: absolute;
    width: 24px;
    height: 24px;
    right: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: .2s;
    box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--sky); }
.switch input:checked + .slider::before { transform: translateX(-22px); }

/* صفوف ملخص التقرير */
.report-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: 15px;
}
.report-row:last-child { border-bottom: none; }
.report-row .r-label { color: var(--muted); }
.report-row .r-value { font-weight: 700; }
.report-row .r-value.green { color: var(--green); }
.report-row .r-value.red { color: var(--red); }

/* مجموعة أزرار الاختيار (نوع التقرير) */
.segmented {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.segmented button {
    flex: 1;
    padding: 11px 8px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.segmented button.active {
    background: var(--sky-tint);
    border-color: var(--sky);
    color: var(--sky-darker);
}

.date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ---------- شريط التنقل السفلي ---------- */
#bottomnav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--maxw);
    height: var(--nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 40;
    box-shadow: 0 -2px 14px rgba(23, 60, 90, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    flex: 1;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    color: var(--muted-2);
    padding: 6px 2px;
    font-family: inherit;
}
.nav-item svg { width: 23px; height: 23px; }
.nav-item span { font-size: 11.5px; font-weight: 500; }
.nav-item.active { color: var(--sky); }
.nav-item.active span { font-weight: 700; }

/* ---------- زر الإضافة العائم ---------- */
.fab {
    position: fixed;
    bottom: calc(var(--nav-h) + 16px);
    left: 50%;
    transform: translateX(calc(-1 * var(--maxw) / 2 + 16px));
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: var(--sky);
    color: #fff;
    border: none;
    box-shadow: 0 6px 18px rgba(43, 169, 224, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 45;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: translateX(calc(-1 * var(--maxw) / 2 + 16px)) scale(0.94); }

@media (max-width: 560px) {
    .fab { transform: none; right: auto; left: 18px; }
    .fab:active { transform: scale(0.94); }
}

/* ---------- التنبيه (Snackbar/Toast) ---------- */
.toast {
    position: fixed;
    bottom: calc(var(--nav-h) + 24px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #17242E;
    color: #fff;
    padding: 13px 20px;
    border-radius: 12px;
    font-size: 14.5px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 100;
    max-width: 90%;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #14794A; }
.toast.error   { background: #B82626; }
.toast.info    { background: var(--sky-darker); }

/* ---------- النافذة المنبثقة (تأكيد) ---------- */
#modal-root:empty { display: none; }
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
    animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: #fff;
    border-radius: 20px;
    padding: 24px 20px 20px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-md);
    text-align: center;
}
.modal .modal-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--red-bg);
    color: var(--red);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal .modal-icon svg { width: 30px; height: 30px; }
.modal h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }
.modal p { font-size: 14.5px; color: var(--muted); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* تحميل صغير */
.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--sky-tint);
    border-top-color: var(--sky);
    border-radius: 50%;
    margin: 40px auto;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
