@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    /* Color Palette */
    --primary-color: #2c3e50;
    --primary-light: #34495e;
    --secondary-color: #3498db;
    --secondary-dark: #2980b9;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --info-color: #17a2b8;
    
    /* Backgrounds & Text */
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-muted: #6c757d;
    --text-light: #ecf0f1;
    --border-color: #e9ecef;

    /* UI Elements */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 15px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    --transition: all 0.3s ease;
    
    /* Sidebar */
    --sidebar-width: 260px;
    --header-height: 60px;
}

/* Global Reset & Typography */
html, body {
    direction: rtl;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 16px;
    margin: 0;
    padding: 0;
    line-height: 1.6;
    min-height: 100vh;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 1rem;
}

/* Layout Structure */
.page {
    position: relative;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

main {
    flex: 1;
    padding: 2rem;
    transition: var(--transition);
    width: 100%;
    max-width: 100vw;
}

/* Sidebar Styles (Moved from MainLayout) */
.sidebar {
    position: fixed;
    top: 0;
    right: 0; /* RTL: Right side */
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: var(--text-light);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: var(--transition);
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1rem;
}

.user-info {
    padding: 1.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info span {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
}

.role-badge {
    display: inline-block;
    background-color: var(--secondary-color);
    color: white;
    font-size: 0.8rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    margin-top: 0.5rem;
}

.nav-button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    padding: 0.8rem 1rem;
    text-align: right; /* RTL */
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    font-size: 1rem;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

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

.nav-button:hover, .nav-button.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateX(-5px); /* RTL Slide effect */
}

.nav-button.logout-button {
    margin-top: auto;
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.2);
}

.nav-button.logout-button:hover {
    background-color: #e74c3c;
    color: white;
}

.nav-spacer {
    flex-grow: 1;
}

/* Mobile Sidebar Toggle */
.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    right: 15px; /* RTL */
    z-index: 1001;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 15px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

/* Responsive Sidebar Logic */
@media (min-width: 769px) {
    .page {
        padding-right: var(--sidebar-width); /* Push content for sidebar */
    }
    .sidebar {
        transform: translateX(0);
    }
    .menu-toggle {
        display: none;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%); /* Hide off-screen right */
    }
    .sidebar.visible {
        transform: translateX(0);
    }
    .menu-toggle {
        display: block;
    }
    main {
        padding: 4rem 1rem 1rem 1rem; /* Top padding for toggle button */
    }
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-family: inherit;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--secondary-color);
    color: white;
    box-shadow: 0 4px 6px rgba(52, 152, 219, 0.2);
}

.btn-primary:hover {
    background-color: var(--secondary-dark);
    box-shadow: 0 6px 8px rgba(52, 152, 219, 0.3);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-danger {
    background-color: var(--accent-color);
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #219150;
}

/* Forms */
.form-control {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-body);
    color: var(--text-main);
    transition: var(--transition);
    font-family: inherit;
    font-size: 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--secondary-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-group {
    margin-bottom: 1.5rem;
    text-align: right; /* RTL */
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    background: #fff;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0;
}

.table th {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
}

.table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    vertical-align: middle;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: rgba(52, 152, 219, 0.05);
}

/* Loading & Errors */
.loading-progress {
    display: block;
    width: 8rem;
    height: 8rem;
    margin: 20vh auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e0e0e0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--secondary-color);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #856404;
    text-align: center;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Login Page Specific */
.full-width {
    padding: 0 !important;
    max-width: 100% !important;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    min-height: 100vh;
}

/* CSS Icons (replacement for Font Awesome) */
.fa, .fas, .far, .fab {
    display: inline-block;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
    line-height: 1;
}

.fa-bars::before { content: "☰"; font-size: 1.3em; }
.fa-coins::before { content: "💰"; }
.fa-calendar::before { content: "📅"; }
.fa-money-bill::before { content: "💵"; }
.fa-book-open::before { content: "📖"; }
.fa-list::before { content: "📋"; }
.fa-book::before { content: "📚"; }
.fa-database::before { content: "🗄️"; }
.fa-users-cog::before { content: "👥"; }
.fa-sign-out-alt::before { content: "🚪"; }

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

/* Enhanced Mobile Support */
@media (max-width: 768px) {
    .sidebar {
        box-shadow: -2px 0 8px rgba(0,0,0,0.3);
    }
    
    .nav-button {
        padding: 1rem;
        font-size: 1.1rem;
        min-height: 48px; /* Touch-friendly size */
    }
    
    .menu-toggle {
        padding: 12px 18px;
        font-size: 1.2rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    .user-info {
        padding: 1.2rem;
        font-size: 1.05rem;
    }
    
    /* Better touch targets */
    button, .btn, a {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
    
    /* Prevent text selection on double tap */
    .sidebar, .nav-button, .menu-toggle {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}
