:root {
    --primary: #335CFF;
    --primary-dark: #2544D1;
    --primary-light: #EEF2FF;
    --success: #17C964;
    --success-dark: #12A350;
    --success-light: #E8FBF0;
    --danger: #F43F5E;
    --danger-dark: #D81B49;
    --danger-light: #FFEBF0;
    --warning: #FFA800;
    --warning-dark: #D98C00;
    --warning-light: #FFF7E6;
    --info: #0EA5E9;
    --info-light: #E6F7FD;
    --bg: #F3F5FC;
    --card: #ffffff;
    --border: #E4E7F1;
    --text: #1D2433;
    --text-muted: #6B7280;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 56, 0.04);
    --shadow-md: 0 4px 16px rgba(29, 36, 72, 0.07);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; }

/* Sidebar layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex-shrink: 0;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 60;
}
.sidebar-brand {
    padding: 22px 22px 14px;
}
.sidebar-brand a {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text);
    letter-spacing: -0.01em;
}
.sidebar-brand a:hover { text-decoration: none; }

.sidenav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 14px;
    overflow-y: auto;
}
.sidenav a {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--text-muted);
    font-size: 0.89rem;
    font-weight: 600;
    padding: 10px 13px;
    border-radius: 10px;
    transition: background .12s, color .12s;
}
.sidenav a:hover { color: var(--primary); text-decoration: none; background: var(--primary-light); }
.sidenav a.active { color: var(--primary); background: var(--primary-light); }
.sidenav a.active .nav-icon { color: var(--primary); }
.nav-icon { flex-shrink: 0; color: var(--text-muted); }
.sidenav a:hover .nav-icon, .sidenav a.active .nav-icon { color: inherit; }

.sidebar-footer {
    padding: 14px 14px 18px;
    border-top: 1px solid var(--border);
}
.sidebar-user {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    padding: 6px 13px 10px;
}
.sidenav-logout {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--danger) !important;
    font-size: 0.89rem;
    font-weight: 600;
    padding: 10px 13px;
    border-radius: 10px;
}
.sidenav-logout:hover { background: var(--danger-light); text-decoration: none; }

.main-area { flex: 1; min-width: 0; }

.nav-toggle {
    display: none;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 70;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px;
    cursor: pointer;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

@media (max-width: 860px) {
    .nav-toggle { display: flex; }
    .sidebar {
        position: fixed;
        left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .18s ease;
        box-shadow: var(--shadow-md);
    }
    .sidebar.open { transform: translateX(0); }
    .container { padding-top: 64px; }
}

/* Cards / layout */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat-tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.stat-tile .num { font-size: 1.9rem; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.stat-tile .label { color: var(--text-muted); font-size: 0.82rem; margin-top: 4px; font-weight: 600; }

/* Forms */
label { display: block; font-weight: 700; margin: 12px 0 6px; font-size: 0.86rem; color: var(--text); }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=datetime-local], input[type=file], select, textarea {
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    transition: border-color .12s, box-shadow .12s;
}
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; }
.form-row { margin-bottom: 8px; }
.form-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 5px; }
fieldset { border: 1.5px solid var(--border); border-radius: var(--radius-sm); margin: 14px 0; padding: 14px; }
legend { font-weight: 700; padding: 0 6px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; margin: 12px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

input[type=checkbox], input[type=radio] {
    accent-color: var(--primary);
    width: 17px;
    height: 17px;
    cursor: pointer;
}

/* Toggle switches - same markup as .checkbox-row, add .toggle-row for a pill switch */
.toggle-row input[type=checkbox] {
    appearance: none;
    -webkit-appearance: none;
    width: 42px;
    height: 24px;
    background: #D7DCEA;
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
    accent-color: initial;
}
.toggle-row input[type=checkbox]::before {
    content: '';
    position: absolute;
    top: 3px; left: 3px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform .15s;
    box-shadow: 0 1px 3px rgba(16, 24, 56, 0.25);
}
.toggle-row input[type=checkbox]:checked { background: var(--primary); }
.toggle-row input[type=checkbox]:checked::before { transform: translateX(18px); }

/* Buttons */
.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 0.89rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    transition: background .12s, transform .05s, box-shadow .12s;
    box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 0.78rem; }
