:root {
  --ink: #13233a; --muted: #5d6b7e; --brand: #176b87; --brand2: #0d526b;
  --paper: #fff; --bg: #f2f6f8; --line: #ced9e0; --ok: #16734b;
  --warn: #8a5a00; --bad: #a12b35; --radius: 14px; --sidebar: 280px;
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, Segoe UI, sans-serif; }
body.nav-open { overflow: hidden; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: clamp(2rem, 6vw, 3.4rem); margin: .4rem 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; color: var(--brand); font-weight: 700; font-size: .8rem; }
.app-content { min-height: 100vh; margin-left: var(--sidebar); }
main { width: min(100% - 2rem, 1120px); margin: 0 auto; padding: 2.5rem 0; }
.app-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar); overflow-y: auto; background: var(--ink); color: #fff; padding: 1.2rem 1rem 2rem; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .35rem .5rem 1.2rem; }
.sidebar-brand { font-size: 1.3rem; font-weight: 800; letter-spacing: .02em; text-decoration: none; }
.sidebar-close, .menu-toggle { display: none; }
.nav-section { margin: 1.5rem .7rem .5rem; color: #9eb5c5; font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.nav-link, .nav-group summary, .nav-placeholder { display: block; width: 100%; border-radius: 8px; padding: .62rem .7rem; text-decoration: none; }
.nav-link:hover, .nav-group summary:hover { background: #ffffff12; }
.nav-link.active { background: #fff; color: var(--ink); font-weight: 800; box-shadow: inset 4px 0 var(--brand); }
.nav-link.active::before { content: "›"; margin-right: .45rem; }
.nav-group { margin: .1rem 0; }
.nav-group summary { cursor: pointer; font-weight: 750; list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after { content: "+"; float: right; font-weight: 400; }
.nav-group[open] summary::after { content: "−"; }
.nav-module { margin-bottom: .2rem; }
.nav-module-content { padding-left: .45rem; }
.nav-module-content .nav-group summary, .nav-module-content > .nav-sublink { padding-left: 1rem; }
.nav-sublink { padding-left: 1.25rem; font-size: .92rem; }
.nav-placeholder { padding-left: 1.25rem; color: #9eb5c5; font-size: .9rem; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1.15rem, 3vw, 2rem); box-shadow: 0 8px 30px #13233a0c; }
.dashboard-hero, .page-heading { margin-bottom: 2rem; }
.dashboard-hero { max-width: 780px; }
.category-grid, .exam-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.category-card { min-height: 190px; display: flex; flex-direction: column; justify-content: space-between; text-decoration: none; transition: transform .16s ease, box-shadow .16s ease; }
a.category-card:hover { transform: translateY(-2px); box-shadow: 0 12px 34px #13233a18; }
.category-card h2, .exam-card h2 { margin: .25rem 0; }
.card-link { color: var(--brand); font-weight: 800; }
.preparing { border-style: dashed; box-shadow: none; }
.exam-card { display: grid; gap: 1.25rem; align-content: space-between; }
.meta { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1rem; }
.pill { background: #e7f3f7; padding: .3rem .7rem; border-radius: 999px; }
.button, button { appearance: none; border: 0; border-radius: 9px; background: var(--brand); color: #fff; padding: .75rem 1.1rem; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; display: inline-block; }
.button:hover, button:hover { background: var(--brand2); }
button.secondary, .button.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
button.warn { background: #8a3e16; }
button:disabled { opacity: .55; cursor: not-allowed; }
.history-list { display: grid; gap: .8rem; }
.history-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 1rem; text-decoration: none; }
.history-card h2 { margin: 0; font-size: 1.08rem; }
.history-card p { margin: .25rem 0 0; }
.history-score { text-align: right; display: grid; }
.history-score strong { color: var(--brand); font-size: 1.55rem; }
.history-score small { font-size: .55em; color: var(--muted); }
.history-score span { color: var(--muted); font-size: .85rem; }
.exam-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.timer { font-variant-numeric: tabular-nums; font-size: 1.25rem; font-weight: 800; }
.timer[aria-label*="restantes: 0"] { color: var(--bad); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 1.25rem; }
.question-text, .option-text, .explanation p, .passage-text { font-size: 1.25rem; font-weight: 650; white-space: pre-line; overflow-wrap: anywhere; }
.option-text, .explanation p { font-size: inherit; font-weight: inherit; }
.question-passage { margin-bottom: 1.75rem; padding: 1.25rem; border: 1px solid var(--line); border-radius: 10px; background: #f8fbfc; }
.question-passage h2 { margin: .25rem 0 1rem; }
.passage-text { font-size: 1rem; font-weight: 400; }
.question-image { display: block; width: auto; max-width: 100%; height: auto; max-height: none; object-fit: contain; margin: 1rem auto; border-radius: 8px; }
.options { border: 0; padding: 0; margin: 1.4rem 0; display: grid; gap: .75rem; }
.option { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: .6rem; align-items: start; padding: .8rem 1rem; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; text-align: left; min-width: 0; }
.option input { width: auto; margin: .28rem 0 0; }
.option-letter { font-weight: 800; white-space: nowrap; }
.option-text { min-width: 0; width: 100%; text-align: left; }
.option:has(input:checked) { border-color: var(--brand); background: #eff8fb; }
.admission-config { grid-column: 1 / -1; max-width: 680px; }
.count-selector { border: 0; padding: 0; margin: 0; }
.count-selector legend { margin-bottom: .55rem; font-weight: 800; }
.count-selector { display: flex; gap: .65rem; flex-wrap: wrap; }
.count-selector label { cursor: pointer; }
.count-selector input { position: absolute; opacity: 0; pointer-events: none; }
.count-selector span { display: block; min-width: 4.25rem; padding: .65rem 1rem; border: 2px solid var(--line); border-radius: 9px; text-align: center; font-weight: 800; }
.count-selector input:checked + span { border-color: var(--brand); background: #eff8fb; color: var(--brand2); }
.count-selector input:focus-visible + span { outline: 3px solid #176b8755; outline-offset: 2px; }
.admission-config-summary { margin: 0; color: var(--brand2); font-weight: 800; }
.actions { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.question-review-action { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: 1rem 0; padding-top: 1rem; border-top: 1px solid var(--line); }
.question-review-action small { color: var(--muted); }
.review-flag-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; align-items: end; gap: .75rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.review-flag-controls label { display: grid; gap: .3rem; font-weight: 700; }
.review-required-indicator { display: block; color: var(--warn); font-weight: 800; margin: 0; }
.review-flag-controls .review-required-indicator { grid-column: 1 / -1; }
.review-reason { display: block; margin-top: .25rem; color: var(--muted); }
.review-required-banner { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: 1rem; border: 1px solid var(--warn); border-radius: 10px; background: #fff7df; }
.review-required-banner span { flex: 1; }
.review-checkbox { display: flex !important; grid-template-columns: auto 1fr; align-items: center; justify-content: start; }
.review-checkbox input { width: auto; }
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.nav-question { padding: .5rem .2rem; background: #fff; color: var(--ink); border: 2px solid var(--line); position: relative; }
.nav-question.answered { border-color: var(--ok); }
.nav-question.answered::after { content: "✓"; font-size: .7rem; margin-left: .15rem; }
.nav-question.marked { outline: 2px dashed var(--warn); outline-offset: 2px; }
.nav-question.marked::before { content: "⚑"; font-size: .7rem; }
.nav-question.current { background: var(--ink); color: #fff; border-color: var(--ink); }
.legend { font-size: .82rem; color: var(--muted); margin-top: 1rem; }
.side-actions { margin-top: 1.5rem; }
.score { font-size: clamp(3rem, 10vw, 5.5rem); font-weight: 800; color: var(--brand); line-height: 1; }
.stats, .domains { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin: 2rem 0; }
.stat, .domain { border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.domains { grid-template-columns: repeat(2, 1fr); }
.domain { display: flex; justify-content: space-between; }
.domain span { display: grid; gap: .25rem; }
.domain small { color: var(--muted); font-weight: 500; }
.review-item { margin: 1rem 0; }
.review-item.correct { border-left: 5px solid var(--ok); }
.review-item.incorrect { border-left: 5px solid var(--bad); }
.review-item.unanswered { border-left: 5px solid var(--warn); }
.answer-line { padding: .55rem; border-radius: 6px; }
.answer-line.selected { background: #fff2e4; }
.answer-line.correct-answer { background: #e6f5ed; }
.error { color: var(--bad); background: #fff0f1; padding: .8rem; border-radius: 8px; }
.success { color: var(--ok); background: #e6f5ed; padding: .8rem; border-radius: 8px; }
.admin-heading, .preview-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.filter-grid, .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.filter-grid { grid-template-columns: repeat(6, minmax(120px, 1fr)); align-items: end; }
.filter-grid label, .editor-form label { display: grid; gap: .35rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: .7rem; background: #fff; color: var(--ink); font: inherit; }
textarea { resize: vertical; }
.editor-form { display: grid; gap: 1.25rem; }
.answer-editor { border: 1px solid var(--line); border-radius: 10px; padding: 1rem; }
.answer-row { grid-template-columns: auto auto 1fr !important; align-items: center; margin: .65rem 0; }
.answer-row input[type="radio"], .answer-row input[type="checkbox"] { width: auto; }
.question-table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.question-table { width: 100%; border-collapse: collapse; min-width: 980px; }
.question-table th, .question-table td { padding: .8rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.table-actions button { padding: .45rem .6rem; font-size: .85rem; }
.status-badge { display: inline-block; padding: .25rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 800; background: #e7edf1; }
.status-badge.published { background: #e6f5ed; color: var(--ok); }
.status-badge.review { background: #fff2d6; color: var(--warn); }
.preview-dialog { width: min(760px, calc(100% - 2rem)); max-width: 760px; }
.preview-dialog .card { box-shadow: none; }
.empty-state { text-align: center; }
dialog { border: 0; border-radius: 14px; padding: 1.5rem; max-width: 430px; box-shadow: 0 15px 50px #0005; }
dialog::backdrop { background: #102033aa; }
.exam-mode .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; }
.exam-mode .app-content { margin-left: 0; }
.exam-mode .menu-toggle { display: block; position: fixed; z-index: 35; top: .75rem; left: .75rem; }
.exam-mode main { padding-top: 4.5rem; }
.exam-mode.nav-open .app-sidebar { transform: translateX(0); }
.exam-mode .nav-overlay { display: none; }
.exam-mode.nav-open .nav-overlay { display: block; position: fixed; inset: 0; z-index: 30; background: #10203388; }

@media (max-width: 820px) {
  .app-content { margin-left: 0; }
  main { padding-top: 4.8rem; }
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 8px 0 30px #0003; }
  .menu-toggle { display: block; position: fixed; z-index: 35; top: .75rem; left: .75rem; }
  .sidebar-close { display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; padding: 0; background: transparent; font-size: 1.8rem; }
  .nav-overlay { display: none; }
  body.nav-open .app-sidebar { transform: translateX(0); }
  body.nav-open .nav-overlay { display: block; position: fixed; inset: 0; z-index: 30; background: #10203388; }
  .layout { grid-template-columns: 1fr; }
  .exam-head { align-items: flex-start; }
  .stats, .domains { grid-template-columns: 1fr; }
  .palette { grid-template-columns: repeat(10, 1fr); }
  .exam-navigation { order: -1; }
  .actions button { flex: 1; }
  .actions .warn { flex-basis: 100%; }
  .question-review-action { align-items: stretch; flex-direction: column; }
  .review-flag-controls { grid-template-columns: 1fr; }
  .review-flag-controls .review-required-indicator { grid-column: 1; }
  .filter-grid, .form-grid { grid-template-columns: 1fr; }
  .admin-heading { align-items: flex-start; }
}
@media (max-width: 640px) {
  .category-grid, .exam-grid { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 1fr; }
  .history-score { text-align: left; }
}
@media (max-width: 460px) {
  .app-sidebar { width: min(88vw, 320px); }
  .palette { grid-template-columns: repeat(5, 1fr); }
  .option { gap: .45rem; padding: .7rem; }
  .count-selector label { flex: 1; }
  .count-selector span { min-width: 0; padding-inline: .6rem; }
}
