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

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface2: #21262d;
    --border: #30363d;
    --accent: #5865f2;
    --accent-hover: #4752c4;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --success: #3fb950;
    --danger: #f85149;
    --radius: 10px;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* NAV */
.nav-logo {
    height: 64px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
    display: block;
}

nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 84px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    text-decoration: none;
    margin-right: 16px;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--text); background: var(--surface2); }

/* USER BADGE */
.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.15s;
}

.user-badge:hover { background: var(--surface2); }

.user-badge img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.user-badge span {
    font-size: 0.875rem;
    color: var(--text);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* LOGOUT DROPDOWN */
.logout-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    min-width: 120px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
}

.logout-dropdown.open { display: block; }

.logout-btn {
    width: 100%;
    background: none;
    border: none;
    color: var(--danger);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}

.logout-btn:hover { background: rgba(248, 81, 73, 0.1); }

/* DEPARTMENT PANEL */
.department-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.department-header {
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 700;
    font-family: inherit;
    transition: background 0.15s;
}

.department-header:hover { background: var(--surface2); }

.department-icon { font-size: 1.1rem; }
.department-name { flex: 1; text-align: left; }

.department-arrow {
    color: var(--text-muted);
    font-size: 1rem;
    transition: transform 0.2s;
}

.department-arrow.collapsed { transform: rotate(-90deg); }

.department-body {
    border-top: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.department-body.hidden { display: none; }

/* MAIN */
main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 560px;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* LOGIN SCREEN */
.login-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    padding: 16px 0;
}

.login-screen .logo {
    width: 64px;
    height: 64px;
    background: var(--surface2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.login-screen h2 { font-size: 1.1rem; }
.login-screen p { font-size: 0.875rem; color: var(--text-muted); max-width: 320px; }

/* FORM */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

label .required { color: var(--danger); margin-left: 2px; }

input[type="text"],
input[type="number"],
textarea,
select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9375rem;
    padding: 10px 12px;
    outline: none;
    width: 100%;
    transition: border-color 0.15s;
    font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea { resize: vertical; min-height: 80px; }

.field-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* FILE INPUT */
.file-input {
    width: 100%;
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    font-family: inherit;
}

.file-input::file-selector-button {
    background: var(--surface2);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    margin-right: 12px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-family: inherit;
}

.file-input::file-selector-button:hover { background: var(--border); }

.field-error {
    font-size: 0.75rem;
    color: var(--danger);
}

input.input-error {
    border-color: var(--danger);
}

/* Hide number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* DISCORD USER CARD */
.discord-user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
}

.discord-user-card img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.discord-user-card .info { line-height: 1.3; }
.discord-user-card .name { font-weight: 600; font-size: 0.9375rem; }
.discord-user-card .id { font-size: 0.75rem; color: var(--text-muted); }

/* COOLDOWN BANNER */
.cooldown-banner {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.cooldown-banner .timer {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--danger);
}

/* SUCCESS BANNER */
.success-banner {
    background: rgba(63, 185, 80, 0.1);
    border: 1px solid rgba(63, 185, 80, 0.3);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.success-banner .icon { font-size: 2rem; }
.success-banner h3 { font-size: 1rem; color: var(--success); }
.success-banner p { font-size: 0.875rem; color: var(--text-muted); }

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 600;
    padding: 10px 20px;
    transition: opacity 0.15s, background 0.15s;
    text-decoration: none;
    font-family: inherit;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-discord { background: #5865f2; color: #fff; }
.btn-discord:hover { background: #4752c4; }

.btn-sm { padding: 6px 14px; font-size: 0.8125rem; }
.btn-ghost { background: var(--surface2); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }

/* DIVIDER */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* TAB SELECTOR */
.tab-group {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 24px;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    font-family: inherit;
}

.tab-btn.active { background: var(--surface2); color: var(--text); font-weight: 600; }
.tab-btn:hover:not(.active) { color: var(--text); }

/* SPINNER */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* HOME PAGE CARDS */
.form-cards {
    display: grid;
    gap: 12px;
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s, background 0.15s;
}

.form-card:hover { border-color: var(--accent); background: var(--surface2); }

.form-card-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.form-card-info h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 2px; }
.form-card-info p { font-size: 0.8125rem; color: var(--text-muted); }
.form-card-arrow { color: var(--text-muted); font-size: 1.2rem; }

.section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
    margin-top: 28px;
}
.section-title:first-child { margin-top: 0; }

/* RANK SECTION TITLE */
.rank-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 16px;
}

/* QUIZ */
.test-rank-btn,
.report-rank-btn {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    color: var(--text);
}

.test-rank-btn:disabled,
.report-rank-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.quiz-header {
    margin-bottom: 24px;
}

.quiz-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.quiz-progress-bar {
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    overflow: hidden;
}

.quiz-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.quiz-question {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    margin-bottom: 6px;
}

.quiz-hint {
    font-size: 0.8rem;
    color: var(--accent);
    margin-bottom: 20px;
    min-height: 1.2em;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.quiz-option {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-size: 0.9375rem;
    color: var(--text);
    text-align: left;
    font-family: inherit;
    width: 100%;
}

.quiz-option:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--surface2);
}

.quiz-option.selected {
    border-color: var(--accent);
    background: rgba(88, 101, 242, 0.1);
}

.quiz-option.correct {
    border-color: var(--success);
    background: rgba(63, 185, 80, 0.1);
}

.quiz-option.wrong {
    border-color: var(--danger);
    background: rgba(248, 81, 73, 0.1);
}

.quiz-option:disabled { cursor: default; }

.quiz-option-marker {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: border-color 0.15s, background 0.15s;
}

.quiz-option.multi .quiz-option-marker {
    border-radius: 4px;
}

.quiz-option.selected .quiz-option-marker,
.quiz-option.correct .quiz-option-marker {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

.quiz-option.wrong .quiz-option-marker {
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
}

.result-card {
    text-align: center;
    padding: 16px 0;
}

.result-icon { font-size: 3rem; margin-bottom: 12px; }

.result-score {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.result-score.pass { color: var(--success); }
.result-score.fail { color: var(--danger); }

.result-label {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.result-sub {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* ADMIN STATS */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.1;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 4px;
}

/* ADMIN */
.admin-filters {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.admin-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
}

.admin-card.type-exam   { border-left-color: var(--accent); }
.admin-card.type-report { border-left-color: var(--success); }
.admin-card.type-test   { border-left-color: #d29922; }

.admin-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
    flex-wrap: wrap;
}

.admin-type { font-weight: 700; font-size: 0.9375rem; }
.admin-date { font-size: 0.75rem; color: var(--text-muted); }

.admin-user { font-size: 0.875rem; margin-bottom: 10px; }

.admin-data {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-row { display: flex; gap: 10px; font-size: 0.8125rem; }
.admin-row-key { color: var(--text-muted); min-width: 90px; flex-shrink: 0; }

/* RESPONSIVE */
@media (max-width: 480px) {
    .card { padding: 20px 16px; }
    nav { padding: 0 12px; height: 62px; }
    .nav-logo { height: 42px; }
    .nav-brand { font-size: 0.875rem; }
}

/* CREDIT */
.site-credit {
    position: fixed;
    right: 12px;
    bottom: 10px;
    z-index: 50;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s;
}
.site-credit:hover {
    opacity: 1;
    color: var(--accent);
}
