/* ==========================================================================
   1. DESIGN TOKENS & TEMAS PROFISSIONAIS (EDITORIAL PAPER & OBSIDIAN SLATE)
   ========================================================================== */
:root,
[data-theme="light"] {
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --border-color: #E2E8F0;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: rgba(37, 99, 235, 0.1);

  /* Semântica Git Diff */
  --diff-add-bg: rgba(34, 197, 94, 0.15);
  --diff-add-text: #16A34A;
  --diff-del-bg: rgba(239, 68, 68, 0.15);
  --diff-del-text: #DC2626;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.12);
}

[data-theme="dark"] {
  --bg-app: #0B0F19;
  --bg-surface: #111827;
  --bg-subtle: #1E293B;
  --border-color: #1F2937;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --accent: #3B82F6;
  --accent-hover: #60A5FA;
  --accent-soft: rgba(59, 130, 246, 0.15);

  /* Semântica Git Diff */
  --diff-add-bg: rgba(34, 197, 94, 0.18);
  --diff-add-text: #4ADE80;
  --diff-del-bg: rgba(239, 68, 68, 0.18);
  --diff-del-text: #F87171;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   2. RESET E TIPOGRAFIA BASE
   ========================================================================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
}

code, pre, .mono-hash, .kbd-hint {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

a { color: inherit; text-decoration: none; }

/* ==========================================================================
   3. TOPBAR FIXA
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  max-width: 1320px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }

.brand { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; letter-spacing: -0.02em; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 10px;
  width: 360px;
  height: 36px;
}
.search-box:focus-within { border-color: var(--accent); background: var(--bg-surface); }
.search-box input {
  border: none; background: transparent; color: var(--text-primary);
  width: 100%; padding: 0 8px; font-size: 0.9rem; outline: none;
}
.kbd-hint {
  font-size: 0.75rem; color: var(--text-muted);
  border: 1px solid var(--border-color); border-radius: 4px; padding: 1px 6px;
}

.btn {
  border: none; border-radius: 8px; padding: 8px 14px;
  font-weight: 600; font-size: 0.875rem; cursor: pointer; transition: 0.15s;
}
.btn-primary { background: var(--accent); color: #FFF; }
.btn-primary:hover { background: var(--accent-hover); }

.icon-btn {
  background: transparent; border: 1px solid var(--border-color); color: var(--text-primary);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-subtle); }

.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border-color); font-size: 0.85rem; font-weight: 500;
}

/* ==========================================================================
   4. GRID DE 3 COLUNAS RESPONSIVO
   ========================================================================== */
.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  grid-template-columns: 230px minmax(0, 740px) 280px;
  gap: 24px;
  justify-content: center;
}

.sidebar-left { position: sticky; top: 80px; height: calc(100vh - 100px); display: flex; flex-direction: column; }
.nav-group { margin-bottom: 24px; }
.nav-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 700; margin-bottom: 8px; padding: 0 10px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 8px; font-size: 0.9rem; color: var(--text-secondary); font-weight: 500;
  background: transparent; border: none; width: 100%; text-align: left;
  font-family: inherit; cursor: pointer;
}
.nav-item:hover, .nav-item.active { background: var(--accent-soft); color: var(--accent); }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.sidebar-footer { margin-top: auto; font-size: 0.78rem; color: var(--text-muted); padding: 0 10px; }

/* ==========================================================================
   5. CARDS DO FEED E ÁRVORE DE RESPOSTAS
   ========================================================================== */
.feed-header { margin-bottom: 16px; }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.tab {
  background: transparent; border: none; color: var(--text-secondary);
  padding: 6px 12px; border-radius: 6px; font-weight: 600; font-size: 0.875rem; cursor: pointer;
}
.tab.active { background: var(--accent-soft); color: var(--accent); }

.post-card, .widget-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.post-meta { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; margin-bottom: 12px; }
.meta-text { display: flex; flex-direction: column; }
.author-row { display: flex; align-items: center; gap: 6px; }

