/* ========== CSS Reset & Variables ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #f8faf9;
    --bg-secondary: #f0f4f2;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-input-focus: #ffffff;
    --border-color: #e2e8f0;
    --border-focus: #0ea5e9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-primary: #0ea5e9;
    --accent-secondary: #0284c7;
    --accent-gradient: linear-gradient(135deg, #0ea5e9, #0284c7);
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.08);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.06);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.06);
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --shadow-sm: 0 1px 2px 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.07), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px rgba(14, 165, 233, 0.1);
    --transition: 0.15s ease-in-out;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ========== Layout ========== */
.page-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.container--narrow { max-width: 600px; }
.container--wide { max-width: 1400px; }

/* ========== Header ========== */
.header {
    padding: 12px 0;
    border-bottom: 2px solid var(--accent-primary);
    background: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    position: relative;
}

.header__mobile-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-primary);
}

.header__mobile-toggle svg { width: 28px; height: 28px; }

.header__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
}

.header__icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.header__title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: normal;
}

.header__nav {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.header__link {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}

.header__link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.header__link--active {
    color: var(--accent-primary);
    background: var(--success-bg);
}

.header__link--main {
    background: oklch(96.7% 0.003 264.542);
    padding: 20px 20px !important;
    margin: -12px 0;
    height: 100%;
    display: inline-flex;
    align-items: start;
    font-weight: bold !important;
    border-radius: 0;
    transition: var(--transition);
}

.header__link--main:hover {
    opacity: 0.92;
    box-shadow: inset 0 0 100px rgba(0,0,0,0.1);
}

/* ========== Main Content ========== */
.main { flex: 1; padding: 36px 36px; }

/* ========== Card ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.card__header { padding: 28px 28px 0; }
.card__body { padding: 28px; }
.card__footer {
    padding: 20px 28px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.015);
}

/* ========== Typography ========== */
.page-title {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 6px;
    color: var(--accent-primary);
}

.page-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ========== Form Styles ========== */
.form-group { margin-bottom: 20px; }

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    transition: var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(0, 152, 126, 0.1);
}

.form-input::placeholder { color: var(--text-muted); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-error { margin-top: 5px; font-size: 0.78rem; color: var(--error); }
.form-error ul { list-style: none; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn svg { width: 1.25rem; height: 1.25rem; }

.btn--primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 2px 4px rgba(0, 152, 126, 0.2);
}

.btn--primary:hover {
    background: var(--accent-secondary);
    transform: translateY(-1px);
}

.btn--secondary {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn--secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--border-focus);
}

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

.btn--danger {
    background: #dc2626;
    color: white;
}

.btn--sm { padding: 6px 14px; font-size: 0.8rem; }
.btn--sm svg { width: 1rem; height: 1rem; }
.btn--full { width: 100%; }

/* ========== Alerts ========== */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert svg { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }

.alert--success {
    background: var(--success-bg);
    border: 1px solid rgba(0, 152, 126, 0.15);
    color: var(--success);
}

.alert--error {
    background: var(--error-bg);
    border: 1px solid rgba(203, 42, 42, 0.15);
    color: var(--error);
}

.alert--warning {
    background: var(--warning-bg);
    border: 1px solid rgba(204, 132, 0, 0.15);
    color: var(--warning);
}

/* ========== Table ========== */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    min-width: 800px;
}

.data-table th {
    padding: 14px 16px;
    text-align: right;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.data-table tbody tr:hover { background: rgba(0, 152, 126, 0.02); }

.data-table .row-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 600;
}

.data-table .row-link:hover { text-decoration: underline; }

/* ========== Pagination ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 0;
    flex-wrap: wrap;
}

.pagination__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition);
    border: 1px solid var(--border-color);
    background: white;
}

.pagination__link--active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* ========== Filters Panel ========== */
.filters-panel {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.filters-panel__header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: white;
}

.filters-panel__title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.filters-panel__title svg { width: 1.25rem; height: 1.25rem; color: var(--accent-primary); }

.filters-panel__toggle {
    transition: var(--transition);
    color: var(--text-muted);
}

.filters-panel__toggle--open { transform: rotate(180deg); }

.filters-panel__body {
    padding: 0 20px 20px;
    display: none;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.filters-panel__body--open { display: block; }

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.filters-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dotted var(--border-color);
}

/* ========== Badge ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge--accent {
    background: var(--success-bg);
    color: var(--accent-primary);
}

/* ========== Stats Bar ========== */
.stats-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 150px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border-inline-start: 4px solid var(--accent-primary);
}

