/* =============================================================
   Sistema QUAD — Estilos principais (dark/light com CSS vars)
   ============================================================= */

:root {
  --primary: #E11D48;
  --primary-hover: #BE123C;
  --primary-soft: rgba(225, 29, 72, 0.12);
  --accent: #3B82F6;

  /* Dark (padrão) */
  --bg: #0B0D10;
  --bg-elevated: #15181D;
  --bg-card: #1A1F26;
  --bg-hover: #232A33;
  --border: #2A323D;
  --border-soft: #1F252E;
  --text: #E6E9EF;
  --text-muted: #8A93A2;
  --text-dim: #5B6472;
  --shadow: 0 10px 40px rgba(0,0,0,0.4);
  --modal-overlay: rgba(0,0,0,0.7);
}

[data-tema="light"] {
  --bg: #F6F7F9;
  --bg-elevated: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-hover: #F1F3F6;
  --border: #E2E6EC;
  --border-soft: #ECEFF3;
  --text: #1A1F26;
  --text-muted: #5B6472;
  --text-dim: #8A93A2;
  --shadow: 0 8px 30px rgba(20,30,50,0.08);
  --modal-overlay: rgba(20,25,35,0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== Layout principal ========== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  transition: grid-template-columns .18s ease;
}
.layout.is-collapsed {
  grid-template-columns: 58px 1fr;
}

/* ========== Sidebar ========== */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 14px 0 4px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  /* Barra de rolagem discreta (estilo ChatGPT/Claude) — fina, sobreposta,
     sem "lane"/trilho visível; polegar bem sutil, fica mais visível no hover. */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar:hover::-webkit-scrollbar-thumb { background: var(--text-dim); }
.sidebar__brand-row {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 12px 14px;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.sidebar__brand-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  object-fit: cover;
}
.sidebar__brand-text { min-width: 0; }
.sidebar__brand-name { font-weight: 600; font-size: 14px; white-space: nowrap; }

.layout.is-collapsed .sidebar__brand-text { display: none; }

/* Logo = botão de EXPANDIR quando retraída (não navega). */
.sidebar__logo-btn {
  background: transparent;
  border: none;
  padding: 4px;
  margin: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
  cursor: default;            /* expandida: não faz nada */
}
.layout.is-collapsed .sidebar__logo-btn { cursor: pointer; }   /* retraída: clica pra expandir */
.layout.is-collapsed .sidebar__logo-btn:hover { background: var(--bg-hover); }

/* Botão de RETRAIR (visível só quando expandida), alinhado ao "Sistema QUAD". */
.sidebar__collapse-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
}
.sidebar__collapse-btn:hover { background: var(--bg-hover); color: var(--text); }
.layout.is-collapsed .sidebar__collapse-btn { display: none; }

.sidebar__section { padding: 14px 14px 4px; }
.sidebar__section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 8px 8px;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 4px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .08s;
  position: relative;
  text-decoration: none;
}
.sidebar__link:hover { background: var(--bg-hover); text-decoration: none; }
.sidebar__link.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 500;
}
.sidebar__link-icon { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar__link-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__link-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}

/* Tooltip pra sidebar minimizada — flutua via JS (position:fixed) pra não ser
   cortado pelo overflow do <aside>. Aparece sem delay (transition 0s). */
.sb-tip {
  position: fixed;
  transform: translateY(-50%);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s;
  z-index: 1000;
}
.sb-tip.is-visible { opacity: 1; }
.layout.is-collapsed .sidebar__link-text,
.layout.is-collapsed .sidebar__link-badge,
.layout.is-collapsed .sidebar__section-title,
.layout.is-collapsed .sidebar__user-info {
  display: none;
}
.layout.is-collapsed .sidebar__link {
  justify-content: center;
  padding: 8px 4px;
}
.layout.is-collapsed .sidebar__user {
  justify-content: center;
}
.layout.is-collapsed .sidebar__brand-row {
  justify-content: center;
  padding: 4px 8px 14px;
}

