/* ================================================
   Installment Sales System — Modern Redesign
   Mobile-first · RTL + LTR · Creative & Clean
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Tajawal:wght@300;400;500;700&display=swap');

/* ===== VARIABLES ===== */
:root {
    --sidebar-width: 260px;
    --sidebar-mini: 68px;
    --topbar-h: 64px;
    --bottom-nav-h: 65px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Palette */
    --sidebar-bg: #0f172a;
    --page-bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;

    --primary: #3b82f6;
    --primary-d: #1d4ed8;
    --primary-l: #eff6ff;
    --success: #10b981;
    --success-l: #ecfdf5;
    --danger: #ef4444;
    --danger-l: #fef2f2;
    --warning: #f59e0b;
    --warning-l: #fffbeb;
    --info: #06b6d4;
    --info-l: #ecfeff;
    --purple: #8b5cf6;

    --text: #1e293b;
    --text-2: #64748b;
    --text-3: #94a3b8;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; scroll-behavior: smooth; }
@media (min-width: 768px) { html { font-size: 15px; } }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--page-bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body, .rtl-body {
    font-family: 'Tajawal', 'Inter', system-ui, sans-serif;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s cubic-bezier(.4,0,.2,1),
                transform 0.3s cubic-bezier(.4,0,.2,1);
}

[dir="rtl"] .sidebar { left: auto; right: 0; }

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: var(--topbar-h);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    text-decoration: none;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.15rem;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(59,130,246,0.45);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.4);
    font-weight: 400;
}

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 10px 20px;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }

.nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.3);
    padding: 18px 10px 6px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    margin-bottom: 2px;
    position: relative;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    flex-shrink: 0;
    width: 22px;
    text-align: center;
    transition: transform 0.2s;
}

.sidebar .nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.sidebar .nav-link:hover i { transform: scale(1.1); }

.sidebar .nav-link.active {
    background: linear-gradient(135deg, rgba(59,130,246,0.9), rgba(139,92,246,0.7));
    color: #fff;
    box-shadow: 0 4px 14px rgba(59,130,246,0.3);
}

/* Collapsed sidebar (desktop) */
.sidebar.collapsed { width: var(--sidebar-mini); }
.sidebar.collapsed .sidebar-brand-text { opacity: 0; width: 0; }
.sidebar.collapsed .nav-section-label { opacity: 0; height: 10px; padding: 0; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 11px; gap: 0; }
.sidebar.collapsed .nav-link span { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .nav-link.active { border-radius: 12px; }

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 1035;
    opacity: 0;
    transition: opacity 0.3s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin 0.3s cubic-bezier(.4,0,.2,1);
}
[dir="rtl"] .main-content { margin-left: 0; margin-right: var(--sidebar-width); }
.main-content.expanded { margin-left: var(--sidebar-mini); }
[dir="rtl"] .main-content.expanded { margin-left: 0; margin-right: var(--sidebar-mini); }

/* ===== TOPBAR ===== */
.topbar {
    height: var(--topbar-h);
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 10px;
    transition: box-shadow 0.2s;
}

.topbar-scrolled { box-shadow: 0 4px 20px rgba(0,0,0,0.08); }

.topbar-toggle {
    width: 38px;
    height: 38px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.topbar-toggle:hover { background: var(--page-bg); color: var(--primary); border-color: var(--primary); }

.page-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-icon-btn {
    width: 38px;
    height: 38px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    position: relative;
    flex-shrink: 0;
}
.topbar-icon-btn:hover { background: var(--page-bg); color: var(--primary); border-color: var(--primary); }

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 5px;
    border: 1.5px solid var(--border);
    border-radius: 99px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}
.user-chip:hover { border-color: var(--primary); background: var(--primary-l); color: var(--primary); }
[dir="rtl"] .user-chip { padding: 5px 5px 5px 12px; }

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* ===== CONTENT AREA ===== */
.content-area {
    flex: 1;
    padding: 24px;
}

