:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e2e5e9;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-dark: #1f2937;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.55;
}

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

/* Topbar */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .logo img { display: block; height: 36px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions .admin-name { color: var(--color-text-muted); font-size: 13px; }

.search-form { display: flex; flex: 1; max-width: 480px; margin: 0 16px; }
.search-form input[type="text"] {
  flex: 1; padding: 9px 14px; border: 1px solid var(--color-border);
  border-radius: var(--radius) 0 0 var(--radius); font-size: 14px; outline: none;
}
.search-form input[type="text"]:focus { border-color: var(--color-primary); }
.search-form button {
  padding: 9px 16px; border: none; background: var(--color-primary); color: #fff;
  border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer; font-size: 14px;
}
.search-form button:hover { background: var(--color-primary-dark); }

.btn {
  display: inline-block; padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--color-border); background: var(--color-surface);
  color: var(--color-text); cursor: pointer; font-size: 14px;
}
.btn:hover { text-decoration: none; border-color: var(--color-primary); }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-danger { background: #fff; border-color: var(--color-danger); color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* App shell */
.app-shell { display: flex; min-height: calc(100vh - 58px); align-items: flex-start; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--color-surface);
  border-right: 1px solid var(--color-border); padding: 20px 0; min-height: calc(100vh - 58px);
}
.sidebar h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); padding: 0 20px; margin: 0 0 10px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar > ul > li { margin-bottom: 2px; }
.sidebar .cat-link {
  display: flex; align-items: center; padding: 9px 20px; color: var(--color-text);
  font-weight: 600; font-size: 14px; cursor: pointer; user-select: none;
}
.sidebar a.cat-link { justify-content: space-between; }
.sidebar .cat-link:hover, .sidebar .cat-link.active { background: #eef2ff; text-decoration: none; color: var(--color-primary); }
.sidebar .cat-link-row { flex: 1; display: flex; justify-content: space-between; align-items: center; }
.sidebar ul ul { padding-left: 12px; }
.sidebar ul ul a { font-weight: 400; padding: 7px 20px 7px 28px; font-size: 13.5px; }
.sidebar .count { color: var(--color-text-muted); font-weight: 400; font-size: 12px; }

/* Categorias com subcategorias (profundidade ilimitada) usando <details>/<summary>.
   Clicar em qualquer parte do nome (todo o "summary") expande/recolhe -
   nao ha link de navegacao aqui, so nas categorias de ultimo nivel. */
.sidebar details.cat-branch { margin-bottom: 2px; }
.sidebar details.cat-branch > summary { list-style: none; }
.sidebar details.cat-branch > summary::-webkit-details-marker { display: none; }
.sidebar details.cat-branch > summary.cat-link::before {
  content: '▸'; display: inline-block; width: 18px; text-align: center; flex-shrink: 0;
  color: var(--color-text-muted); font-size: 10px; transition: transform .15s ease;
}
.sidebar details.cat-branch[open] > summary.cat-link::before { transform: rotate(90deg); }
.sidebar details.cat-branch ul { padding-left: 16px; }
.sidebar details.cat-branch ul .cat-link { font-weight: 400; font-size: 13.5px; }
.sidebar details.cat-branch ul details.cat-branch > summary.cat-link { font-weight: 500; }

.main { flex: 1; padding: 28px 32px; min-width: 0; }

.page-title { margin: 0 0 6px; font-size: 22px; }
.page-subtitle { color: var(--color-text-muted); margin: 0 0 22px; font-size: 14px; }

/* Post cards */
.post-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.post-card h2 { margin: 0 0 6px; font-size: 17px; }
.post-card .meta { color: var(--color-text-muted); font-size: 12.5px; margin-bottom: 8px; }
.post-card p { margin: 0; color: #374151; }

.post-full {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 28px 32px; box-shadow: var(--shadow);
}
.post-full .meta { color: var(--color-text-muted); font-size: 13px; margin-bottom: 20px; border-bottom: 1px solid var(--color-border); padding-bottom: 16px; }
.post-content img { max-width: 100%; height: auto; }
.post-content table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.post-content table, .post-content th, .post-content td { border: 1px solid var(--color-border); }
.post-content th, .post-content td { padding: 8px 10px; text-align: left; }
.post-content pre { background: #f3f4f6; padding: 12px; border-radius: 6px; overflow-x: auto; }
.post-content blockquote { border-left: 4px solid var(--color-primary); margin: 12px 0; padding: 4px 16px; color: var(--color-text-muted); }

/* Linha de acoes do post (rodape): exportar para Word (qualquer pessoa
   logada) e editar post (so ADM) lado a lado */
.post-actions-row {
  margin-top: 24px; padding-top: 18px; border-top: 1px dashed var(--color-border);
  display: flex; gap: 10px; flex-wrap: wrap;
}

/* Aviso de pre-visualizacao (post ainda nao salvo) */
.preview-banner {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  padding: 10px 16px; border-radius: 6px; margin-bottom: 18px; font-weight: 600;
}

/* Feedback widget */
.feedback-box {
  margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--color-border);
}
.feedback-box .question { font-weight: 600; margin-bottom: 10px; }
.feedback-actions { display: flex; gap: 10px; }
.feedback-reason { display: none; margin-top: 14px; }
.feedback-reason textarea {
  width: 100%; min-height: 80px; padding: 10px; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-family: inherit; font-size: 14px; resize: vertical;
}
.feedback-thanks { color: var(--color-success); font-weight: 600; }

/* Tables (admin) */
table.data-table { width: 100%; border-collapse: collapse; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
table.data-table th, table.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--color-border); text-align: left; font-size: 13.5px; }
table.data-table th { background: #f9fafb; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; font-size: 11.5px; letter-spacing: .03em; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #fafbfc; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge-published { background: #dcfce7; color: #15803d; }
.badge-draft { background: #fef3c7; color: #b45309; }
.badge-useful { background: #dcfce7; color: #15803d; }
.badge-not-useful { background: #fee2e2; color: #b91c1c; }
.badge-role { background: #e5e7eb; color: #374151; }
.badge-admin { background: #dbeafe; color: #1d4ed8; }

/* Stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-tile .value { font-size: 26px; font-weight: 700; color: var(--color-dark); }
.stat-tile .label { color: var(--color-text-muted); font-size: 13px; margin-top: 2px; }

.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card h3 { margin-top: 0; font-size: 15px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13.5px; }
.form-group input[type="text"], .form-group input[type="password"], .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: 14px; font-family: inherit;
}
.form-group .hint { color: var(--color-text-muted); font-size: 12.5px; margin-top: 4px; }
.hint { color: var(--color-text-muted); font-size: 12.5px; }

/* Textarea de "Codigo HTML" no formulario de post (ver views/admin/post-form.ejs).
   E um textarea normal (onde a pessoa digita/cola), com uma copia colorida
   (destacando tags/atributos) exibida atras dele, alinhada pixel a pixel -
   por isso as duas caixas precisam ter exatamente a mesma fonte, tamanho,
   espacamento e borda. */
.html-code-wrap { position: relative; margin-top: 8px; }
.html-code-wrap .content-html-editor,
.html-code-wrap .content-html-highlight {
  min-height: 480px; font-family: Consolas, 'Courier New', monospace; font-size: 13.5px;
  line-height: 1.55; padding: 9px 12px; border: 1px solid var(--color-border); border-radius: var(--radius);
  white-space: pre-wrap; word-break: break-word; margin: 0; box-sizing: border-box;
}
.content-html-highlight {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  overflow: auto; background: #fff; color: var(--color-text); pointer-events: none;
}
.content-html-highlight code { font-family: inherit; white-space: inherit; word-break: inherit; }
.content-html-editor {
  position: relative; width: 100%; background: transparent; color: transparent; caret-color: #111827;
}
.content-html-editor::selection { background: #bfdbfe; color: transparent; }
.hl-tag { color: #1d4ed8; font-weight: 600; }
.hl-attr { color: #b45309; }
.hl-string { color: #15803d; }
.hl-comment { color: #6b7280; font-style: italic; }

/* Arrastar-e-soltar para reordenar categorias (tela "Gerenciar menu") */
.drag-handle { cursor: grab; color: var(--color-text-muted); margin-right: 6px; }
tbody.cat-block { cursor: grab; }
tbody.cat-block.dragging { opacity: .4; }
tbody.cat-block.drop-before tr.cat-row td { box-shadow: inset 0 2px 0 0 var(--color-primary); }
tbody.cat-block.drop-after tr.cat-row td { box-shadow: inset 0 -2px 0 0 var(--color-primary); }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.admin-shell { display: flex; align-items: flex-start; }
.admin-nav { width: 220px; flex-shrink: 0; background: var(--color-dark); min-height: calc(100vh - 58px); padding: 18px 0; }
.admin-nav a { display: block; padding: 10px 22px; color: #cbd5e1; font-size: 14px; }
.admin-nav a:hover, .admin-nav a.active { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.admin-main { flex: 1; padding: 28px 32px; min-width: 0; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--color-text-muted); }

.top-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }

.tag-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.tag-row a { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--color-border); font-size: 13px; color: var(--color-text); }
.tag-row a.active, .tag-row a:hover { background: var(--color-primary); color: #fff; border-color: var(--color-primary); text-decoration: none; }

footer.site-footer { text-align: center; padding: 20px; color: var(--color-text-muted); font-size: 12.5px; }

/* Tela inicial: quadro de recados (esquerda) + links rapidos (direita) */
.home-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 260px); gap: 16px; margin-bottom: 26px; align-items: start; max-width: 820px; }
.announcement-board, .quick-links-board { margin-bottom: 0; display: flex; flex-direction: column; }
/* O quadro de recados ocupa toda a largura da sua coluna (sem sobra de
   espaco entre ele e o Acesso rapido). Quem controla o tamanho do quadro
   agora e a largura da coluna do Acesso rapido ao lado, que fica entre
   180px e 260px - estreita o bastante pra poucos links, mas cresce um
   pouco sozinha se links com nomes maiores forem cadastrados. */
.announcement-board h3, .quick-links-board h3 { margin: 0 0 12px; font-size: 14px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .03em; }
.announcement-empty { color: var(--color-text-muted); font-size: 14px; padding: 30px 0; text-align: center; }

/* Formato fixo tipo banner (16:9) - nao estica mais para acompanhar a altura
   do quadro de acesso rapido ao lado. Tamanho de imagem recomendado: 1200x675px
   (ou qualquer imagem na proporcao 16:9); imagens fora dessa proporcao sao
   cortadas nas bordas (object-fit: cover) para preencher o retangulo sem
   distorcer. */
.announcement-slideshow { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #f3f4f6; }
.announcement-slide {
  position: absolute; inset: 0; margin: 0; opacity: 0; transition: opacity .6s ease;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; /* evita que um slide invisivel (empilhado por baixo) "roube"
                            o clique do link do slide ativo, que fica por cima dele */
}
.announcement-slide.active { opacity: 1; pointer-events: auto; }
.announcement-slide img { width: 100%; height: 100%; object-fit: cover; background: #111827; }
/* Quando a imagem do quadro de recados tem um link (opcional) associado */
.announcement-slide-link { position: absolute; inset: 0; display: block; cursor: pointer; }
.announcement-slide figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 14px; font-size: 13px;
  background: rgba(17,24,39,0.65); color: #fff;
}
.announcement-dots { position: absolute; bottom: 8px; right: 10px; display: flex; gap: 5px; z-index: 2; }
.announcement-dots .dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,0.55); cursor: pointer; }
.announcement-dots .dot.active { background: #fff; }

.announcement-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(17,24,39,0.45); color: #fff; font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.announcement-nav:hover { background: rgba(17,24,39,0.7); }
.announcement-nav.prev { left: 10px; }
.announcement-nav.next { right: 10px; }

.quick-links-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.quick-links-list li a {
  display: block; padding: 10px 12px; border-radius: 6px; color: var(--color-text); font-size: 14px; font-weight: 500;
}
.quick-links-list li a:hover { background: #eef2ff; color: var(--color-primary); text-decoration: none; }

@media (max-width: 860px) {
  .app-shell, .admin-shell { flex-direction: column; }
  .sidebar, .admin-nav { width: 100%; min-height: auto; border-right: none; border-bottom: 1px solid var(--color-border); }
  .main, .admin-main { padding: 20px; }
  .search-form { max-width: none; margin: 10px 0 0; width: 100%; }
  .home-top { grid-template-columns: 1fr; }
}

/* Modal simples (aviso central com botao OK) - usado, por exemplo, para
   mostrar erros de formulario sem depender do alert() nativo do navegador. */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal-box {
  background: var(--color-surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 360px; padding: 22px; text-align: center;
}
.modal-box p { margin: 0 0 18px; color: var(--color-text); font-size: 14.5px; line-height: 1.5; }
.modal-box .btn { min-width: 96px; }
