/* Esqueleto do sistema: menu lateral e barra superior (computador) ou barra
   superior e barra inferior (celular). Carregado por último; o restante das
   telas vive em base.css e workspace.css. */

.app-shell { --lateral: 252px; --topo-h: 60px; --tabbar-h: 62px; }
.app-shell { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }

/* ---------- Marca ---------- */
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--ink); font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em;
  text-decoration: none; min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark { flex: none; }

/* ---------- Menu lateral (só computador) ---------- */
.sidebar { display: none; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-grupo {
  margin: 1.25rem 0 0.3rem 0.75rem; color: var(--ink-faint);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
}
.nav-grupo:first-child { margin-top: 0; }
.nav a {
  display: flex; align-items: center; gap: 0.7rem; min-height: 40px;
  padding: 0.5rem 0.75rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: 0.93rem; font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.icone { flex: none; }

.sidebar-rodape { margin-top: auto; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.sidebar-rodape .menu-usuario > summary { width: 100%; box-sizing: border-box; justify-content: flex-start; }
.sidebar-rodape .user-name { flex: 1; }
.sidebar-rodape .chevron { margin-left: auto; }
.sidebar-rodape .menu-painel { left: 0; right: auto; top: auto; bottom: calc(100% + 8px); min-width: 100%; width: max-content; max-width: 320px; box-sizing: border-box; }

/* Contador (ex.: quantos itens em "Cobrar hoje") */
.selo {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 22px; height: 22px; margin-left: auto; padding: 0 7px; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--on-accent);
  font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* ---------- Barra superior ---------- */
.topo {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 0.25rem;
  height: var(--topo-h); padding: 0 0.75rem 0 1rem;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand--topo { margin-right: auto; }
.topo-acoes { display: flex; align-items: center; gap: 0.25rem; }
.topo-busca {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: var(--radius-sm); color: var(--ink-soft);
}
.topo-busca:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }

/* Campo de busca (computador) */
.busca {
  display: none; align-items: center; gap: 0.6rem;
  flex: 0 1 440px; margin-right: auto; height: 40px; padding: 0 0.75rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--ink-faint);
}
.busca:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.busca input[type=search] {
  flex: 1; min-width: 0; width: auto; height: 100%; min-height: 0; padding: 0; margin: 0;
  border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: none;
  color: var(--ink); font: inherit; font-size: 0.93rem;
}
.busca input[type=search]::placeholder { color: var(--ink-faint); }
.busca-atalho {
  flex: none; padding: 1px 7px; border: 1px solid var(--line-strong); border-radius: 5px;
  background: var(--surface-2); color: var(--ink-faint); font: inherit; font-size: 0.75rem; line-height: 1.5;
}
.busca:focus-within .busca-atalho { display: none; }

/* ---------- Menus suspensos (usuário e "Mais") ---------- */
.menu-pop { position: relative; }
.menu-pop > summary { list-style: none; cursor: pointer; }
.menu-pop > summary::-webkit-details-marker { display: none; }
.menu-usuario > summary {
  display: flex; align-items: center; gap: 0.5rem; min-height: 40px;
  padding: 0.2rem 0.5rem 0.2rem 0.3rem; border-radius: var(--radius-sm); color: var(--ink-soft);
}
.menu-usuario > summary:hover, .menu-usuario[open] > summary { background: var(--surface-2); }
.user-avatar {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-wash); color: var(--accent-ink); font-size: 0.8rem; font-weight: 700;
}
.user-name { display: none; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-size: 0.9rem; }
.chevron { flex: none; transition: transform 0.15s ease; }
.menu-usuario[open] .chevron { transform: rotate(180deg); }
.menu-painel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; min-width: 230px; width: max-content; max-width: min(92vw, 360px); padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--raise-hover);
}
.menu-quem { display: grid; gap: 2px; margin-bottom: 6px; padding: 0.6rem 0.7rem 0.7rem; border-bottom: 1px solid var(--line); }
.menu-quem strong { font-size: 0.92rem; }
/* O e-mail não pode quebrar no meio ("...gmail.co" / "m"): o painel cresce até
   caber, e só e-mails enormes quebram (depois de @, ., _ ou -). */
