.app-shell {
  min-height: 100vh;
  background: #eeeeef;
  /* Fonte unica da altura do topbar - todo modulo que faz
     calc(100vh - Npx) usa var(--topbar-h) em vez de repetir o numero,
     senao cada breakpoint que muda a altura do topbar quebra as telas
     que ainda descontam o valor antigo (ex.: Venda Mesa). */
  --topbar-h: 58px;
}

/* ── Top bar ────────────────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 0 26px 0 0;
  color: #1A1A1A;
  background: #ffffff;
  box-shadow: 0 1px 0 #E5E7EB, 0 4px 12px rgba(27, 31, 35, 0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-area,
.top-actions,
.session-box,
.form-actions,
.list-header {
  display: flex;
  align-items: center;
}

.brand-area {
  gap: 14px;
  min-width: 0;
  align-self: stretch;
}

/* Bloco vermelho da logo: mesma largura do menu lateral (270px aberto,
   64px recolhido) - recolhido sobra so o icone, centralizado em cima da
   coluna de icones do menu. */
.top-brand {
  width: 270px;
  height: 100%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border-right: 1px solid #E5E7EB;
  box-sizing: border-box;
  transition: width 0.18s ease;
}

.app-shell.menu-collapsed .top-brand { width: 64px; }

.top-logo {
  width: 170px;
  height: 42px;
  border: 0;
  box-shadow: none;
  background: transparent;
  object-fit: contain;
}

.top-logo-icon {
  display: none;
  width: 40px;
  height: 40px;
  border: 0;
  box-shadow: none;
  background: transparent;
  object-fit: contain;
}

.app-shell.menu-collapsed .top-logo { display: none; }
.app-shell.menu-collapsed .top-logo-icon { display: block; }

.top-empresa-nome {
  font-size: 1rem;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--menu-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.system-name {
  font-size: 1rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.top-actions {
  gap: 16px;
}

.top-icon-button {
  color: #1A1A1A;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: 700;
  min-width: 36px;
  min-height: 36px;
  padding: 6px;
}

#menu-toggle {
  border-radius: 5px;
  transition: background 0.15s ease;
}

#menu-toggle:hover { background: var(--orange); }

#menu-toggle:hover .hamburger-icon,
#menu-toggle:hover .hamburger-icon::before,
#menu-toggle:hover .hamburger-icon::after { background: #ffffff; }

.delivery-bell {
  position: relative;
  font-size: 18px;
  opacity: 0.7;
}

.delivery-bell.bell-enabled {
  opacity: 1;
}

.delivery-bell.bell-ringing .delivery-bell-icon {
  display: inline-block;
  animation: dlvp-bell-shake 0.6s ease-in-out infinite;
}

.delivery-bell-badge {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 8px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.delivery-bell-badge.hidden {
  display: none;
}

@keyframes dlvp-bell-shake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-15deg); }
  40% { transform: rotate(12deg); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(5deg); }
}


.hamburger-icon,
.hamburger-icon::before,
.hamburger-icon::after {
  display: block;
  width: 20px;
  height: 3px;
  border-radius: 3px;
  background: #4F5660;
}

.hamburger-icon {
  position: relative;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger-icon::before {
  top: -7px;
}

.hamburger-icon::after {
  top: 7px;
}


/* ── Workspace ──────────────────────────────────────── */

.workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
  margin-top: -2px;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.menu-collapsed .workspace {
  grid-template-columns: 64px minmax(0, 1fr);
}

/* ── Sidebar ────────────────────────────────────────── */

.sidebar {
  height: calc(100vh - var(--topbar-h));
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-right: 1px solid #d7d9de;
  box-shadow: 5px 0 14px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  z-index: 50;
}

/* align-content: start - sem isso o grid estica cada item pra preencher
   a altura que o flex:1 da (itens ficavam com ~64px em vez de 45px). */
.sidebar > .menu-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  /* max-content: com overflow:hidden no submenu o grid espremia a linha dele
     quando o menu passava da altura da tela (ultimo item ficava embaixo do
     proximo menu). Assim cada linha tem a altura do conteudo e o menu rola. */
  grid-auto-rows: max-content;
}

.menu-user {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px calc(16px + env(safe-area-inset-bottom, 0px)) 18px;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
}

