/* ===================================================================
   EPCAR Estuda — sistema de estudo para o Exame de Admissão ao CPCAR
   =================================================================== */

:root {
  --navy-900: #0a1730;
  --navy-800: #0f2148;
  --navy-700: #15305f;
  --navy-600: #1c3f7a;
  --sky-500: #3b8ed4;
  --sky-400: #5aa8e8;
  --sky-100: #e6f2fc;
  --gold-500: #d4af37;
  --gold-600: #b6932a;
  --green-500: #1f9d55;
  --green-100: #e4f8ec;
  --red-500: #d9483a;
  --red-100: #fdeceb;
  --ink-900: #16202e;
  --ink-600: #4a5568;
  --ink-400: #8a94a3;
  --paper: #f7f9fc;
  --card: #ffffff;
  --border: #e1e7f0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 33, 72, 0.08);
  --shadow-lg: 0 8px 30px rgba(15, 33, 72, 0.14);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink-900);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: var(--sky-500); }

/* ---------- Layout shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-900), var(--navy-700));
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand .badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--sky-500), var(--navy-600));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  border: 1px solid rgba(212,175,55,0.6);
}

.brand h1 {
  font-size: 16px;
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.brand span {
  display: block;
  font-size: 11px;
  color: var(--gold-500);
  font-weight: 600;
  letter-spacing: 0.8px;
}

nav.main-nav {
  flex: 1;
  padding: 14px 10px;
  overflow-y: auto;
}

nav.main-nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 4px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.82);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

nav.main-nav button .ic { font-size: 17px; width: 22px; text-align: center; }

nav.main-nav button:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

nav.main-nav button.active {
  background: var(--sky-500);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59,142,212,0.4);
}

.sidebar-footer {
  padding: 14px 18px 18px;
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  border-top: 1px solid rgba(255,255,255,0.1);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.topbar {
  display: none;
}

/* ---------- mobile ---------- */

.menu-toggle {
  display: none;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 250px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--navy-900);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .topbar h1 { font-size: 15px; margin: 0; flex: 1; }
  .menu-toggle {
    display: flex;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    width: 36px; height: 36px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    font-size: 18px;
  }
  .main { padding: 18px 16px 50px; }
  .overlay {
    position: fixed; inset: 0;
    background: rgba(10,23,48,0.45);
    z-index: 35;
  }
  .overlay[hidden] { display: none; }
}

/* ---------- generic pieces ---------- */

.view[hidden] { display: none !important; }

.page-head {
  margin-bottom: 22px;
}

.page-head h2 {
  margin: 0 0 4px;
  font-size: 24px;
  color: var(--navy-900);
}

