/* ============ AMALGAMA v4 - STYLES ============ */
:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --success: #27ae60;
    --success-dark: #219a52;
    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --warning: #f39c12;
    --warning-dark: #d68910;
    --info: #16a085;
    --info-dark: #138d75;
    --dark: #2c3e50;
    --darker: #1a252f;
    --light: #ecf0f1;
    --gray: #95a5a6;
    --gray-light: #bdc3c7;
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --text-lighter: #95a5a6;
    --border: #dcdde1;
    --border-light: #eee;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --sidebar-width: 260px;
    --topbar-height: 60px;
}

[data-theme="dark"] {
    --bg: #1a1d23;
    --card: #22262d;
    --text: #e0e4e8;
    --text-light: #9ca3af;
    --text-lighter: #6b7280;
    --border: #3a3f4a;
    --border-light: #2d3340;
    --dark: #111418;
    --darker: #0a0c0f;
    --light: #2d3340;
    --gray: #6b7280;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

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

#sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: var(--light);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }

#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

#sidebar-overlay.active { display: block; }

.logo {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.logo h2 { font-size: 1.3em; font-weight: 700; letter-spacing: -0.5px; }
.logo small { color: rgba(255,255,255,0.5); font-size: 0.75em; text-transform: uppercase; letter-spacing: 1px; }

#nav-menu { list-style: none; padding: 10px 0; }

#nav-menu a {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    transition: var(--transition);
    font-size: 0.9em;
    font-weight: 500;
    border-left: 3px solid transparent;
}

#nav-menu a:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

#nav-menu a.active {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border-left-color: var(--primary);
}

#nav-menu a .icon {
    margin-right: 12px;
    font-size: 1.15em;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

main {
    flex: 1;
    margin-left: var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#topbar {
    background: var(--card);
    padding: 0 25px;
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

#topbar h1 { font-size: 1.35em; font-weight: 700; letter-spacing: -0.3px; }

#menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px 10px;
    margin-right: 10px;
    color: var(--text);
}

#topbar-actions { display: flex; align-items: center; gap: 12px; }

#page-content { padding: 25px; flex: 1; }

/* ============ COMPONENTS ============ */

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--border-light);
    transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
}

.card-header h3 { font-size: 1em; font-weight: 600; }
.card-body { padding: 20px; }

/* Grid */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Stat Cards */
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: default;
    transition: var(--transition);
    border: 1px solid var(--border-light);
}

.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    flex-shrink: 0;
}

.stat-info h4 { font-size: 1.75em; font-weight: 700; letter-spacing: -0.5px; }
.stat-info p { color: var(--text-light); font-size: 0.85em; font-weight: 500; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: white;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-dark); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: var(--warning-dark); }
.btn-info { background: var(--info); }
.btn-info:hover { background: var(--info-dark); }
.btn-secondary { background: var(--gray); }
.btn-secondary:hover { background: var(--text-lighter); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }

.btn-sm { padding: 5px 12px; font-size: 0.8em; border-radius: 4px; }
.btn-lg { padding: 13px 28px; font-size: 1em; }
.btn-icon { padding: 7px 10px; min-width: 36px; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.88em; color: var(--text); }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9em;
    background: var(--card);
    color: var(--text);
    transition: var(--transition);
    font-family: var(--font);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}

.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* Search & Filter Bar */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-bar input,
.search-bar select {
    padding: 9px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88em;
    background: var(--card);
    color: var(--text);
    transition: var(--transition);
}

.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}

.search-bar input[type="text"],
.search-bar input[type="search"] { min-width: 200px; flex: 1; }