.sidebar__bottom {
  margin-top: auto;
  padding: 12px 14px 6px;
  border-top: 1px solid var(--border-soft);
}
.sidebar__user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
}
.sidebar__user:hover { background: var(--bg-hover); }
.sidebar__user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 12px; font-weight: 600;
  object-fit: cover;
  flex-shrink: 0;
}
img.sidebar__user-avatar { background: transparent; }
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { font-size: 11px; color: var(--text-muted); }

.sidebar__user-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 4px;
  right: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* IMPORTANTE: o atributo `hidden` precisa vencer o display:flex acima */
.sidebar__user-menu[hidden] { display: none !important; }
.sidebar__user-menu a {
  padding: 7px 10px;
  border-radius: 5px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}
.sidebar__user-menu a:hover { background: var(--bg-hover); }
.layout.is-collapsed .sidebar__user-menu {
  left: calc(100% + 8px);
  right: auto;
  bottom: 0;
  width: 200px;
}

/* ========== Main ========== */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar__breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}
.topbar__breadcrumb b { color: var(--text); }

.topbar__search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  min-width: 260px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
}
.topbar__search:hover { border-color: var(--accent); }
.topbar__search kbd {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  color: var(--text-muted);
  margin-left: auto;
}

.topbar__theme-toggle {
  width: 34px; height: 34px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.topbar__theme-toggle:hover { background: var(--bg-hover); color: var(--text); }

.content {
  padding: 28px 32px 80px;
  flex: 1;
  max-width: 1400px;
  width: 100%;
}

/* ========== Headers de página ========== */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  display: flex; align-items: center; gap: 12px;
  font-size: 28px;
  font-weight: 700;
}
.page-title__icon {
  font-size: 28px;
  width: 44px; height: 44px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white;
}
.page-subtitle {
  color: var(--text-muted);
  margin-top: 4px;
  font-size: 13px;
}

/* ========== Botões ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all .1s;
  font-family: inherit;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-muted); text-decoration: none; }
.btn--primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--ghost { background: transparent; border: none; padding: 6px 10px; color: var(--text-muted); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn--danger { color: var(--primary); border-color: rgba(225,29,72,0.3); }
.btn--danger:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn--sm { padding: 4px 10px; font-size: 12px; }
.btn--icon {
  width: 28px; height: 28px;
  padding: 0;
  justify-content: center;
}

/* ========== Filtros ========== */
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.filter-chip:hover { background: var(--bg-hover); }

/* Filtro de múltipla escolha (dropdown com checkboxes) */
.multifilter { position: relative; display: inline-block; }
.multifilter__btn { border: none; font: inherit; }
.multifilter--ativo .multifilter__btn { background: var(--primary-soft); border-color: var(--primary); color: var(--text); }
.multifilter__caret { font-size: 9px; opacity: .7; }
.multifilter__panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  min-width: 210px; max-height: 320px; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 9px; box-shadow: 0 8px 28px rgba(0,0,0,.35);
  padding: 6px;
}
.multifilter__opt {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text);
}
.multifilter__opt:hover { background: var(--bg-hover); }
.multifilter__opt input { cursor: pointer; }
.filter-chip select {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  font-family: inherit;
}

/* ========== Tabelas (database view) ========== */
.table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  background: var(--bg-card);
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
/* Cabeçalho ordenável (setinha asc/desc) */
.table thead th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.table thead th[data-sort]:hover { color: var(--text); }
.table thead th[data-sort] .sort-arrow { margin-left: 4px; opacity: .45; font-size: 11px; }
.table thead th[data-sort]:hover .sort-arrow { opacity: .8; }
.table thead th[data-sort] .sort-arrow.is-active { opacity: 1; color: var(--primary); }
.table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .col-actions { width: 1px; white-space: nowrap; line-height: 0; }
/* Alinha verticalmente os botões de ação (lápis + duplicar + lixeira) — todos na mesma altura.
   O !important vence o style="display:inline" inline dos <form>, senão os botões caem por baseline
   (e SVG x emoji têm baselines diferentes → ficam desalinhados). */
