/* ==========================================================================
   Layout do app: shell com sidebar (rail) + topbar + área de conteúdo.
   Desktop: sidebar fixa à esquerda. Mobile: sidebar vira drawer sobre overlay.
   ========================================================================== */

/* Shell só aparece quando autenticado (app.js alterna .app-shell / .auth-screen). */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.app-shell[hidden] { display: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  grid-column: 1; background: linear-gradient(180deg, var(--rail-bg-2), var(--rail-bg));
  color: var(--rail-text); display: flex; flex-direction: column;
  padding: 18px 14px; gap: 8px; position: sticky; top: 0; height: 100dvh;
  border-right: 1px solid rgba(255, 255, 255, .05);
}
/* Marca: logo branco (logo-white.png) direto sobre o rail escuro. */
.sidebar-brand {
  display: flex; align-items: center; justify-content: center; padding: 10px 12px 16px;
}
.sidebar-brand .sidebar-logo { width: 100%; max-height: 92px; height: auto; object-fit: contain; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; overflow-y: auto; }
.nav-section {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--rail-text); opacity: .6; padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px;
  color: var(--rail-text); font-size: 14px; font-weight: 600; text-decoration: none;
  border: none; background: transparent; cursor: pointer; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item .ico { display: inline-flex; align-items: center; justify-content: center; width: 20px; flex: none; }
.nav-item:hover { background: var(--rail-hover); color: var(--rail-text-strong); }
.nav-item.active { background: rgba(20, 179, 156, .18); color: var(--rail-text-strong); }
.nav-item.active .ico { color: var(--rail-active); }
.nav-item.locked { opacity: .45; cursor: default; }
.nav-item.locked:hover { background: transparent; color: var(--rail-text); }
.nav-item .badge-soon {
  margin-left: auto; font-size: 9px; font-weight: 700; text-transform: uppercase;
  background: rgba(255, 255, 255, .1); color: var(--rail-text); padding: 2px 7px; border-radius: 5px;
}
.nav-item .lbl { flex: 1; }

/* Grupo expansível (Relatórios comerciais) */
.nav-group-toggle .caret { display: inline-flex; align-items: center; transition: transform .18s; opacity: .8; }
.nav-group.open .nav-group-toggle .caret { transform: rotate(90deg); }
.nav-sub { display: none; flex-direction: column; gap: 2px; margin: 2px 0 4px 20px;
  padding-left: 12px; border-left: 1px solid rgba(255, 255, 255, .1); }
.nav-group.open .nav-sub { display: flex; }
.nav-subitem {
  display: block; padding: 9px 12px; border-radius: 7px; color: var(--rail-text);
  font-size: 13px; font-weight: 600; text-decoration: none; transition: background .15s, color .15s;
}
.nav-subitem:hover { background: var(--rail-hover); color: var(--rail-text-strong); }
.nav-subitem.active { background: rgba(245, 107, 27, .18); color: var(--rail-text-strong); }

.sidebar-foot {
  margin-top: auto; padding: 14px 12px 4px; display: flex; flex-direction: column;
  align-items: center; gap: 8px; border-top: 1px solid rgba(255, 255, 255, .07);
}
.sidebar-foot .foot-drapps { width: 108px; max-width: 70%; height: auto; opacity: .85; }
.sidebar-foot .foot-ver { font-size: 11px; color: var(--rail-text); opacity: .55; }

/* ---------- Coluna principal ---------- */
.main-col { grid-column: 2; display: flex; flex-direction: column; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px;
  padding: 0 22px; background: var(--card-bg); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
  padding-top: env(safe-area-inset-top, 0);
}
.topbar .burger {
  display: none; background: transparent; border: none; color: var(--text-main);
  font-size: 22px; cursor: pointer; padding: 6px; border-radius: 8px;
}
.topbar .burger:hover { background: var(--seg-bg); }
.topbar .page-title {
  font-size: 16px; font-weight: 800; color: var(--teal-d); text-transform: uppercase; letter-spacing: .4px;
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .spacer { flex: 1; min-width: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* Chip de empresa selecionada */
.empresa-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 10px;
  border: 1px solid var(--border); background: var(--card-bg-2); border-radius: 8px;
  cursor: pointer; font-family: inherit; transition: border-color .15s;
}
.empresa-chip:hover { border-color: var(--brand-l); }
.empresa-chip .ec-ico { display: inline-flex; color: var(--brand); }
.empresa-chip .ec-caret { display: inline-flex; color: var(--text-muted); }
.empresa-chip .ec-meta { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.empresa-chip .ec-lbl { font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.empresa-chip .ec-nome { font-size: 13px; font-weight: 800; color: var(--brand); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 620px) { .empresa-chip .ec-meta { display: none; } .empresa-chip { padding: 8px; } }
.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-muted);
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer; font-size: 17px;
  display: inline-flex; align-items: center; justify-content: center; transition: all .15s;
}
.icon-btn:hover { color: var(--teal-d); background: var(--card-bg-2); border-color: var(--border); }

/* Chip do usuário na topbar */
.user-chip { display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 5px; border-radius: 8px; cursor: pointer; border: 1px solid var(--border); background: var(--card-bg-2); }
.user-chip:hover { border-color: var(--teal-l); }
.user-chip img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--seg-bg); }
.user-chip .u-name { font-size: 13px; font-weight: 700; color: var(--text-main); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .u-role { font-size: 11px; color: var(--text-muted); font-weight: 600; }
@media (max-width: 560px) { .user-chip .u-meta { display: none; } }

/* Área de conteúdo (host das views) */
.view-host { flex: 1; padding: 24px 26px 48px; max-width: var(--content-max); width: 100%; margin: 0 auto; }

/* ---------- Overlay do drawer (mobile) ---------- */
.drawer-overlay { display: none; position: fixed; inset: 0; background: rgba(8, 22, 20, .5); z-index: 40; }

/* ---------- Responsivo: sidebar vira drawer ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50; width: min(84vw, var(--sidebar-w));
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .35);
  }
  .main-col { grid-column: 1; }
  .topbar .burger { display: inline-flex; }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .drawer-overlay { display: block; }
}
@media (max-width: 560px) {
  .view-host { padding: 16px 14px 40px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .page-title { font-size: 13px; letter-spacing: .2px; }
}