.menu-quem span { color: var(--ink-faint); font-size: 0.8rem; overflow-wrap: break-word; word-break: normal; }
.menu-item {
  display: flex; align-items: center; gap: 0.65rem; width: 100%; min-height: 42px; padding: 0.5rem 0.7rem;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink);
  font: inherit; font-size: 0.92rem; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item .icone { color: var(--ink-faint); }
/* Itens do card de notificações, por gravidade: vermelho = quebrado/ação já, âmbar = atenção. */
.menu-item--erro { background: var(--critical-wash); }
.menu-item--erro .icone { color: var(--critical-ink); }
.menu-item--aviso { background: var(--amber-wash); }
.menu-item--aviso .icone { color: var(--amber-ink); }
.menu-item--erro:hover { background: color-mix(in srgb, var(--critical-wash) 82%, var(--critical)); }
.menu-item--aviso:hover { background: color-mix(in srgb, var(--amber-wash) 82%, var(--amber)); }
.menu-notificacoes .menu-item + .menu-item { margin-top: 0.3rem; }

/* ---------- Barra inferior (celular) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar > a, .tabbar summary {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; color: var(--ink-faint); font-size: 0.68rem; font-weight: 500; text-decoration: none;
}
.tabbar > a:hover { text-decoration: none; }
.tabbar .active { color: var(--accent-ink); font-weight: 600; }
.tabbar .active .icone { stroke-width: 2.2; }
.tabbar .menu-mais { display: flex; }
.tabbar .menu-mais > summary { flex: 1; }
.tabbar .menu-mais .menu-painel { top: auto; bottom: calc(100% + 8px); right: 8px; }
.selo--tab { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; margin: 0; padding: 0 5px; font-size: 0.65rem; }

/* ---------- Conteúdo ---------- */
.app-shell .wrap { max-width: 1280px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.app-shell .wrap.wrap--wide { max-width: 1440px; }

/* Busca como página (celular): campo grande no topo dos resultados. */
.busca-pagina { display: flex; gap: 0.5rem; margin: 0 0 1.25rem; }
.busca-pagina input[type=search] { flex: 1; min-width: 0; }
.resultado-grupo { margin: 1.5rem 0 0.5rem; }
.resultado-grupo small { color: var(--ink-faint); font-weight: 400; font-size: 0.85rem; }

@media (min-width: 640px) {
  .user-name { display: inline; }
  .topo { padding: 0 1.25rem; }
  .app-shell .wrap { padding: 1.75rem 1.5rem 3rem; }
}

@media (min-width: 1024px) {
  .app-shell { padding-left: var(--lateral); padding-bottom: 0; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 25; display: flex; flex-direction: column; gap: 1.75rem;
    width: var(--lateral); padding: 1.25rem 1rem; overflow-y: auto; scrollbar-width: none;
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .sidebar .brand { padding: 0.25rem 0.5rem; }
  .brand--topo, .topo-busca, .tabbar, .menu-usuario--topo { display: none; }
  .busca { display: flex; }
  .topo { padding: 0 2rem; gap: 1rem; }
  .app-shell .wrap { padding: 2rem 2rem 4rem; }
  .busca-pagina { display: none; }
}

@media print {
  .sidebar, .topo, .tabbar { display: none !important; }
  .app-shell { padding: 0; }
  .app-shell .wrap { max-width: none; padding: 0; }
}

/* ---------- Sugestões da busca ---------- */
.busca { position: relative; }
.busca-sugestoes {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 45;
  max-height: min(70vh, 460px); overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--raise-hover);
}
.busca-sugestoes[hidden] { display: none; }
.busca-grupo {
  padding: 0.55rem 0.7rem 0.25rem; color: var(--ink-faint);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
}
.busca-item {
  display: flex; flex-direction: column; gap: 1px; padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm); color: var(--ink); text-decoration: none;
}
.busca-item:hover, .busca-item.ativo { background: var(--accent-wash); text-decoration: none; }
.busca-item-titulo { font-size: 0.93rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busca-item-detalhe { color: var(--ink-faint); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busca-todos { margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-sm) var(--radius-sm); color: var(--accent-ink); font-size: 0.88rem; font-weight: 600; }
.busca-vazio { padding: 0.9rem 0.7rem; color: var(--ink-faint); font-size: 0.9rem; }

.selo--alerta, .selo--bloqueio { background: var(--critical); color: #fff; }
.report-filter .form-row[hidden] { display: none; }
.report-filter-erro { border-left-width: 1px; margin: 0.75rem 0 1.25rem; }

/* ---------- Seletor de período (relatórios) ---------- */
.report-filter { display: block; position: relative; }
.periodo { display: inline-block; max-width: 100%; }
/* Garante que o pop-up do calendário fique acima do conteúdo que vem depois. */
.report-filter { z-index: 20; }
.periodo-botao {
  display: inline-flex; align-items: center; gap: 0.6rem;
  min-height: var(--tap); padding: 0 0.9rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; font-weight: 500; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.periodo-botao:hover, .periodo-botao[aria-expanded="true"] { border-color: var(--accent); }
.periodo-botao[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--accent-wash); }
.periodo-botao svg { flex: none; color: var(--ink-faint); }
.periodo-rotulo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.periodo-pop {
  position: absolute; z-index: 30; top: calc(100% - 0.6rem); left: 1.25rem; right: 1.25rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 18px 44px rgb(17 24 39 / 18%), 0 2px 6px rgb(17 24 39 / 8%);
  animation: periodo-entra .14s ease-out;
  user-select: none;
}
@keyframes periodo-entra { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .periodo-pop { animation: none; } }
.periodo-pop[hidden] { display: none; }
.periodo-corpo { display: grid; grid-template-columns: 1fr; }
.periodo-atalhos {
  display: flex; gap: 0.4rem; overflow-x: auto; padding: 0.75rem;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.periodo-atalho {
  display: inline-flex; align-items: center; gap: 0.5rem; flex: none;
  padding: 0.4rem 0.8rem; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-pill);
  font: inherit; font-size: 0.88rem; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.periodo-atalho:hover { border-color: var(--line-strong); }
.periodo-atalho[aria-checked="true"] { border-color: var(--accent); background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.periodo-radio { display: none; flex: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); box-sizing: border-box; transition: border .12s; }
.periodo-atalho[aria-checked="true"] .periodo-radio { border: 5px solid var(--accent); }
.periodo-cal { padding: 0.7rem 0.8rem 0.4rem; min-width: 0; max-width: 280px; }
.periodo-nav { display: flex; align-items: flex-start; gap: 0.2rem; }
.periodo-meses { flex: 1; display: grid; grid-template-columns: 1fr; gap: 1rem; min-width: 0; }
.periodo-meses .periodo-mes:nth-child(2) { display: none; }
.periodo-seta {
  flex: none; width: 28px; height: 28px; font-size: 1.3rem; line-height: 1; padding: 0 0 2px;
  background: transparent; color: var(--ink-soft); border: 0; border-radius: 50%; cursor: pointer;
  transition: background .12s, color .12s;
}
.periodo-seta:hover { background: var(--accent-wash); color: var(--accent-ink); }
.periodo-mes-titulo { text-align: center; font-weight: 600; font-size: 0.85rem; text-transform: capitalize; margin: 0.15rem 0 0.4rem; }
.periodo-grade { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; }
.periodo-dow { text-align: center; font-size: 0.65rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-faint); padding: 0 0 0.25rem; }
.periodo-dia {
  position: relative; isolation: isolate; height: 30px; padding: 0;
  background: transparent; color: var(--ink); border: 0; border-radius: 0;
  font: inherit; font-size: 0.82rem; font-variant-numeric: tabular-nums; cursor: pointer;
}
.periodo-dia::before {
  content: ""; position: absolute; z-index: -1; inset: 0 calc(50% - 15px);
  border-radius: 8px; transition: background .1s;
}
.periodo-dia.fds { color: var(--ink-soft); }
.periodo-dia:hover::before { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.periodo-dia.hoje::after {
  content: ""; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px;
  margin-left: -2px; border-radius: 50%; background: var(--accent);
}
/* faixa contínua do intervalo: mesma altura do círculo, pontas de pílula
   no começo/fim de cada linha da semana */
.periodo-dia.no-periodo, .periodo-dia.previa { background: var(--accent-wash); }
.periodo-dia.ini-semana.no-periodo, .periodo-dia.ini-semana.previa { border-radius: 8px 0 0 8px; }
.periodo-dia.fim-semana.no-periodo, .periodo-dia.fim-semana.previa { border-radius: 0 8px 8px 0; }
.periodo-dia.ini-semana.fim-semana.no-periodo { border-radius: 8px; }
.periodo-dia.no-periodo:hover::before, .periodo-dia.previa:hover::before { background: var(--accent-wash); box-shadow: inset 0 0 0 1px var(--accent); }
/* pontas: quadrado arredondado cheio + meia faixa do lado do intervalo */
.periodo-dia.ponta { color: var(--on-accent); font-weight: 600; }
.periodo-dia.ponta::before, .periodo-dia.ponta:hover::before { background: var(--accent); box-shadow: none; }
.periodo-dia.ponta.hoje::after { background: var(--on-accent); }
.periodo-dia.ponta-ini:not(.ponta-fim) { background: linear-gradient(to right, transparent 50%, var(--accent-wash) 50%); }
.periodo-dia.ponta-fim:not(.ponta-ini) { background: linear-gradient(to left, transparent 50%, var(--accent-wash) 50%); }
.periodo-dia.ponta-ini.ponta-fim { background: transparent; }
.periodo-rodape {
  display: grid; gap: 0.5rem; padding: 0.6rem 0.8rem 0.7rem;
  border-top: 1px solid var(--line); background: var(--surface);
}
.periodo-resumo { font-size: 0.8rem; color: var(--ink-soft); }
.periodo-resumo strong { color: var(--ink); font-weight: 600; }
.periodo-campos { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.periodo-campos label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--ink-faint); }
.periodo-campos input { min-height: 34px; }
.periodo-acoes { display: flex; gap: 0.5rem; justify-content: flex-end; }
@media (min-width: 720px) {
  .periodo { position: relative; }
  .periodo-pop { top: calc(100% + 0.5rem); left: 0; right: auto; width: 460px; }
  .periodo-corpo { grid-template-columns: 150px 1fr; }
  .periodo-atalhos { flex-direction: column; overflow: visible; border-bottom: 0; border-right: 1px solid var(--line); padding: 0.6rem 0.4rem; gap: 1px; max-height: 280px; overflow-y: auto; }
  .periodo-atalho { background: transparent; border: 0; border-radius: var(--radius-sm); padding: 0.4rem 0.55rem; font-size: 0.82rem; }
  .periodo-atalho:hover { background: var(--surface); }
  .periodo-atalho[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--raise); }
  .periodo-radio { display: inline-block; width: 13px; height: 13px; }
  .periodo-rodape { grid-template-columns: 1fr auto; align-items: center; }
  .periodo-resumo { grid-column: 1 / -1; }
}

/* ---------- Ícones em cores, uma cor por seção ----------
   Dia a dia = azul · Cadastros = roxo · Conexões = verde · Análise = laranja.
   Todos os ícones de uma seção têm a mesma cor, na mesma intensidade (nível
   600 no tema claro, 400 no escuro). Vale no menu (lateral, barra de baixo e
   "Mais") e no título das páginas; botões e o resto do sistema seguem com a
   cor do texto. Vermelho fica reservado a alertas. */
.app-shell {
  --ic-assistente: #2563eb; --ic-inicio: #2563eb; --ic-cobrar: #2563eb; --ic-proximas: #2563eb; --ic-bloqueio: #2563eb; --ic-pix: #2563eb; --ic-historico: #2563eb; --ic-whatsapp: #2563eb;
  --ic-clientes: #7c3aed; --ic-contratos: #7c3aed; --ic-aparelhos: #7c3aed;
  --ic-conexoes: #059669;
  --ic-relatorios: #ea580c; --ic-juros: #ea580c; --ic-financeiro: #ea580c;
}
:root[data-tema="escuro"] .app-shell {
  --ic-assistente: #60a5fa; --ic-inicio: #60a5fa; --ic-cobrar: #60a5fa; --ic-proximas: #60a5fa; --ic-bloqueio: #60a5fa; --ic-pix: #60a5fa; --ic-historico: #60a5fa; --ic-whatsapp: #60a5fa;
  --ic-clientes: #a78bfa; --ic-contratos: #a78bfa; --ic-aparelhos: #a78bfa;
  --ic-conexoes: #34d399;
  --ic-relatorios: #fb923c; --ic-juros: #fb923c; --ic-financeiro: #fb923c;
}
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="inicio"] { color: var(--ic-inicio); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="cobrar"] { color: var(--ic-cobrar); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="assistente"] { color: var(--ic-assistente); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="proximas"] { color: var(--ic-proximas); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="bloqueio"] { color: var(--ic-bloqueio); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="pix"] { color: var(--ic-pix); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="historico"] { color: var(--ic-historico); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="whatsapp"] { color: var(--ic-whatsapp); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="clientes"] { color: var(--ic-clientes); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="contratos"] { color: var(--ic-contratos); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="aparelhos"] { color: var(--ic-aparelhos); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="conexoes"] { color: var(--ic-conexoes); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="relatorios"] { color: var(--ic-relatorios); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="juros"] { color: var(--ic-juros); }
:is(.sidebar .nav, .tabbar, .menu-mais .menu-painel, h1) .icone[data-icone="financeiro"] { color: var(--ic-financeiro); }
.sidebar .nav a.active .icone, .tabbar a.active .icone { stroke-width: 2.2; }
/* Menu lateral: ícones maiores, para ocupar melhor a barra. */
.sidebar .nav a { gap: 0.85rem; min-height: 44px; }
.sidebar .nav a .icone { width: 24px; height: 24px; }
/* Sem barra de rolagem no menu lateral: em telas baixas ele se compacta para caber; se ainda faltar, rola com a roda do mouse. */
.sidebar::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) and (max-height: 1040px) {
  .sidebar { gap: 1rem; padding-block: 1rem; }
  .sidebar .nav a { min-height: 40px; }
  .sidebar .nav-grupo { margin-top: 0.9rem; }
}