.table .col-actions > a,
.table .col-actions > form { vertical-align: middle; }
.table .col-actions form { display: inline-flex !important; align-items: center; margin: 0; }
.table .col-actions .btn--icon { vertical-align: middle; }
.table .codigo {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ========== Badges ========== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge--dep { background: var(--primary-soft); color: var(--primary); }
.badge--sub { background: rgba(59,130,246,0.12); color: var(--accent); }
.badge--status-ativo { background: rgba(34,197,94,0.12); color: #22C55E; }
.badge--status-inativo { background: rgba(156,163,175,0.12); color: #9CA3AF; }
.badge--status-rascunho { background: rgba(234,179,8,0.12); color: #EAB308; }
.badge--tipo { background: var(--bg-hover); color: var(--text); }

/* ========== Cards grid (Pastas) ========== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}
.card__cover {
  height: 100px;
  background: linear-gradient(135deg, #1E3A8A 0%, #1E40AF 100%);
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 32px;
  position: relative;
}
.card__cover::before {
  content: '🏆';
  position: absolute;
  top: 8px; left: 12px;
  font-size: 18px;
}
.card__body { padding: 14px; flex: 1; }
.card__title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card__desc { font-size: 12px; color: var(--text-muted); }
.card__footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border-soft);
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--text-muted);
}

/* ========== Formulários ========== */
.form-grid { display: grid; gap: 16px; max-width: 880px; }
.form-row { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.form-row--full { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-control {
  padding: 9px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.form-control:focus { border-color: var(--primary); }
textarea.form-control { min-height: 80px; resize: vertical; }

.form-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  margin-top: 8px;
}

/* ========== Sections em detail view ========== */
.detail-header {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 24px;
}
.detail-codigo {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
}
.detail-title { font-size: 26px; font-weight: 700; margin-bottom: 10px; }
.detail-meta {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.detail-intro {
  background: var(--bg-card);
  border-left: 3px solid var(--primary);
  padding: 14px 18px;
  border-radius: 0 7px 7px 0;
  margin-top: 14px;
  font-size: 14px;
  color: var(--text);
}
.detail-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  margin-bottom: 24px;
  position: relative;
}
.detail-content.is-truncated {
  max-height: 480px;
  overflow: hidden;
}
.detail-content.is-truncated::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 110px;
  background: linear-gradient(to bottom, transparent, var(--bg-elevated) 85%);
  pointer-events: none;
}
/* "Mostrar mais" fica DENTRO do campo de texto, no rodapé (sobre o degradê). */
.detail-content.has-more { padding-bottom: 58px; }
.detail-content__more {
  position: absolute;
  left: 0; right: 0; bottom: 16px;
  text-align: center;
  z-index: 3;
}

/* Modo apresentação */
.modo-apresentacao { background: var(--bg); padding: 60px 8vw; min-height: 100vh; }
.modo-apresentacao__topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 28px; }
.modo-apresentacao h1 { font-size: 38px; margin-bottom: 12px; }
.modo-apresentacao .detail-content { font-size: 18px; line-height: 1.75; padding: 32px 40px; }
.modo-apresentacao .detail-content h1 { font-size: 30px; }
.modo-apresentacao .detail-content h2 { font-size: 24px; }
.modo-apresentacao .detail-content h3 { font-size: 20px; }
.detail-content h1 { font-size: 1.7em; font-weight: 700; margin: 22px 0 10px; }
.detail-content h2 { font-size: 1.4em; font-weight: 600; margin: 20px 0 10px; }
.detail-content h3 { font-size: 1.2em; font-weight: 600; margin: 18px 0 10px; }
.detail-content p { margin: 6px 0; }
/* linhas em branco (<p><br></p>) mais compactas — reduz o espaço entre parágrafos */
.detail-content p:has(> br:only-child) { margin: 2px 0; line-height: 1; }
.detail-content ul, .detail-content ol { margin: 8px 0 8px 28px; }
.detail-content li { margin: 4px 0; }
.detail-content ul ul, .detail-content ol ol, .detail-content ol ul, .detail-content ul ol { margin: 4px 0 4px 28px; }
.detail-content blockquote {
  border-left: 3px solid var(--primary);
  padding: 10px 18px;
  margin: 14px 0;
  color: var(--text);
  background: var(--primary-soft);
  border-radius: 0 7px 7px 0;
  font-style: italic;
}
/* Citação: linhas consecutivas (Enter/Shift+Enter dentro da citação) formam UMA citação contínua */
.detail-content blockquote + blockquote,
.quill-wrap .ql-editor blockquote + blockquote { margin-top: 0; padding-top: 2px; border-top-left-radius: 0; border-top-right-radius: 0; }
.detail-content blockquote:has(+ blockquote),
.quill-wrap .ql-editor blockquote:has(+ blockquote) { margin-bottom: 0; padding-bottom: 2px; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.detail-content pre, .detail-content code {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 13px;
}
.detail-content pre { padding: 12px 16px; margin: 12px 0; overflow-x: auto; }
.detail-content code { padding: 1px 6px; }
.detail-content pre code { background: transparent; border: none; padding: 0; }
.detail-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 22px 0;
}
.detail-content a { color: var(--accent); text-decoration: underline; }
.detail-content img { max-width: 100%; height: auto; border-radius: 7px; margin: 10px 0; }
.detail-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}
.detail-content table th, .detail-content table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
}
.detail-content table th { background: var(--bg-card); }
.detail-content .ql-align-center { text-align: center; }
.detail-content .ql-align-right { text-align: right; }
.detail-content .ql-align-justify { text-align: justify; }
/* Indents do Quill (sub-níveis) */
.detail-content .ql-indent-1 { padding-left: 3em; }
.detail-content .ql-indent-2 { padding-left: 6em; }
.detail-content .ql-indent-3 { padding-left: 9em; }
.detail-content .ql-indent-4 { padding-left: 12em; }

/* Caixa de destaque (atributo de bloco) — sem título. Funciona em parágrafos E em listas. */
.detail-content p.quad-callout, .detail-content div.quad-callout,
.quill-wrap .ql-editor p.quad-callout, .quill-wrap .ql-editor div.quad-callout,
.detail-content ol:has(> li.quad-callout), .detail-content ul:has(> li.quad-callout),
.quill-wrap .ql-editor ol:has(> li.quad-callout), .quill-wrap .ql-editor ul:has(> li.quad-callout) {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 7px;
  padding: 12px 16px;
  margin: 14px 0;
}
/* lista-callout: a CAIXA fica na lista (não em cada item); padding extra p/ os marcadores */
.detail-content ol:has(> li.quad-callout), .detail-content ul:has(> li.quad-callout),
.quill-wrap .ql-editor ol:has(> li.quad-callout), .quill-wrap .ql-editor ul:has(> li.quad-callout) {
  padding-left: 40px;
}
/* item de lista dentro da caixa NÃO desenha caixa própria (a lista já desenha) */
.detail-content li.quad-callout, .quill-wrap .ql-editor li.quad-callout {
  background: none; border: none; border-radius: 0; padding: 0;
}
/* parágrafos consecutivos com callout viram visualmente UMA caixa só */
.detail-content p.quad-callout + p.quad-callout, .detail-content div.quad-callout + div.quad-callout,
.quill-wrap .ql-editor p.quad-callout + p.quad-callout, .quill-wrap .ql-editor div.quad-callout + div.quad-callout {
  border-top: none; border-top-left-radius: 0; border-top-right-radius: 0;
  margin-top: 0; padding-top: 0;
}
.detail-content p.quad-callout:has(+ p.quad-callout), .detail-content div.quad-callout:has(+ div.quad-callout),
.quill-wrap .ql-editor p.quad-callout:has(+ p.quad-callout), .quill-wrap .ql-editor div.quad-callout:has(+ div.quad-callout) {
  border-bottom: none; border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  margin-bottom: 0; padding-bottom: 0;
}

.linked-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
}
.linked-section__header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}
.linked-section__title { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ========== Modal / Pop-up empilhável ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 20px;
  overflow-y: auto;
}
.modal-overlay.is-stacked { background: transparent; backdrop-filter: blur(2px); }
.modal {
  background: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 920px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
}
.modal__header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.modal__header-label {
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.modal__header-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  display: flex; align-items: center; gap: 4px;
}
.modal__header-back:hover { background: var(--bg-hover); color: var(--text); }
.modal__header-actions { margin-left: auto; display: flex; gap: 6px; }
.modal__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  width: 28px; height: 28px;
  border-radius: 5px;
}
.modal__close:hover { background: var(--bg-hover); color: var(--text); }
.modal__body { padding: 24px 28px; overflow-y: auto; flex: 1; }