.menu-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  background: var(--orange);
  color: #ffffff;
}

.menu-user-text {
  flex: 1;
  min-width: 0;
}

.menu-user-text b {
  display: block;
  color: #1A1A1A;
  font-weight: 700;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-user-text small {
  display: block;
  color: #6F7782;
  font-size: 12px;
}

.menu-user-logout {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #6F7782;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.menu-user-logout .icon {
  width: 18px;
  height: 18px;
}

.menu-user-logout:hover {
  background: var(--orange);
  color: #ffffff;
}

.app-shell.menu-collapsed .menu-user-text,
.app-shell.menu-collapsed .menu-user-logout {
  display: none;
}

.app-shell.menu-collapsed .menu-user {
  justify-content: center;
  padding: 14px 0 16px;
}

.menu-list {
  display: grid;
  padding: 22px 0 28px;
}

.menu-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 10px 14px;
}

.menu-button {
  width: 100%;
  min-height: 45px;
  display: grid;
  grid-template-columns: 34px 1fr 24px;
  align-items: center;
  gap: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0 14px 0 12px;
  background: transparent;
  color: #565d66;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  transition: background 0.16s ease, color 0.16s ease;
}

.app-shell.menu-collapsed .menu-button {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 0;
}

.app-shell.menu-collapsed .menu-button span:not(.menu-icon) {
  display: none;
}

.menu-button:hover,
.menu-button.active {
  background: var(--orange);
  color: #ffffff;
}

.menu-icon {
  font-size: 1.15rem;
  line-height: 1;
  display: flex;
  align-items: center;
}

