:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --line: #e2dfd8;
  --text: #1d1c1a;
  --muted: #6b6860;
  --accent: #2f5bd3;

  --trt: #1f6f8b;
  --trt-soft: #e0f0f5;
  --sead: #b4541e;
  --sead-soft: #fbeadf;
  --both: #6a3fb5;
  --both-soft: #eee6fa;

  --good: #2e7d4f;
  --warn: #a66b00;
  --bad: #b3261e;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412;
    --surface: #1d1c1a;
    --surface-2: #262522;
    --line: #34322e;
    --text: #ecebe7;
    --muted: #a19d94;
    --accent: #7c9cff;
    --trt: #5fb6d3;
    --trt-soft: #15313b;
    --sead: #f0915b;
    --sead-soft: #3a2316;
    --both: #b493f0;
    --both-soft: #2b2140;
    --good: #5cc488;
    --warn: #e0a640;
    --bad: #ef7a72;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1c1a; --surface-2: #262522; --line: #34322e;
  --text: #ecebe7; --muted: #a19d94; --accent: #7c9cff;
  --trt: #5fb6d3; --trt-soft: #15313b; --sead: #f0915b; --sead-soft: #3a2316;
  --both: #b493f0; --both-soft: #2b2140;
  --good: #5cc488; --warn: #e0a640; --bad: #ef7a72; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 16px 64px; }

/* Header */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.eyebrow { margin: 0 0 4px; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.sub { margin: 4px 0 0; color: var(--muted); }
.legend { display: flex; gap: 6px; }
.top-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync.ok::before { background: var(--good); }
.sync.busy::before { background: var(--warn); }
.sync.off { color: var(--bad); cursor: pointer; }
.sync.off::before { background: var(--bad); }
@media (max-width: 760px) { .top-side { align-items: flex-start; } }

.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tag-t { color: var(--trt); background: var(--trt-soft); }
.tag-s { color: var(--sead); background: var(--sead-soft); }
.tag-ts { color: var(--both); background: var(--both-soft); }

/* Exam cards */
.exams { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 14px; }
.exam { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 4px solid var(--c); }
.exam.t { --c: var(--trt); }
.exam.s { --c: var(--sead); }
.exam-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.exam h2 { margin: 0; font-size: 18px; }
.exam .cargo { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.count { text-align: right; flex-shrink: 0; }
.count b { display: block; font-size: 28px; line-height: 1; color: var(--c); font-variant-numeric: tabular-nums; }
.count span { font-size: 12px; color: var(--muted); }
.exam ul { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.exam li { margin: 2px 0; }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 500; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 99px; transition: width .25s; }

/* Toolbar */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 0; margin-bottom: 8px;
  background: var(--bg);
}
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.excl { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toolbar select, .toolbar input[type=search] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13.5px;
}
.toolbar input[type=search] { flex: 1; min-width: 160px; }
button, .btn { cursor: pointer; }
.ghost, .foot button, .btn {
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; font-weight: 500;
}
.ghost:hover, .foot button:hover, .btn:hover { background: var(--surface-2); }
.danger { color: var(--bad); }

/* Disciplines */
.disc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden; }
.disc > summary { list-style: none; cursor: pointer; padding: 14px 18px; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center; }
.disc > summary::-webkit-details-marker { display: none; }
.disc-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; }
.disc-title::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s; }
.disc[open] .disc-title::before { transform: rotate(90deg); }
.disc-meta { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1; font-size: 12px; color: var(--muted); }
.disc-meta .peso { padding: 1px 0; }
.disc-prog { grid-row: 1 / span 2; grid-column: 2; text-align: right; min-width: 120px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.disc-prog b { color: var(--text); }

/* Topic table */
.rows { border-top: 1px solid var(--line); }
.row-head, .row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 82px 52px 120px 64px 64px 52px 34px;
  align-items: center; gap: 6px; padding: 7px 18px;
}
.row-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); font-weight: 600; }
.row-head .c, .row .c { text-align: center; }
.row { border-top: 1px solid var(--line); }
.row-sub { padding: 10px 18px 6px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--muted); background: var(--surface-2); }
.row:first-of-type { border-top: 0; }
.row.done .txt { color: var(--muted); }
.num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.txt { font-size: 14px; }
.revs { display: flex; gap: 4px; justify-content: center; }

