:root {
    --bg-main: radial-gradient(circle at 20% 20%, #7c3aed 0%, transparent 40%), radial-gradient(circle at 80% 80%, #06b6d4 0%, transparent 40%), linear-gradient(135deg, #0f172a, #020617);
    --text: #ffffff;
    --muted: rgba(255,255,255,0.72);
    --surface: rgba(255,255,255,0.07);
    --surface-strong: rgba(255,255,255,0.12);
    --border: rgba(255,255,255,0.12);
    --table-border: rgba(255,255,255,0.1);
    --topbar-bg: rgba(8,14,30,0.74);
    --accent: linear-gradient(90deg,#6366f1,#7c3aed);
    --danger: linear-gradient(90deg,#b91c1c,#ef4444);
    --shadow: 0 18px 44px rgba(0,0,0,0.32);
}

html[data-theme="light"] {
    --bg-main: radial-gradient(circle at 15% 15%, #c4b5fd 0%, transparent 35%), radial-gradient(circle at 85% 80%, #99f6e4 0%, transparent 35%), linear-gradient(135deg, #f8fafc, #e2e8f0);
    --text: #0f172a;
    --muted: rgba(15,23,42,0.68);
    --surface: rgba(255,255,255,0.84);
    --surface-strong: rgba(255,255,255,0.96);
    --border: rgba(100,116,139,0.22);
    --table-border: rgba(100,116,139,0.2);
    --topbar-bg: rgba(255,255,255,0.9);
    --shadow: 0 16px 34px rgba(15,23,42,0.14);
}

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

body {
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    background: var(--bg-main);
    background-attachment: fixed;
    color: var(--text);
    overflow-x: hidden;
}

.app-container { display: flex; min-height: calc(100vh - 136px); }

.topbar {
    height: 136px;
    overflow: visible;
    backdrop-filter: blur(18px);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-left, .top-right { display: flex; align-items: center; gap: 12px; }
.top-left { justify-content: flex-start; }
.top-right { justify-content: flex-end; min-height: 42px; }
.top-center { display: flex; justify-content: center; }
.top-center-stack { display:flex; flex-direction:column; align-items:center; gap:4px; }
.top-badge { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.top-logo { width: 152px; height: 152px; object-fit: contain; filter: drop-shadow(0 14px 26px rgba(0,0,0,.34)); transform: translateY(6px); }
.sidebar-toggle { border: 1px solid var(--border); background: var(--surface-strong); color: var(--text); border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 700; }
.sidebar-toggle:hover { box-shadow: 0 10px 22px rgba(99,102,241,.28); }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.username { font-weight: 600; max-width: 270px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { padding: 8px 16px; border-radius: 10px; background: var(--danger); color: #fff; text-decoration: none; }

.sidebar {
    width: 290px;
    transition: width .22s ease, padding .22s ease;
    background: var(--surface);
    backdrop-filter: blur(18px);
    border-right: 1px solid var(--border);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideIn .45s ease;
}

.nav-link {
    display: block;
    padding: 12px 14px;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    opacity: 0.92;
    transition: all .22s ease;
    border: 1px solid transparent;
}

.nav-link:hover, .nav-link.active {
    background: var(--accent);
    color: #fff;
    opacity: 1;
    transform: translateX(0);
    box-shadow: 0 8px 22px rgba(124,58,237,0.35);
}

.main-content { flex: 1; padding: 36px; animation: fadeIn .6s ease; }
.main-content.no-sidebar { width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 32px 14px; gap: 18px; }

.page-title {
    font-size: clamp(28px, 4vw, 38px);
    font-weight: 800;
    margin-bottom: 24px;
    background: linear-gradient(90deg,#a78bfa,#22d3ee);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }

.card {
    padding: 22px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: transform .22s ease, box-shadow .22s ease;
}

.card::before {
    content: "";
    position: absolute;
    inset: -1px;
    background: linear-gradient(130deg, rgba(168,85,247,.35), rgba(34,211,238,.2), transparent 60%);
    opacity: .75;
    pointer-events: none;
}

.card > * { position: relative; z-index: 1; }
.card:hover { transform: translateY(-3px); box-shadow: 0 22px 42px rgba(0,0,0,0.28); }
.card-title { font-size: 15px; color: var(--muted); margin-bottom: 8px; }
.card-value { font-size: 32px; font-weight: 800; }

.btn {
    display: inline-block;
    padding: 12px 18px;
    border-radius: 12px;
    border: 0;
    cursor: pointer;
    text-decoration: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    transition: transform .2s ease, box-shadow .2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(99,102,241,.4); }

.input-field {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    margin-bottom: 12px;
    outline: none;
}
.input-field:focus { border-color: rgba(99,102,241,.75); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }
.input-field option { color: #0f172a; }

.auth-wrapper { width: 100%; display: flex; justify-content: center; align-items: center; }
.auth-card {
    width: 100%; max-width: 600px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 34px;
    box-shadow: var(--shadow);
}
.auth-header { text-align: center; margin-bottom: 20px; }
.auth-header p, .auth-footer, .muted-text { color: var(--muted); }
.auth-logo { width: 120px; height: 120px; object-fit: contain; }
.auth-btn { width: 100%; }
.auth-footer a { color: #a78bfa; text-decoration: none; }

.flash-wrapper { position: fixed; right: 14px; top: 102px; display: flex; flex-direction: column; gap: 8px; z-index: 120; }
.flash-message { background: var(--surface-strong); border: 1px solid var(--border); padding: 10px 12px; border-radius: 10px; box-shadow: var(--shadow); }

.form-card h2, .list-card h2 { margin-bottom: 12px; }
.field-label { font-size: 14px; color: var(--muted); display: inline-block; margin-bottom: 6px; }
.table-wrap { overflow-x: auto; }

.grade-table { width: 100%; border-collapse: collapse; }
.grade-table th, .grade-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--table-border); }
.grade-table th { white-space: nowrap; }
.badge {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 4px 12px; border-radius: 999px;
    background: rgba(129,140,248,0.22);
    border: 1px solid rgba(129,140,248,0.55);
}

.role-sticker {
    display: inline-flex; align-items: center; justify-content: center;
    width: 148px; height: 148px; border-radius: 34px; font-size: 68px;
    box-shadow: var(--shadow);
    position: relative;
    border: 1px solid rgba(255,255,255,.24);
}
.sticker-icon { filter: drop-shadow(0 8px 16px rgba(0,0,0,.28)); }
.role-sticker::after {
    content: "";
    position: absolute;
    width: 80%; height: 80%; border-radius: 24px;
    border: 1px dashed rgba(255,255,255,0.35);
}
.student-sticker { background: linear-gradient(145deg, rgba(59,130,246,0.34), rgba(129,140,248,0.24)); }
.teacher-sticker { background: linear-gradient(145deg, rgba(16,185,129,0.35), rgba(52,211,153,0.26)); }

.subject-tags, .quick-actions, .status-chip-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.subject-tag, .status-chip {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    font-size: 13px;
}
.dashboard-actions { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.student-grades { margin-top: 14px; }
.hidden { display: none; }
.select-highlight { border-color: rgba(167,139,250,.9); }
.hint-text { font-size: 13px; margin-top: 6px; }
.home-main-logo { width: 250px; height: 250px; margin-bottom: 8px; }

.teacher-header-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.teacher-metrics-grid .card-value { font-size: clamp(24px, 2.7vw, 34px); }

.journal-filter-row {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.journal-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 10px 0 14px;
    flex-wrap: wrap;
}

.journal-toolbar-actions { display: flex; align-items: center; gap: 10px; }
.journal-toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

.journal-wrap { max-width: calc(100vw - 380px); border: 1px solid var(--border); border-radius: 16px; box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.journal-table { min-width: max-content; width: auto; border-collapse: separate; border-spacing: 0; }
.journal-table th, .journal-table td { min-width: 70px; padding: 4px; vertical-align: top; border-right: 1px solid var(--table-border); border-bottom: 1px solid var(--table-border); text-align: center; }
.journal-table th:first-child, .journal-table td:first-child { min-width: 210px; text-align: left; }
.journal-table thead th { position: sticky; top: 0; z-index: 4; background: var(--surface-strong); font-size: 12px; font-weight: 800; }

.journal-cell {
    margin: 0;
    width: 52px;
    min-width: 52px;
    height: 30px;
    font-size: 13px;
    font-weight: 800;
    text-align: center;
    padding: 4px 3px;
    border-radius: 8px;
}

.journal-comment {
    margin: 3px 0 0;
    width: 52px;
    min-width: 52px;
    height: 24px;
    font-size: 9px;
    padding: 3px 4px;
    border-radius: 7px;
}

.sidebar {
    transform: translateX(0);
}

.sticky-col {
    position: sticky;
    left: 0;
    background: var(--surface-strong);
    z-index: 2;
}

.sticky-head {
    top: 0;
    z-index: 3;
}

.journal-bottom-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.badge-danger { background: rgba(185,28,28,0.95); border-color: rgba(239,68,68,0.95); color: #fff; }

html[data-compact="on"] .main-content { padding: 24px; }
html[data-compact="on"] .card { padding: 16px; border-radius: 16px; }
html[data-compact="on"] .btn { padding: 10px 14px; border-radius: 10px; }
html[data-compact="on"] .input-field { margin-bottom: 9px; padding: 10px 12px; }

html[data-animations="off"] *,
@media (prefers-reduced-motion: reduce) {
    animation: none !important;
    transition: none !important;
}

@keyframes slideIn { from { transform: translateX(-28px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 980px) {
    .topbar { height: 112px; padding: 0 12px; grid-template-columns: auto 1fr auto; gap: 10px; }
    .top-logo { width: 112px; height: 112px; transform: translateY(4px); }
    .username { display: none; }
    .app-container { flex-direction: column; min-height: auto; }
    .sidebar {
        width: 100%; border-right: 0; border-bottom: 1px solid var(--border);
        padding: 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .nav-link { text-align: center; }
    .main-content { padding: 18px 12px; }
    .home-main-logo { width: 170px; height: 170px; }
    .role-sticker { width: 108px; height: 108px; font-size: 48px; }
    .auth-card { padding: 20px; }
    .panel-grid { grid-template-columns: 1fr; }
    .journal-wrap { max-width: 100%; }
    .journal-toolbar-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
    .journal-table th:first-child, .journal-table td:first-child { min-width: 170px; }
    .goal-grid { grid-template-columns: 1fr; }
    body.sidebar-collapsed .main-content { padding-left: 12px; }
}


.grade-strip {
    display: flex;
    align-items: stretch;
    gap: 8px;
    flex-wrap: wrap;
}

.grade-chip {
    min-width: 64px;
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    text-align: center;
}

.grade-date {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
}

.grade-number {
    font-size: 18px;
    font-weight: 800;
}

.grade-comment {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted);
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


.pager {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.pager-link {
    display: inline-flex;
    min-width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    text-decoration: none;
}

.pager-link.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.password-field-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.password-field-wrap .input-field {
    margin-bottom: 12px;
    padding-right: 110px;
}

.ghost-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
}

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    margin-bottom: 12px;
    font-size: 14px;
}

.back-to-top {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    transform: translateY(8px);
    z-index: 150;
}

.back-to-top.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.legal-footer {
    margin-top: 26px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.legal-footer a {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
}

.legal-footer a:hover {
    color: var(--text);
}

.subtle-footer {
    opacity: .8;
}

html .main-content.no-sidebar .legal-footer {
    width: min(960px, 100%);
    justify-content: center;
}


.legal-footer {
    margin-top: 26px;
    width: 100%;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}
.legal-links { display:flex; gap:14px; flex-wrap:wrap; }
.legal-links a { color: var(--muted); text-decoration:none; }
.legal-links a:hover { color: var(--text); }
.legal-meta { margin-top: 8px; font-size: 13px; }

.progress-line {
    position: relative;
    margin-top: 14px;
    min-height: 68px;
    border-top: 2px solid var(--border);
}
.progress-point {
    position: absolute;
    top: -8px;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.progress-point::before {
    content: '';
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22d3ee;
    box-shadow: 0 0 0 5px rgba(34,211,238,.18);
}
.progress-value { font-size: 12px; font-weight: 700; }
.progress-label { font-size: 11px; color: var(--muted); }


.schedule-day-block {
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.schedule-day-title {
    margin-bottom: 8px;
    font-size: 20px;
}


body.sidebar-collapsed .sidebar { width: 0; padding: 0; border-right: 0; overflow: hidden; }
body.sidebar-collapsed .main-content { padding-left: 24px; }
body.sidebar-collapsed .sidebar .nav-link { opacity: 0; }

.student-rating-scale { margin-top: 10px; height: 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-strong); overflow: hidden; }
.student-rating-fill { height: 100%; background: linear-gradient(90deg,#22c55e,#f59e0b,#ef4444); }


.today-highlight {
    animation: pulseToday 1.2s ease;
    background: rgba(34, 211, 238, 0.28) !important;
}

@keyframes pulseToday {
    0% { background: rgba(34, 211, 238, 0.55); }
    100% { background: rgba(34, 211, 238, 0.18); }
}

.goal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    align-items: end;
}

.alerts-list {
    list-style: none;
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
}

.alert-item {
    border: 1px solid var(--border);
    background: var(--surface-strong);
    border-radius: 12px;
    padding: 10px 12px;
}

.alert-item-warn {
    border-color: rgba(245, 158, 11, 0.8);
    background: rgba(245, 158, 11, 0.12);
}

.alert-item-danger {
    border-color: rgba(239, 68, 68, 0.85);
    background: rgba(239, 68, 68, 0.16);
}


.journal-table .sticky-col {
    box-shadow: 8px 0 18px rgba(0,0,0,.18);
}

.journal-cell:not(:placeholder-shown) {
    background: rgba(34, 211, 238, 0.13);
    border-color: rgba(34, 211, 238, 0.45);
    color: var(--text);
}

.journal-comment-input:not(:placeholder-shown) {
    background: rgba(167, 139, 250, 0.12);
    border-color: rgba(167, 139, 250, 0.36);
}

.journal-table tbody tr:hover td {
    background: rgba(255,255,255,.055);
}

.journal-table tbody tr:hover .sticky-col {
    background: var(--surface-strong);
}

.journal-table td:last-child,
.journal-table th:last-child {
    border-right: 0;
}

.journal-selected {
    outline: 2px solid rgba(34,211,238,.8);
    outline-offset: -2px;
    background: rgba(34,211,238,.12) !important;
}

.journal-dirty {
    box-shadow: 0 0 0 2px rgba(245,158,11,.34);
}

.journal-toast {
    position: fixed;
    right: 18px;
    bottom: 76px;
    z-index: 220;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity .2s ease, transform .2s ease;
}

.journal-toast.show {
    opacity: 1;
    transform: translateY(0);
}