.stat-card__label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-card__value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* ========== Form select custom ========== */
select.form-input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20' stroke='%2383918a' stroke-width='1.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    background-size: 22px;
    padding-left: 40px;
    padding-right: 14px;
}

/* ========== Detail Page ========== */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.detail-field { margin-bottom: 24px; }
.detail-field__label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.detail-field__value {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.detail-image {
    max-width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* ========== Footer ========== */
.footer {
    padding: 24px 0;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: white;
}

/* ========== Utilities ========== */
.text-center { text-align: center; }
.mt-4 { margin-top: 16px; }
.mb-6 { margin-bottom: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }

/* ========== Modal ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 20px;
}

.modal--open { display: flex; }

.modal__content {
    background: white;
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal__header {
    padding: 24px 24px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal__icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--warning-bg);
    color: var(--warning);
}

.modal__title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal__body {
    padding: 24px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

.modal__footer {
    padding: 16px 24px;
    background: var(--bg-secondary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========== Responsive ========== */
@media (max-width: 1100px) {
    .header__mobile-toggle { display: block; }
    .header__nav {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        width: 100%;
        background: white;
        flex-direction: column;
        padding: 16px;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
        z-index: 1000;
        gap: 4px;
    }
    .header__nav.active { display: flex; }
    .header__link { width: 100%; border-radius: var(--radius-md); padding: 12px; }
    .header__link--main { 
        width: 100%; 
        margin: 0 0 10px 0 !important; 
        height: 54px;
    }
    .header__brand { flex: 1; }
}

@media (max-width: 768px) {
    .form-row, .grid, .detail-grid { grid-template-columns: 1fr !important; gap: 0; }
    .flex-between { flex-direction: column; align-items: flex-start; }
    .stats-bar { flex-direction: column; }
}

/* ========== Comprehensive Mobile Responsive (max-width: 640px) ========== */
@media (max-width: 640px) {
    /* Remove card styling on mobile - full screen usage */
    .card {
        border: none;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }
    
    .card__header,
    .card__body,
    .card__footer {
        padding: 16px 0;
    }
    
    .card__footer {
        border-top: 1px solid var(--border-color);
        background: transparent;
    }
    
    /* Container adjustments for mobile */
    .container {
        padding: 0 16px;
    }
    
    .container--narrow {
        max-width: 100%;
        padding: 0 12px;
    }
    
    /* Main content padding reduction */
    .main {
        padding: 16px 0;
    }
    
    /* Form adjustments */
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 14px;
    }
    
    /* Typography adjustments */
    .page-title {
        font-size: 1.4rem;
    }
    
    .page-subtitle {
        font-size: 0.85rem;
    }
    
    /* Stats bar mobile */
    .stats-bar {
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .stat-card {
        min-width: 100%;
        padding: 16px;
    }
    
    .stat-card__value {
        font-size: 1.25rem;
    }
    
    /* Filters panel mobile */
    .filters-panel {
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 16px;
    }
    
    .filters-panel__header {
        padding: 12px 0;
    }
    
    .filters-panel__body {
        padding: 16px 0;
    }
    
    .filters-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* Table adjustments */
    .table-wrapper {
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    .data-table {
        font-size: 0.8rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 12px 10px;
    }
    
    /* Pagination mobile */
    .pagination {
        padding: 16px 0;
        gap: 4px;
    }
    
    .pagination__link {
        min-width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    /* Button full width on mobile */
    .btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .btn--sm {
        padding: 10px 16px;
        font-size: 0.85rem;
    }
    
    /* Detail grid mobile */
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .detail-field {
        margin-bottom: 16px;
    }
    
    /* Modal mobile */
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal__content {
        max-width: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Header mobile adjustments */
    .header__title {
        font-size: 1rem;
    }
    
    /* Alerts mobile */
    .alert {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
    
    /* Footer mobile */
    .footer {
        padding: 16px 0;
        font-size: 0.8rem;
    }
}

/* ========== Small Mobile Devices (max-width: 380px) ========== */
@media (max-width: 380px) {
    .container {
        padding: 0 12px;
    }
    
    .page-title {
        font-size: 1.2rem;
    }
    
    .btn {
        padding: 10px 16px;
    }
    
    .header__title {
        font-size: 0.9rem;
    }
}

/* ========== Tablet Adjustments (641px - 1024px) ========== */
@media (min-width: 641px) and (max-width: 1024px) {
    .container {
        padding: 0 20px;
    }
    
    .main {
        padding: 24px 0;
    }
    
    .card__header,
    .card__body {
        padding: 20px;
    }
    
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* ========== Large Screens (min-width: 1400px) ========== */
@media (min-width: 1400px) {
    .container--wide {
        max-width: 1600px;
    }
}
