/*
  shell.css
  Layout autenticado do ERP: navegação lateral + área de conteúdo dos módulos.
*/

:root {
  color-scheme: light;

  --c-bg: #f7faf8;
  --c-surface: #ffffff;
  --c-primary: #070613;
  --c-primary-hover: #1c1b3a;
  --c-blue: #17408b;
  --c-gold: #f2b705;
  --c-ink: #16241d;
  --c-ink-muted: #5c6b62;
  --c-border: #dfe6e1;

  --font: 'Inter', system-ui, -apple-system, sans-serif;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;

  --radius: 10px;
  --sidebar-w: 248px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--c-ink);
  background: var(--c-bg);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  /* Altura fixa da janela: o conteúdo rola dentro do .shell__main e o menu (com o perfil no rodapé) nunca é empurrado para baixo. */
  height: 100vh;
  height: 100dvh;
}

/* Menu lateral na cor do tema (--c-primary: tema "Meia-noite" do SysproBR, fixo no portal), texto branco. */
.shell__sidebar {
  background: var(--c-primary);
  color: #fff;
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-height: 0;
  overflow: hidden;
}

.shell__sidebar > .shell__brand,
.shell__sidebar > .shell__session {
  flex: none;
}

/* O logo é preto com detalhes verdes: fica num cartão branco para não sumir no verde. */
.shell__brand {
  display: flex;
  justify-content: center;
  padding: var(--sp-3) var(--sp-2);
  border-radius: var(--radius);
  background: var(--c-surface);
  box-shadow: 0 2px 8px rgb(0 0 0 / 14%);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--c-primary);
}

.shell__brand-logo {
  display: block;
  width: 70%;
  height: auto;
}

/* Logo cadastrada pela empresa: formato livre, então ocupa mais largura e limita a altura. */
.shell__brand--org .shell__brand-logo {
  width: auto;
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}

.shell__brand-fallback[hidden] {
  display: none;
}

/* Em telas baixas só a lista de módulos rola; logo e perfil continuam visíveis. */
.shell__nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.shell__nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  color: #fff;
  text-decoration: none;
  font-size: 0.92rem;
  cursor: not-allowed;
  transition: background-color 140ms ease, color 140ms ease;
}

.shell__nav-icon {
  width: 1.25em;
  text-align: center;
  flex: none;
}

.shell__nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell__nav-item[data-enabled='true'] {
  color: #fff;
  cursor: pointer;
}

.shell__nav-item[data-enabled='true']:hover {
  background: rgb(255 255 255 / 14%);
}

.shell__nav-item:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Item ativo: texto branco, destacado por um fundo mais claro e um contorno fino. */
.shell__nav-item[aria-current='page'],
.shell__nav-item[aria-current='page']:hover {
  background: rgb(255 255 255 / 22%);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 40%);
}

.shell__nav-item[data-enabled='false'] {
  opacity: 0.6; /* "em breve": mesma cor branca, só apagado */
}

.shell__nav-item[data-enabled='false']::after {
  content: 'em breve';
  margin-left: auto;
  font-size: 0.7rem;
  color: #fff;
  background: rgb(255 255 255 / 12%);
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 999px;
  padding: 2px 8px;
}

.shell__main {
  padding: var(--sp-5);
  min-height: 0;
  overflow-y: auto;
}

/* Seção seguida de outra com título (legend): o título já traz a própria linha, então some a divisória de baixo para não ficar duas. */
fieldset[class*='__secao']:has(+ fieldset[class*='__secao'] > legend) {
  border-bottom: 0;
}

.shell__placeholder {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  color: var(--c-ink-muted);
}

/* Rodapé do menu (mesmo formato do Sentinel): botão único com avatar, nome e papel; abre o Perfil. */
.shell__session {
  margin-top: 0;
  padding-top: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  border-top: 1px solid rgb(255 255 255 / 22%);
  color: #fff;
}

.shell__session-perfil {
  flex: 1;
  min-width: 0;
  padding: var(--sp-1) var(--sp-2);
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.shell__session-perfil:hover {
  background: rgb(255 255 255 / 14%);
}

.shell__logout {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: #fff;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.shell__logout:hover {
  background: #c62828;
}

.shell__logout:disabled {
  cursor: wait;
  opacity: 0.65;
}

.shell__session-perfil:focus-visible,
.shell__logout:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.shell__session-avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--c-primary);
  font-size: 0.9rem;
  font-weight: 700;
}

.shell__session-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.1;
}

.shell__session-user {
  font-size: 0.85rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell__session-tag {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
}

/* Cabeçalhos de tabela sempre pretos (padrão de todas as listas). */
th {
  color: #000;
}

/* Aviso de 2FA exigido e ainda não ativado (js/shell/shell.js). */
.shell__aviso {
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid #f5d98b;
  border-radius: 7px;
  background: #fff8e1;
  color: #7a5b00;
  font-size: 13px;
}

.shell__aviso a {
  color: inherit;
  font-weight: 600;
}

/* Leitor só consulta: some o que cria, edita ou exclui (a API também recusa; ver shared/sessao.js). */
body[data-papel="LEITOR"] :is(
    [data-acao="nova"],
    [data-acao="novo"],
    [data-acao="novo-vazio"],
    [data-acao="nova-conta"],
    [data-acao="transferir"],
    [data-acao="importar"],
    [data-acao="incluir-item"],
    [data-acao="emitir"],
    [data-acao="editar"],
    [data-acao="excluir"]
  ) {
  display: none !important;
}

/* Barra superior e gaveta do menu: só existem no celular/tablet estreito. */
.shell__topbar,
.shell__backdrop {
  display: none;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .shell__topbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    background: var(--c-primary);
    color: #fff;
  }

  .shell__menu-toggle {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: var(--radius);
    background: rgb(255 255 255 / 14%);
    color: inherit;
    cursor: pointer;
  }

  .shell__topbar-titulo {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
  }

  .shell__sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1200;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }

  .shell--menu-aberto .shell__sidebar {
    transform: none;
    visibility: visible;
    box-shadow: 0 0 32px rgb(0 0 0 / 30%);
  }

  .shell--menu-aberto .shell__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1150;
    background: rgb(16 24 40 / 48%);
  }

  .shell__main {
    min-width: 0;
  }
}
