:root {
    --bg: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --accent: #0284c7;
    --accent2: #7c3aed;
    --text: #0f172a;
    --muted: #64748b;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --makeup: #7c3aed;
    --glass: 0 4px 12px rgba(15, 23, 42, 0.03), 0 1px 2px rgba(15, 23, 42, 0.05);
    --sidebar-w: 220px;
    --header-h: 56px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }

/* HEADER */
header {
    height: var(--header-h);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem;
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
}
.header-brand { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; font-weight: 700;
    background: linear-gradient(135deg, #1e40af, #3b82f6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-brand svg { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; }
.header-brand a { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 0.5rem; }
.header-actions { display: flex; gap: 0.35rem; align-items: center; }

/* LAYOUT */
.app-layout { display: flex; min-height: 100vh; padding-top: var(--header-h); }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w); background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    overflow-y: auto; padding: 0.75rem 0; z-index: 100;
    display: flex; flex-direction: column;
}
.sidebar-section { padding: 0.25rem 0; }
.sidebar-label { font-size: 0.68rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; padding: 0.4rem 1rem 0.2rem; }
.nav-item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 1rem; font-size: 0.88rem; font-weight: 500;
    color: var(--muted); cursor: pointer; transition: all 0.15s ease-in-out;
    border-left: 3px solid transparent;
    text-decoration: none;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: #f8fafc; }
.nav-item.active { color: var(--primary); border-left-color: var(--primary); background: #eff6ff; }
.nav-item.disabled { opacity: 0.55; cursor: not-allowed; }
.nav-item.disabled:hover { background: transparent; color: var(--muted); }
.nav-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.35rem; min-width: 18px; text-align: center; margin-left: auto; }

/* MAIN CONTENT */
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 1rem 1.25rem; min-width: 0; }

/* CLASS SELECTOR BAR */
.class-selector-bar {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 0.5rem; padding: 0.75rem 1rem;
    display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap;
    margin-bottom: 1rem; box-shadow: var(--glass);
}
.class-selector-bar .form-group { flex: 1; min-width: 180px; margin: 0; }

/* PANEL */
.panel {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 0.5rem; padding: 1.15rem;
    box-shadow: var(--glass); margin-bottom: 0.85rem;
}
.panel-title {
    font-size: 1.05rem; font-weight: 600; color: var(--text);
    border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;
    margin-bottom: 0.75rem; display: flex; justify-content: space-between; align-items: center;
}
.panel-title .actions { display: flex; gap: 0.35rem; }

/* GRID */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }

