/* ===== DESIGN SYSTEM ===== */
:root {
    /* Colors */
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    
    --success: #10B981;
    --success-light: #D1FAE5;
    --info: #3B82F6;
    --info-light: #DBEAFE;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;
    
    --bg-primary: #FFFFFF;
    --bg-secondary: #F9FA FB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Border radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Shadows */
    --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);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Sidebar */
    --sidebar-width: 260px;
}

/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--gray-50);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== LAYOUT ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1E293B 0%, #0F172A 100%);
    color: white;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    z-index: 1000;
}

.sidebar-header {
    padding: var(--space-xl);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    margin: 0;
}

.sidebar-nav {
    padding: var(--space-lg);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateX(4px);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.nav-icon {
    font-size: 1.25rem;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.content-wrapper {
    padding: var(--space-2xl);
    max-width: 1400px;
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
    margin-bottom: var(--space-lg);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: var(--space-xl);
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-lg);
}

/* ===== ALERTS & FLASH MESSAGES ===== */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
    font-weight: 500;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert-success {
    background: var(--success-light);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.alert-info {
    background: var(--info-light);
    color: var(--info);
    border-left: 4px solid var(--info);
}

.alert-warning {
    background: var(--warning-light);
    color: var(--warning);
    border-left: 4px solid var(--warning);
}

.alert-danger {
    background: var(--danger-light);
    color: var(--danger);
    border-left: 4px solid var(--danger);
}

/* ===== CARDS ===== */
.card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.card-body {
    color: var(--text-secondary);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

.stat-card {
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    color: white;
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
    border: none;
}

.stat-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--shadow-xl);
}

.stat-card.primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
}

.stat-card.success {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
}

.stat-card.warning {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
}

.stat-card.info {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
}

.stat-label {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

.stat-description {
    font-size: 0.875rem;
    opacity: 0.8;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    line-height: 1.5;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.813rem;
}

.btn-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

/* ===== FORMS ===== */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.938rem;
    color: var(--gray-900);
    background: white;
    transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* ===== TABLES ===== */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

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

.table thead {
    background: var(--gray-50);
    border-bottom: 2px solid var(--border-color);
}

.table th {
    padding: var(--space-md) var(--space-lg);
    text-align: left;
    font-weight: 600;
    font-size: 0.813rem;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table td {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    color: var(--gray-600);
}

.table tbody tr {
    transition: background 0.2s ease;
}

.table tbody tr:hover {
    background: var(--gray-50);
}

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

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-info {
    background: var(--info-light);
    color: var(--info);
}

.badge-warning {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

/* ===== CHARTS ===== */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

.chart-container {
    background: white;
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.chart-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--space-lg);
}

/* ===== UTILITY CLASSES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --space-2xl: 1.5rem;
        --space-xl: 1.25rem;
        --space-lg: 1rem;
    }

    body {
        padding-bottom: 70px; /* Space for bottom nav */
    }

    /* Layout */
    .app-container {
        display: block;
    }

    .main-content {
        margin-left: 0;
        min-height: auto;
    }

    .content-wrapper {
        padding: var(--space-lg);
        max-width: 100%;
    }

    /* Sidebar -> Bottom Nav */
    .sidebar {
        width: 100%;
        height: auto;
        top: auto;
        bottom: 0;
        left: 0;
        background: white;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        padding: 0;
        z-index: 2000;
    }

    .sidebar-header {
        display: none;
    }

    .sidebar-nav {
        padding: 0;
        display: flex;
        width: 100%;
        justify-content: space-around;
    }

    .nav-item {
        flex-direction: column;
        gap: 4px;
        padding: 8px;
        margin: 0;
        border-radius: 0;
        color: var(--gray-500);
        font-size: 0.75rem;
        flex: 1;
        justify-content: center;
        text-align: center;
    }

    .nav-item:hover {
        background: transparent;
        color: var(--primary);
        transform: none;
    }

    .nav-item.active {
        background: transparent;
        color: var(--primary);
        box-shadow: none;
    }

    .nav-icon {
        font-size: 1.5rem;
        margin-bottom: 2px;
    }
    
    /* Make text visible again but small */
    .sidebar-title {
        display: none;
    }
    
    .nav-item span:not(.nav-icon) {
        display: block;
    }

    /* Stack flex containers */
    .flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-md);
    }
    
    .flex-between .btn {
        width: 100%;
        justify-content: center;
    }

    /* Tables */
    .table-container {
        overflow-x: auto;
    }
    
    .table th, .table td {
        white-space: nowrap;
        padding: var(--space-sm) var(--space-md);
    }

    /* Forms */
    form[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    .card[style*="max-width"] {
        max-width: 100% !important;
    }

    /* Typography */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    
    .page-title {
        margin-bottom: var(--space-md);
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }
    
    .stat-value {
        font-size: 2rem;
    }

    /* Application Show Page */
    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== RESPONSIVE UTILITIES ===== */
.grid-view-detail {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-xl);
}

.filter-form {
    display: flex;
    gap: var(--space-md);
    align-items: flex-end;
}

.flex-grow {
    flex: 1;
}

@media (max-width: 1024px) {
    .grid-view-detail {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    .filter-form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-form .btn {
        width: 100%;
        margin-top: var(--space-sm);
    }

    /* Fix table cells on mobile */
    .table td[data-label="Actions"] .flex {
        flex-direction: row !important; /* Keep actions in row */
        justify-content: flex-end;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}