/* "onde parei": sempre visível embaixo do tópico; discreto vazio, destacado quando preenchido */
.where { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.wp {
  flex: 1; min-width: 0; max-width: 460px;
  padding: 3px 8px; border: 1px solid transparent; border-radius: 7px;
  background: transparent; font-size: 13px; color: var(--text);
}
.wp::placeholder { color: var(--muted); opacity: .55; }
.row:hover .wp::placeholder, .wp:focus::placeholder { opacity: .9; }
.wp:hover { border-color: var(--line); }
.wp:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }
.where.filled .wp { background: var(--both-soft); border-color: transparent; }
.where.filled .wp:focus { border-color: var(--accent); }
.wp-when { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.chk { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; border: 1.5px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; display: inline-grid; place-content: center; margin: 0; }
.chk::after { content: ""; width: 10px; height: 6px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.chk:checked { background: var(--good); border-color: var(--good); }
.chk:checked::after { opacity: 1; }
.chk.rev { width: 30px; border-radius: 6px; font-size: 10.5px; font-weight: 600; color: var(--muted); }
.chk.rev::before { content: attr(data-l); }
.chk.rev::after { display: none; }
.chk.rev:checked { background: var(--accent); border-color: var(--accent); }
.chk.rev:checked::before { color: #fff; }
.chk:focus-visible, .nbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.n { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); text-align: center; font-variant-numeric: tabular-nums; font-size: 13.5px; }
.n { -moz-appearance: textfield; }
.n::-webkit-inner-spin-button, .n::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pct { text-align: center; font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.pct.good { color: var(--good); } .pct.warn { color: var(--warn); } .pct.bad { color: var(--bad); }
.nbtn { border: 0; background: none; padding: 4px; border-radius: 6px; color: var(--muted); font-size: 15px; line-height: 1; }
.nbtn:hover { background: var(--surface-2); }
.nbtn.has { color: var(--accent); }
.note { grid-column: 2 / -1; display: none; }
.note.open { display: block; }
.note textarea { width: 100%; min-height: 60px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font: inherit; font-size: 13.5px; color: inherit; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Footer */
.foot { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; color: var(--muted); font-size: 13px; }
.foot p { margin: 0; max-width: 520px; }
.foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Mobile: rows become cards */
/* grupos da linha: no computador não existem para o grid (cada item vira uma coluna da tabela) */
.ctrl, .nums { display: contents; }
.teo-l { display: none; }
.exam-more > summary { display: none; }
@media (min-width: 761px) { .n::placeholder { color: transparent; } }

/* Celular */
@media (max-width: 760px) {
  .wrap { padding-top: 18px; }
  h1 { font-size: 24px; }
  .top { margin-bottom: 14px; }
  .toolbar { position: static; }

  /* provas: só nome e contagem; detalhes ficam num "Detalhes da prova" recolhível */
  .exams { gap: 10px; margin-bottom: 10px; }
  .exam { padding: 12px 14px; }
  .exam .cargo { font-size: 12px; }
  .count b { font-size: 24px; }
  .exam-more > summary { display: list-item; margin-top: 8px; font-size: 13px; color: var(--accent); cursor: pointer; }
  .exam-more ul { margin-top: 8px; }

  /* resumo em 3 colunas compactas */
  .summary { grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
  .stat { padding: 9px 10px; }
  .stat .k { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat .v { font-size: 17px; }
  .stat .v small { display: block; font-size: 11px; }
  .bar { margin-top: 6px; height: 5px; }

  .seg { width: 100%; }
  .seg button { flex: 1; padding: 8px 4px; }
  .toolbar select { flex: 1; }
  .toolbar select, .toolbar input[type=search], .ghost { padding: 9px 10px; }

  .disc > summary { padding: 12px 14px; }
  .disc-prog { min-width: 0; }
  .row-head { display: none; }

  /* tópico em 3 linhas: texto+acompanhamento / concurso, teoria, revisões / questões, acertos, %, notas */
  .row { display: flex; flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 14px; }
  .row .num { display: none; }
  .ctrl, .nums { display: flex; align-items: center; gap: 8px; }
  .ctrl .revs { margin-left: auto; gap: 6px; }
  .teo { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
  .teo-l { display: inline; font-size: 13px; color: var(--muted); }
  .chk { width: 28px; height: 28px; border-radius: 7px; }
  .chk::after { width: 12px; height: 7px; }
  .chk.rev { width: 40px; height: 32px; font-size: 12px; }
  .nums .qcol, .nums .acol { flex: 1; min-width: 0; }
  .n { height: 36px; font-size: 15px; }
  .n::placeholder { font-size: 13px; color: var(--muted); opacity: .8; }
  /* com valor preenchido, o nome do campo vira uma legenda pequena dentro dele */
  .nums .qcol, .nums .acol { position: relative; }
  .nums .qcol::before, .nums .acol::before { position: absolute; top: 3px; left: 0; right: 0; text-align: center; font-size: 9.5px; line-height: 1; color: var(--muted); pointer-events: none; opacity: 0; }
  .nums .qcol::before { content: "Questões"; }
  .nums .acol::before { content: "Acertos"; }
  .nums .qcol:has(.n:not(:placeholder-shown))::before, .nums .acol:has(.n:not(:placeholder-shown))::before { opacity: 1; }
  .nums .n:not(:placeholder-shown) { padding-top: 12px; }
  .pct { min-width: 44px; }
  .nbtn { width: 36px; height: 36px; font-size: 17px; }
  .wp { max-width: none; padding: 6px 8px; font-size: 14px; }
  .note { width: 100%; }
}

/* Login */
body.locked .wrap { filter: blur(6px); pointer-events: none; user-select: none; }
.login { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--bg) 70%, transparent); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: 0 8px 30px rgba(0,0,0,.12); display: grid; gap: 12px; }
.login-card h2 { margin: 0 0 4px; font-size: 22px; }
.login-card .eyebrow { margin: 0; }
.google { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-weight: 600; font-size: 15px; }
.google:hover { background: var(--surface-2); }
.google:disabled { opacity: .6; cursor: wait; }
.google:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-hint { margin: 0; font-size: 12px; color: var(--muted); }
.link { border: 0 !important; background: none !important; padding: 0 !important; color: var(--accent); font-size: 13px; text-decoration: underline; cursor: pointer; justify-self: start; }
.login-msg { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--bad); }

/* Confirmação de zerar */
.danger-dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; max-width: 440px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.danger-dialog::backdrop { background: rgba(0,0,0,.45); }
.danger-dialog form { padding: 22px; display: grid; gap: 12px; }
.danger-dialog h2 { margin: 0; font-size: 19px; color: var(--bad); }
.danger-dialog p { margin: 0; font-size: 14px; color: var(--muted); }
.danger-dialog p b { color: var(--text); }
.danger-dialog label { display: grid; gap: 6px; font-size: 14px; }
.danger-dialog input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); font-size: 15px; letter-spacing: .05em; }
.danger-dialog input:focus { outline: 2px solid var(--bad); outline-offset: 1px; }
.danger-dialog .link { font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog-actions button { padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; }
.danger-solid { background: var(--bad) !important; border-color: var(--bad) !important; color: #fff; font-weight: 600 !important; }
.danger-solid:disabled { opacity: .4; cursor: not-allowed; }
