/* =========================================================================
   Layout: shell da aplicação (sidebar + header + conteúdo) e telas de acesso
   ========================================================================= */

/* ---------- Shell ---------- */
.shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.conteudo {
  flex: 1;
  padding: 26px;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  width: var(--side-largura);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--side-bg);
  color: var(--side-txt);
  border-right: 1px solid var(--side-bd);
  transition: width var(--t-lenta) var(--ease), transform var(--t-lenta) var(--ease);
  z-index: 40;
}

.sidebar-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 14px 14px 18px;
}

.sidebar-marca {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #fff;
}

.sidebar-marca:hover { text-decoration: none; }
.sidebar-marca img { height: 30px; width: auto; }

.sidebar-marca span {
  font-family: var(--fonte-display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--side-mut);
  white-space: nowrap;
}

.sidebar-recolher {
  background: none;
  border: none;
  color: var(--side-mut);
  padding: 6px;
  border-radius: var(--r-sm);
  transition: background var(--t) ease, color var(--t) ease, transform var(--t-lenta) var(--ease);
}

.sidebar-recolher:hover { background: var(--side-hover); color: #fff; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--side-txt);
  transition: background var(--t-rapida) ease, color var(--t-rapida) ease;
  white-space: nowrap;
}

.nav-item:hover { background: var(--side-hover); color: #fff; text-decoration: none; }

.nav-item.ativo {
  background: var(--side-ativo-bg);
  color: var(--side-ativo-txt);
  font-weight: 600;
}

.nav-item .nav-texto { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.nav-fase {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.1);
  color: var(--side-mut);
}

.nav-grupo { margin-top: 4px; }

.nav-grupo summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--side-mut);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-rapida) ease, color var(--t-rapida) ease;
}

.nav-grupo summary::-webkit-details-marker { display: none; }
.nav-grupo summary:hover { background: var(--side-hover); color: #fff; }
.nav-grupo summary .nav-texto { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-grupo summary .chevron { transition: transform var(--t) var(--ease); }
.nav-grupo[open] summary .chevron { transform: rotate(180deg); }
.nav-grupo-itens { display: flex; flex-direction: column; gap: 2px; padding: 2px 0 4px 8px; }

.sidebar-rodape {
  border-top: 1px solid var(--side-bd);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Sidebar recolhida (desktop): só ícones */
.shell[data-sidebar="recolhida"] .sidebar { width: var(--side-recolhida); }
.shell[data-sidebar="recolhida"] .sidebar .nav-texto,
.shell[data-sidebar="recolhida"] .sidebar .nav-fase,
.shell[data-sidebar="recolhida"] .sidebar .chevron,
.shell[data-sidebar="recolhida"] .sidebar-marca span,
.shell[data-sidebar="recolhida"] .nav-grupo-itens { display: none; }
.shell[data-sidebar="recolhida"] .sidebar-topo { flex-direction: column; padding: 16px 10px 10px; }
.shell[data-sidebar="recolhida"] .sidebar-marca img { height: 22px; }
.shell[data-sidebar="recolhida"] .sidebar-recolher { transform: rotate(180deg); }
.shell[data-sidebar="recolhida"] .nav-item,
.shell[data-sidebar="recolhida"] .nav-grupo summary { justify-content: center; padding: 10px; }

.sidebar-fundo { display: none; }

/* ---------- Header ---------- */
.topo {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-altura);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--surf) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--bd);
}

.topo .topo-menu { display: none; }

