/* ===== Temas ============================================================
   Cada tema só redefine variáveis. Para criar um tema novo: copie um bloco,
   troque o nome e as cores, e adicione a chave em THEMES no app.py. */
:root, [data-theme="claro"] {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1d2330; --muted: #667085;
  --border: #e2e5ea; --accent: #3b5bdb; --accent-text: #ffffff; --accent-soft: #e8edff; --link: #3451c7;
  --danger: #d6336c; --warn: #b7791f; --ok: #2b8a3e; --code-bg: #f1f3f5; --mark: #ffe58a;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08); color-scheme: light;
}
[data-theme="escuro"] {
  --bg: #0f1218; --surface: #181c25; --surface-2: #1f2430; --text: #e6e9ef; --muted: #98a2b3;
  --border: #2b3140; --accent: #7c93ff; --accent-text: #0f1218; --accent-soft: #232b45; --link: #9db0ff;
  --danger: #ff6b9a; --warn: #f0b955; --ok: #69db7c; --code-bg: #12151c; --mark: #6b5a12;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
[data-theme="sepia"] {
  --bg: #f3ecdf; --surface: #fbf6ec; --surface-2: #efe5d3; --text: #3b2f22; --muted: #7a6a55;
  --border: #e0d3bc; --accent: #9c5b2e; --accent-text: #fffaf2; --accent-soft: #f1e0cc; --link: #8a4b20;
  --danger: #b23a48; --warn: #a66a00; --ok: #4d7c2a; --code-bg: #efe4cf; --mark: #f7d98b;
  --shadow: 0 1px 3px rgba(80,55,20,.12); color-scheme: light;
}
[data-theme="oceano"] {
  --bg: #0b1d2a; --surface: #102938; --surface-2: #153446; --text: #e0f2f7; --muted: #8fb3c2;
  --border: #1f4458; --accent: #2ec4c4; --accent-text: #062028; --accent-soft: #134654; --link: #6fe0e0;
  --danger: #ff7a8a; --warn: #ffc857; --ok: #5ee39b; --code-bg: #0a1924; --mark: #275e6b;
  --shadow: 0 1px 3px rgba(0,0,0,.45); color-scheme: dark;
}
[data-theme="floresta"] {
  --bg: #eef3ec; --surface: #fbfdf9; --surface-2: #e6eee2; --text: #1f2d1f; --muted: #5f7360;
  --border: #d3dfcf; --accent: #2f7d4f; --accent-text: #ffffff; --accent-soft: #dcefdf; --link: #276a42;
  --danger: #c0392b; --warn: #a8701a; --ok: #2f7d4f; --code-bg: #e9f0e5; --mark: #e8e27a;
  --shadow: 0 1px 3px rgba(30,60,30,.1); color-scheme: light;
}
[data-theme="contraste"] {
  --bg: #000000; --surface: #000000; --surface-2: #111111; --text: #ffffff; --muted: #e0e0e0;
  --border: #ffffff; --accent: #ffee00; --accent-text: #000000; --accent-soft: #333300; --link: #66ccff;
  --danger: #ff5c5c; --warn: #ffee00; --ok: #00ff88; --code-bg: #111111; --mark: #ffee00;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0f1218; --surface: #181c25; --surface-2: #1f2430; --text: #e6e9ef; --muted: #98a2b3;
    --border: #2b3140; --accent: #7c93ff; --accent-text: #0f1218; --accent-soft: #232b45; --link: #9db0ff;
    --danger: #ff6b9a; --warn: #f0b955; --ok: #69db7c; --code-bg: #12151c; --mark: #6b5a12;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}

/* ===== Base ============================================================ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: .2em 0 .3em; }
h2, .h2 { font-size: 1.2rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 0 0 .5em; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; width: 100%; }
main.wrap { flex: 1; padding-top: 20px; padding-bottom: 40px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.inline { display: inline; margin: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== Topbar ========================================================== */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; align-items: center; gap: 14px; flex: 1; justify-content: flex-end; }
.mainnav > a { color: var(--text); white-space: nowrap; }
.searchbox input { width: 190px; }
.theme-form select { max-width: 170px; }
.icon-link { position: relative; font-size: 1.1rem; }
.icon-link:hover { text-decoration: none; }
.count { position: absolute; top: -6px; right: -10px; background: var(--accent); color: var(--accent-text);
  font-size: .68rem; font-weight: 700; border-radius: 999px; padding: 0 5px; line-height: 16px; }
.count.warn, .tabs .count { background: var(--danger); color: #fff; position: static; }
.me { display: flex; align-items: center; gap: 6px; color: var(--text); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; font-size: 1.2rem; padding: 2px 10px; cursor: pointer; }
.linkish { background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; padding: 0; }

/* ===== Forms & buttons ================================================= */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
.form label input, .form label select, .form label textarea { font-weight: 400; width: 100%; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; margin: 0; white-space: nowrap; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--accent-text);
  border: 1px solid var(--accent); border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: 3px 10px; font-size: .85rem; }

/* ===== Cards, lists ==================================================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.list { padding: 0; overflow: hidden; }
.list-head, .row { display: grid; gap: 12px; align-items: center; padding: 12px 16px; }
.list-head { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.row { border-top: 1px solid var(--border); color: inherit; }
.list-head + .row, .card.list > .row:first-child { border-top: 0; }
a.row:hover { background: var(--surface-2); text-decoration: none; }
.row.empty { display: block; color: var(--muted); text-align: center; padding: 26px; }
.row-title { font-weight: 600; color: var(--text); }
.cols-cat { grid-template-columns: 1fr 80px 90px 220px; }
.cols-topic { grid-template-columns: 1fr 80px 70px 150px; }
.cols-recent { grid-template-columns: 1fr 130px; }
.cols-msg { grid-template-columns: 170px 1fr 110px; }
.cols-user { grid-template-columns: minmax(180px, 1fr) 1fr auto; }
.num { text-align: center; font-variant-numeric: tabular-nums; }
.is-pinned { background: var(--accent-soft); }
.is-deleted { opacity: .55; }
.unread { background: var(--accent-soft); font-weight: 600; }
.notif { grid-template-columns: 1fr auto; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: 4px; }
.section-title { margin-top: 26px; }
.layout { display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
.side h3 { margin-bottom: 8px; }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; }
.stats dd { margin: 0; font-weight: 700; text-align: right; }
.inline-stats { display: flex; flex-wrap: wrap; gap: 4px 8px; }
.inline-stats dt { color: var(--muted); }
.inline-stats dd { margin-right: 14px; }
.staff-name { font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.row-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wrap-ok { justify-content: flex-end; }

.badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2);
  color: var(--muted); border: 1px solid var(--border); vertical-align: middle; text-transform: uppercase; letter-spacing: .03em; }
.badge-admin { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.badge-mod { background: var(--ok); color: #fff; border-color: var(--ok); }
.badge-danger { background: var(--danger); color: #fff; border-color: var(--danger); }

.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash-ok { border-left: 4px solid var(--ok); }
.flash-warn { border-left: 4px solid var(--warn); }
.flash-error { border-left: 4px solid var(--danger); }
.announcement { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; }
.setup { border: 2px dashed var(--warn); }

/* ===== Avatars ========================================================= */
.avatar { width: var(--s); height: var(--s); border-radius: 50%; object-fit: cover; flex: none; display: inline-block; vertical-align: middle; }
.avatar-letter { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff;
  background: hsl(var(--h) 55% 45%); font-size: calc(var(--s) * .45); }

/* ===== Posts =========================================================== */
.post { display: grid; grid-template-columns: 150px 1fr; gap: 18px; scroll-margin-top: 70px; }
.post:target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.post-author { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; border-right: 1px solid var(--border); padding-right: 14px; }
.author-meta span { display: block; }
.post-main > .badge { align-self: flex-start; margin-bottom: 6px; }
.author-name { font-weight: 700; color: var(--text); word-break: break-all; }
.post-main { min-width: 0; display: flex; flex-direction: column; }
.post-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.post-num { margin-left: auto; }
.signature { border-top: 1px dashed var(--border); margin-top: 14px; padding-top: 6px; }
.post-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; padding-top: 12px; }
.act { background: none; border: 1px solid transparent; color: var(--muted); border-radius: 6px; padding: 2px 8px; font: inherit; font-size: .85rem; cursor: pointer; }
.act:hover:not(:disabled) { background: var(--surface-2); color: var(--text); text-decoration: none; }
.act.liked { color: var(--danger); font-weight: 700; }
.act.danger:hover { color: var(--danger); }
.act:disabled { cursor: default; }
.modbar summary { cursor: pointer; font-weight: 600; }
.modbar-body { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.modbar-body form.grow { display: flex; gap: 6px; }
.modbar-body form.grow input { flex: 1; }

/* ===== Markdown content =============================================== */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md blockquote { margin: .6em 0; padding: .4em 1em; border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--muted); }
.md pre { background: var(--code-bg); border: 1px solid var(--border); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.md .table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md a.mention { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; font-weight: 600; }
.quote-box { background: var(--surface-2); max-height: 260px; overflow: auto; }

/* ===== Editor ========================================================== */
.editor { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 12px; background: var(--surface); }
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor-bar { display: flex; gap: 2px; flex-wrap: wrap; align-items: center; padding: 4px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.editor-bar button, .upload-btn { background: none; border: 0; color: var(--text); border-radius: 6px; min-width: 32px; height: 30px; cursor: pointer; font: inherit; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; font-weight: 400; margin: 0; flex-direction: row; }
.editor-bar button:hover, .upload-btn:hover { background: var(--surface); }
.editor-bar .spacer { flex: 1; }
.editor-bar .tab.active { background: var(--surface); font-weight: 700; }
.editor textarea { border: 0; border-radius: 0; box-shadow: none !important; }
.editor .preview { padding: 12px; min-height: 120px; }
.editor.uploading { opacity: .7; }

/* ===== Misc pages ====================================================== */
.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin: 14px 0; }
.pagination a, .pagination span { padding: 4px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.pagination .current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
.pagination .gap { border: 0; background: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); font-weight: 700; }
.small-tabs a { padding: 4px 10px; font-size: .9rem; }
.auth { max-width: 420px; margin: 20px auto; }
.profile-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.member { display: flex; gap: 12px; align-items: center; color: var(--text); margin: 0; }
.member:hover { text-decoration: none; border-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 4px; }
.stat-v { font-size: 1.5rem; font-weight: 800; }
.cat-edit { grid-template-columns: 64px 160px 1fr auto auto auto 170px auto; }
.w-num { width: 64px; }
.new-cat { margin-top: 14px; }
.report .quote-box { margin: 8px 0; padding: 10px; border-radius: 8px; }
.search-form { display: flex; gap: 8px; }
.search-form input { flex: 1; }
.error-box { padding: 40px 20px; }
.error-code { font-size: 3.5rem; font-weight: 800; color: var(--accent); line-height: 1; }
.theme-swatches { display: flex; gap: 8px; margin: -6px 0 14px; flex-wrap: wrap; }
.swatch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); padding: 4px; gap: 3px; }
.swatch i { width: 16px; height: 22px; border-radius: 4px; display: block; }
.swatch i:nth-child(1) { background: var(--surface); border: 1px solid var(--border); }
.swatch i:nth-child(2) { background: var(--accent); }
.swatch i:nth-child(3) { background: var(--text); }
.footer { border-top: 1px solid var(--border); background: var(--surface); padding: 16px 0; font-size: .85rem; color: var(--muted); }
.footer .wrap { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
code.copy { cursor: pointer; background: var(--code-bg); padding: 2px 6px; border-radius: 4px; }

/* ===== Responsivo ====================================================== */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .cat-edit { grid-template-columns: 1fr 1fr; }
  .cat-edit .grow { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .topbar-inner { flex-wrap: wrap; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; gap: 10px; padding-bottom: 12px; }
  .mainnav.open { display: flex; }
  .searchbox input, .theme-form select { width: 100%; max-width: none; }
  .count { position: static; margin-left: 4px; }
  .list-head { display: none; }
  .cols-cat, .cols-topic, .cols-recent, .cols-msg, .cols-user { grid-template-columns: 1fr; gap: 4px; }
  .num { display: none; }
  .right { text-align: left; }
  .post { grid-template-columns: 1fr; gap: 10px; }
  .post-author { flex-direction: row; text-align: left; border-right: 0; border-bottom: 1px solid var(--border); padding: 0 0 10px; flex-wrap: wrap; }
  .post-author .avatar { --s: 40px !important; width: 40px; height: 40px; }
  .author-meta span { display: inline; }
  .author-meta span + span::before { content: "· "; }
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
  .card { padding: 14px; }
}