.btn-secondary { background: #4B5566; }
.btn-secondary:hover { background: #343D4D; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-dark); }
.btn-warning { background: var(--warning); color: #4A3200; }
.btn-warning:hover { background: var(--warning-dark); color: #4A3200; }
.btn-info { background: var(--info); }
.btn-info:hover { background: #0B86BC; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); box-shadow: none; }
.btn-outline:hover { background: var(--primary-light); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: #EEF0F6; color: var(--text); }
.btn-block { display: block; width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #F7F8FC; font-weight: 700; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFBFE; }

/* Alerts / badges */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.89rem; border: 1.5px solid transparent; }
.alert-success { background: var(--success-light); color: #0D7A3C; border-color: #BCF0D4; }
.alert-error { background: var(--danger-light); color: #BE123C; border-color: #FBCBD7; }
.alert-warning { background: var(--warning-light); color: #92600A; border-color: #FBE3AD; }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 0.73rem; font-weight: 700; }
.badge-open { background: var(--success-light); color: #0D7A3C; }
.badge-upcoming { background: var(--primary-light); color: var(--primary-dark); }
.badge-closed { background: #EEF0F6; color: #4B5566; }
.badge-progress { background: var(--warning-light); color: #92600A; }
.badge-submitted { background: #EDE9FE; color: #5B21B6; }

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }

/* Auth pages */
.auth-wrap { max-width: 420px; margin: 48px auto; }
.auth-wrap .card { padding: 32px 28px; }
.auth-wrap h1 { font-size: 1.35rem; text-align: center; margin-bottom: 4px; letter-spacing: -0.01em; }
.auth-wrap .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 22px; font-size: 0.9rem; }

.email-prompt { text-align: center; padding: 12px 0 4px; }
.email-prompt-icon {
    width: 56px; height: 56px; line-height: 56px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 1.6rem;
    margin: 0 auto 14px;
}
.email-prompt p { color: var(--text); font-size: 0.92rem; }

/* Password rules checklist */
.rule-list { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 6px; }
.rule-list li { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--text-muted); }
.rule-list .rule-icon {
    width: 16px; height: 16px; border-radius: 50%;
    background: #E4E7F1;
    flex-shrink: 0;
    position: relative;
}
.rule-list li.met { color: var(--success-dark); }
.rule-list li.met .rule-icon { background: var(--success); }
.rule-list li.met .rule-icon::after {
    content: '';
    position: absolute; left: 5px; top: 2px;
    width: 4px; height: 8px;
    border: solid #fff; border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.rule-list li.unmet .rule-icon::after {
    content: '';
    position: absolute; left: 5px; top: 7px;
    width: 6px; height: 2px;
    background: #B6BCCB;
}

/* Activity taking */
.watermark-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
    opacity: 0.14;
}
.watermark-layer span {
    position: absolute;
    white-space: nowrap;
    font-size: 14px;
    color: #000;
    transform: rotate(-30deg);
}
.taking-layout { display: flex; gap: 18px; align-items: flex-start; }
.taking-main { flex: 1; min-width: 0; }
.taking-nav {
    width: 220px;
    flex-shrink: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: sticky;
    top: 70px;
    box-shadow: var(--shadow-sm);
}
.item-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 10px; }
.item-grid a {
    border: 1.5px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 7px 0;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text) !important;
    text-align: center;
    display: block;
    text-decoration: none !important;
}
.item-grid a.answered { background: var(--success-light); border-color: #9EEFC0; color: #0D7A3C !important; }
.item-grid a.flagged { outline: 2px solid var(--warning); outline-offset: 1px; }
.item-grid a.current { border-color: var(--primary); border-width: 2px; font-weight: 800; box-shadow: 0 0 0 3px var(--primary-light); }
.timer-box {
    text-align: center;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-weight: 800;
    font-size: 1.15rem;
    box-shadow: var(--shadow-sm);
    letter-spacing: -0.01em;
}
.timer-box.low { background: var(--danger-light); color: var(--danger-dark); border-color: #FBCBD7; }
.choice-option { display: flex; align-items: flex-start; gap: 9px; padding: 11px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; transition: border-color .12s, background .12s; }
.choice-option:hover { background: var(--primary-light); border-color: #C7D2FE; }
.choice-option input { margin-top: 3px; width: auto; }

.fs-fallback { position: fixed; top: 0; left: 0; right: 0; z-index: 1001; margin: 0; border-radius: 0; cursor: pointer; text-align: center; }

@media (max-width: 800px) {
    .taking-layout { flex-direction: column; }
    .taking-nav { width: 100%; position: static; }
    .item-grid { grid-template-columns: repeat(6, 1fr); }
}

.violation-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--danger);
    color: #fff;
    padding: 10px 16px;
    text-align: center;
    font-weight: 700;
    z-index: 1000;
    display: none;
}

.disabled-select { user-select: none; -webkit-user-select: none; }

/* Grades page */
.policy-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-top: 12px; }
.policy-card { border: 1.5px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; }
.policy-card h4 { margin: 0 0 4px; font-size: 0.92rem; }
.policy-card .policy-band { font-size: 0.78rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.03em; }
.policy-card ul { margin: 8px 0 0; padding-left: 18px; font-size: 0.83rem; color: var(--text-muted); }
.policy-card li { margin-bottom: 5px; }

.grade-layout { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 16px; }
.grade-details { flex: 2; min-width: 260px; }
.grade-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.grade-row:last-child { border-bottom: none; }
.grade-row .grade-label { color: var(--text-muted); font-weight: 600; }
.grade-row .grade-value { font-weight: 700; color: var(--text); text-align: right; }
.grade-row .grade-value.is-missing { color: var(--danger); }
.grade-row .grade-value.is-none { color: var(--text-muted); font-weight: 600; }

.grade-overall { flex: 1; min-width: 180px; display: flex; }
.overall-badge {
    background: var(--primary-light);
    border-radius: var(--radius);
    padding: 22px;
    text-align: center;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.overall-badge.band-passed { background: var(--success-light); }
.overall-badge.band-failed { background: var(--danger-light); }
.overall-badge.band-conditional { background: var(--warning-light); }
.overall-num { font-size: 2.1rem; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.overall-badge.band-passed .overall-num { color: var(--success-dark); }
.overall-badge.band-failed .overall-num { color: var(--danger-dark); }
.overall-badge.band-conditional .overall-num { color: var(--warning-dark); }
.overall-sub { font-size: 1rem; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
.overall-label { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-top: 10px; font-weight: 700; }
.overall-status { margin-top: 8px; }

.missing-list { margin: 10px 0 0; padding-left: 18px; font-size: 0.88rem; }
.missing-list li { margin-bottom: 4px; }

.grade-options { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(17, 22, 44, 0.55);
    display: flex; align-items: center; justify-content: center;
    padding: 20px; z-index: 2000;
}
.modal-box {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-md);
    max-width: 480px; width: 100%; padding: 24px; max-height: 90vh; overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-box ul { padding-left: 20px; margin: 12px 0; font-size: 0.9rem; }
.modal-box ul li { margin-bottom: 6px; }