/* ===== ALERTS ===== */
.alert {
    border: none;
    border-radius: var(--radius);
    padding: 14px 18px;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid;
    box-shadow: var(--shadow-sm);
}
.alert-success { background: var(--success-l); color: #065f46; border-color: var(--success); }
.alert-danger  { background: var(--danger-l);  color: #991b1b; border-color: var(--danger);  }
.alert-warning { background: var(--warning-l); color: #92400e; border-color: var(--warning); }
[dir="rtl"] .alert { border-left: none; border-right: 4px solid; }

/* ===== CARDS ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.25s, transform 0.25s;
    overflow: hidden;
}
.card:hover { box-shadow: var(--shadow); }

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 20px; }

/* ===== STAT CARDS ===== */
.stat-card {
    border-radius: var(--radius-lg);
    padding: 22px;
    color: #fff;
    position: relative;
    overflow: hidden;
    border: none;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: -30px;
    right: -20px;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    pointer-events: none;
}

.stat-card::after {
    content: '';
    position: absolute;
    bottom: -25px;
    left: -15px;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    pointer-events: none;
}

[dir="rtl"] .stat-card::before { right: auto; left: -20px; }
[dir="rtl"] .stat-card::after { left: auto; right: -15px; }

.stat-card .stat-icon {
    font-size: 2.2rem;
    opacity: 0.2;
    position: absolute;
    top: 18px;
    right: 18px;
    pointer-events: none;
}
[dir="rtl"] .stat-card .stat-icon { right: auto; left: 18px; }

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 6px;
    position: relative;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    opacity: 0.88;
    font-weight: 500;
    position: relative;
}

.stat-primary, .stat-card-primary { background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%); }
.stat-success, .stat-card-success { background: linear-gradient(135deg, #064e3b 0%, #10b981 100%); }
.stat-warning, .stat-card-warning { background: linear-gradient(135deg, #78350f 0%, #f59e0b 100%); }
.stat-danger,  .stat-card-danger  { background: linear-gradient(135deg, #7f1d1d 0%, #ef4444 100%); }
.stat-info,    .stat-card-info    { background: linear-gradient(135deg, #164e63 0%, #06b6d4 100%); }

/* ===== TABLES ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table { margin-bottom: 0; }

.table th {
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
    padding: 13px 16px;
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
    white-space: nowrap;
    border-top: none;
}

.table td {
    padding: 13px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text);
}

.table tbody tr:last-child td { border-bottom: none; }

.table-hover tbody tr:hover {
    background: var(--primary-l);
    cursor: pointer;
}

/* ===== BADGES ===== */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 99px;
    letter-spacing: 0.02em;
}

.badge-draft       { background: #f1f5f9; color: #475569; }
.badge-pending     { background: #fef3c7; color: #92400e; }
.badge-active      { background: #d1fae5; color: #065f46; }
.badge-closed      { background: #dbeafe; color: #1d4ed8; }
.badge-cancelled   { background: #fee2e2; color: #991b1b; }
.badge-defaulted   { background: #ede9fe; color: #5b21b6; }
.badge-paid        { background: #d1fae5; color: #065f46; }
.badge-overdue     { background: #fee2e2; color: #991b1b; }
.badge-duetoday    { background: #fef3c7; color: #92400e; }
.badge-partialPaid { background: #dbeafe; color: #1d4ed8; }
.badge-confirmed   { background: #d1fae5; color: #065f46; }
.badge-rejected    { background: #fee2e2; color: #991b1b; }
.badge-reversed    { background: #ede9fe; color: #5b21b6; }
.badge-pendinggapproval { background: #fef3c7; color: #92400e; }

/* ===== FORMS ===== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    padding: 10px 14px;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    outline: none;
}

.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-2);
    margin-bottom: 6px;
    display: block;
}

textarea.form-control { resize: vertical; min-height: 90px; }

/* ===== BUTTONS ===== */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8rem;
    padding: 9px 18px;
    transition: all 0.2s;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1.5px solid transparent;
    font-family: inherit;
    cursor: pointer;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}
.btn-primary:hover {
    background: var(--primary-d);
    border-color: var(--primary-d);
    color: #fff;
    box-shadow: 0 4px 14px rgba(59,130,246,0.4);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    box-shadow: 0 2px 8px rgba(16,185,129,0.3);
}
.btn-success:hover { background: #059669; border-color: #059669; color: #fff; transform: translateY(-1px); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; transform: translateY(-1px); }

.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-warning:hover { background: #d97706; border-color: #d97706; color: #fff; }

.btn-outline-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text-2);
}
.btn-outline-secondary:hover { background: var(--page-bg); border-color: #94a3b8; color: var(--text); }

.btn-outline-primary { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

.btn-outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-outline-success { background: transparent; border-color: var(--success); color: var(--success); }
.btn-outline-success:hover { background: var(--success); color: #fff; }

.btn-sm { font-size: 0.75rem; padding: 7px 14px; }
.btn-lg { font-size: 0.9rem; padding: 12px 24px; }

/* ===== DROPDOWN ===== */
.dropdown-menu {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    font-size: 0.875rem;
    animation: dropIn 0.15s ease;
}
@keyframes dropIn { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }

.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    transition: background 0.15s;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.dropdown-item:hover { background: var(--page-bg); color: var(--text); }
.dropdown-divider { border-color: var(--border); margin: 4px 0; }

/* ===== MODALS ===== */
.modal-content {
    border-radius: var(--radius-xl);
    border: none;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 18px 22px;
    font-weight: 600;
}
.modal-body { padding: 22px; }
.modal-footer { border-top: 1px solid var(--border); padding: 16px 22px; }

/* ===== PAGINATION ===== */
.page-link {
    border-radius: var(--radius-sm) !important;
    margin: 0 2px;
    border: 1.5px solid var(--border);
    color: var(--text-2);
    font-size: 0.8rem;
    padding: 7px 13px;
    transition: all 0.2s;
}
.page-link:hover { background: var(--page-bg); border-color: var(--primary); color: var(--primary); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* ===== INSTALLMENT ROWS ===== */
.installment-row-paid    { background: rgba(16,185,129,0.05) !important; }
.installment-row-overdue { background: rgba(239,68,68,0.05) !important; }
.installment-row-today   { background: rgba(245,158,11,0.06) !important; }

/* ===== NOTIFICATIONS ===== */
.notification-item { border-left: 3px solid transparent; padding: 14px 16px; transition: background 0.15s; }
.notification-item.unread { border-left-color: var(--primary); background: var(--primary-l); }
[dir="rtl"] .notification-item { border-left: none; border-right: 3px solid transparent; }
[dir="rtl"] .notification-item.unread { border-right-color: var(--primary); }

/* ===== CHARTS ===== */
.chart-container { position: relative; height: 280px; }

/* ===== LOGIN PAGE ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #3b82f6 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    top: -20%;
    left: -10%;
    width: 60%;
    height: 70%;
    background: radial-gradient(ellipse, rgba(139,92,246,0.18) 0%, transparent 70%);
    pointer-events: none;
}

.login-wrapper::after {
    content: '';
    position: absolute;
    bottom: -20%;
    right: -10%;
    width: 60%;
    height: 70%;
    background: radial-gradient(ellipse, rgba(59,130,246,0.18) 0%, transparent 70%);
    pointer-events: none;
}

.login-card {
    width: 100%;
    max-width: 430px;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: 0 30px 60px rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.08);
    position: relative;
    z-index: 1;
}

/* ===== BOTTOM NAV (Mobile only) ===== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 1030;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.07);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 3px;
    color: var(--text-3);
    text-decoration: none;
    font-size: 0.62rem;
    font-weight: 600;
    padding: 8px 4px;
    transition: all 0.2s;
    position: relative;
    cursor: pointer;
    background: transparent;
    border: none;
    letter-spacing: 0.01em;
}

.bottom-nav-item i {
    font-size: 1.25rem;
    transition: all 0.2s;
}

.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active i {
    background: var(--primary-l);
    border-radius: 10px;
    padding: 4px 12px;
    color: var(--primary);
}

.bottom-nav-item:active { transform: scale(0.92); }

/* ===== RESPONSIVE ===== */
@media (max-width: 767.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar.show { transform: translateX(0); }

    .main-content,
    [dir="rtl"] .main-content { margin: 0 !important; }

    .content-area {
        padding: 14px;
        padding-bottom: calc(var(--bottom-nav-h) + 14px);
    }

    .bottom-nav { display: flex; }

    .topbar { padding: 0 14px; gap: 8px; }

    .user-name-text { display: none; }

    .stat-card .stat-value { font-size: 1.4rem; }
    .stat-card { padding: 16px; }

    .card-header { padding: 12px 14px; }
    .card-body { padding: 14px; }

    h4, h5 { font-size: 1rem !important; }

    .d-flex.gap-2 { gap: 6px !important; }

    .btn { padding: 8px 14px; }
    .btn-sm { padding: 6px 11px; }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    :root { --sidebar-width: 220px; }
    .content-area { padding: 18px; }
}

/* ===== PRINT ===== */
@media print {
    .sidebar, .topbar, .btn, .alert, .bottom-nav,
    .sidebar-overlay { display: none !important; }
    .main-content, [dir="rtl"] .main-content { margin: 0 !important; }
    .content-area { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}
