@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Dark mode (default) ── */
:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #263146;
  --sidebar-bg: #0b1628;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37,99,235,0.12);
  --accent: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-w: 220px;
  --th-bg: rgba(30,41,59,.6);
  --td-border: rgba(51,65,85,.5);
  --modal-shadow: rgba(0,0,0,.5);
  --toast-shadow: rgba(0,0,0,.4);
  --overlay-bg: rgba(0,0,0,.7);
}

/* ── Light mode ── */
[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --sidebar-bg: #1e293b;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: rgba(37,99,235,0.08);
  --accent: #2563eb;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --th-bg: #f8fafc;
  --td-border: #e2e8f0;
  --modal-shadow: rgba(0,0,0,.15);
  --toast-shadow: rgba(0,0,0,.1);
  --overlay-bg: rgba(0,0,0,.4);
}

/* Light mode sidebar stays dark (better contrast) */
[data-theme="light"] #sidebar { background: #1e293b; border-right-color: #334155; }
[data-theme="light"] #sidebar .nav-item { color: #94a3b8; }
[data-theme="light"] #sidebar .nav-item:hover { background: #263146; color: #e2e8f0; }
[data-theme="light"] #sidebar .nav-item.active { background: rgba(37,99,235,.25); color: #93c5fd; }
[data-theme="light"] .sidebar-logo-sub { color: #64748b; }
[data-theme="light"] #sidebar .sidebar-footer { border-top-color: #334155; }
[data-theme="light"] #sidebar .text-muted { color: #64748b; }
[data-theme="light"] #sidebar a { color: #94a3b8; }
[data-theme="light"] #mobile-bar { background: #1e293b; border-top-color: #334155; }
[data-theme="light"] .mob-nav { color: #94a3b8; }
[data-theme="light"] .mob-nav.active { color: #93c5fd; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* Layout */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#page { flex: 1; overflow-y: auto; }
#mobile-bar { display: none; background: var(--sidebar-bg); }

/* Sidebar */
.sidebar-logo { padding: 18px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon { width: 28px; height: 28px; background: var(--primary); border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-logo-text { font-weight: 700; font-size: 14px; }
.sidebar-logo-sub { font-size: 10px; color: var(--text-muted); }
nav { flex: 1; padding: 8px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-weight: 500; font-size: 13px; transition: all .15s; margin-bottom: 1px; text-decoration: none; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(37,99,235,0.15); color: var(--accent); }
.nav-item svg { flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* Page header */
.page-header { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; background: var(--bg); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.page-title { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.card-body { padding: 16px; }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; display: flex; align-items: center; justify-content: between; gap: 8px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; font-family: inherit; transition: all .15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { background: var(--surface2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Form elements */
input, select, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: 7px; color: var(--text); padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; min-height: 70px; }
label { font-size: 11px; color: var(--text-muted); font-weight: 500; display: block; margin-bottom: 4px; }
.form-group { margin-bottom: 14px; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.input-sm { padding: 5px 8px; font-size: 12px; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-blue { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge-green { background: rgba(16,185,129,.15); color: #34d399; }
.badge-amber { background: rgba(245,158,11,.15); color: #fbbf24; }
.badge-red { background: rgba(239,68,68,.15); color: #f87171; }
.badge-gray { background: rgba(148,163,184,.1); color: #94a3b8; }
.badge-active { background: rgba(37,99,235,.2); color: var(--accent); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { padding: 8px 12px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); background: var(--th-bg); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--td-border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.table-wrap { overflow-x: auto; }

/* Grade matrix */
.grade-table th { position: sticky; top: 0; z-index: 5; }
.grade-table th:first-child, .grade-table td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 4; border-right: 1px solid var(--border); min-width: 150px; }
.grade-table th:first-child { z-index: 6; }
.grade-cell { text-align: center; cursor: pointer; min-width: 60px; padding: 0; height: 40px; }
.grade-cell:hover { background: var(--primary-light) !important; }
.grade-btn { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: none; border: none; cursor: pointer; font-size: 14px; font-weight: 700; color: var(--text); font-family: inherit; }
.grade-1, .grade-2 { color: #34d399; }
.grade-3 { color: #fbbf24; }
.grade-4 { color: #fb923c; }
.grade-5, .grade-6 { color: #f87171; }
.grade-avg { font-weight: 800; color: var(--accent); }

/* Timetable */
.timetable-grid { display: grid; grid-template-columns: 54px repeat(5, 1fr); gap: 3px; }
.tt-header { background: var(--surface2); border-radius: 7px; padding: 8px; text-align: center; font-size: 12px; font-weight: 600; }
.tt-header.today { background: var(--primary); color: white; }
.tt-time { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--text-muted); padding: 6px; }
.tt-cell { min-height: 70px; border-radius: 8px; border: 1.5px dashed var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 20px; transition: all .15s; }
.tt-cell:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.tt-slot { min-height: 70px; border-radius: 8px; padding: 8px; cursor: pointer; position: relative; overflow: hidden; }
.tt-slot:hover .tt-slot-actions { opacity: 1; }
.tt-slot-actions { position: absolute; top: 4px; right: 4px; opacity: 0; display: flex; gap: 3px; transition: opacity .15s; }
.tt-slot-name { font-size: 12px; font-weight: 700; }
.tt-slot-sub { font-size: 11px; opacity: 0.7; margin-top: 2px; }

/* Calendar */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day-header { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 6px; }
.cal-day { min-height: 90px; background: var(--surface); border-radius: 8px; padding: 6px; cursor: pointer; border: 1px solid transparent; transition: all .15s; }
.cal-day:hover { border-color: var(--primary); background: var(--surface2); }
.cal-day.today .cal-day-num { background: var(--primary); color: white; border-radius: 50%; }
.cal-day.other-month { opacity: 0.35; }
.cal-day.weekend { background: rgba(30,41,59,.4); }
.cal-day-num { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.cal-event { font-size: 10px; padding: 2px 5px; border-radius: 4px; margin-top: 2px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-lesson { background: rgba(59,130,246,.2); color: #60a5fa; }
.ev-test { background: rgba(239,68,68,.2); color: #f87171; }
.ev-appointment { background: rgba(16,185,129,.2); color: #34d399; }
.ev-holiday { background: rgba(148,163,184,.1); color: #94a3b8; }
.ev-reminder { background: rgba(245,158,11,.2); color: #fbbf24; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay-bg); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 64px var(--modal-shadow); }
.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body { padding: 18px 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 13px; min-width: 240px; max-width: 360px; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px var(--toast-shadow); animation: slideIn .2s ease; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* Empty state */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 24px; text-align: center; color: var(--text-muted); gap: 12px; }
.empty svg { opacity: 0.25; }
.empty-text { font-size: 14px; }
.empty-sub { font-size: 12px; color: var(--text-muted); }

/* Misc */
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.p-4 { padding: 16px; } .p-6 { padding: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat-val { font-size: 26px; font-weight: 800; margin-bottom: 2px; }
.stat-label { font-size: 11px; color: var(--text-muted); }
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Expanded class row */
.class-row { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.class-row-header { padding: 12px 16px; background: var(--surface); display: flex; align-items: center; cursor: pointer; gap: 10px; }
.class-row-header:hover { background: var(--surface2); }
.class-row-body { border-top: 1px solid var(--border); }

/* Responsive */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #mobile-bar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--sidebar-bg); border-top: 1px solid var(--border); z-index: 50; padding: 4px; justify-content: space-around; }
  .mob-nav { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 10px; font-weight: 500; min-width: 48px; text-decoration: none; border: none; background: none; font-family: inherit; }
  .mob-nav.active { color: var(--accent); }
  #page { padding-bottom: 72px; }
  .page-header { padding: 12px 16px; }
  .cal-day { min-height: 60px; }
  .form-row { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
