:root {
  --bm-red: #8b0000;
  --bm-red-light: #b22222;
  --bm-dark: #1a1a2e;
  --bm-navy: #16213e;
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #1f2937;
  --text-muted: #6b7280;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* HEADER */
header {
  background: linear-gradient(135deg, var(--bm-dark), var(--bm-red));
  color: white; padding: 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
}
.header-logo { display: flex; align-items: center; gap: 14px; }
.logo-img { width: 56px; height: 56px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4)); }
.logo-title { font-size: 20px; font-weight: 700; letter-spacing: 1px; }
.logo-sub { font-size: 12px; opacity: 0.85; }
.header-actions { display: flex; gap: 8px; }

/* NAV */
nav {
  background: var(--bm-navy); padding: 0 24px;
  display: flex; gap: 4px; overflow-x: auto;
}
.nav-btn {
  background: none; border: none; color: rgba(255,255,255,0.65);
  padding: 12px 20px; cursor: pointer; font-size: 14px;
  border-bottom: 3px solid transparent; transition: all 0.2s; white-space: nowrap;
}
.nav-btn:hover { color: white; }
.nav-btn.active { color: white; border-bottom-color: var(--bm-red-light); }

/* MAIN */
main { padding: 24px; max-width: 1280px; margin: 0 auto; padding-bottom: 80px; }
.section { display: none; }
.section.active { display: block; }

/* CARDS */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: var(--text); }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* STAT CARDS */
.stat-card { text-align: center; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--bm-red); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* BUTTONS */
.btn {
  padding: 8px 16px; border-radius: var(--radius); border: none;
  cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--bm-red); color: white; }