/* ========== Cmd+K Search ========== */
.search-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.search-modal__input {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.search-modal__input input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.search-modal__results { overflow-y: auto; padding: 8px; }
.search-result {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  cursor: pointer;
}
.search-result:hover, .search-result.is-focused { background: var(--bg-hover); }
.search-result__icon {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.search-result__main { flex: 1; min-width: 0; }
.search-result__title { font-size: 13px; font-weight: 500; }
.search-result__meta { font-size: 11px; color: var(--text-muted); }
.search-result__entity {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--bg-card);
  border-radius: 4px;
}
.search-modal__empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ========== Flash messages ========== */
.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid;
}
.flash--success { background: rgba(34,197,94,0.08); color: #22C55E; border-color: rgba(34,197,94,0.3); }
.flash--error { background: var(--primary-soft); color: var(--primary); border-color: rgba(225,29,72,0.3); }

/* ========== Login ========== */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-brand__logo {
  width: 64px; height: 64px;
  border-radius: 14px;
  margin: 0 auto 12px;
  display: block;
  object-fit: cover;
}
.login-brand__title { font-size: 20px; font-weight: 700; }
.login-brand__subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ========== Misc ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state__icon { font-size: 42px; margin-bottom: 12px; }

.linked-mini-table { width: 100%; font-size: 13px; }
.linked-mini-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.linked-mini-table tr:last-child td { border-bottom: none; }
.linked-mini-table .actions { width: 1px; white-space: nowrap; }

/* Embed preview de anexos */
.anexo-embed {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 12px 0;
}
.anexo-embed iframe, .anexo-embed video, .anexo-embed img {
  width: 100%;
  border: none;
  display: block;
}
.anexo-embed iframe { height: 460px; }

/* Galeria de anexos (vários arquivos): miniaturas em cima, 1 aberto por vez */
.anexo-galeria { margin: 14px 0; }
.anexo-galeria__thumbs {
  display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.anexo-thumb {
  flex: 0 0 auto; width: 116px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-card); padding: 8px; cursor: pointer; display: flex; flex-direction: column;
  gap: 6px; align-items: center; text-align: center; transition: border-color .15s, box-shadow .15s;
}
.anexo-thumb:hover { border-color: var(--text-dim); }
.anexo-thumb.is-active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.anexo-thumb__preview {
  width: 100%; height: 64px; display: flex; align-items: center; justify-content: center;
  overflow: hidden; border-radius: 6px; background: var(--bg);
}
.anexo-thumb__preview img { width: 100%; height: 100%; object-fit: cover; }
.anexo-thumb__ic { font-size: 30px; line-height: 1; }
.anexo-thumb__nome {
  font-size: 11px; color: var(--text-muted); width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Stats dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card__label {
  font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  font-weight: 600;
}
.stat-card__value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card__icon { float: right; font-size: 22px; opacity: 0.6; }

/* Visualizadores embed quad */
.entity-toolbar {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.entity-toolbar .codigo {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
}

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .form-row { grid-template-columns: 1fr; }
}

/* ===== Quill editor — adapta cores ao tema ===== */
/* O wrap inteiro vira um "campo" cinza, destacado do fundo da página */
.quill-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.quill-wrap .ql-toolbar.ql-snow {
  background: var(--bg-elevated);
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
}
.quill-wrap .ql-container.ql-snow {
  border: none;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-card);
  border-radius: 0 0 8px 8px;
}
.quill-wrap .ql-editor {
  min-height: 280px;
  /* Altura limitada: o campo ocupa quase toda a tela mas não cresce infinito —
     textos grandes rolam DENTRO do campo (igual à descrição curta). */
  max-height: calc(100vh - 340px);
  overflow-y: auto;
  color: var(--text);
  background: var(--bg-card);
  border-radius: 0 0 8px 8px;
}
.quill-wrap .ql-editor.ql-blank::before {
  color: var(--text-dim);
  font-style: normal;
}
/* dark mode: inverte botões da toolbar */
[data-tema="dark"] .quill-wrap .ql-stroke { stroke: var(--text-muted); }
[data-tema="dark"] .quill-wrap .ql-fill { fill: var(--text-muted); }
[data-tema="dark"] .quill-wrap .ql-picker-label { color: var(--text-muted); }
[data-tema="dark"] .quill-wrap .ql-toolbar button:hover .ql-stroke,
[data-tema="dark"] .quill-wrap .ql-toolbar button.ql-active .ql-stroke,
[data-tema="dark"] .quill-wrap .ql-toolbar .ql-picker-label:hover { color: var(--text); }
[data-tema="dark"] .quill-wrap .ql-toolbar button:hover .ql-stroke,
[data-tema="dark"] .quill-wrap .ql-toolbar button.ql-active .ql-stroke { stroke: var(--primary); }
[data-tema="dark"] .quill-wrap .ql-toolbar button:hover .ql-fill,
[data-tema="dark"] .quill-wrap .ql-toolbar button.ql-active .ql-fill { fill: var(--primary); }
[data-tema="dark"] .quill-wrap .ql-snow .ql-picker-options {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}
[data-tema="dark"] .quill-wrap a { color: var(--accent); }
/* Popover de link/url do Quill — fix de corte e cores no dark */
.quill-wrap .ql-tooltip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 200;
  white-space: nowrap;
  padding: 6px 10px;
}
.quill-wrap .ql-tooltip input[type=text] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 8px;
  width: 240px;
  font-size: 13px;
}
.quill-wrap .ql-tooltip a.ql-action,
.quill-wrap .ql-tooltip a.ql-remove,
.quill-wrap .ql-tooltip a.ql-preview {
  color: var(--accent);
  margin-left: 6px;
  font-weight: 500;
}
/* Garante que o tooltip não fique cortado pelo overflow do form */
.form-group, form { overflow: visible !important; }
.quill-wrap { position: relative; overflow: visible; }
.quill-wrap .ql-container { overflow: visible; }
.quill-wrap .ql-editor { overflow-x: auto; }
.quill-wrap .ql-editor h1 { font-size: 1.7em; margin: 0.6em 0 0.3em; font-weight: 700; }
.quill-wrap .ql-editor h2 { font-size: 1.4em; margin: 0.6em 0 0.3em; font-weight: 600; }
.quill-wrap .ql-editor h3 { font-size: 1.2em; margin: 0.6em 0 0.3em; font-weight: 600; }
.quill-wrap .ql-editor blockquote {
  border-left: 3px solid var(--primary);
  padding: 4px 14px;
  color: var(--text-muted);
  margin: 10px 0;
}
/* Pincel "copiar formatação" ativo (classe própria — o Quill reseta a ql-active) */
.quill-wrap .ql-toolbar button.ql-format-painter.quad-painter-on { background: var(--primary-soft); border-radius: 4px; }
.quill-wrap .ql-toolbar button.ql-format-painter.quad-painter-on .ql-stroke { stroke: var(--primary); }
.quill-wrap .ql-toolbar button.ql-format-painter.quad-painter-on .ql-fill { fill: var(--primary); }
.quill-wrap .ql-toolbar button.ql-format-painter.quad-painter-sticky { box-shadow: inset 0 0 0 1.5px var(--primary); }
/* Botão "Desvincular" no popup de seleção (item já vinculado) — verde, fica vermelho ao passar o mouse */
.vinc-btn.is-vinculado { color: #16a34a; border-color: #16a34a; background: transparent; }
.vinc-btn.is-vinculado::before { content: '✓ '; }
.vinc-btn.is-vinculado:hover { color: #dc2626; border-color: #dc2626; background: rgba(239,68,68,.10); }
.quill-wrap .ql-editor pre.ql-syntax {
  background: var(--bg-card);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'SF Mono', Menlo, monospace;
}

/* ===== Ações da barra de entidade: só ícone + tooltip instantâneo ===== */
.entity-toolbar form { display: inline-flex; }
.icon-action {
  position: relative;
  width: 34px; height: 34px;
  padding: 0;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.icon-action::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0s;
  z-index: 60;
}
.icon-action:hover::after { opacity: 1; }
.icon-action svg { display: block; }
.btn--icon svg { width: 15px; height: 15px; display: block; }

/* ===== Tutorial do dashboard (com Mostrar mais / menos) ===== */
.tutorial { position: relative; overflow: hidden; font-size: 13px; line-height: 1.6; color: var(--text); }
.tutorial.is-collapsed { max-height: 360px; }
.tutorial.is-collapsed::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0; height: 70px;
  background: linear-gradient(to bottom, transparent, var(--bg-elevated));
  pointer-events: none;
}
.tutorial__h { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--text); }
.tutorial__list { margin: 0 0 12px; padding-left: 18px; }
.tutorial__list li { margin: 6px 0; }
.tutorial kbd {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: inherit;
}
.tutorial__more { margin-top: 10px; text-align: center; }

