/* =====================================================
   نظام إدارة جباية المولدات — الأنماط العامة
   ===================================================== */

:root {
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --secondary: #6c757d;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
    --light: #f8f9fa;
    --dark: #212529;

    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #0d6efd;
    --sidebar-text: #cbd5e1;
    --sidebar-text-active: #ffffff;
    --sidebar-width: 260px;

    --body-bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

body {
    font-family: 'Tajawal', 'Cairo', 'Tahoma', Arial, sans-serif;
    background: var(--body-bg);
    color: #1e293b;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

/* تحميل خط Tajawal */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');

a { text-decoration: none; }

/* ========== Layout الرئيسي ========== */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    overflow-y: auto;
    transition: transform .3s ease;
    z-index: 1000;
}

.sidebar-brand {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
}

.sidebar-brand i { font-size: 1.6rem; color: var(--warning); }

.sidebar-nav {
    list-style: none;
    padding: 10px 0;
    margin: 0;
}

.sidebar-nav .nav-section {
    padding: 12px 20px 6px;
    font-size: .75rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: var(--sidebar-text);
    transition: all .2s;
    border-right: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
    border-right-color: var(--warning);
    font-weight: 500;
}

.sidebar-nav i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* ========== المحتوى الرئيسي ========== */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    padding: 12px 24px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 999;
}

.topbar .toggle-btn { display: none; background: none; border: 0; font-size: 1.4rem; }

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-avatar {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--info));
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.user-info { line-height: 1.2; }
.user-info .user-name { font-weight: 600; font-size: .9rem; }
.user-info .user-role { font-size: .75rem; color: var(--secondary); }

.page-content { padding: 24px; flex: 1; }

/* ========== Cards ========== */
.card {
    border: 0;
    box-shadow: var(--card-shadow);
    border-radius: 10px;
}
.card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 14px 18px;
    font-weight: 600;
}
.card-body { padding: 18px; }