.topo-titulo {
  flex: 1;
  min-width: 0;
  font-size: 18px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topo-acoes { display: flex; align-items: center; gap: 4px; }

/* "Sair" direto no topo (como no sistema antigo), além do menu do avatar. */
.topo-sair { display: flex; }

/* Instalar aplicativo: some dentro do app instalado (o app.js cobre o iOS, que usa navigator.standalone). */
@media (display-mode: standalone) {
  .topo-instalar { display: none; }
}

.instalar-passos { display: flex; flex-direction: column; gap: 16px; font-size: 14px; }
.instalar-passos .negrito { margin-bottom: 4px; }
.instalar-passos .icone { vertical-align: -3px; }

.topo-sino { position: relative; }

.topo-sino .contador {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--critico);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.topo-usuario {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 6px;
  padding: 3px;
  background: none;
  border: none;
  border-radius: var(--r-pill);
}

.topo-usuario:hover .avatar { box-shadow: 0 0 0 3px var(--acc-suave); }

/* Alternância de ícone de tema/valores conforme o estado */
.so-claro,
.so-escuro { display: none; }
[data-theme="claro"] .so-escuro,
[data-theme="escuro"] .so-claro { display: block; }
[data-theme="sistema"] .so-escuro { display: block; }
@media (prefers-color-scheme: dark) {
  [data-theme="sistema"] .so-escuro { display: none; }
  [data-theme="sistema"] .so-claro { display: block; }
}
.so-visivel,
.so-oculto { display: none; }
[data-valores="visiveis"] .so-visivel,
[data-valores="ocultos"] .so-oculto { display: block; }

/* Logo por tema (texto escuro no claro, texto branco no escuro) */
.logo-tema-escuro { display: none; }
[data-theme="escuro"] .logo-tema-claro { display: none; }
[data-theme="escuro"] .logo-tema-escuro { display: block; }
@media (prefers-color-scheme: dark) {
  [data-theme="sistema"] .logo-tema-claro { display: none; }
  [data-theme="sistema"] .logo-tema-escuro { display: block; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, var(--side-largura));
    transform: translateX(-100%);
    box-shadow: var(--sombra-menu);
  }

  .shell[data-sidebar] .sidebar { width: min(86vw, var(--side-largura)); }
  .shell[data-sidebar] .sidebar .nav-texto,
  .shell[data-sidebar] .sidebar .nav-fase,
  .shell[data-sidebar] .sidebar .chevron,
  .shell[data-sidebar] .sidebar-marca span { display: initial; }
  .shell[data-sidebar] .nav-grupo[open] .nav-grupo-itens { display: flex; }
  .shell[data-sidebar] .nav-item,
  .shell[data-sidebar] .nav-grupo summary { justify-content: flex-start; padding: 9px 12px; }
  .shell[data-sidebar] .sidebar-topo { flex-direction: row; padding: 18px 14px 14px 18px; }
  .sidebar-recolher { display: none; }

  .shell.sidebar-aberta .sidebar { transform: none; }

  .shell.sidebar-aberta .sidebar-fundo {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 35;
  }

  .topo { padding: 0 14px; padding-top: env(safe-area-inset-top); height: calc(var(--header-altura) + env(safe-area-inset-top)); }
  .topo .topo-menu { display: inline-flex; }
  .topo-titulo { font-size: 16px; }
  .conteudo { padding: 16px; }
}

@media (max-width: 520px) {
  .topo-acoes .opcional-mobile { display: none; }
}

/* ---------- Telas de acesso (login Lumen: card flutuante com glow) ---------- */
.acesso {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--acc) 9%, transparent), transparent 60%), var(--bg);
}

.acesso::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--bd-forte) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.5;
  pointer-events: none;
}

.acesso-glow {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: 620px;
  max-width: 100vw;
  height: 380px;
  background: radial-gradient(ellipse, color-mix(in srgb, var(--acc) 24%, transparent), transparent 70%);
  filter: blur(24px);
  pointer-events: none;
}

.acesso-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surf);
  border: 1px solid var(--bd);
  border-radius: var(--r-2xl);
  padding: 38px;
  box-shadow: var(--sombra-glow);
  animation: flutuar 5s ease-in-out infinite;
}

@keyframes flutuar {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

.acesso-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.acesso-logo img { height: 44px; width: auto; }
.acesso-card h1 { font-size: 24px; text-align: center; }
.acesso-sub { color: var(--mut); font-size: 14px; margin-top: 6px; text-align: center; }
.acesso-form { margin-top: 8px; }
.acesso-linha { display: flex; align-items: center; justify-content: space-between; margin: 16px 0; font-size: 13px; }
.acesso-rodape { margin-top: 22px; text-align: center; font-size: 12px; color: var(--mut); }

@media (max-width: 480px) {
  .acesso-card { padding: 28px 22px; animation: none; }
}

/* ---------- Páginas de erro ---------- */
.erro-pagina { text-align: center; max-width: 440px; }
.erro-codigo {
  font-family: var(--fonte-display);
  font-size: 72px;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: var(--gradiente-marca);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
