/* School ERP CSS Architecture - Phase 20 Polish */
:root {
    /* Colors */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    
    --secondary: #64748b;
    --secondary-dark: #475569;
    --secondary-light: #f1f5f9;

    --success: #10b981;
    --success-light: #d1fae5;
    
    --danger: #ef4444;
    --danger-light: #fee2e2;
    
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    
    --info: #3b82f6;
    --info-light: #dbeafe;
    
    /* Structure */
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    
    /* Text */
    --text: #334155;
    --text-muted: #64748b;
    --text-inverse: #ffffff;
    
    /* Geometry */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    
    /* Layout */
    --sidebar-width: 250px;
    --header-height: 64px;
    --font-sans: 'Inter', system-ui, sans-serif;
}

/* Base Reset & Typography */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 600; line-height: 1.2; margin-bottom: var(--spacing-sm); }
a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-dark); }

/* Layout Architecture */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: var(--text-inverse);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 1000;
}
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}
.topbar {
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: var(--shadow-sm);
}
.content-area { padding: var(--spacing-lg); flex: 1; }
.footer {
    padding: var(--spacing-md) var(--spacing-lg);
    text-align: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Sidebar Navigation */
.sidebar-header {
    padding: var(--spacing-lg);
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-nav { padding: var(--spacing-md) 0; }
.nav-group {
    padding: var(--spacing-sm) var(--spacing-lg);
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #94a3b8;
    font-weight: 600;
    margin-top: var(--spacing-md);
    letter-spacing: 0.05em;
}
.nav-link {
    display: flex;
    align-items: center;
    padding: 0.625rem var(--spacing-lg);
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.2s, color 0.2s, border-left 0.2s;
    border-left: 3px solid transparent;
}
.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.05);
    color: var(--text-inverse);
    border-left-color: var(--primary);
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: var(--spacing-md);
}
.breadcrumbs .separator { color: var(--border); }
.breadcrumbs a { color: var(--text-muted); font-weight: 500; }
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs .current { color: var(--text); font-weight: 600; }

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
}
.page-title { margin-bottom: 0; font-size: 1.5rem; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: var(--spacing-lg);
    display: flex;
    flex-direction: column;
}
.card-header {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h2, .card-header h3, .card-header h4 { margin-bottom: 0; font-size: 1.125rem; }
.card-body { padding: var(--spacing-lg); flex: 1; }
.card-footer {
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border);
    background: var(--background);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Grids */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}
.stat-card {
    background: var(--surface);
    padding: var(--spacing-lg);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1; margin-bottom: var(--spacing-xs); }
.stat-label { color: var(--text-muted); font-size: 0.875rem; font-weight: 500; }

.grid-cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: var(--spacing-lg); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    cursor: pointer; transition: all 0.2s; text-decoration: none;
    line-height: 1.25rem; font-family: inherit;
}
.btn:focus { outline: 2px solid var(--primary-light); outline-offset: 2px; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

.btn-primary { background: var(--primary); color: var(--text-inverse); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--background); border-color: var(--secondary); }
.btn-danger { background: var(--danger); color: var(--text-inverse); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: var(--text-inverse); }
.btn-success:hover { background: #059669; }
.btn-info { background: var(--info); color: var(--text-inverse); }

/* Badges */
.badge {
    display: inline-flex; align-items: center; padding: 0.125rem 0.5rem;
    font-size: 0.75rem; font-weight: 600; border-radius: 9999px; line-height: 1.25rem;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info { background: var(--info-light); color: #1e40af; }
.badge-secondary { background: var(--secondary-light); color: var(--secondary-dark); }

/* Alerts / Flash Messages */
.alert {
    padding: var(--spacing-md); border-radius: var(--radius-md); margin-bottom: var(--spacing-lg);
    display: flex; justify-content: space-between; align-items: flex-start; gap: var(--spacing-md);
    font-size: 0.875rem; box-shadow: var(--shadow-sm);
}
.alert-success { background: var(--success-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-error, .alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--info-light); color: #1e40af; border: 1px solid #bfdbfe; }
.alert-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; line-height: 1; opacity: 0.6; color: inherit; }
.alert-close:hover { opacity: 1; }

/* Forms */
.form-group { margin-bottom: var(--spacing-md); }
.form-label {
    display: block; font-size: 0.875rem; font-weight: 600; color: var(--text); margin-bottom: var(--spacing-xs);
}
.form-label.required::after { content: "*"; color: var(--danger); margin-left: 0.25rem; }
.form-control, .form-select {
    width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-family: inherit; font-size: 0.875rem;
    color: var(--text); background-color: var(--surface); transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-control:disabled, .form-select:disabled {
    background-color: var(--background); color: var(--text-muted); cursor: not-allowed;
}
.form-error {
    display: block; font-size: 0.75rem; color: var(--danger); margin-top: var(--spacing-xs); font-weight: 500;
}
.is-invalid { border-color: var(--danger) !important; }
.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-light) !important; }

/* Tables */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; text-align: left; background: var(--surface); white-space: nowrap; }
.table th, .table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.table th { background: var(--background); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.75rem; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background-color: var(--background); }
.table-actions { display: flex; gap: var(--spacing-sm); align-items: center; }

/* Empty States */
.empty-state {
    text-align: center; padding: var(--spacing-xl) var(--spacing-lg);
    background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius-md);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.empty-state-icon { font-size: 3rem; color: var(--border); margin-bottom: var(--spacing-md); }
.empty-state-title { font-size: 1.125rem; font-weight: 600; color: var(--text); margin-bottom: var(--spacing-xs); }
.empty-state-text { color: var(--text-muted); font-size: 0.875rem; margin-bottom: var(--spacing-md); max-width: 400px; }

/* Pagination */
.pagination { display: flex; list-style: none; gap: 0.25rem; margin-top: var(--spacing-lg); justify-content: center; }
.pagination li { display: inline-block; }
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 2rem; height: 2rem; padding: 0 0.5rem; border-radius: var(--radius-sm);
    font-size: 0.875rem; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    text-decoration: none; transition: all 0.2s;
}
.pagination a:hover { background: var(--background); border-color: var(--secondary); }
.pagination .active span { background: var(--primary); color: var(--text-inverse); border-color: var(--primary); }
.pagination .disabled span { opacity: 0.5; cursor: not-allowed; background: var(--background); }