.trust-badge {
  font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  background: var(--bg-subtle); color: var(--text-secondary); border: 1px solid var(--border-color);
}
.author-op {
  font-size: 0.7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
}
.category-tag { font-size: 0.78rem; color: var(--text-muted); }

.revision-badge {
  margin-left: auto; background: var(--bg-subtle); border: 1px solid var(--border-color);
  color: var(--text-secondary); font-size: 0.78rem; padding: 4px 10px;
  border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
}
.revision-badge:hover { border-color: var(--accent); color: var(--accent); }

.post-title { font-size: 1.2rem; line-height: 1.35; margin-bottom: 8px; letter-spacing: -0.01em; }
.post-title a:hover { color: var(--accent); }
.post-excerpt { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 16px; }

.post-actions { display: flex; align-items: center; gap: 12px; }
.action-btn {
  background: var(--bg-subtle); border: 1px solid transparent; color: var(--text-secondary);
  padding: 5px 10px; border-radius: 6px; font-size: 0.82rem; font-weight: 500; cursor: pointer;
}
.action-btn:hover { border-color: var(--border-color); color: var(--text-primary); }
.action-btn.subtle { margin-left: auto; background: transparent; }

/* Árvore de Respostas Aninhadas */
.thread-replies { margin-top: 20px; }
.reply-node { display: flex; gap: 12px; margin-top: 14px; }
.reply-node.collapsed > .reply-body > p,
.reply-node.collapsed > .reply-body > .reply-node { display: none; }
.branch-line {
  width: 3px; background: var(--border-color); border-radius: 2px;
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
}
.branch-line:hover { background: var(--accent); }
.reply-body { flex: 1; background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: 10px; padding: 14px 16px; }

/* Coluna Direita */
.widget-card h3 { font-size: 0.92rem; margin-bottom: 12px; }
.rules-list, .trending-list { padding-left: 16px; font-size: 0.85rem; color: var(--text-secondary); display: flex; flex-direction: column; gap: 10px; }
.trending-list a { display: block; font-weight: 600; color: var(--text-primary); }
.trending-list span { font-size: 0.78rem; color: var(--text-muted); }

/* ==========================================================================
   6. MODAL DE HISTÓRICO DE REVISÕES & GIT DIFF
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal-backdrop.hidden { display: none; }

.modal-window {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: 14px; width: 100%; max-width: 920px; max-height: 85vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
  display: flex; justify-content: space-between; align-items: center;
}
.mono-hash { color: var(--text-muted); font-size: 0.78rem; }

.modal-split { display: grid; grid-template-columns: 280px 1fr; flex: 1; overflow: hidden; }
.commit-list { border-right: 1px solid var(--border-color); overflow-y: auto; padding: 12px; }
.commit-item {
  padding: 10px 12px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; margin-bottom: 8px;
}
.commit-item:hover { background: var(--bg-subtle); }
.commit-item.active { background: var(--accent-soft); border-color: var(--accent); }
.commit-msg { font-weight: 600; font-size: 0.86rem; display: block; }
.commit-meta { font-size: 0.75rem; color: var(--text-muted); }

.diff-viewer { display: flex; flex-direction: column; overflow: hidden; }
.diff-toolbar {
  padding: 10px 16px; background: var(--bg-subtle); border-bottom: 1px solid var(--border-color);
  display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-secondary);
}
.diff-content { padding: 20px; overflow-y: auto; white-space: pre-wrap; font-size: 0.9rem; line-height: 1.7; }

ins { background: var(--diff-add-bg); color: var(--diff-add-text); text-decoration: none; padding: 1px 3px; border-radius: 3px; }
del { background: var(--diff-del-bg); color: var(--diff-del-text); text-decoration: line-through; padding: 1px 3px; border-radius: 3px; }

/* ==========================================================================
   7. RESPONSIVIDADE
   ========================================================================== */
.mobile-only { display: none; }
@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .sidebar-right { display: none; }
}
@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .search-box { width: 180px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar-left {
    display: none; position: fixed; top: 56px; left: 0; bottom: 0; width: 260px;
    background: var(--bg-surface); border-right: 1px solid var(--border-color); padding: 16px; z-index: 50;
  }
  .sidebar-left.open { display: flex; }
  .modal-split { grid-template-columns: 1fr; }
}