/* Nomes/títulos clicáveis nas listagens: cor neutra (não azul de link) */
.table tbody a[data-popup]:not(.btn) {
  color: var(--text);
  font-weight: 600;
}
.table tbody a[data-popup]:not(.btn):hover {
  color: var(--primary);
  text-decoration: none;
}
/* Nomes não-clicáveis (listas de config) — mesmo peso/cor dos clicáveis */
.table tbody .cell-nome { font-weight: 600; color: var(--text); }

/* ===== Botão Exportar com menu (PDF / DOCX) ===== */
.export-dd { position: relative; display: inline-flex; }
.export-dd__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 168px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.export-dd__menu[hidden] { display: none !important; }
.export-dd__menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}
.export-dd__menu a:hover { background: var(--bg-hover); text-decoration: none; }

/* ========== Central de notificações (sininho) ========== */
.notif { position: relative; display: inline-flex; }
.notif__badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}
.notif__panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 360px; max-width: 92vw;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
  z-index: 80; overflow: hidden;
}
.notif__panel[hidden] { display: none !important; }
.notif__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.notif__list { max-height: 380px; overflow-y: auto; }
.notif__item {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 11px 14px; border-bottom: 1px solid var(--border-soft);
}
.notif__item:last-child { border-bottom: none; }
.notif__item.is-unread { background: var(--primary-soft); }
.notif__item-main { flex: 1; min-width: 0; text-decoration: none; color: var(--text); display: block; }
.notif__item-main:hover { text-decoration: none; }
.notif__item-main:hover .notif__item-title { color: var(--primary); }
.notif__item-title { font-size: 13px; font-weight: 600; }
.notif__item-msg { font-size: 12px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.notif__item-time { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.notif__item-read {
  flex-shrink: 0; background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); width: 24px; height: 24px; border-radius: 6px;
  cursor: pointer; font-size: 12px; line-height: 1;
}
.notif__item-read:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-muted); }
.notif__empty { padding: 22px 14px; text-align: center; color: var(--text-muted); font-size: 13px; }
.notif__all {
  display: block; text-align: center; padding: 9px; font-size: 12px;
  border-top: 1px solid var(--border); color: var(--accent); text-decoration: none;
}
.notif__all:hover { background: var(--bg-hover); text-decoration: none; }

