:root {
    --ink: #17203b;
    --muted: #70778d;
    --paper: #f5f6fa;
    --card: #ffffff;
    --line: #e3e6ef;
    --brand: #5b5ce2;
    --brand-strong: #4647ca;
    --sidebar: #11162a;
    --success: #138a6a;
    --warning: #d3832c;
    --danger: #c55050;
    --shadow: 0 12px 36px rgba(23, 32, 59, .07);
    --bs-primary: #5b5ce2;
    --bs-primary-rgb: 91, 92, 226;
    --bs-font-sans-serif: 'DM Sans', system-ui, sans-serif;
}

[data-bs-theme="dark"] {
    --ink: #eef0fa;
    --muted: #9da5bd;
    --paper: #0d1120;
    --card: #161c31;
    --line: #28304a;
    --sidebar: #090c17;
    --shadow: 0 18px 46px rgba(0, 0, 0, .22);
    color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: 'DM Sans', sans-serif; }
h1,h2,h3,h4,h5,.brand-mark { font-family: 'Manrope', sans-serif; letter-spacing: -.035em; }
a { color: inherit; }
.btn { font-weight: 700; border-radius: .75rem; padding: .68rem 1.1rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover,.btn-primary:focus { background: var(--brand-strong); border-color: var(--brand-strong); }
.form-control,.form-select { border-color: var(--line); background-color: var(--card); border-radius: .75rem; padding: .72rem .9rem; }
.form-control:focus,.form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(91,92,226,.13); }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.1fr) minmax(400px, .9fr); background: var(--card); }
.login-visual { position: relative; overflow: hidden; display: flex; align-items: center; padding: 8vw; color: white; background: #11162a; }
.login-visual::after { content: ''; position: absolute; width: 460px; height: 460px; border-radius: 50%; right: -110px; top: -140px; background: rgba(91,92,226,.36); filter: blur(1px); }
.login-orbit { position: absolute; border: 1px solid rgba(255,255,255,.14); border-radius: 50%; }
.orbit-one { width: 54vw; height: 54vw; left: -18vw; bottom: -28vw; }
.orbit-two { width: 38vw; height: 38vw; left: -9vw; bottom: -20vw; }
.login-quote { position: relative; z-index: 2; max-width: 620px; }
.login-quote h1 { font-size: clamp(3.4rem, 6vw, 6.6rem); line-height: .96; margin: 1rem 0 2rem; }
.login-quote p { color: #b8bfd8; max-width: 470px; font-size: 1.15rem; }
.login-panel { display: grid; place-items: center; padding: 3rem; }
.login-form { width: min(100%, 430px); }
.login-form h2 { font-size: 2rem; }
.brand-mark { display: inline-block; font-size: 1.45rem; font-weight: 800; letter-spacing: -.08em; }
.brand-mark > span { color: #8d8eff; }
.overline,.topbar-kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .7rem; font-weight: 800; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; color: #dfe3f4; background: var(--sidebar); padding: 1.4rem 1rem; display: flex; flex-direction: column; }
.sidebar-brand { display: flex; align-items: center; gap: .85rem; text-decoration: none; padding: .5rem .7rem 2rem; }
.brand-copy { font-weight: 700; line-height: 1.15; }
.brand-copy small,.sidebar-foot small { display: block; font-weight: 400; color: #7e879f; font-size: .72rem; margin-top: .2rem; }
.main-nav { display: grid; gap: .3rem; }
.main-nav a { color: #aeb5ca; text-decoration: none; padding: .72rem .8rem; border-radius: .75rem; display: flex; align-items: center; gap: .85rem; font-weight: 600; font-size: .93rem; }
.main-nav a:hover { color: white; background: rgba(255,255,255,.06); }
.main-nav a.active { background: #252c4b; color: white; box-shadow: inset 3px 0 #8d8eff; }
.nav-icon { width: 1.35rem; text-align: center; font-size: 1.1rem; }
.sidebar-section-label { color: #5f6881; font-size: .65rem; letter-spacing: .14em; font-weight: 800; margin: 1.8rem .8rem .6rem; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #252b40; padding: 1rem .55rem .1rem; display: flex; align-items: center; gap: .7rem; font-size: .82rem; }
.profile-dot { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%; background: #5b5ce2; color: white; font-weight: 800; }
.icon-button { border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 40px; height: 40px; border-radius: .7rem; display: inline-grid; place-items: center; font-size: 1.12rem; }
.sidebar .icon-button { border-color: #303750; background: transparent; color: #aeb5ca; width: 34px; height: 34px; }

.workspace { margin-left: 260px; min-height: 100vh; }
.topbar { height: 108px; display: flex; align-items: center; justify-content: space-between; padding: 1.4rem clamp(1.5rem, 4vw, 4rem); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 12; }
.topbar-kicker { color: var(--muted); margin: 0 0 .2rem; }
.topbar h1 { font-size: 1.7rem; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: .7rem; }
.content { padding: 2rem clamp(1.2rem, 4vw, 4rem) 4rem; max-width: 1500px; margin: auto; }
.page-loading { min-height: 55vh; display: grid; place-items: center; }

.hero-card { background: var(--sidebar); color: white; border-radius: 1.35rem; padding: clamp(1.5rem, 4vw, 3.2rem); position: relative; overflow: hidden; min-height: 250px; box-shadow: var(--shadow); }
.hero-card::after { content: ''; position: absolute; width: 320px; height: 320px; right: -70px; top: -90px; border: 58px solid rgba(141,142,255,.16); border-radius: 50%; }
.hero-card > * { position: relative; z-index: 1; }
.hero-card h2 { font-size: clamp(2rem, 3.7vw, 3.7rem); max-width: 720px; margin: .6rem 0 1rem; }
.hero-card p { color: #adb5ce; max-width: 620px; }
.countdown { display: inline-flex; align-items: center; gap: .7rem; padding: .55rem .8rem; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.11); border-radius: 2rem; color: #dfe2f2; font-size: .85rem; }
.countdown strong { color: #a9aaff; }

.section-head { display: flex; align-items: end; justify-content: space-between; margin: 2.3rem 0 1rem; gap: 1rem; }
.section-head h2 { font-size: 1.35rem; margin: 0; }
.section-head p { color: var(--muted); margin: .25rem 0 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1rem; margin-top: 1rem; }
.metric-card,.surface { background: var(--card); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); }
.metric-card { padding: 1.2rem; }
.metric-card small { color: var(--muted); font-weight: 600; }
.metric-card strong { display: block; font-family: 'Manrope'; font-size: 1.8rem; margin-top: .3rem; }
.subject-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1rem; }
.subject-card { text-decoration: none; padding: 1.35rem; min-height: 235px; display: flex; flex-direction: column; transition: transform .18s ease, box-shadow .18s ease; }
.subject-card:hover { transform: translateY(-3px); box-shadow: 0 18px 46px rgba(23,32,59,.12); }
.subject-accent { width: 44px; height: 8px; border-radius: 4px; margin-bottom: 1.6rem; }
.subject-card h3 { font-size: 1.25rem; }
.subject-card p { color: var(--muted); font-size: .9rem; }
.card-meta { display: flex; gap: .8rem; color: var(--muted); font-size: .78rem; margin-top: auto; }
.progress { height: 7px; background: color-mix(in srgb, var(--line) 80%, transparent); }
.progress-bar { background: var(--brand); }

.unit-list { display: grid; gap: .9rem; }
.unit-card { padding: 1.25rem; display: grid; grid-template-columns: 54px minmax(0,1fr) auto; gap: 1.1rem; align-items: start; }
.unit-number { width: 54px; height: 54px; display: grid; place-items: center; border-radius: .85rem; background: rgba(91,92,226,.1); color: var(--brand); font-family: 'Manrope'; font-weight: 800; }
.unit-card h3 { font-size: 1.05rem; margin: .2rem 0 .4rem; }
.unit-card p { color: var(--muted); font-size: .88rem; margin: 0; }
.document-pills { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .8rem; }
.document-pill { display: inline-flex; gap: .35rem; align-items: center; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: .55rem; text-decoration: none; font-size: .76rem; font-weight: 700; color: var(--ink); }
.document-pill:hover { border-color: var(--brand); color: var(--brand); }
.unit-progress { min-width: 140px; }
.unit-progress label { font-size: .72rem; color: var(--muted); display: flex; justify-content: space-between; }
.form-range { accent-color: var(--brand); }

.quiz-setup { max-width: 820px; padding: clamp(1.25rem,4vw,2.5rem); }
.quiz-shell { max-width: 900px; margin: 0 auto; }
.quiz-progress { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; color: var(--muted); font-size: .86rem; }
.question-card { padding: clamp(1.2rem,4vw,2.4rem); }
.question-card h2 { font-size: clamp(1.25rem,3vw,1.8rem); line-height: 1.35; margin: .6rem 0 1.7rem; }
.option-list { display: grid; gap: .7rem; }
.option { display: grid; grid-template-columns: 38px 1fr; align-items: center; gap: .8rem; border: 1px solid var(--line); border-radius: .85rem; padding: .8rem; cursor: pointer; background: var(--card); transition: border .15s, background .15s; }
.option:hover { border-color: #b9baf5; }
.option.selected { border-color: var(--brand); background: rgba(91,92,226,.07); }
.option.correct { border-color: var(--success); background: rgba(19,138,106,.08); }
.option.wrong { border-color: var(--danger); background: rgba(197,80,80,.07); }
.option:disabled { cursor: default; color: var(--ink); opacity: 1; }
.option-key { width: 38px; height: 38px; border-radius: .65rem; display: grid; place-items: center; background: var(--paper); font-weight: 800; }
.quiz-actions { display: flex; justify-content: space-between; gap: .7rem; margin-top: 1.3rem; }
.explanation { margin-top: 1.2rem; padding: 1rem; border-left: 4px solid var(--brand); background: var(--paper); border-radius: .5rem; }
.explanation.feedback-correct { border-left-color: var(--success); background: rgba(19,138,106,.08); }
.explanation.feedback-wrong { border-left-color: var(--danger); background: rgba(197,80,80,.08); }
.explanation .correct-answer { margin-top: .55rem; }
.score-ring { width: 160px; height: 160px; border-radius: 50%; display: grid; place-items: center; margin: 1rem auto; background: conic-gradient(var(--brand) var(--score-angle), var(--line) 0); position: relative; }
.score-ring::after { content: ''; position: absolute; width: 124px; height: 124px; border-radius: 50%; background: var(--card); }
.score-ring strong { position: relative; z-index: 1; font-size: 2rem; }

.plan-filters { display: flex; flex-wrap: wrap; gap: .55rem; margin-bottom: 1.2rem; }
.filter-chip { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 2rem; padding: .45rem .8rem; font-size: .8rem; font-weight: 700; }
.filter-chip.active { color: white; background: var(--brand); border-color: var(--brand); }
.plan-year { margin-top: 2rem; }
.plan-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .8rem; }
.plan-item { padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.plan-item h4 { font-family: 'DM Sans'; font-size: .94rem; line-height: 1.35; margin: 0; letter-spacing: 0; }
.badge-status { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; border-radius: 2rem; padding: .35rem .55rem; }
.status-validated,.status-approved { color: #087256; background: #dff5ed; }
.status-enrolled { color: #4b4db7; background: #e8e8ff; }
.status-pending { color: #7a8195; background: #eceef3; }
[data-bs-theme="dark"] .status-validated,[data-bs-theme="dark"] .status-approved { color: #83dfc5; background: #183d36; }
[data-bs-theme="dark"] .status-enrolled { color: #b7b8ff; background: #292a59; }
[data-bs-theme="dark"] .status-pending { color: #b0b6c9; background: #292f42; }

.history-table { overflow-x: auto; }
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); --bs-table-border-color: var(--line); margin: 0; }
.admin-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 1rem; }
.admin-card { padding: 1.4rem; }
.admin-card h3 { font-size: 1.05rem; margin-bottom: 1rem; }
.empty-state { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.app-toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; background: var(--sidebar); color: white; border-radius: .75rem; padding: .85rem 1rem; box-shadow: var(--shadow); transform: translateY(130%); transition: transform .2s; max-width: 360px; }
.app-toast.show { transform: translateY(0); }
.mobile-nav { display: none; }

@media (max-width: 1050px) {
    .metric-grid { grid-template-columns: repeat(2,1fr); }
    .subject-grid { grid-template-columns: repeat(2,1fr); }
    .plan-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 760px) {
    .login-screen { grid-template-columns: 1fr; }
    .login-visual { display: none; }
    .login-panel { min-height: 100vh; padding: 1.4rem; }
    .sidebar { display: none; }
    .workspace { margin-left: 0; padding-bottom: 78px; }
    .topbar { height: 86px; padding: 1rem 1.2rem; }
    .topbar h1 { font-size: 1.35rem; }
    .content { padding: 1.2rem 1rem 2rem; }
    .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(5,1fr); inset: auto 0 0; height: calc(66px + env(safe-area-inset-bottom)); padding: .35rem .25rem env(safe-area-inset-bottom); background: color-mix(in srgb, var(--card) 95%, transparent); backdrop-filter: blur(18px); border-top: 1px solid var(--line); z-index: 50; }
    .mobile-nav a { text-decoration: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; font-size: .64rem; font-weight: 700; }
    .mobile-nav a span { font-size: 1.15rem; }
    .mobile-nav a.active { color: var(--brand); }
    .hero-card { min-height: 300px; }
    .metric-grid,.subject-grid,.plan-grid,.admin-grid { grid-template-columns: 1fr; }
    .subject-card { min-height: 210px; }
    .unit-card { grid-template-columns: 44px minmax(0,1fr); }
    .unit-number { width: 44px; height: 44px; }
    .unit-progress { grid-column: 1 / -1; min-width: 0; }
    .section-head { align-items: start; }
    .quiz-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
