:root {
  --azul: #1f564f;
  --azul-med: #2a7b71;
  --azul-claro: #e7f1ed;
  --verde: #1A7A4F;
  --verde-claro: #D5F5E3;
  --amarelo: #B7950B;
  --amarelo-claro: #FEF9E7;
  --vermelho: #922B21;
  --vermelho-claro: #FADBD8;
  --cinza: #F4F6F9;
  --cinza-med: #E8ECF0;
  --cinza-texto: #6B7280;
  --texto: #1C2B3A;
  --branco: #FFFFFF;
  --sombra: 0 2px 12px rgba(26,79,122,0.10);
  --sombra-forte: 0 8px 32px rgba(26,79,122,0.18);
  --border: #DDE3EA;
  --sidebar-w: 260px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter Tight', sans-serif; background: var(--cinza); color: var(--texto); min-height: 100vh; }

/* ── LOGIN: estilos migrados para index.html (shell v4 / nova identidade) ── */

/* ── APP LAYOUT ── */
#app { display: none; min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }

/* SIDEBAR — handoff (branca, ícones SVG, hover translateX + inset shadow) */
.sidebar {
  width: var(--sidebar-w); background: #fff;
  border-right: 1px solid var(--ink-200, #e2e8f0);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; overflow-y: auto;
  transition: transform 0.3s;
}
.sidebar-header { padding: 16px; border-bottom: 1px solid var(--ink-200, #e2e8f0); }
.sidebar-header .logo { display: flex; align-items: center; gap: 10px; }
.sidebar-header .logo-glyph {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--teal-600, #1f564f); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.sidebar-header .logo-wordmark { font-size: 15px; font-weight: 700; color: var(--ink-900, #0f172a); letter-spacing: -0.02em; line-height: 1.1; }
.sidebar-header .logo-wordmark span { color: var(--teal-600, #1f564f); }
.sidebar-header .logo-subtitle { font-size: 10px; color: var(--ink-500, #64748b); font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; margin-top: 2px; }

/* Compat: estrutura antiga .sidebar-logo remapeada para visual branco */
.sidebar-logo { padding: 16px; border-bottom: 1px solid var(--ink-200, #e2e8f0); }
.sidebar-logo-top { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-icon { width: 32px; height: 32px; flex-shrink: 0; background: var(--teal-600, #1f564f); color: #fff; border-radius: 8px; display: grid; place-items: center; font-size: 16px; overflow: hidden; }
.sidebar-logo-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-logo-name { font-family: 'Inter Tight', sans-serif; font-weight: 700; color: var(--ink-900, #0f172a); font-size: 15px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.02em; }
.sidebar-municipio { font-size: 11px; color: var(--ink-500, #64748b); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.sidebar-populacao { font-size: 10px; color: var(--ink-500, #64748b); margin-top: 1px; }

.sidebar-muni {
  margin: 12px; padding: 8px 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--ink-50, #f4f6f9); border: 1px solid var(--ink-200, #e2e8f0);
  border-radius: 6px; cursor: pointer; text-align: left;
  font-family: inherit;
}
.sidebar-muni-avatar {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--teal-100, #ccddd8); color: var(--teal-700, #174239);
  display: grid; place-items: center; font-weight: 700; font-size: 11px; flex-shrink: 0;
}
.sidebar-muni-name { font-size: 13px; font-weight: 600; color: var(--ink-900, #0f172a); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-muni-meta { font-size: 11px; color: var(--ink-500, #64748b); }

.sidebar-nav { flex: 1; overflow: auto; padding: 4px 8px 16px; }

.sidebar-section-label, .sidebar-section {
  padding: 4px 8px; margin-top: 14px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-500, #64748b);
  background: transparent;
}

.sidebar-item, .nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; margin: 2px 0; border-radius: 6px;
  color: var(--ink-700, #334155); font-weight: 500; font-size: 13px;
  cursor: pointer; text-decoration: none;
  transition: background 180ms ease,
              color 180ms ease,
              transform 240ms cubic-bezier(.34,1.56,.64,1),
              box-shadow 180ms ease;
  will-change: transform;
}
.sidebar-item:hover, .nav-item:hover {
  background: var(--teal-50, #e7f1ed);
  color: var(--teal-700, #174239);
  transform: translateX(3px);
  box-shadow: inset 2px 0 0 var(--teal-400, #3e8a80), 0 2px 6px rgba(31,86,79,0.08);
}
.sidebar-item.active, .nav-item.active {
  background: var(--teal-50, #e7f1ed);
  color: var(--teal-700, #174239);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--teal-600, #1f564f);
}

.sidebar-item .ic, .nav-item .ic {
  width: 16px; height: 16px; flex-shrink: 0;
  stroke: currentColor; fill: none; stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar-item .icon, .nav-item .icon { width: 16px; text-align: center; font-size: 14px; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--red-solid, #dc2626); color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
}

.sidebar-footer, .sidebar-user {
  margin-top: auto;
  padding: 12px; border-top: 1px solid var(--ink-200, #e2e8f0);
  display: flex; align-items: center; gap: 10px;
}
.avatar-circle, .user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--teal-600, #1f564f); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--ink-900, #0f172a); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--ink-500, #64748b); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-logout, .btn-logout-sb {
  color: var(--ink-500, #64748b);
  background: none; border: none;
  font-size: 14px; cursor: pointer; padding: 6px;
  border-radius: 6px; transition: color 0.2s, background 0.2s;
  display: grid; place-items: center;
}
.btn-logout:hover, .btn-logout-sb:hover {
  color: var(--red-fg, #dc2626);
  background: var(--red-bg, #fee2e2);
}

/* MAIN */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

.topbar {
  background: white; padding: 0 28px; height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50;
  box-shadow: var(--sombra);
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--texto); }
.topbar-sub { font-size: 12px; color: var(--cinza-texto); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-btn {
  padding: 8px 18px; border-radius: 8px; font-size: 13px;
  font-weight: 600; cursor: pointer; font-family: 'Inter Tight', sans-serif;
  border: none; transition: all 0.18s;
}
.btn-primary { background: var(--azul); color: white; }
.btn-primary:hover { background: var(--azul-med); }
.btn-secondary { background: var(--cinza-med); color: var(--texto); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--verde); color: white; }
.btn-danger-outline { background: transparent; color: var(--vermelho); border: 1.5px solid var(--vermelho); }

.content { padding: 28px; flex: 1; }

/* CARDS */
.card {
  background: white; border-radius: 14px; box-shadow: var(--sombra);
  border: 1px solid var(--border); overflow: hidden;
}
.card-header {
  padding: 18px 22px; border-bottom: 1px solid var(--cinza-med);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 15px; font-weight: 700; color: var(--texto); }
.card-body { padding: 22px; }

/* STAT CARDS */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white; border-radius: 14px; padding: 20px 22px;
  border: 1px solid var(--border); box-shadow: var(--sombra);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.stat-card.azul::before { background: var(--azul); }
.stat-card.verde::before { background: var(--verde); }
.stat-card.amarelo::before { background: var(--amarelo); }
.stat-card.vermelho::before { background: var(--vermelho); }
.stat-icon { font-size: 28px; margin-bottom: 12px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--texto); line-height: 1; }
.stat-label { font-size: 12px; color: var(--cinza-texto); margin-top: 4px; }
.stat-change { font-size: 12px; margin-top: 8px; font-weight: 600; }
.stat-change.up { color: var(--verde); }
.stat-change.down { color: var(--vermelho); }

/* GRID LAYOUTS */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* TABLES */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { background: var(--cinza); padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700; color: var(--cinza-texto); letter-spacing: 0.05em; text-transform: uppercase; border-bottom: 1px solid var(--border); }
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--cinza-med); color: var(--texto); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFBFC; }

/* BADGES */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-verde { background: var(--verde-claro); color: var(--verde); }
.badge-amarelo { background: var(--amarelo-claro); color: var(--amarelo); }
.badge-vermelho { background: var(--vermelho-claro); color: var(--vermelho); }
.badge-azul { background: var(--azul-claro); color: var(--azul); }
.badge-cinza { background: var(--cinza-med); color: var(--cinza-texto); }

/* PROGRESS */
.progress-bar { height: 6px; background: var(--cinza-med); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.6s; }
.fill-verde { background: var(--verde); }
.fill-azul { background: var(--azul-med); }
.fill-amarelo { background: var(--amarelo); }
.fill-vermelho { background: var(--vermelho); }
.fill-cinza { background: var(--cinza-texto); }

/* FORMS */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-row.single { grid-template-columns: 1fr; }
.form-row.triple { grid-template-columns: 1fr 1fr 1fr; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--cinza-texto); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 13.5px; font-family: 'Inter Tight', sans-serif;
  color: var(--texto); background: var(--cinza); outline: none; transition: border-color 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--azul-med); background: white; }
.field textarea { resize: vertical; min-height: 80px; }

/* PAGES */
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ALERT / NOTIFICATION */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.alert-info { background: var(--azul-claro); color: var(--azul); border-left: 4px solid var(--azul-med); }
.alert-success { background: var(--verde-claro); color: var(--verde); border-left: 4px solid var(--verde); }
.alert-warn { background: var(--amarelo-claro); color: var(--amarelo); border-left: 4px solid var(--amarelo); }
.alert-danger { background: var(--vermelho-claro); color: var(--vermelho); border-left: 4px solid var(--vermelho); }

/* CHART FAKE */
.chart-bar-group { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 0 4px; }
.chart-bar-wrap { display: flex; flex-direction: column; align-items: center; flex: 1; gap: 3px; justify-content: flex-end; }
.chart-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-label { font-size: 10px; color: var(--cinza-texto); }
.chart-axis { display: flex; justify-content: space-between; padding: 4px 4px 0; }

/* TIMELINE */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: var(--cinza-med); }
.tl-item { position: relative; margin-bottom: 20px; }
.tl-dot { position: absolute; left: -24px; top: 2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid white; box-shadow: 0 0 0 2px currentColor; }
.tl-dot.verde { color: var(--verde); background: var(--verde); }
.tl-dot.amarelo { color: var(--amarelo); background: var(--amarelo); }
.tl-dot.cinza { color: var(--cinza-med); background: var(--cinza-med); }
.tl-title { font-size: 13.5px; font-weight: 600; color: var(--texto); }
.tl-meta { font-size: 11px; color: var(--cinza-texto); margin-top: 2px; }

/* MODAL */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 16px; padding: 28px; width: 600px; max-height: 85vh; overflow-y: auto; box-shadow: var(--sombra-forte); animation: fadeUp 0.25s ease; }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 20px; color: var(--texto); display: flex; align-items: center; gap: 8px; }
.modal-footer { margin-top: 24px; display: flex; gap: 10px; justify-content: flex-end; }

/* SECTION HEADER */
.sec-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.sec-title { font-size: 22px; font-weight: 700; color: var(--texto); }
.sec-sub { font-size: 13px; color: var(--cinza-texto); margin-top: 2px; }
.breadcrumb { font-size: 12px; color: var(--cinza-texto); margin-bottom: 6px; }
.breadcrumb span { color: var(--azul-med); }

/* TABS */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--cinza-med); margin-bottom: 24px; }
.tab { padding: 10px 18px; font-size: 13.5px; font-weight: 600; color: var(--cinza-texto); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.18s; }
.tab.active { color: var(--azul); border-bottom-color: var(--azul); }
.tab:hover:not(.active) { color: var(--texto); }

/* INDICADOR CARD */
.ind-card { padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: white; }
.ind-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.ind-vals { display: flex; justify-content: space-between; font-size: 12px; color: var(--cinza-texto); margin-bottom: 6px; }
.ind-num { font-size: 20px; font-weight: 700; }

/* ACTION BUTTONS */
.action-btns { display: flex; gap: 8px; }
.icon-btn { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: white; cursor: pointer; font-size: 14px; transition: all 0.18s; }
.icon-btn:hover { background: var(--cinza); }

/* STEP WIZARD */
.steps { display: flex; align-items: center; margin-bottom: 28px; }
.step { display: flex; align-items: center; gap: 8px; }
.step-num { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.step.done .step-num { background: var(--verde); color: white; }
.step.active .step-num { background: var(--azul); color: white; }
.step.pending .step-num { background: var(--cinza-med); color: var(--cinza-texto); }
.step-label { font-size: 12px; font-weight: 600; }
.step.active .step-label { color: var(--azul); }
.step.done .step-label { color: var(--verde); }
.step.pending .step-label { color: var(--cinza-texto); }
.step-line { flex: 1; height: 2px; background: var(--cinza-med); margin: 0 8px; }
.step-line.done { background: var(--verde); }

/* TOOLTIP CHIP */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; background: var(--cinza); border-radius: 6px; font-size: 11px; color: var(--cinza-texto); }

/* RESPONSIVE helpers */
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--cinza-texto); }
.font-bold { font-weight: 700; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
/* ── Admin / utilitários ── */
@keyframes spin{to{transform:rotate(360deg)}}
.maa-tab{flex:1;padding:11px 8px;font-size:13px;font-weight:600;border:none;background:none;cursor:pointer;color:#64748b;border-bottom:2px solid transparent;transition:color .15s}
.maa-tab:hover{color:#0f172a}
.maa-tab-active{color:#1f564f;border-bottom-color:#1f564f}

/* ── Acessibilidade: screen-reader only ── */
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);clip-path:inset(50%);white-space:nowrap;border:0}

/* ── Responsividade: grids em telas menores ── */
@media (max-width: 1000px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
.content { overflow-x: hidden; }

/* ── Elementos ocultos por padrão (necessário pois CSP bloqueia style="display:none") ── */
#tela-2fa { display: none; }
#ls-error { display: none; }
#ls-error-2fa { display: none; }
#ls-rec-step2 { display: none; }
#modal-lgpd-aceite { display: none; }
#modal-2fa-setup { display: none; }
#ls-form-rec { display: none; }
#2fa-passo-qr { display: none; }
#2fa-passo-backup { display: none; }
#2fa-passo-desativar { display: none; }
#2fa-passo-ativo { display: none; }
#2fa-passo-inativo { display: none; }
#2fa-confirm-erro { display: none; }
#2fa-desativar-erro { display: none; }

/* ── ACESSIBILIDADE: Focus ring visível para navegação por teclado (WCAG 2.1 AA) ── */
:focus-visible {
  outline: 3px solid var(--azul-med);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) {
  outline: none;
}

/* ── RESPONSIVIDADE: Hamburger oculto no desktop ── */
#btn-sidebar-toggle { display: none; }

/* ── RESPONSIVIDADE: Sidebar mobile ── */
@media (max-width: 768px) {
  /* Sidebar oculta por padrão, desliza da esquerda */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }
  /* Sidebar aberta quando JS adiciona classe .open */
  .sidebar.open {
    transform: translateX(0);
  }
  /* Conteúdo principal sem margem lateral em mobile */
  .main {
    margin-left: 0;
  }
  /* Botão hamburger visível em mobile */
  #btn-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  /* Overlay escuro quando sidebar está aberta */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
  }
  #sidebar-overlay.open {
    display: block;
  }
}

/* ── ACESSIBILIDADE: Respeitar preferência de movimento reduzido ── */
@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
  .nav-item,
  .btn-primary,
  .btn-secondary,
  .btn-success {
    transition: none;
  }
}