/* Filter Bar */
.filter-bar {
    background: var(--surface); padding: var(--spacing-md); border-radius: var(--radius-md);
    border: 1px solid var(--border); margin-bottom: var(--spacing-lg);
    display: flex; gap: var(--spacing-md); align-items: flex-end; flex-wrap: wrap; box-shadow: var(--shadow-sm);
}
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 200px; }

/* Topbar User Menu */
.sidebar-toggler {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted);
    padding: var(--spacing-sm); border-radius: var(--radius-sm); transition: background 0.2s;
}
.sidebar-toggler:hover { background: var(--background); color: var(--text); }
.user-menu-wrapper { position: relative; }
.user-menu-btn {
    background: none; border: 1px solid var(--border); font-size: 0.875rem; font-weight: 500;
    cursor: pointer; display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm); transition: all 0.2s; color: var(--text);
}
.user-menu-btn:hover { background: var(--background); }
.user-dropdown {
    position: absolute; right: 0; top: 100%; min-width: 200px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-md); margin-top: var(--spacing-xs); display: none; overflow: hidden; z-index: 1000;
}
.user-dropdown.show { display: block; }
.dropdown-header { padding: var(--spacing-md); border-bottom: 1px solid var(--border); background: var(--background); }
.dropdown-header strong { display: block; font-size: 0.875rem; color: var(--text); }
.dropdown-header small { display: block; font-size: 0.75rem; color: var(--text-muted); }
.dropdown-item {
    display: flex; align-items: center; padding: 0.75rem var(--spacing-md); color: var(--text);
    text-decoration: none; font-size: 0.875rem; transition: background 0.2s;
}
.dropdown-item:hover { background: var(--background); color: var(--primary); }
.logout-form { margin: 0; border-top: 1px solid var(--border); }
.logout-btn {
    width: 100%; text-align: left; background: none; border: none; cursor: pointer;
    padding: 0.75rem var(--spacing-md); font-size: 0.875rem; color: var(--danger); font-family: inherit;
    transition: background 0.2s; display: flex; align-items: center;
}
.logout-btn:hover { background: var(--danger-light); }

/* Responsive */
.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5); z-index: 950; display: none;
    backdrop-filter: blur(2px);
}

@media (max-width: 992px) {
    .grid-cols-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .sidebar-overlay.show { display: block; }
    .page-header { flex-direction: column; align-items: flex-start; gap: var(--spacing-md); }
}

/* Print Styles */
.print-only { display: none; }
@media print {
    body { background: white; color: black; font-size: 12pt; }
    .sidebar, .topbar, .footer, .print-hide, .breadcrumbs, .filter-bar, .alert, .table-actions, .pagination { display: none !important; }
    .main-wrapper { margin-left: 0; padding: 0; }
    .content-area { padding: 0; }
    .card { border: none; box-shadow: none; margin-bottom: 0; break-inside: avoid; }
    .card-header { border-bottom: 2px solid black; padding: 0.5rem 0; }
    .table th, .table td { border-bottom: 1px solid #ccc; padding: 0.5rem; white-space: normal; }
    .table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .table-responsive { overflow-x: visible; border: none; }
    .print-only { display: block; }
    .badge { border: 1px solid #000; color: #000; background: none; }
}
