:root {
    --primary: #4F46E5;
    --primary-light: #6366F1;
    --primary-dark: #3730A3;
    --secondary: #06B6D4;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --sidebar-bg: #1E1B4B;
    --sidebar-text: #C7D2FE;
    --sidebar-active: #4F46E5;
    --sidebar-hover: rgba(255,255,255,0.07);
    --bg: #F8FAFC;
    --card-bg: #FFFFFF;
    --text: #1E293B;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --sidebar-width: 280px;
    --topbar-height: 70px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.7;
}

/* ── Layout ── */
.wrapper { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width 0.3s ease;
    overflow: hidden;
}
.sidebar.collapsed { width: 70px; }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .menu-label,
.sidebar.collapsed .menu-item span,
.sidebar.collapsed .sidebar-badge,
.sidebar.collapsed .user-details { display: none; }
.sidebar.collapsed .menu-item { justify-content: center; padding: 12px; }
.sidebar.collapsed .sidebar-logo { justify-content: center; }
.sidebar.collapsed .user-info { justify-content: center; }

.sidebar-header { padding: 24px 18px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.sidebar-logo { display: flex; align-items: center; gap: 14px; }
.logo-icon {
    width: 44px; height: 44px;
    background: var(--primary);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 22px; color: white;
    flex-shrink: 0;
}
.logo-title { display: block; font-weight: 700; font-size: 19px; color: white; line-height: 1.2; }
.logo-sub { display: block; font-size: 13px; color: var(--sidebar-text); letter-spacing: 0.5px; }

.sidebar-menu { flex: 1; padding: 18px 12px; overflow-y: auto; }
.menu-section { margin-bottom: 28px; }
.menu-label {
    font-size: 12px; font-weight: 600; letter-spacing: 1px;
    color: rgba(199,210,254,0.4); text-transform: uppercase;
    padding: 0 10px; display: block; margin-bottom: 8px;
}
.menu-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 10px;
    color: var(--sidebar-text); text-decoration: none;
    font-weight: 500; font-size: 15px;
    transition: all 0.2s; margin-bottom: 4px;
}
.menu-item:hover { background: var(--sidebar-hover); color: white; }
.menu-item.active { background: var(--primary); color: white; }
.menu-item i { font-size: 19px; flex-shrink: 0; width: 22px; text-align: center; }
.menu-item span:first-of-type { flex: 1; }
.sidebar-badge {
    background: #22C55E; color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1;
    padding: 3px 6px; border-radius: 10px;
    min-width: 18px; text-align: center;
    margin-left: auto;
}
.sidebar-badge-warning { background: #F59E0B; }

.sidebar-footer {
    padding: 18px; border-top: 1px solid rgba(255,255,255,0.07);
    display: flex; align-items: center; justify-content: space-between;
}
.user-info { display: flex; align-items: center; gap: 12px; overflow: hidden; }
.user-avatar {
    width: 42px; height: 42px; background: var(--primary); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px; color: white; flex-shrink: 0;
}
.user-name { display: block; font-size: 15px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.user-role { display: block; font-size: 13px; color: var(--sidebar-text); }
.logout-btn {
    color: var(--sidebar-text); font-size: 20px; text-decoration: none;
    padding: 8px; border-radius: 8px; transition: all 0.2s; flex-shrink: 0;
}
.logout-btn:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1; min-height: 100vh;
    transition: margin-left 0.3s ease;
}
.main-content.expanded { margin-left: 70px; }

/* ── Topbar ── */
.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; position: sticky; top: 0; z-index: 200;
    box-shadow: var(--shadow);
}
.sidebar-toggle {
    background: none; border: none; font-size: 22px;
    color: var(--text-muted); cursor: pointer; padding: 6px;
    border-radius: 8px; transition: all 0.2s;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.sidebar-toggle:hover { background: var(--bg); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.lang-select {
    border: 1px solid var(--border); border-radius: 8px;
    padding: 6px 10px; font-size: 13px; font-family: inherit;
    color: var(--text); background: var(--card-bg); cursor: pointer;
    outline: none; transition: border-color 0.2s;
}
.lang-select:focus { border-color: var(--primary); }

/* ── Page Content ── */
.messages-container { padding: 16px 24px 0; }
.page-content { padding: 24px; }

/* ── Page Header ── */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px;
}
.page-title { font-size: 26px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 15px; color: var(--text-muted); margin-top: 4px; }

/* ── Cards ── */
.card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--card-bg);
}
.card-title { font-size: 17px; font-weight: 600; color: var(--text); margin: 0; }
.card-body { padding: 24px; }