.menu-icon .icon,
.icon {
  width: 19px;
  height: 19px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-chevron {
  justify-self: end;
  font-size: 0.8rem;
  opacity: 0.6;
}

/* ── Submenu group ──────────────────────────────────── */

.submenu-group {
  display: none;
  flex-direction: column;
  background: #f6f7f9;
  border-left: 3px solid var(--orange);
  margin: 0;
  overflow: hidden;
}

.submenu-group.open {
  display: flex;
}

.submenu-button {
  width: 100%;
  min-height: 38px;
  padding: 0 14px 0 20px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  transition: background 0.14s, color 0.14s;
  border-bottom: 1px solid rgba(232,64,14,0.06);
  display: flex;
  align-items: center;
  gap: 8px;
}

.submenu-button:last-child { border-bottom: 0; }

.submenu-button:hover {
  background: rgba(232,64,14,0.08);
  color: var(--orange);
}

.submenu-button.active {
  background: var(--orange);
  color: #ffffff;
}

.submenu-icon {
  font-size: 1rem;
  flex-shrink: 0;
  width: 1.4em;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.submenu-icon .icon {
  width: 16px;
  height: 16px;
}

/* ── Submenu colapsado ──────────────────────────────── */

.app-shell.menu-collapsed .submenu-group.open {
  display: flex;
}

.app-shell.menu-collapsed .submenu-button {
  padding: 0;
  justify-content: center;
  min-height: 42px;
  font-size: 0;
  letter-spacing: 0;
  gap: 0;
}

.app-shell.menu-collapsed .submenu-icon {
  font-size: 1.2rem;
}

/* ── Content area ───────────────────────────────────── */

.content-stack {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 22px;
  padding: 18px;
}

/* Overlay escuro da sidebar — oculto por padrão em todos os tamanhos */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 499;
}

/* Com a gaveta aberta no mobile, trava o conteudo de tras: nao rola nem
   recebe clique/toque, so a propria gaveta e o overlay respondem. O scroll
   real e da <body> (o layout aqui nao usa altura fixa + scroll interno tipo
   pdv_off), entao precisa travar a body mesmo, nao so um wrapper interno. */
body.sidebar-locked {
  overflow: hidden;
  touch-action: none;
}
.app-shell.sidebar-open #module-content {
  overflow: hidden;
  touch-action: none;
  pointer-events: none;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 820px) {
  .app-shell { --topbar-h: 52px; }
  .topbar {
    height: auto;
    min-height: 52px;
    flex-wrap: nowrap;
    padding: 0 12px 0 0;
    gap: 10px;
  }

  .brand-area {
    gap: 8px;
  }

  /* No celular o menu abre por cima da tela - o bloco da logo so precisa
     caber a logo, sem acompanhar a largura do menu. */
  .top-brand,
  .app-shell.menu-collapsed .top-brand {
    width: auto;
    padding: 0 12px;
  }

  .top-logo {
    width: 130px;
    height: 38px;
  }

  .system-name {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Sidebar desliza como overlay — não empilha */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 270px;
    height: 100vh;
    height: 100dvh; /* 100vh no celular passa da barra do navegador e esconde o Sair */
    overflow-y: auto;
    z-index: 500;
    transition: left 0.22s ease;
    box-shadow: none;
  }

  .app-shell.sidebar-open .sidebar {
    left: 0;
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.3);
  }

  .app-shell.sidebar-open .sidebar-overlay {
    display: block;
  }

  .menu-list {
    padding: 8px 0;
  }

  .menu-button {
    border-radius: 0;
  }

  .content-stack {
    padding: 8px;
  }

  /* Igual pdv_off: a pagina em si nao rola/balanca (sem bounce do iOS) -
     so a area de conteudo rola por dentro, isolada, com o topbar sempre
     parado. Usa overflow-y (nao "hidden" puro como no pdv_off) porque as
     telas da gestao web foram feitas pra rolar a pagina toda, nao tem
     scroll interno proprio — travar de vez cortaria conteudo. */
  html { height: 100%; }
  /* So trava o body depois do login (app-shell visivel) - a tela de login
     e curta mas nao vale o risco de cortar o botao de entrar se o teclado
     abrir num celular bem pequeno. */
  body:has(.app-shell:not(.hidden)) {
    height: 100%;
    overflow: hidden;
  }
  .content-stack {
    height: calc(100vh - var(--topbar-h));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Responsivo: celular (mesmo tratamento do pdv_off PWA) ─────────── */
@media (max-width: 600px) {
  /* iPhone: viewport-fit=cover deixa a pagina ir por baixo do notch/relogio -
     soma o respiro do status bar na altura do topbar (0 em Android/desktop,
     ja que env() so retorna valor no iOS com notch). */
  .topbar {
    height: calc(56px + env(safe-area-inset-top, 0px));
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 8px 0 0;
    gap: 8px;
  }
  .brand-area { gap: 8px; }
  .top-logo { width: 112px; height: 34px; }
  .top-empresa-nome { display: none; }
  .top-actions { gap: 6px; }
  .top-icon-button { min-width: 32px; min-height: 32px; padding: 4px; }
  .app-shell.sidebar-open .sidebar { width: 84vw; left: 0; }
  .workspace { min-height: calc(100vh - 56px - env(safe-area-inset-top, 0px)); }
  .sidebar {
    height: calc(100vh - 56px - env(safe-area-inset-top, 0px));
    height: calc(100dvh - 56px - env(safe-area-inset-top, 0px));
    top: calc(56px + env(safe-area-inset-top, 0px));
  }
  /* Sem folga embaixo, o ultimo card/tabela da tela fica colado na barra
     do navegador (some antes de acabar de rolar). */
  .content-stack { padding: 8px 8px calc(48px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 480px) {
  .topbar          { padding: env(safe-area-inset-top, 0px) 8px 0 0; min-height: calc(48px + env(safe-area-inset-top, 0px)); height: calc(48px + env(safe-area-inset-top, 0px)); }
  .top-logo        { width: 104px; height: 32px; }
  .top-empresa-nome { display: none; }
  .content-stack   { padding: 4px 4px calc(48px + env(safe-area-inset-bottom, 0px)); }
  .workspace { min-height: calc(100vh - 48px - env(safe-area-inset-top, 0px)); }
  .sidebar {
    height: calc(100vh - 48px - env(safe-area-inset-top, 0px));
    height: calc(100dvh - 48px - env(safe-area-inset-top, 0px));
    top: calc(48px + env(safe-area-inset-top, 0px));
  }
}

/* Menu do computador como antes: ao lado, o ☰ recolhe pra so' icones e
   expande de volta (.menu-collapsed, lembrado no localStorage). Celular segue
   com a gaveta. Saiu o menu escondido por cima e o cadeado. */