/* Ícone antes do título da página */
h1 > .icone { width: 1.05em; height: 1.05em; margin-right: 0.45rem; vertical-align: -0.1em; stroke-width: 2; }

/* "Sair": no hover, fundo vermelho suave (translúcido) e texto/ícone em vermelho. */
.menu-item--sair:hover, .menu-item--sair:focus-visible {
  background: color-mix(in srgb, var(--critical) 14%, transparent);
  color: var(--critical-ink);
}
.menu-item--sair:hover .icone, .menu-item--sair:focus-visible .icone { color: var(--critical-ink); }

/* ───────────── Menu lateral recolhível + movimento (computador) ───────────── */
.lateral-toggle { display: none; }

@media (min-width: 1024px) {
  .lateral-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 40px; height: 40px; border: 0; border-radius: var(--radius-sm); background: transparent;
    color: var(--ink-soft); cursor: pointer;
  }
  .lateral-toggle:hover { background: var(--surface-2); color: var(--ink); }
  .lateral-toggle svg { transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
  :root[data-lateral="recolhida"] .lateral-toggle svg { transform: scaleX(-1); }

  .nav a { position: relative; }
  .nav-grupo { white-space: nowrap; }

  /* Recolhido: só os ícones (76 px). Tudo o que muda passa por uma transição. */
  :root[data-lateral="recolhida"] .app-shell { --lateral: 76px; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) { width: 76px; }
  /* Passou o mouse: abre por cima do conteúdo (a página não se mexe) e fecha de novo ao sair. */
  :root[data-lateral="recolhida"] .sidebar:is(:hover, :has(details[open])) { width: 252px; z-index: 40; box-shadow: 0 10px 30px rgb(0 0 0 / 14%); }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) { padding-inline: .75rem; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .brand { justify-content: center; gap: 0; padding-inline: 0; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .nav a { justify-content: center; gap: 0; padding-inline: 0; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .nav a > span:not(.selo):not(.sr-only),
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .brand-nome,
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .user-name,
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .chevron { max-width: 0; opacity: 0; margin: 0; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .nav-grupo {
    font-size: 0; height: 1px; margin: .7rem .6rem; padding: 0; background: var(--line); opacity: 1;
  }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .nav-grupo:first-child { display: none; }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .selo {
    position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; margin: 0; padding: 0 4px; font-size: .6rem;
  }
  :root[data-lateral="recolhida"] .sidebar:not(:hover):not(:has(details[open])) .sidebar-rodape .menu-usuario > summary { justify-content: center; gap: 0; padding-inline: 0; }

  /* A lateral e o conteúdo andam juntos, na mesma velocidade. */
  .sidebar, .app-shell { transition: width .3s cubic-bezier(.2, .8, .2, 1), padding-left .3s cubic-bezier(.2, .8, .2, 1), padding-inline .3s cubic-bezier(.2, .8, .2, 1); }
  .sidebar .nav a > span:not(.selo):not(.sr-only), .brand-nome, .sidebar .user-name, .sidebar .chevron {
    display: inline-block; max-width: 14rem; overflow: hidden; white-space: nowrap;
    transition: max-width .3s cubic-bezier(.2, .8, .2, 1), opacity .2s ease, margin .3s ease;
  }
  .sidebar .nav a, .sidebar .brand, .sidebar-rodape .menu-usuario > summary { transition: gap .3s ease, padding .3s ease, background-color .15s ease, color .15s ease; }
  .sidebar .nav-grupo { transition: font-size .2s ease, height .3s ease, margin .3s ease, background-color .3s ease; overflow: hidden; }
  .sidebar .selo { transition: top .3s ease, right .3s ease, min-width .3s ease, height .3s ease, padding .3s ease; }
}

@media (prefers-reduced-motion: no-preference) {
  /* Itens do menu: o ícone dá um leve "pulinho" e o item ativo ganha uma barra que desliza. */
  .nav a .icone { transition: transform .2s cubic-bezier(.2, .8, .2, 1), color .15s ease; }
  .nav a:hover .icone { transform: scale(1.12); }
  .nav a:active { transform: scale(.98); }
  /* A barrinha da página atual é uma só e desliza até o item novo (ver static/js/menu.js). */
  .nav-marcador { transition: transform .38s cubic-bezier(.3, 1.2, .4, 1), height .3s ease, opacity .2s ease; }
  .nav-marcador.sem-transicao { transition: none; }
  .selo { animation: selo-pop .35s cubic-bezier(.3, 1.6, .5, 1) backwards; }
  @keyframes selo-pop { from { transform: scale(0); } to { transform: scale(1); } }
  .menu-pop > .menu-painel { animation: menu-abre .18s cubic-bezier(.2, .8, .2, 1) both; transform-origin: bottom left; }
  @keyframes menu-abre { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
  .menu-pop .chevron { transition: transform .2s ease; }
  .menu-pop[open] .chevron { transform: rotate(180deg); }

  /* Entre uma página e outra (Chrome/Edge): o menu e a barra de cima ficam parados e só o conteúdo troca. */
  @view-transition { navigation: auto; }
  .sidebar { view-transition-name: lateral; }
  .topo { view-transition-name: topo; }
  ::view-transition-group(lateral), ::view-transition-group(topo) { animation-duration: 0s; }
  ::view-transition-old(root) { animation: vt-sai .14s ease-in both; }
  ::view-transition-new(root) { animation: vt-entra .22s ease-out both; }
  @keyframes vt-sai { to { opacity: 0; } }
  @keyframes vt-entra { from { opacity: 0; } }
}

/* O botão de recolher fica colado na borda do menu lateral; a busca continua alinhada ao conteúdo. */
@media (min-width: 1024px) {
  .topo { padding-left: .5rem; }
  .lateral-toggle { margin-right: .5rem; }
}

.nav { position: relative; }
.nav-marcador {
  position: absolute; left: -.5rem; top: 0; width: 3px; height: 20px; border-radius: 3px;
  background: var(--accent); opacity: 0; pointer-events: none; will-change: transform;
}
@media (min-width: 1024px) { .nav-marcador.visivel { opacity: 1; } }

/* ── Marca CellPage ── */
:root { --marca-1: #0a2a6b; --marca-2: #0a66ff; }
:root[data-tema="escuro"] { --marca-1: #a9c2f7; --marca-2: #4d94ff; }
.brand-nome { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-nome b { color: var(--marca-1); font-weight: inherit; }
.brand-nome i { color: var(--marca-2); font-style: normal; }
.brand-mark { transition: transform .35s cubic-bezier(.3, 1.4, .5, 1); }
.brand:hover .brand-mark { transform: rotate(-8deg) scale(1.06); }

/* ── Balão de ajuda: "Como funciona" e afins abrem um balão por cima da página, sem empurrar nada. ── */
details.balao { position: relative; display: inline-block; margin: 0 0 16px; font-size: 14px; }
details.balao > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  color: var(--accent-ink); font-weight: 500; border-radius: 6px;
}
details.balao > summary::-webkit-details-marker { display: none; }
details.balao > summary::before {
  content: "?"; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-wash); font-size: 12px; font-weight: 700;
}
details.balao > summary:hover { text-decoration: underline; }
details.balao > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.balao-conteudo {
  position: absolute; left: 0; top: calc(100% + 10px); z-index: 30; width: min(380px, calc(100vw - 32px));
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  box-shadow: var(--raise-hover); color: var(--ink-soft); line-height: 1.55; font-size: 14px;
}
.balao-conteudo--largo { width: min(520px, calc(100vw - 32px)); }
.balao-conteudo::before {
  content: ""; position: absolute; left: 18px; top: -7px; width: 12px; height: 12px; background: var(--surface);
  border-left: 1px solid var(--line); border-top: 1px solid var(--line); transform: rotate(45deg);
}
.balao-conteudo p { margin: 0; }
.balao-conteudo p + p { margin-top: 8px; }
@media (prefers-reduced-motion: no-preference) {
  details.balao[open] .balao-conteudo { animation: balao-abre .18s cubic-bezier(.2, .8, .2, 1); transform-origin: 24px 0; }
  @keyframes balao-abre { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
}
.balao-mais { display: inline-block; margin-top: 10px; font-weight: 600; color: var(--accent-ink); }
.balao-mais::after { content: " →"; }

/* Página de ajuda */
.ajuda { max-width: 760px; }
.ajuda-sub { margin: 6px 0 24px; color: var(--ink-soft); }
.ajuda-indice { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 28px; padding: 0; list-style: none; }
.ajuda-indice a { display: inline-block; padding: 6px 14px; border-radius: 999px; background: var(--accent-wash); color: var(--accent-ink); font-weight: 500; font-size: 14px; }
.ajuda-secao { margin: 0 0 20px; padding: 22px 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--raise); scroll-margin-top: calc(var(--topo-h) + 16px); }
.ajuda-secao:target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.ajuda-secao h2 { margin: 0 0 12px; padding: 0; border: 0; font-size: 19px; text-transform: none; letter-spacing: -.01em; color: var(--ink); }
.ajuda-secao h3 { margin: 18px 0 6px; font-size: 15px; color: var(--ink); }
.ajuda-secao p, .ajuda-secao li { color: var(--ink-soft); line-height: 1.6; }
.ajuda-secao p { margin: 0 0 10px; }
.ajuda-secao ul { margin: 0 0 10px; padding-left: 1.2rem; }
.ajuda-secao li + li { margin-top: 4px; }

/* ── Regra geral de espaço: telas mais compactas, sem vazios grandes. ──
   Vale para o sistema todo (este arquivo é carregado por último). Telas novas devem seguir estes valores. */
:root { --space-3: 1.25rem; --space-4: 1.5rem; --space-5: 2rem; }
.app-shell .wrap { max-width: 1360px; }
.app-shell .wrap.wrap--wide { max-width: 1600px; }
@media (min-width: 640px) { .app-shell .wrap { padding: 1.25rem 1.25rem 2.25rem; } }
@media (min-width: 1024px) { .app-shell .wrap { padding: 1.25rem 1.75rem 2.5rem; } }
h1 { margin-bottom: .75rem; }
h2 { margin: 1.4rem 0 .65rem; }
.card { margin: .75rem 0; padding: 1rem 1.15rem; }
.empty { padding: 1.5rem 1.25rem; gap: .5rem; }
.toolbar { margin-bottom: .65rem; }

/* Botão de ajuda na barra de cima, ao lado do tema */
.topo-ajuda {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: var(--radius-sm); color: var(--ink-soft);
}
.topo-ajuda:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topo-ajuda:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Balão aberto fica por cima dos cartões que vêm depois dele. */
details.balao[open] { z-index: 40; }

/* Ícone do título: centralizado na altura das letras (antes ficava 2px acima do texto). */
h1:has(> .icone) { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h1 > .icone { width: 1em; height: 1em; margin: 0; vertical-align: baseline; flex: none; }

/* Parcela atrasada na tela do contrato: juros e total a cobrar hoje abaixo do saldo. */
.parcela-juros { color: var(--critical-ink); font-size: .8rem; }
.parcela-total-hoje { font-size: .9rem; color: var(--ink); }