/* Rótulo de seção na busca global (ex.: "Nos conteúdos") */
.search-group-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 12px 16px 5px; border-top: 1px solid var(--border-soft);
}

/* ========== Checkboxes interativos por usuário (conteúdo de POP/Playbook) ========== */
.detail-content li[data-list="checked"],
.detail-content li[data-list="unchecked"] {
  list-style: none;
  position: relative;
  cursor: pointer;
  padding-left: 28px;
  margin-left: 0;
}
.detail-content li[data-list="checked"]::marker,
.detail-content li[data-list="unchecked"]::marker { content: ''; }
.detail-content li[data-list] > .ql-ui { display: none; }   /* artefato do Quill, escondido fora do editor */
.detail-content li[data-list="checked"]::before,
.detail-content li[data-list="unchecked"]::before {
  content: '';
  position: absolute; left: 0; top: 3px;
  width: 17px; height: 17px;
  border: 1.5px solid var(--text-muted);
  border-radius: 4px;
  box-sizing: border-box;
  transition: background .12s, border-color .12s;
}
.detail-content li[data-list="unchecked"]:hover::before { border-color: var(--primary); }
.detail-content li[data-list="checked"]::before {
  background: var(--primary);
  border-color: var(--primary);
}
.detail-content li[data-list="checked"]::after {
  content: '✓';
  position: absolute; left: 3px; top: 2px;
  color: #fff; font-size: 12px; font-weight: 700; line-height: 17px;
  pointer-events: none;
}
.detail-content li[data-list="checked"] { color: var(--text-muted); }   /* sem tachado ao marcar */