.page-head p {
  margin: 0;
  color: var(--ink-600);
  font-size: 14.5px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-card .label {
  font-size: 12.5px;
  color: var(--ink-600);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 800;
  color: var(--navy-900);
}
.stat-card .sub { font-size: 12.5px; color: var(--ink-400); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  border: none;
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 600;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--sky-500); color: #fff; box-shadow: 0 4px 14px rgba(59,142,212,0.35); }
.btn-primary:hover { background: #3480c2; }
.btn-gold { background: var(--gold-500); color: var(--navy-900); }
.btn-gold:hover { background: var(--gold-600); }
.btn-ghost { background: var(--sky-100); color: var(--navy-700); }
.btn-ghost:hover { background: #d7ebfb; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--ink-900); }
.btn-outline:hover { border-color: var(--sky-500); color: var(--sky-500); }
.btn-danger { background: var(--red-500); color: #fff; box-shadow: 0 4px 14px rgba(217,72,58,0.35); }
.btn-danger:hover { background: #c23f32; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.pill-facil { background: var(--green-100); color: var(--green-500); }
.pill-medio { background: #fff4dd; color: var(--gold-600); }
.pill-dificil { background: var(--red-100); color: var(--red-500); }
.pill-neutral { background: var(--sky-100); color: var(--navy-700); }
.pill-oficial { background: #fff4dd; color: var(--gold-600); border: 1px solid var(--gold-500); }
.pill-revisao { background: var(--red-100); color: var(--red-500); border: 1px solid var(--red-500); }

.nav-badge {
  margin-left: auto;
  background: var(--red-500);
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  min-width: 16px;
  text-align: center;
}

/* ---------- Dashboard ---------- */

.subject-card {
  border-radius: var(--radius);
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s;
}
.subject-card:hover { transform: translateY(-3px); }
.subject-card.mat { background: linear-gradient(135deg, #123a7a, #2f6fc4); }
.subject-card.por { background: linear-gradient(135deg, #7a2b3d, #c4507a); }
.subject-card.ing { background: linear-gradient(135deg, #1e6b4f, #3fae86); }
.subject-card .icon { font-size: 26px; opacity: 0.9; }
.subject-card h3 { margin: 10px 0 2px; font-size: 18px; }
.subject-card .meta { font-size: 12.5px; opacity: 0.85; }
.subject-card .bar-bg {
  margin-top: 12px;
  height: 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.25);
  overflow: hidden;
}
.subject-card .bar-fill { height: 100%; background: var(--gold-500); }

.quick-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

/* ---------- Study / filters ---------- */

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.filters select, .filters input[type=number] {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  font-size: 14px;
  background: #fff;
  color: var(--ink-900);
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.topic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.topic-row .name { font-weight: 600; font-size: 14.5px; }
.topic-row .stats { font-size: 12.5px; color: var(--ink-400); }
.mini-bar { width: 90px; height: 6px; border-radius: 4px; background: var(--border); overflow: hidden; margin-top: 4px; }
.mini-bar > div { height: 100%; background: var(--sky-500); }

/* ---------- Quiz ---------- */

.quiz-wrap { max-width: 760px; margin: 0 auto; }

.quiz-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-600);
}
.quiz-progress .bar {
  flex: 1;
  height: 8px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
}
.quiz-progress .bar > div { height: 100%; background: var(--sky-500); transition: width 0.2s; }
.quiz-timer {
  font-weight: 700;
  color: var(--navy-900);
  background: var(--sky-100);
  padding: 4px 10px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.quiz-timer.low { background: var(--red-100); color: var(--red-500); }

.question-card .qtop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.question-card .statement {
  font-size: 16.5px;
  line-height: 1.6;
  white-space: pre-line;
  margin-bottom: 18px;
  color: var(--ink-900);
}
.question-image {
  margin: 4px 0 18px;
  text-align: center;
}
.question-image img {
  max-width: 100%;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.alt-list { display: flex; flex-direction: column; gap: 10px; }
.alt-btn {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  padding: 13px 14px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: #fff;
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink-900);
}
.alt-btn .letter {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--sky-100);
  color: var(--navy-700);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.alt-btn:hover:not(.disabled) { border-color: var(--sky-400); background: var(--sky-100); }
.alt-btn.selected { border-color: var(--sky-500); background: var(--sky-100); }
.alt-btn.correct { border-color: var(--green-500); background: var(--green-100); }
.alt-btn.correct .letter { background: var(--green-500); color: #fff; }
.alt-btn.wrong { border-color: var(--red-500); background: var(--red-100); }
.alt-btn.wrong .letter { background: var(--red-500); color: #fff; }
.alt-btn.disabled { cursor: default; }

.explanation-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--sky-100);
  border-left: 4px solid var(--sky-500);
  font-size: 14px;
  line-height: 1.55;
  color: var(--navy-800);
}

.quiz-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Results ---------- */

.result-hero {
  text-align: center;
  padding: 30px 20px;
}
.result-hero .score-circle {
  width: 130px; height: 130px;
  border-radius: 50%;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  background: conic-gradient(var(--sky-500) calc(var(--pct, 0) * 1%), var(--border) 0);
  position: relative;
}
.result-hero .score-circle::before {
  content: "";
  position: absolute;
  inset: 10px;
  background: #fff;
  border-radius: 50%;
}
.result-hero .score-circle .num {
  position: relative;
  font-size: 26px;
  font-weight: 800;
  color: var(--navy-900);
}
.result-hero .score-circle .lbl {
  position: relative;
  font-size: 11px;
  color: var(--ink-400);
}

.review-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
}
.review-item .rtop { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 13px; }
.review-item .rtop b { font-size: 14px; }
.review-item p { margin: 4px 0; font-size: 13.5px; }
.tag-ok { color: var(--green-500); font-weight: 700; }
.tag-bad { color: var(--red-500); font-weight: 700; }

/* ---------- Flashcards ---------- */

.flash-tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.flash-tabs button {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-600);
}
.flash-tabs button.active { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

.flash-stage { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.flashcard {
  width: 100%;
  max-width: 480px;
  height: 260px;
  perspective: 1200px;
}
.flashcard .inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
  cursor: pointer;
}
.flashcard.flipped .inner { transform: rotateY(180deg); }
.flashcard .face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  padding: 26px;
  font-size: 17px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
}
.flashcard .front { background: linear-gradient(135deg, var(--navy-800), var(--navy-600)); color: #fff; font-weight: 600; }
.flashcard .back { background: #fff; color: var(--navy-900); border: 1.5px solid var(--sky-400); transform: rotateY(180deg); white-space: pre-line; }
.flash-hint { font-size: 12.5px; color: var(--ink-400); }
.flash-nav { display: flex; gap: 12px; align-items: center; }
.flash-counter { font-size: 13px; color: var(--ink-600); font-weight: 600; }

/* ---------- Redação ---------- */

.tema-card { margin-bottom: 14px; }
.tema-card h4 { margin: 0 0 6px; color: var(--navy-900); font-size: 16px; }
.tema-card .motivador { font-size: 13.5px; color: var(--ink-600); white-space: pre-line; margin-bottom: 8px; }
.tema-card .proposta { font-size: 14px; font-weight: 600; color: var(--navy-800); }
.checklist-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.checklist-item input { margin-top: 3px; }
.crit-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.crit-item .n { width: 26px; height: 26px; border-radius: 50%; background: var(--sky-500); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; flex-shrink: 0; }
.crit-item b { font-size: 14px; }
.crit-item p { margin: 2px 0 0; font-size: 13px; color: var(--ink-600); }

/* ---------- Conteúdo programático ---------- */

.content-block { margin-bottom: 22px; }
.content-block h3 { color: var(--navy-900); border-left: 4px solid var(--sky-500); padding-left: 10px; margin-bottom: 10px; }
.content-block ul { margin: 6px 0; padding-left: 22px; line-height: 1.7; font-size: 14.5px; }
.content-block .materials { background: var(--sky-100); border-radius: 10px; padding: 12px 16px; font-size: 13.5px; margin-top: 8px; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; padding: 12px 0 12px 40px; position: relative; border-bottom: 1px solid var(--border); font-size: 14.5px; line-height: 1.5; }
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--gold-500); color: var(--navy-900);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
}
.steps li b { display: block; color: var(--navy-900); margin-bottom: 2px; }

/* ---------- Syllabus (conteúdo programático oficial) ---------- */

details.syllabus {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
details.syllabus > summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 20px;
  font-size: 16.5px;
  font-weight: 700;
  color: var(--navy-900);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
details.syllabus > summary::-webkit-details-marker { display: none; }
details.syllabus > summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--ink-400);
  transition: transform 0.15s;
}
details.syllabus[open] > summary::after { transform: rotate(180deg); }
details.syllabus > summary:hover { background: var(--sky-100); }

.syllabus-body {
  padding: 4px 20px 18px;
  border-top: 1px solid var(--border);
}
.syl-sub { margin-top: 14px; }
.syl-sub h4 {
  margin: 0 0 6px;
  font-size: 14.5px;
  color: var(--sky-500);
  font-weight: 700;
}
.syl-sub ul {
  margin: 0;
  padding-left: 20px;
  font-size: 13.8px;
  line-height: 1.7;
  color: var(--ink-900);
}
.syl-sub ul li { margin-bottom: 3px; }

.biblio-list {
  margin: 0;
  padding-left: 20px;
  font-size: 12.8px;
  line-height: 1.7;
  color: var(--ink-600);
}
.biblio-list li { margin-bottom: 6px; }

/* ---------- Aulas de Matemática (trilha) ---------- */

.level-card.locked {
  opacity: 0.6;
  background: var(--paper);
}
.level-card.locked h3 { color: var(--ink-400); }

.lesson-row { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.lesson-row:hover { border-color: var(--sky-400); background: var(--sky-100); }

.example-block {
  padding: 14px 16px;
  border-left: 4px solid var(--gold-500);
  background: #fffaf0;
  border-radius: 0 10px 10px 0;
  margin-bottom: 12px;
}
.example-block:last-child { margin-bottom: 0; }
.example-problem { font-weight: 700; color: var(--navy-900); margin-bottom: 6px; font-size: 14.5px; }
.example-solution { font-size: 14px; color: var(--ink-900); white-space: pre-line; line-height: 1.6; }

/* ---------- Progress ---------- */

.bar-chart { display: flex; flex-direction: column; gap: 12px; }
.bar-chart .row { display: flex; align-items: center; gap: 10px; }
.bar-chart .row .name { width: 150px; font-size: 13px; color: var(--ink-600); flex-shrink: 0; }
.bar-chart .row .track { flex: 1; height: 14px; border-radius: 7px; background: var(--border); overflow: hidden; }
.bar-chart .row .track > div { height: 100%; border-radius: 7px; }
.bar-chart .row .pct { width: 44px; text-align: right; font-size: 12.5px; font-weight: 700; color: var(--ink-900); flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-400);
}
.empty-state .ic { font-size: 40px; margin-bottom: 10px; }

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy-900);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