/* ==========================================================================
   8. COMPONENTES DINÂMICOS (FEED, AUTH, FORMULÁRIOS E TOASTS)
   ========================================================================== */
.hidden { display: none !important; }

.muted { color: var(--text-muted); font-size: 0.85rem; }
.empty-state { padding: 24px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.warning-text {
  background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--text-secondary); border-radius: 8px; padding: 12px; margin-bottom: 16px;
}
.form-error { color: var(--diff-del-text); font-size: 0.85rem; margin-top: 4px; }

.btn-ghost { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text-primary); }
.btn-danger { background: #DC2626; color: #FFF; }
.btn-danger:hover { background: #B91C1C; }
.link-btn {
  background: transparent; border: none; color: var(--accent); cursor: pointer;
  font-size: 0.82rem; font-weight: 600; padding: 0 4px; font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }

.auth-area { display: flex; align-items: center; gap: 8px; }
.username { font-weight: 600; }
.dot { color: var(--text-muted); }
.identicon { flex-shrink: 0; }

.load-more { display: block; margin: 16px auto; }

.post-content { font-size: 0.95rem; color: var(--text-secondary); overflow-wrap: anywhere; }
.post-content p { margin: 0 0 10px; }
.post-content code {
  background: var(--bg-subtle); border-radius: 4px; padding: 1px 5px; font-size: 0.88em;
}
.post-content pre {
  background: var(--bg-subtle); border-radius: 8px; padding: 12px;
  overflow-x: auto; margin: 10px 0;
}
.post-content pre code { background: transparent; padding: 0; }
.post-content a { color: var(--accent); text-decoration: underline; }

.action-btn.static { cursor: default; }
.action-btn.static:hover { border-color: transparent; color: var(--text-secondary); }
.commit-note { font-size: 0.8rem; color: var(--text-muted); font-style: italic; margin-bottom: 8px; }

.thread-detail, .legal-document {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: 12px; padding: 24px; box-shadow: var(--shadow-sm);
}
.thread-header { border-bottom: 1px solid var(--border-color); padding-bottom: 16px; }
.thread-header h1 { font-size: 1.5rem; line-height: 1.3; margin: 8px 0; }
.thread-footer { border-top: 1px solid var(--border-color); margin-top: 20px; padding-top: 16px; }

.reply-node.level-2 { margin-left: 20px; }
.reply-node.level-3 { margin-left: 32px; }

.legal-document section { padding: 16px 0; border-bottom: 1px solid var(--border-color); }
.legal-document section h2 { font-size: 1.1rem; margin-bottom: 8px; }
.legal-document section p { color: var(--text-secondary); margin-bottom: 8px; }
.legal-footer { padding-top: 16px; }

/* Modal genérico de formulários */
.modal-window:not(.modal-wide) { max-width: 520px; }
.modal-body { padding: 20px; overflow-y: auto; }
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field small { color: var(--text-muted); font-size: 0.78rem; }
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg-app); color: var(--text-primary);
  border: 1px solid var(--border-color); border-radius: 8px;
  padding: 9px 11px; font-size: 0.9rem; font-family: inherit; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 90px; }
.checkbox-field { display: flex; gap: 8px; align-items: flex-start; font-size: 0.85rem; }
.checkbox-field a { color: var(--accent); text-decoration: underline; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

/* Toasts */
#toastContainer {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-color); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; font-size: 0.88rem;
  box-shadow: var(--shadow-lg); max-width: 360px;
}
.toast-success { border-left-color: var(--diff-add-text); }
.toast-error { border-left-color: var(--diff-del-text); }

/* Ajustes de largura em telas menores */
@media (max-width: 560px) {
  .topbar-inner { gap: 8px; padding: 0 10px; }
  .search-box { width: 130px; }
  .auth-area .btn-ghost { display: none; }
  .app-shell { padding: 16px 10px; }
  .thread-detail, .legal-document { padding: 16px; }
}