/* ========== Stat Cards (Dashboard) ========== */
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    gap: 16px;
    border-right: 4px solid var(--primary);
    transition: transform .2s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-icon {
    width: 56px; height: 56px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem;
    color: #fff;
    flex-shrink: 0;
}
.stat-icon.bg-primary  { background: linear-gradient(135deg, #0d6efd, #0a58ca); }
.stat-icon.bg-success  { background: linear-gradient(135deg, #198754, #146c43); }
.stat-icon.bg-danger   { background: linear-gradient(135deg, #dc3545, #b02a37); }
.stat-icon.bg-warning  { background: linear-gradient(135deg, #ffc107, #cc9a06); }
.stat-icon.bg-info     { background: linear-gradient(135deg, #0dcaf0, #0aa2c0); }

.stat-content { flex: 1; min-width: 0; }
.stat-label { font-size: .85rem; color: var(--secondary); margin: 0; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--dark); margin: 0; }
.stat-meta { font-size: .75rem; color: var(--secondary); }

.stat-card.danger  { border-right-color: var(--danger); }
.stat-card.success { border-right-color: var(--success); }
.stat-card.warning { border-right-color: var(--warning); }
.stat-card.info    { border-right-color: var(--info); }

/* ========== الجداول ========== */
.table-card .card-body { padding: 0; }
.table { margin: 0; }
.table thead th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: .85rem;
    border-bottom: 2px solid #e2e8f0;
    padding: 12px;
}
.table tbody td { padding: 12px; vertical-align: middle; }
.table tbody tr:hover { background: #f8fafc; }

/* ========== الأزرار ========== */
.btn { font-weight: 500; border-radius: 8px; padding: .5rem 1rem; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-icon { padding: .35rem .55rem; }

/* ========== الـ Badges ========== */
.badge { font-weight: 500; padding: .4em .7em; border-radius: 6px; }
.badge-status-paid     { background: #d1fae5; color: #065f46; }
.badge-status-unpaid   { background: #fee2e2; color: #991b1b; }
.badge-status-partial  { background: #fef3c7; color: #92400e; }
.badge-status-cancelled{ background: #e5e7eb; color: #374151; }
.badge-status-active   { background: #dbeafe; color: #1e3a8a; }
.badge-status-suspended{ background: #fef3c7; color: #78350f; }
.badge-status-disconnected { background: #fecaca; color: #7f1d1d; }

/* ========== النماذج ========== */
.form-label { font-weight: 500; color: #374151; margin-bottom: 6px; }
.form-control, .form-select {
    border-radius: 8px;
    border-color: #cbd5e1;
    padding: .5rem .75rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(13,110,253,.15);
}

/* ========== Pagination ========== */
.pagination { gap: 4px; }
.page-link { border-radius: 6px !important; border: 1px solid #e2e8f0; color: var(--primary); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* ========== طبقة التعتيم خلف الشريط الجانبي (موبايل) ========== */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s ease;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

/* زر إغلاق الشريط الجانبي (يظهر على الهاتف فقط) */
.sidebar-close {
    background: none;
    border: 0;
    color: #cbd5e1;
    font-size: 1.35rem;
    line-height: 1;
    margin-right: auto;   /* يدفعه لأقصى اليسار في RTL */
    padding: 2px 6px;
    cursor: pointer;
}
.sidebar-close:hover { color: #fff; }

/* ========== شبكة أسعار الأمبير (متجاوبة) ========== */
.price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}
.price-cell {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 8px;
    text-align: center;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.price-cell-current { background: #fff8e1; border-color: var(--warning); }
.price-month { font-size: .8rem; color: #64748b; font-weight: 600; }
.price-value { font-size: 1.05rem; min-height: 1.3em; display: flex; align-items: center; }
.price-btn { padding: .2rem .5rem; font-size: .75rem; width: 100%; }
@media (max-width: 380px) {
    .price-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ========== Responsive ========== */

/* أجهزة لوحية وهواتف (الشريط الجانبي ينطوي) */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(100%);
        box-shadow: -4px 0 24px rgba(0,0,0,.25);
    }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-right: 0; }
    .topbar .toggle-btn { display: inline-flex; }
    /* منع التمرير الأفقي غير المقصود */
    body { overflow-x: hidden; }
    /* منع تمرير الصفحة أثناء فتح القائمة */
    body.sidebar-open { overflow: hidden; }
    /* أهداف لمس أكبر في القائمة */
    .sidebar-nav a { padding: 13px 20px; }
}

/* أجهزة لوحية */
@media (max-width: 768px) {
    .topbar { padding: 10px 16px; }
    .topbar h5 { font-size: 1rem; }
    .page-content { padding: 16px; }
    .card-body { padding: 16px; }
    .stat-card { padding: 16px; gap: 12px; }
    .stat-icon { width: 48px; height: 48px; font-size: 1.4rem; }
    .stat-value { font-size: 1.3rem; }
}

/* هواتف صغيرة */
@media (max-width: 576px) {
    .page-content { padding: 12px; }
    .topbar { padding: 10px 12px; }
    .card-body { padding: 14px; }
    .sidebar-brand { font-size: 1rem; padding: 16px; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 1.2rem; }
    .stat-label { font-size: .8rem; }

    /* جداول قابلة للتمرير أفقياً مع منع ضغط النص */
    .table-responsive table { min-width: 560px; }
    .table thead th, .table tbody td { padding: 10px 8px; font-size: .82rem; }

    /* أزرار الإجراءات في الجداول تبقى بجانب بعضها */
    .table .btn-sm { padding: .25rem .45rem; }

    /* عناوين الصفحات وأزرارها تتكدّس رأسياً بأناقة */
    .page-content > .d-flex.justify-content-between { flex-wrap: wrap; gap: 10px; }

    h4 { font-size: 1.15rem; }
}

/* ========== الطباعة ========== */
@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main-content { margin: 0 !important; }
    body { background: #fff; }
    .page-content { padding: 0; }
}

/* ========== مساعد ========== */
.text-muted-2 { color: #94a3b8; }
.cursor-pointer { cursor: pointer; }
