/* =========================================================================
   VARIABLES & THEME
   ========================================================================= */
:root {
    /* Color Palette */
    --primary-color: #0d47a1;
    /* Deep Blue typical for corporate/banks */
    --primary-light: #5472d3;
    --primary-dark: #002171;
    --secondary-color: #f57c00;
    /* Orange accent */

    /* Status Colors */
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #ef6c00;
    --info: #0277bd;

    /* Backgrounds & Text */
    --bg-main: #f4f6f9;
    --bg-surface: #ffffff;
    --bg-dark: #1e293b;
    --text-primary: #334155;
    --text-secondary: #64748b;
    --text-light: #f8fafc;

    /* Borders & Shadows */
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Dimensions */
    --sidebar-width: 280px;
    --header-height: 70px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
}

/* =========================================================================
   RESET & BASE
   ========================================================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

button {
    cursor: pointer;
    border: none;
    outline: none;
    background: none;
    font-family: inherit;
}

/* =========================================================================
   LAYOUT
   ========================================================================= */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.03);
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header p {
    font-size: 0.8rem;
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0.8rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.8rem 1rem;
    color: #94a3b8;
    transition: all 0.3s ease;
    gap: 12px;
    font-weight: 500;
    border-radius: 12px;
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-light);
    transform: translateX(-5px);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(13, 71, 161, 0.2) 0%, rgba(13, 71, 161, 0.1) 100%);
    color: white;
    border-color: rgba(13, 71, 161, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.nav-link.active i {
    color: var(--primary-light);
}

.nav-link i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.sidebar-separator {
    padding: 1.5rem 1rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 800;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.05);
}

.role-switcher {
    padding: 1.5rem;
    background-color: rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.role-switcher label {
    display: block;
    font-size: 0.85rem;
    color: #cbd5e1;
    margin-bottom: 8px;
}

.role-switcher select {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.role-switcher select option {
    background: var(--bg-dark);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.top-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 10;
}

#page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-btn {
    font-size: 1.5rem;
    color: var(--primary-dark);
    display: none;
    padding: 5px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-light);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

#currentUserRoleLabel {
    font-weight: 600;
    font-size: 0.95rem;
}

/* View Container */
.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* =========================================================================
   COMPONENTS
   ========================================================================= */

/* Cards */
.card {
    background-color: var(--bg-surface);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* Dashboard Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-surface);
    border-radius: var(--border-radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    border-right: 4px solid var(--primary-color);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: rgba(13, 71, 161, 0.1);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.stat-info p {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.6rem 1.2rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #e65100;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background-color: var(--bg-main);
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    border-color: var(--primary-light);
    outline: none;
    box-shadow: 0 0 0 3px rgba(84, 114, 211, 0.2);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
    margin-bottom: 1rem;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: var(--bg-main);
    font-weight: 700;
    color: var(--text-secondary);
}

.table tr:hover {
    background-color: rgba(0, 0, 0, 0.01);
}

/* Badges for Status */
.badge {
    padding: 0.35em 0.65em;
    font-size: 0.85em;
    font-weight: 700;
    border-radius: 0.25rem;
    display: inline-block;
    text-align: center;
}

.badge-success {
    background-color: rgba(46, 125, 50, 0.1);
    color: var(--success);
}

.badge-danger {
    background-color: rgba(198, 40, 40, 0.1);
    color: var(--danger);
}

.badge-warning {
    background-color: rgba(239, 108, 0, 0.1);
    color: var(--warning);
}

.badge-info {
    background-color: rgba(2, 119, 189, 0.1);
    color: var(--info);
}

.badge-dark {
    background-color: rgba(30, 41, 59, 0.1);
    color: var(--bg-dark);
}

/* Modal/Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-surface);
    width: 90%;
    max-width: 600px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(-20px);
    transition: transform 0.3s;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

/* Utilities */
.hidden {
    display: none !important;
}

.text-right {
    text-align: right;
}

.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 100%;
        /* Initially hidden in RTL */
        height: 100vh;
        z-index: 1000;
    }

    .sidebar.active {
        left: 0;
        right: 0;
    }

    .main-content {
        width: 100vw;
    }

    .view-container {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }

    .top-header {
        padding: 0 1rem;
    }

    .menu-btn {
        display: block;
    }

    #page-title {
        font-size: 1.2rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   PRINT STYLES
   ========================================================================= */
@media print {
    body {
        background: white;
    }

    .sidebar,
    .top-header,
    .btn,
    .card-header button,
    .action-column,
    th:last-child,
    td:last-child {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
        width: 100%;
    }

    .card {
        border: none;
        box-shadow: none;
        margin: 0;
        padding: 0;
    }

    .view-container {
        padding: 0;
        overflow: visible;
    }

    .table th,
    .table td {
        border-color: #000;
        color: #000;
        font-size: 12px;
        padding: 0.5rem;
    }

    .badge {
        border: 1px solid #000;
        background: transparent !important;
        color: #000 !important;
    }
}