/* FORM */
.form-group { margin-bottom: 0.75rem; }
.form-label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.25rem; font-weight: 500; }
.form-control {
    width: 100%; padding: 0.5rem 0.75rem;
    background: #ffffff; border: 1px solid #cbd5e1;
    border-radius: 0.375rem; color: var(--text); font-size: 0.88rem;
    outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
select.form-control option { background: #ffffff; color: var(--text); }
textarea.form-control { resize: vertical; min-height: 100px; font-family: monospace; font-size: 0.82rem; line-height: 1.5; background: #ffffff; border: 1px solid #cbd5e1; color: var(--text); }

/* BUTTONS */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
    padding: 0.45rem 0.85rem; border-radius: 0.375rem; font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.15s ease-in-out; border: none; text-decoration: none; white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.78rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background: #ffffff; color: var(--text); border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #0369a1; }
.btn-makeup { background: var(--makeup); color: #fff; }
.btn-makeup:hover { background: #6d28d9; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* TABLES */
.table-responsive { width: 100%; overflow-x: auto; border-radius: 0.5rem; border: 1px solid var(--border); background: #ffffff; }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
th, td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
th { background: #f1f5f9; color: #475569; font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }

/* BADGES */
.badge { display: inline-flex; padding: 0.2rem 0.5rem; border-radius: 9999px; font-size: 0.72rem; font-weight: 600; border: 1px solid transparent; }
.badge-success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.badge-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge-warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.badge-makeup { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge-info { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }

/* MATRIX TABLE */
.matrix-table th { text-align: center; min-width: 80px; }
.matrix-table td { text-align: center; }
.matrix-table td.text-left { text-align: left; }
.tick-present { color: var(--success); font-size: 1.1rem; font-weight: 700; }
.tick-claimed { color: var(--accent); }
.tick-makeup { color: var(--makeup); }
.tick-makeup-warning { color: var(--warning); font-size: 1.1rem; font-weight: 700; }
.tick-pending { color: var(--warning); font-size: 0.8rem; font-weight: 600; }
.tick-absent { color: rgba(220,38,38,0.2); font-size: 1.1rem; }
.tick-label { font-size: 0.68rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; margin: 0 auto; margin-top: 1px; color: var(--muted); }
.matrix-table th.sortable { cursor: pointer; user-select: none; transition: background 0.2s; }
.matrix-table th.sortable:hover { background: #e2e8f0 !important; }

/* TABS (inside main) */
.page-section { display: none; }
.page-section.active { display: block; }

/* ALERTS */
#alert-container { position: fixed; top: calc(var(--header-h) + 0.75rem); right: 1.25rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.35rem; max-width: 350px; }
.alert-box {
    padding: 0.65rem 0.85rem; border-radius: 0.375rem; font-size: 0.88rem; font-weight: 500;
    color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
    animation: slideIn 0.25s ease forwards; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.alert-success { background: linear-gradient(135deg, #059669, #10b981); }
.alert-error { background: linear-gradient(135deg, #dc2626, #ef4444); }
@keyframes slideIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(110%); opacity: 0; } }

/* MISC */
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 0.3rem; font-size: 0.82rem; font-family: monospace; border: 1px solid #e2e8f0; color: var(--text); }
hr { border: none; border-top: 1px solid var(--border); margin: 0.75rem 0; }
.info-box { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 0.375rem; padding: 0.6rem 0.85rem; font-size: 0.84rem; color: #1e40af; margin-bottom: 0.75rem; }
.warning-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: 0.375rem; padding: 0.6rem 0.85rem; font-size: 0.84rem; color: #92400e; margin-bottom: 0.75rem; }

/* CHECKLIST for makeup_allowed_from */
.class-checklist { display: flex; flex-direction: column; gap: 0.35rem; max-height: 200px; overflow-y: auto; }
.class-check-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.6rem; border-radius: 0.375rem; background: #ffffff; border: 1px solid var(--border); cursor: pointer; transition: background 0.15s; font-size: 0.85rem; }
.class-check-item:hover { background: #f8fafc; }
.class-check-item input[type=checkbox] { accent-color: var(--primary); width: 14px; height: 14px; }

/* MOBILE */
@media (max-width: 900px) {
    .sidebar { width: 56px; overflow: hidden; }
    .sidebar .nav-item span, .sidebar .sidebar-label, .sidebar .nav-badge { display: none; }
    .sidebar .nav-item { padding: 0.65rem; justify-content: center; border-left: none; border-bottom: 3px solid transparent; }
    .sidebar .nav-item.active { border-bottom-color: var(--primary); background: #eff6ff; }
    .main-content { margin-left: 56px; padding: 0.75rem; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .class-selector-bar { flex-direction: column; }
}
@media (max-width: 600px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 0.75rem; }
    header { padding: 0 1rem; }
}

/* MODAL STYLES */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.open {
    display: flex;
}
.modal-dialog {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    max-width: 480px;
    width: 100%;
    padding: 1.25rem;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}
.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}
.modal-close:hover {
    color: var(--text);
}

/* COURSE TREE STYLES */
.course-box {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.85rem;
    overflow: hidden;
    box-shadow: var(--glass);
}
.course-box-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
}
.course-edit-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.course-edit-row .form-group {
    margin: 0;
    flex: 1;
    min-width: 150px;
}
.course-edit-row .form-control {
    padding: 0.4rem 0.65rem;
    font-size: 0.88rem;
}
.course-actions {
    display: flex;
    gap: 0.35rem;
}
.course-box-body {
    padding: 0.85rem;
}
.classes-header-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}
.class-edit-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.class-edit-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    flex-wrap: wrap;
}
.class-edit-row .form-group {
    margin: 0;
    flex: 1;
    min-width: 140px;
}
.class-edit-row .form-group.class-link-group {
    flex: 2;
    min-width: 200px;
}
.class-edit-row .form-control {
    padding: 0.4rem 0.65rem;
    font-size: 0.85rem;
}
.class-actions {
    display: flex;
    gap: 0.3rem;
}

/* SUB NAVIGATION IN DENTATION */
.nav-sub-item {
    padding-left: 2rem !important;
    font-size: 0.84rem !important;
}

/* MASTER-DETAIL LAYOUTS */
.manage-split-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}
.selectable-list {
    max-height: 380px;
    overflow-y: auto;
    padding-right: 0.25rem;
}
.selectable-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
}
.selectable-item:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}
.selectable-item.active {
    background: #eff6ff;
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}
.selectable-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}
.badge-status {
    font-size: 0.65rem;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-weight: 600;
}
.badge-status-active {
    background: #ecfdf5;
    color: #047857;
}
.badge-status-inactive {
    background: #fef2f2;
    color: #b91c1c;
}

/* MOBILE COLLAPSE */
@media (max-width: 900px) {
    .manage-split-grid {
        grid-template-columns: 1fr;
    }
}

/* MAKEUP MODAL CHIPS AND FILTERS */
.modal-badge-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border: 1px dashed var(--border);
    border-radius: 0.375rem;
    min-height: 44px;
}
/* MAKEUP BADGES FOR MAIN PAGE AND MODAL */
.makeup-badges-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}
.makeup-badge-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    color: #6d28d9;
    font-size: 0.78rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
    transition: all 0.15s ease;
}
.makeup-badge-item:hover {
    background: #eee8ff;
    border-color: #c084fc;
    transform: translateY(-1px);
}
.makeup-badge-item .badge-course-name {
    color: #8b5cf6;
    font-size: 0.72rem;
    font-weight: 400;
    opacity: 0.85;
}
.makeup-badge-close {
    cursor: pointer;
    color: #a78bfa;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.1s;
    margin-left: 0.15rem;
    padding: 0 0.1rem;
}
.makeup-badge-close:hover {
    color: var(--danger);
}
.modal-filter-row {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.6rem;
}
.modal-filter-row .form-group {
    margin: 0;
    flex: 1;
}
.modal-filter-row .form-control {
    padding: 0.4rem 0.65rem;
    font-size: 0.83rem;
}
/* TOGGLE SWITCH STYLE */
.switch-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}
.switch-control {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}
.switch-control input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    border: 1px solid var(--border);
    transition: .3s;
    border-radius: 20px;
}
.switch-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: #fff;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
input:checked + .switch-slider {
    background-color: var(--primary);
    border-color: var(--primary);
}
input:checked + .switch-slider:before {
    transform: translateX(20px);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 5px;
}
@keyframes spin { to { transform: rotate(360deg); } }
