:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #5d6778;
  --line: #dde1e7;
  --brand: #0b5cad;
  --brand-ink: #ffffff;
  --brand-soft: #e6f0fa;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --c-duvida: #0b5cad;
  --c-aviso: #c05621;
  --c-material: #6b46c1;
  --c-discussao: #2f855a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d25;
    --surface-2: #1e2630;
    --text: #e6e9ee;
    --muted: #97a1b0;
    --line: #2b3440;
    --brand: #4c9ee8;
    --brand-ink: #0b1522;
    --brand-soft: #16304a;
    --ok: #4ac26b;
    --ok-soft: #173322;
    --warn: #e3b341;
    --warn-soft: #3a2f12;
    --danger: #f47067;
    --danger-soft: #3d1c1a;
    --c-duvida: #4c9ee8;
    --c-aviso: #ec8a4c;
    --c-material: #a58af0;
    --c-discussao: #58c48a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; line-height: 1.3; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
img { max-width: 100%; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: .75rem 0; }

.wrap { max-width: 1080px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 24px; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.inline { display: inline; }

/* ---------------------------------------------------------------- topo */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; padding-block: 8px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink); font-size: .85rem; letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { color: var(--muted); font-weight: 400; }
.nav { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nav > a:not(.btn) { color: var(--text); }
.me { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: .75rem; text-align: center;
}

/* ------------------------------------------------------------- botões */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }
.link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.danger { color: var(--danger); }

/* --------------------------------------------------------------- cartões */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.narrow { max-width: 520px; margin: 40px auto; }
.center { text-align: center; }
.lead { font-size: 1.05rem; color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.alert { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 8px; }
.warn { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 8px; font-size: .9rem; }
.notice { background: var(--ok-soft); color: var(--ok); padding: 10px 12px; border-radius: 8px; margin: 0 0 16px; }

/* ------------------------------------------------------ lista de tópicos */
.layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
.sidebar { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text);
}
.side-link span { margin-left: auto; color: var(--muted); font-size: .85rem; }
.side-link:hover { background: var(--surface-2); text-decoration: none; }
.side-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-duvida { background: var(--c-duvida); }
.dot-aviso { background: var(--c-aviso); }
.dot-material { background: var(--c-material); }
.dot-discussao { background: var(--c-discussao); }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; }

.topic-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.topic-row { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.topic-row:last-child { border-bottom: 0; }
.topic-row.pinned { background: var(--surface-2); }
.topic-main { flex: 1; min-width: 0; }
.topic-title { font-weight: 600; color: var(--text); font-size: 1rem; }
.topic-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 4px; color: var(--muted); font-size: .85rem; }
.topic-stats { text-align: right; font-size: .85rem; color: var(--muted); min-width: 130px; }
.topic-stats strong { color: var(--text); }
.topic-stats small { display: block; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }
.empty { text-align: center; padding: 40px 20px; }

.tag { padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid currentColor; }
.tag-duvida { color: var(--c-duvida); }
.tag-aviso { color: var(--c-aviso); }
.tag-material { color: var(--c-material); }
.tag-discussao { color: var(--c-discussao); }
.state { padding: 1px 8px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); color: var(--muted); }
.state-ok, .state-ativo { background: var(--ok-soft); color: var(--ok); }
.state-open, .state-pendente { background: var(--warn-soft); color: var(--warn); }
.state-bloqueado { background: var(--danger-soft); color: var(--danger); }
.badge { padding: 1px 7px; border-radius: 6px; font-size: .72rem; font-weight: 600; }
.badge-staff { background: var(--brand-soft); color: var(--brand); }

.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover; }
.avatar-sm { width: 26px; height: 26px; }
.avatar-initial {
  display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700;
}

/* --------------------------------------------------------------- tópico */
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.topic-head { margin-bottom: 16px; }
.solution-banner {
  display: block; background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok);
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px;
}
.post {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow); scroll-margin-top: 16px;
}
.post-first { border-left: 3px solid var(--brand); }
.post-solution { border: 2px solid var(--ok); }
.post:target { outline: 2px solid var(--brand); outline-offset: 2px; }
.post-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.post-flag { margin-left: auto; }
.post-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 10px; font-size: .88rem; }

.md { overflow-wrap: anywhere; }
.md p { margin: .5rem 0; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .5rem 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; }
.md img { border-radius: 6px; }

.attachments { list-style: none; padding: 10px 0 0; margin: 10px 0 0; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 6px; }
.thumb { display: block; max-height: 220px; width: auto; border-radius: 6px; border: 1px solid var(--line); margin-bottom: 4px; }

details.confirm { display: inline-block; }
details.confirm summary { list-style: none; cursor: pointer; }
details.confirm summary::-webkit-details-marker { display: none; }
details.confirm[open] form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; font-size: .88rem; }

/* ----------------------------------------------------------- formulários */
form label { display: block; margin-bottom: 14px; }
form label > span { display: block; font-weight: 600; margin-bottom: 4px; }
input:not([type=radio]):not([type=file]):not([type=hidden]), textarea, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
select { width: auto; }
.search input { width: 100%; }
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.file { margin-top: 16px; }
.file input { font: inherit; }
.form-card { max-width: 760px; margin-inline: auto; }
.categories { border: 0; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.categories legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.choice { margin: 0; }
.choice input { position: absolute; opacity: 0; }
.choice span {
  display: block; height: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.choice span small { display: block; color: var(--muted); font-weight: 400; }
.choice input:checked + span { border-color: var(--brand); background: var(--brand-soft); }
.choice input:focus-visible + span { outline: 2px solid var(--brand); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.actions.left { justify-content: flex-start; }

/* ---------------------------------------------------------------- admin */
.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
table.users th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 8px; }
table.users td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: middle; }
.who { display: flex; gap: 8px; align-items: center; }
.row-actions { white-space: nowrap; }
.row-actions form { display: inline-flex; gap: 6px; align-items: center; }

.footer { color: var(--muted); font-size: .8rem; padding-block: 24px 40px; text-align: center; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar hr { display: none; }
  .side-link { padding: 5px 10px; border: 1px solid var(--line); }
  .side-link span { margin-left: 4px; }
  .topic-stats { display: none; }
  .brand-text small { display: none; }
  .nav { margin-left: 0; }
}
