/* ============================
   نظام متابعة العقود والدفعات - التصميم
   ============================ */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;
    --purple: #8b5cf6;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --body-bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
    font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
    background-color: var(--body-bg);
    direction: rtl;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: #fff;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 16px 20px;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--topbar-height);
}

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

.sidebar-nav { padding: 10px 0; }

.sidebar-nav .nav-label {
    padding: 12px 20px 6px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
}

.sidebar-nav .nav-item {
    display: block;
    padding: 10px 20px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-radius: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.sidebar-nav .nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

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

/* ===== Topbar ===== */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: var(--sidebar-width);
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-left { display: flex; align-items: center; gap: 16px; }

.topbar .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.topbar .user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.topbar .user-name { font-weight: 600; color: #334155; }
.topbar .user-role { font-size: 0.78rem; color: var(--secondary); }

.btn-logout {
    color: var(--danger);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 6px;
    transition: background 0.2s;
}
.btn-logout:hover { background: #fef2f2; color: var(--danger); }

#sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: #334155;
    cursor: pointer;
}

/* ===== Main Content ===== */
.main-content {
    margin-right: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

/* ===== Cards ===== */
.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--card-shadow);
    border: 1px solid #e2e8f0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 12px;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--secondary);
    margin-top: 4px;
}

.icon-primary { background: var(--primary-light); color: var(--primary); }
.icon-success { background: #d1fae5; color: var(--success); }
.icon-danger { background: #fee2e2; color: var(--danger); }
.icon-warning { background: #fef3c7; color: var(--warning); }
.icon-info { background: #cffafe; color: var(--info); }
.icon-purple { background: #ede9fe; color: var(--purple); }

/* ===== Tables ===== */
.table-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.table-card .card-header {
    background: #fff;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-card .table {
    margin-bottom: 0;
    font-size: 0.88rem;
}

.table-card .table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    padding: 12px 16px;
    white-space: nowrap;
}

.table-card .table td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}

.table-card .table tbody tr:hover { background: #f8fafc; }

/* ===== Status Badges ===== */
.badge-status {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-block;
    white-space: nowrap;
}

.badge-paid, .badge-completed { background: #d1fae5; color: #065f46; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-pending, .badge-pending_pm_approval { background: #fef3c7; color: #92400e; }
.badge-sent, .badge-active, .badge-due { background: #dbeafe; color: #1e40af; }
.badge-awaiting_payment { background: #ede9fe; color: #5b21b6; }
.badge-draft, .badge-not_due { background: #f1f5f9; color: #475569; }
.badge-cancelled, .badge-suspended { background: #e2e8f0; color: #334155; }
.badge-pm_approved { background: #cffafe; color: #155e75; }

/* ===== Buttons ===== */
.btn { border-radius: 8px; font-weight: 600; font-size: 0.88rem; padding: 8px 16px; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-action {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
    transition: all 0.2s;
}
.btn-action:hover { background: #f1f5f9; }
.btn-action.edit:hover { color: var(--primary); border-color: var(--primary); }
.btn-action.delete:hover { color: var(--danger); border-color: var(--danger); }
.btn-action.view:hover { color: var(--info); border-color: var(--info); }

/* ===== Forms ===== */
.form-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid #e2e8f0;
    padding: 24px;
}

.form-label { font-weight: 600; font-size: 0.88rem; color: #334155; margin-bottom: 6px; }
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    padding: 10px 14px;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

textarea.form-control { min-height: 80px; }

.required::after { content: ' *'; color: var(--danger); }

/* ===== Login Page ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card .login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-card .login-logo i { font-size: 2.5rem; color: var(--primary); }
.login-card .login-logo h2 { font-size: 1.3rem; font-weight: 700; color: #1e293b; margin-top: 10px; }

.login-card .form-control {
    padding: 12px 16px;
    font-size: 0.95rem;
}

/* ===== Filters ===== */
.filter-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid #e2e8f0;
    padding: 20px;
    margin-bottom: 20px;
}

/* ===== Quick Links ===== */
.quick-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    color: #334155;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 0.88rem;
}
.quick-link:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37,99,235,0.1);
}
.quick-link i { font-size: 1.1rem; }

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--secondary);
}
.empty-state i { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.95rem; }

/* ===== Responsive ===== */
@media (max-width: 992px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.show { transform: translateX(0); }
    .topbar { right: 0; }
    .main-content { margin-right: 0; }
    #sidebar-toggle { display: block; }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1035;
        display: none;
    }
    .sidebar-overlay.show { display: block; }
}

@media (max-width: 576px) {
    .main-content { padding: 16px; }
    .page-header h1 { font-size: 1.2rem; }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 1.3rem; }
}

/* ===== Print ===== */
@media print {
    .sidebar, .topbar, .btn, .filter-card { display: none !important; }
    .main-content { margin: 0; padding: 0; }
}

/* ===== Custom badge purple ===== */
.bg-purple { background-color: var(--purple) !important; }
.text-purple { color: var(--purple) !important; }