/* ── Stat Cards ── */
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 16px; transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
    width: 60px; height: 60px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; flex-shrink: 0;
}
.stat-icon.indigo { background: rgba(79,70,229,0.1); color: var(--primary); }
.stat-icon.cyan { background: rgba(6,182,212,0.1); color: var(--secondary); }
.stat-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.stat-icon.amber { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-icon.red { background: rgba(239,68,68,0.1); color: var(--danger); }
.stat-card > div { min-width: 0; }   /* let the text block shrink instead of overflowing the card */
.stat-value {
    /* scales fluidly with viewport, capped at 30px on desktop, floored at 18px on tiny screens */
    font-size: clamp(18px, 5vw, 30px); font-weight: 700; color: var(--text);
    line-height: 1.1; overflow-wrap: anywhere; word-break: break-word;
}
.stat-label { font-size: 14px; color: var(--text-muted); margin-top: 6px; font-weight: 500; }

/* ── Mobile (< 768px): trim icon + padding so the number gets more room ── */
@media (max-width: 767.98px) {
    .stat-card { padding: 14px; gap: 12px; }
    .stat-icon { width: 46px; height: 46px; font-size: 20px; border-radius: 12px; }
    .stat-label { font-size: 13px; margin-top: 4px; }
}

/* ── Buttons ── */
.btn { border-radius: 8px; font-weight: 500; font-size: 15px; padding: 10px 20px; transition: all 0.2s; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; }

/* ── Tables ── */
.table-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table { margin: 0; }
.table th {
    background: #F8FAFC; font-size: 13px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.table td { padding: 14px 18px; vertical-align: middle; border-color: var(--border); font-size: 15px; }
.table tbody tr:hover { background: rgba(79,70,229,0.02); }

/* ── Badges ── */
.badge-status {
    padding: 4px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
}
.badge-paid { background: rgba(16,185,129,0.1); color: #059669; }
.badge-pending { background: rgba(245,158,11,0.1); color: #D97706; }
.badge-overdue { background: rgba(239,68,68,0.1); color: #DC2626; }
.badge-partial { background: rgba(6,182,212,0.1); color: #0891B2; }
.badge-present { background: rgba(16,185,129,0.1); color: #059669; }
.badge-absent { background: rgba(239,68,68,0.1); color: #DC2626; }
.badge-late { background: rgba(245,158,11,0.1); color: #D97706; }
.badge-excused { background: rgba(99,102,241,0.1); color: #4F46E5; }
.badge-new { background: rgba(79,70,229,0.1); color: #4F46E5; }
.badge-trial_booked { background: rgba(6,182,212,0.1); color: #0891B2; }
.badge-trial_attended { background: rgba(245,158,11,0.1); color: #D97706; }
.badge-thinking { background: rgba(139,92,246,0.1); color: #7C3AED; }
.badge-enrolled { background: rgba(16,185,129,0.1); color: #059669; }
.badge-lost { background: rgba(148,163,184,0.15); color: #64748B; }

/* ── Avatar ── */
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); display: inline-flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: white; flex-shrink: 0;
}
.avatar-lg { width: 64px; height: 64px; font-size: 22px; border-radius: 16px; }

/* ── Forms ── */
.form-control, .form-select {
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 15px; padding: 11px 14px; font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); outline: none;
}
.form-label { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 8px; }

/* ── Search box ── */
.search-box { position: relative; }
.search-box .bi-search {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted); font-size: 14px;
}
.search-box input { padding-left: 36px; }

/* ── Profile card ── */
.profile-card {
    display: flex; align-items: center; gap: 16px;
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.profile-info h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.profile-info p { color: var(--text-muted); font-size: 13px; margin: 0; }

/* ── Detail grid ── */
.detail-row { display: flex; gap: 8px; margin-bottom: 12px; font-size: 13.5px; }
.detail-label { color: var(--text-muted); font-weight: 500; min-width: 140px; }
.detail-value { color: var(--text); }

/* ── Subject chips ── */
.subject-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
/* Subject chip colors generated dynamically in base.html from SubjectCard.color */

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; opacity: 0.3; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── Login page ── */
.login-page {
    min-height: 100vh; display: flex;
    background: linear-gradient(135deg, #1E1B4B 0%, #312E81 50%, #4F46E5 100%);
}
.login-left {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 40px;
    color: white;
}
.login-right {
    width: 460px; background: white; display: flex;
    align-items: center; justify-content: center; padding: 40px;
}
.login-logo { font-size: 64px; margin-bottom: 24px; }
.login-title { font-size: 36px; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { font-size: 16px; opacity: 0.7; text-align: center; max-width: 320px; }
.login-form-container { width: 100%; max-width: 340px; }
.login-form-title { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.login-form-sub { color: var(--text-muted); margin-bottom: 32px; font-size: 16px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
.sidebar-overlay.active { display: block; }
.sidebar-close { display: none; background: none; border: none; color: rgba(255,255,255,0.6); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.sidebar-close:hover { background: rgba(255,255,255,0.1); color: #fff; }

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; overflow-x: hidden; }
    .topbar { position: fixed !important; top: 0; left: 0; right: 0; z-index: 9999 !important; }
    .page-content { padding-top: var(--topbar-height); }
    .login-left { display: none; }
    .login-right { width: 100%; }
    body { overflow-x: hidden; }
    .table-responsive, .card { overflow-x: auto; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .page-header .d-flex { flex-wrap: wrap; }
    .card-body { padding: 12px; }
    .container-fluid { padding-left: 12px; padding-right: 12px; }
    .sidebar-close { display: block; }
    .sidebar-header { justify-content: space-between; }
}

/* ── Alerts ── */
.alert { border: none; border-radius: 8px; font-size: 13.5px; }
.alert-success { background: rgba(16,185,129,0.1); color: #059669; }
.alert-danger, .alert-error { background: rgba(239,68,68,0.1); color: #DC2626; }
.alert-warning { background: rgba(245,158,11,0.1); color: #D97706; }

/* ── Utility ── */
.fw-600 { font-weight: 600 !important; }
.fw-700 { font-weight: 700 !important; }
.flex-1 { flex: 1 !important; }
.text-green { color: #16a34a !important; }
.text-red { color: #dc2626 !important; }
.text-amber { color: #d97706 !important; }
.gap-1 { gap: 4px !important; }
.score-bar { height: 6px; border-radius: 3px; background: #E2E8F0; overflow: hidden; margin-top: 4px; }
.score-bar-fill { height: 100%; border-radius: 3px; transition: width .4s; }
.alert-info { background: rgba(79,70,229,0.1); color: var(--primary); }