.btn-primary:hover { background: var(--bm-red-light); }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: white; }
.btn-outline:hover { background: rgba(255,255,255,0.1); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-success { background: var(--success); color: white; }

/* FORMS */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; color: var(--text);
  transition: border 0.2s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--bm-red);
}
.form-row { display: grid; gap: 12px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* TABLE */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead tr { background: var(--bm-dark); color: white; }
th { padding: 10px 12px; text-align: left; font-weight: 500; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: #f9fafb; }

/* BADGES */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 500;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-gray { background: #f3f4f6; color: #6b7280; }

/* MODAL */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 100;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white; border-radius: var(--radius); width: 560px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal.modal-largo { width: 820px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-header button { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
#modal-body { padding: 20px; }

/* CALENDÁRIO */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day-name {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--text-muted); padding: 8px 0;
}
.cal-day {
  min-height: 80px; background: white; border: 1px solid var(--border);
  border-radius: 4px; padding: 6px; position: relative;
}
.cal-day.outro-mes { background: #f9fafb; }
.cal-day.hoje { border-color: var(--bm-red); }
.cal-day-num { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cal-day.hoje .cal-day-num { color: var(--bm-red); }
.cal-event {
  font-size: 11px; background: var(--bm-red); color: white;
  border-radius: 3px; padding: 1px 4px; margin-bottom: 2px;
  cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.cal-event.municipal { background: var(--info); }

/* PAGE HEADER */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 20px; font-weight: 700; }

/* FILTROS */
.filtros { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filtros input, .filtros select { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }

/* TOTAIS */
.total-bar { display: flex; gap: 20px; background: var(--bm-dark); color: white; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.total-bar strong { color: #fcd34d; }

/* GRÁFICOS */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100% !important; }
.chart-pizza-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.chart-pizza-wrap canvas { flex-shrink: 0; }

.chart-legenda { display: flex; gap: 16px; margin-bottom: 10px; }
.leg-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.leg-cor { display: inline-block; width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }

.pizza-legenda { flex: 1; min-width: 140px; }
.pizza-leg-item { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.pizza-leg-item strong { margin-left: auto; color: var(--text); }

/* ALERTAS DE JORNADA */
.alerta-jornada {
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px;
  font-size: 13px; line-height: 1.5;
}
.alerta-jornada a { font-weight: 600; margin-left: 6px; }
.alerta-warn  { background: #fffbeb; border: 1px solid #f59e0b; color: #92400e; }
.alerta-warn a { color: #b45309; }
.alerta-danger { background: #fef2f2; border: 1px solid #ef4444; color: #991b1b; }
.alerta-danger a { color: #b91c1c; }

/* FOOTER DA APLICAÇÃO */
.app-footer {
  background: var(--bm-dark); color: rgba(255,255,255,0.5);
  font-size: 12px; padding: 10px 24px;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 6px;
}
.footer-autoria { display: flex; align-items: center; gap: 4px; }
.footer-autoria strong { color: rgba(255,255,255,0.8); }
.app-footer a { color: #fbbf24; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* RODAPÉ DE IMPRESSÃO */
.rodape-impressao {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  text-align: center; font-size: 11px; color: #555;
  padding: 6px; border-top: 1px solid #ccc;
  background: white;
}

/* TOUR GUIADO */
.tour-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  z-index: 200; display: flex; align-items: center; justify-content: center;
}
.tour-card {
  background: white; border-radius: 12px; width: 520px; max-width: 95vw;
  padding: 28px; box-shadow: 0 24px 80px rgba(0,0,0,0.4);
  animation: tour-in .25s ease;
}
@keyframes tour-in { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tour-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tour-passo { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.tour-fechar { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 0; }
.tour-titulo { font-size: 20px; font-weight: 700; color: var(--bm-red); margin-bottom: 12px; }
.tour-texto { font-size: 14px; line-height: 1.7; color: var(--text); }
.tour-dots { display: flex; gap: 6px; justify-content: center; margin: 20px 0 16px; }
.tour-dot { width: 8px; height: 8px; border-radius: 50%; background: #d1d5db; transition: background .2s; }
.tour-dot.ativo { background: var(--bm-red); width: 20px; border-radius: 4px; }
.tour-acoes { display: flex; justify-content: space-between; align-items: center; }

/* CENTRAL DE AJUDA */
.ajuda-wrap { display: flex; gap: 0; min-height: 360px; }
.ajuda-menu {
  width: 160px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding-right: 12px; margin-right: 16px; display: flex; flex-direction: column; gap: 4px;
}
.ajuda-menu-item {
  background: none; border: none; text-align: left; padding: 8px 10px;
  border-radius: var(--radius); font-size: 13px; cursor: pointer; color: var(--text);
  transition: background .15s;
}
.ajuda-menu-item:hover { background: #f3f4f6; }
.ajuda-menu-item.ativo { background: #fee2e2; color: var(--bm-red); font-weight: 600; }
.ajuda-conteudo { flex: 1; }
.ajuda-topico {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 8px; overflow: hidden; cursor: pointer;
}
.ajuda-q {
  display: flex; align-items: flex-start; gap: 8px; padding: 11px 14px;
  font-size: 13px; font-weight: 500; background: #f9fafb; user-select: none;
}
.ajuda-seta { margin-left: auto; color: var(--text-muted); transition: transform .2s; }
.ajuda-topico.aberto .ajuda-seta { transform: rotate(90deg); }
.ajuda-r { display: none; padding: 12px 14px; font-size: 13px; line-height: 1.7; color: var(--text); border-top: 1px solid var(--border); }
.ajuda-topico.aberto .ajuda-r { display: block; }
.tip-verde { color: var(--success); font-weight: 600; }
.tip-amarelo { color: var(--warning); font-weight: 600; }
.tip-vermelho { color: var(--danger); font-weight: 600; }

/* BOTÃO FLUTUANTE */
.btn-ajuda-flutuante {
  position: fixed; bottom: 56px; right: 20px; z-index: 90;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--bm-red); color: white; border: none;
  font-size: 20px; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: transform .2s, box-shadow .2s;
}
.btn-ajuda-flutuante:hover { transform: scale(1.1); box-shadow: 0 6px 20px rgba(0,0,0,0.35); }

@media (max-width: 768px) {
  .ajuda-menu { width: 120px; }
  .ajuda-menu-item { font-size: 12px; padding: 7px 8px; }
}
@media (max-width: 540px) {
  .ajuda-wrap { flex-direction: column; }
  .ajuda-menu { width: 100%; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); padding: 0 0 10px; margin: 0 0 14px; }
}

/* PRINT */
@media print {
  @page {
    margin: 1.5cm;
    @bottom-center {
      content: "NÚCLEO DE CANARANA — " counter(page) "/" counter(pages);
      font-size: 10pt;
      color: #555;
    }
    @bottom-left { content: none; }
    @bottom-right { content: none; }
  }
  header, nav, .page-header button, .filtros, .btn, .no-print { display: none !important; }
  .rodape-impressao { display: block; }
  main { padding: 0; max-width: 100%; }
  .card { box-shadow: none; }
  table { font-size: 11px; }
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .form-row.cols-3, .form-row.cols-2 { grid-template-columns: 1fr; }
  .chart-pizza-wrap { flex-direction: column; align-items: flex-start; }
  .chart-pizza-wrap canvas { width: 100% !important; max-width: 220px; }
  .pizza-legenda { width: 100%; }
  .app-footer { flex-direction: column; gap: 4px; text-align: center; }
  .footer-autoria { flex-wrap: wrap; justify-content: center; }
  .total-bar { flex-wrap: wrap; gap: 8px; }
  .modal.modal-largo { width: 98vw; }
}

@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  nav { padding: 0 8px; }
  .nav-btn { padding: 10px 12px; font-size: 13px; }
  .stat-value { font-size: 22px; }
}