/* Listas: o Quill 2 salva tudo num <ol> com <li data-list="..."> (flat + classes ql-indent-N).
   A numeração usa COUNTER que só conta itens "ordered" — assim um bullet/check no meio NÃO
   empurra a contagem (antes a lista começava no "2" por causa do bullet anterior). Espelha o editor. */
.detail-content ol { counter-reset: list-0 list-1 list-2 list-3 list-4 list-5; }
.detail-content li[data-list="bullet"], .detail-content li[data-list="ordered"] { list-style: none; }
.detail-content li[data-list="bullet"]::before, .detail-content li[data-list="ordered"]::before { margin-right: 0.5em; color: var(--text-muted); }
.detail-content li[data-list="bullet"]::before { content: '\2022'; }
.detail-content li[data-list="ordered"] { counter-increment: list-0; counter-reset: list-1 list-2 list-3 list-4 list-5; }
.detail-content li[data-list="ordered"]::before { content: counter(list-0, decimal) '.'; }
.detail-content li[data-list="ordered"].ql-indent-1 { counter-increment: list-1; counter-reset: list-2 list-3 list-4 list-5; }
.detail-content li[data-list="ordered"].ql-indent-1::before { content: counter(list-1, lower-alpha) '.'; }
.detail-content li[data-list="ordered"].ql-indent-2 { counter-increment: list-2; counter-reset: list-3 list-4 list-5; }
.detail-content li[data-list="ordered"].ql-indent-2::before { content: counter(list-2, lower-roman) '.'; }
.detail-content li[data-list="ordered"].ql-indent-3 { counter-increment: list-3; counter-reset: list-4 list-5; }
.detail-content li[data-list="ordered"].ql-indent-3::before { content: counter(list-3, decimal) '.'; }
.detail-content li[data-list="ordered"].ql-indent-4 { counter-increment: list-4; counter-reset: list-5; }
.detail-content li[data-list="ordered"].ql-indent-4::before { content: counter(list-4, lower-alpha) '.'; }