/* Tables */
.table-container { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-light); }
th { background: var(--bg); font-weight: 600; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-light); }
tr:hover { background: rgba(52,152,219,0.03); }
td { font-size: 0.9em; }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: #d5f5e3; color: #1e8449; }
.badge-danger { background: #fadbd8; color: #c0392b; }
.badge-warning { background: #fdebd0; color: #d68910; }
.badge-info { background: #d6eaf8; color: #2471a3; }
.badge-primary { background: #e8daef; color: #7d3c98; }
.badge-secondary { background: var(--light); color: var(--text-light); }

[data-theme="dark"] .badge-success { background: #1e844930; color: #58d68d; }
[data-theme="dark"] .badge-danger { background: #c0392b30; color: #ec7063; }
[data-theme="dark"] .badge-warning { background: #d6891030; color: #f5b041; }
[data-theme="dark"] .badge-info { background: #2471a330; color: #5dade2; }
[data-theme="dark"] .badge-primary { background: #7d3c9830; color: #bb8fce; }

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.78em;
    font-weight: 600;
    white-space: nowrap;
}

/* Avatar */
.student-avatar {
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

/* Contact Icons */
.contact-icons { display: flex; gap: 4px; }
.contact-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg);
    text-decoration: none;
    font-size: 0.85em;
    transition: var(--transition);
    border: 1px solid var(--border-light);
}
.contact-icon:hover { background: var(--primary); color: white; transform: scale(1.1); }

/* Quick Actions */
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 15px 20px; }

/* Empty State */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-light); }
.empty-icon { font-size: 3em; margin-bottom: 15px; opacity: 0.6; }
.empty-state p { font-size: 0.95em; }

/* Loading */
.loading { text-align: center; padding: 50px; color: var(--text-light); }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 15px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Course Cards */
.course-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
    transition: var(--transition);
    border: 1px solid var(--border-light);
}
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.course-card h4 { font-size: 1.05em; margin-bottom: 6px; }

/* Student Chips in Course */
.course-students { margin-top: 10px; }
.student-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.student-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 0.65em;
    font-weight: 700;
}
.student-chip.more { background: var(--gray); font-size: 0.7em; }

/* Grade Colors */
.grade-excellent { color: #27ae60; font-weight: 700; }
.grade-good { color: #17a2b8; font-weight: 700; }
.grade-pass { color: #f39c12; font-weight: 700; }
.grade-fail { color: #e74c3c; font-weight: 700; }

/* Info Box / Section */
.info-section {
    background: var(--bg);
    border-left: 4px solid var(--primary);
    padding: 14px 18px;
    margin: 12px 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.info-section h4 { margin-bottom: 8px; font-size: 0.9em; font-weight: 600; }
.info-section p { margin: 4px 0; font-size: 0.88em; }
.info-section ul { margin: 6px 0; padding-left: 20px; }
.info-section li { margin: 3px 0; font-size: 0.88em; }

/* Toast */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--card);
    color: var(--text);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88em;
    font-weight: 500;
    border-left: 4px solid var(--info);
    animation: toastIn 0.3s ease;
    max-width: 380px;
}

.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info { border-left-color: var(--info); }

.toast-icon { font-size: 1.1em; }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.2s;
}

#modal-overlay.active { opacity: 1; }
#modal-overlay.hidden { display: none; }

#modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s;
}

#modal-overlay.active #modal { transform: scale(1); }

#modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

#modal-header h3 { font-size: 1.1em; font-weight: 600; }
#modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 5px;
    line-height: 1;
}
#modal-close:hover { color: var(--text); }

#modal-body { padding: 22px; }
#modal-footer {
    padding: 15px 22px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: var(--card);
}

/* Attendance Grid */
.attendance-grid { overflow-x: auto; }
.attendance-row {
    display: grid;
    grid-template-columns: 220px repeat(4, 1fr);
    border-bottom: 1px solid var(--border-light);
}
.attendance-row > div {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.attendance-student { justify-content: flex-start !important; font-weight: 600; }

/* Schedule Controls */
.schedule-controls {
    display: flex;
    gap: 20px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 15px;
    flex-wrap: wrap;
    align-items: center;
    border: 1px solid var(--border-light);
}

.control-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88em;
    font-weight: 500;
}

/* Schedule Table */
.schedule-table td.schedule-cell {
    min-width: 130px;
    height: 85px;
    vertical-align: top;
    position: relative;
    border: 1px solid var(--border-light);
    transition: var(--transition);
}

.schedule-cell.empty { background: var(--bg); cursor: pointer; }
.schedule-cell.empty:hover { background: #e8f4fd; border-color: var(--primary); }
.schedule-cell.filled { cursor: move; }
.schedule-cell.dragging { opacity: 0.4; }
.schedule-cell.drag-over { background: #d4edda !important; border-color: #28a745 !important; }
.schedule-cell.swap-selected { box-shadow: 0 0 0 3px var(--primary) inset; }

.cell-content { padding: 8px; height: 100%; position: relative; }
.cell-actions {
    position: absolute;
    bottom: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
}
.empty-text { font-size: 1.4em; color: #bbb; display: block; text-align: center; margin-top: 22px; }

.schedule-hour {
    font-weight: 700;
    text-align: center;
    background: var(--bg);
    min-width: 70px;
    font-size: 0.85em;
}

/* Report Builder */
.report-condition {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border-light);
}

.report-condition select,
.report-condition input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card);
    color: var(--text);
}

/* Debt Widget */
.debt-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.debt-summary-item {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--border-light);
}

.debt-summary-item .count { font-size: 1.4em; font-weight: 700; color: var(--danger); }
.debt-summary-item .label { font-size: 0.78em; color: var(--text-light); }

/* Syllabus Status Badges */
.badge-draft { background: #fdebd0; color: #d68910; }
.badge-progress { background: #d6eaf8; color: #2471a3; }
.badge-completed { background: #d5f5e3; color: #1e8449; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); }
    #menu-toggle { display: block !important; }
    main { margin-left: 0; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar input[type="text"], .search-bar input[type="search"] { min-width: auto; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .attendance-row { grid-template-columns: 130px repeat(4, 1fr); }
    #modal { width: 95%; margin: 10px; max-height: 90vh; }
    .schedule-controls { flex-direction: column; align-items: flex-start; }
    #page-content { padding: 15px; }
    #topbar { padding: 0 15px; }
    #topbar h1 { font-size: 1.1em; }
}

/* Print */
@media print {
    #sidebar, #topbar, .btn, .search-bar, #toast-container { display: none !important; }
    main { margin-left: 0 !important; }
    #page-content { padding: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray); }
