/* layout.css — sidebar, header pill e grid principal */

/* ══════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #ffffff;
  border-right: 1px solid rgba(0,0,0,.09);
  box-shadow: 2px 0 16px rgba(25,118,210,.05);
  display: flex;
  flex-direction: column;
  z-index: 100;
  /* anima width (desktop collapse) e transform (mobile) */
  transition: width .3s cubic-bezier(.22,1,.36,1),
              transform .3s cubic-bezier(.22,1,.36,1);
  overflow: hidden;
}

[data-theme="dark"] .sidebar {
  background: linear-gradient(160deg,
    rgba(15,23,42,.98) 0%,
    rgba(10,16,35,.99) 100%);
  border-right: 1px solid rgba(255,255,255,.07);
  box-shadow: none;
}

/* ── Desktop: colapsa para rail de ícones ── */
body.sidebar-closed .sidebar      { width: var(--sidebar-collapsed-w); }
body.sidebar-closed .main-wrapper { margin-left: var(--sidebar-collapsed-w); }

/* ── Brand ── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid rgba(0,0,0,.07);
  flex-shrink: 0;
  overflow: hidden;
}
[data-theme="dark"] .sidebar-brand { border-bottom-color: rgba(255,255,255,.07); }

.sidebar-logo {
  height: 28px; width: 28px;
  flex-shrink: 0;
  object-fit: contain;
}
[data-theme="dark"] .sidebar-logo { filter: drop-shadow(0 2px 8px rgba(67,97,238,.45)); }

.sidebar-brand-text { overflow: hidden; flex: 1; }
.sidebar-title {
  font-size: .87rem; font-weight: 700;
  color: var(--text); line-height: 1.2; letter-spacing: -.01em;
  white-space: nowrap;
}
.sidebar-subtitle { font-size: .68rem; color: var(--text-muted); margin-top: 1px; white-space: nowrap; }

/* Collapsed: logo fica no mesmo lugar, apenas texto some */
body.sidebar-closed .sidebar-brand-text { display: none; }

/* ── Nav ── */
.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Integrações — fixada na base */
.nav-list--bottom {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,.06);
}
[data-theme="dark"] .nav-list--bottom { border-top-color: rgba(255,255,255,.07); }

/* ── Nav item genérico (a e button) ── */
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: .83rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  position: relative;
  transition: color .16s, background .16s;
  white-space: nowrap;
  overflow: hidden;
  width: 100%;
  /* reset de button */
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.nav-link:hover {
  color: var(--color-primary);
  background: rgba(25,118,210,.07);
}

/* Estado ativo */
.nav-link.active {
  color: var(--color-primary);
  background: rgba(25,118,210,.09);
  font-weight: 600;
}
/* Indicador: barra vertical à direita */
.nav-link.active::after {
  content: '';
  position: absolute;
  right: 0; top: 20%; height: 60%; width: 3px;
  background: var(--color-primary);
  border-radius: 3px 0 0 3px;
}

/* Dark mode */
[data-theme="dark"] .nav-link           { color: rgba(255,255,255,.50); }
[data-theme="dark"] .nav-link:hover     { color: #fff; background: rgba(255,255,255,.07); }
[data-theme="dark"] .nav-link.active    { color: #fff; background: rgba(25,118,210,.28); }
[data-theme="dark"] .nav-link.active::after { background: #42A5F5; }

/* Ícone */
.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .55;
  transition: opacity .16s;
}
.nav-link:hover .nav-icon  { opacity: .9; }
.nav-link.active .nav-icon { opacity: 1; }

/* Dark: ícones mais visíveis sobre fundo escuro */
[data-theme="dark"] .nav-icon                   { opacity: .72; }
[data-theme="dark"] .nav-link:hover .nav-icon   { opacity: 1; }
[data-theme="dark"] .nav-link.active .nav-icon  { opacity: 1; }

/* Label de texto */
.nav-link-label { flex: 1; }

/* ── Collapsed: oculta labels; footer colapsa via transição (sem salto) ── */
body.sidebar-closed .nav-link-label   { display: none; }
body.sidebar-closed .nav-list--bottom { border-top-color: transparent; }

/* ── Collapsed: sidebar permite overflow para mostrar tooltips ── */
body.sidebar-closed .sidebar { overflow: visible; }

/* ── Tooltip dos ícones na sidebar colapsada (somente desktop) ── */
@media (min-width: 901px) {
  body.sidebar-closed .nav-link[data-tooltip] {
    position: relative;
  }
  body.sidebar-closed .nav-link[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) scale(.92);
    background: rgba(15,23,42,.96);
    color: #f1f5f9;
    border: 1px solid rgba(148,163,184,.22);
    box-shadow: 0 4px 18px rgba(0,0,0,.32);
    padding: 5px 12px;
    border-radius: 7px;
    font-size: .76rem;
    font-weight: 500;
    font-family: var(--font);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .14s, transform .14s;
    z-index: 500;
  }
  body.sidebar-closed .nav-link[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
}

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(0,0,0,.07);
  flex-shrink: 0;
  overflow: hidden;
  max-height: 80px;
  opacity: 1;
  transition: max-height .3s cubic-bezier(.22,1,.36,1),
              padding    .3s cubic-bezier(.22,1,.36,1),
              opacity    .18s ease,
              border-top-color .3s;
}
[data-theme="dark"] .sidebar-footer { border-top-color: rgba(255,255,255,.07); }
.sidebar-footer-text { font-size: .70rem; color: var(--text-light); white-space: nowrap; }

/* Collapsed: footer colapsa suavemente — Integrações desce sem salto */
body.sidebar-closed .sidebar-footer {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  border-top-color: transparent;
}

/* ══════════════════════════════════════════════════
   MAIN WRAPPER
══════════════════════════════════════════════════ */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .3s cubic-bezier(.22,1,.36,1);
}

/* ══════════════════════════════════════════════════
   HEADER PILL
══════════════════════════════════════════════════ */
.main-header {
  position: sticky;
  top: 10px;
  margin: 10px 20px 0;
  height: var(--header-h);
  background: var(--lg-bg-strong);
  backdrop-filter: blur(28px) saturate(200%);
  -webkit-backdrop-filter: blur(28px) saturate(200%);
  border: 1px solid var(--lg-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--lg-inset), 0 8px 32px rgba(67,97,238,.10), 0 2px 8px rgba(15,22,40,.06);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  z-index: 50;
}

/* ── Botão hamburger (header) — visível apenas no mobile ── */
.btn-menu {
  display: none;           /* oculto no desktop: toggle fica só na sidebar */
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color .15s, background .15s;
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
}
.btn-menu:hover { background: rgba(25,118,210,.07); color: var(--color-primary); }
.btn-menu svg { width: 18px; height: 18px; }

.header-info { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.header-title {
  font-size: .95rem; font-weight: 700;
  color: var(--color-primary); line-height: 1.2; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-update { font-size: .7rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ── Botão de tema ── */
.btn-theme {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: all .18s;
}
.btn-theme:hover { color: var(--color-primary); background: rgba(67,97,238,.09); }
.btn-theme svg { width: 17px; height: 17px; }
.btn-theme .icon-moon { display: block; }
.btn-theme .icon-sun  { display: none; }
[data-theme="dark"] .btn-theme .icon-moon { display: none; }
[data-theme="dark"] .btn-theme .icon-sun  { display: block; }

/* ── Botão refresh ── */
.btn-refresh {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: all .18s;
}
.btn-refresh:hover {
  color: var(--color-primary);
  background: rgba(67,97,238,.09);
  transform: rotate(20deg);
}
.btn-refresh svg { width: 17px; height: 17px; }

/* ══════════════════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════════════════ */
.main-content { flex: 1; padding: 20px 24px 32px; }

/* ── Sections ── */
.section { display: none; }
.section.active { display: block; }

/* ── KPI grid ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

/* ── Chart rows ── */
.chart-row { margin-bottom: 20px; }
.chart-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ── Tabs (seção Integrações) ── */
.tabs-bar {
  display: flex; gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border-dim);
}
.tab-btn {
  padding: 10px 20px;
  font-size: .84rem; font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  cursor: pointer;
}
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Menu overlay (mobile) ── */
.menu-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(8,12,28,.45);
  backdrop-filter: blur(4px);
  z-index: 99;
}
.menu-overlay.open { display: block; }

/* ══════════════════════════════════════════════════
   RESPONSIVO
══════════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* Header hamburger: aparece apenas no mobile (sidebar está off-canvas) */
  .btn-menu { display: flex; }

  /* Mobile: sidebar off-canvas via transform */
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w);  /* sempre largura normal no mobile */
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
  }
  .main-wrapper   { margin-left: 0; }
  .main-content   { padding: 16px 14px 40px; }
  .kpi-grid       { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .chart-row-2    { grid-template-columns: 1fr; }
  .main-header    { margin: 10px 12px 0; }
  .painel-subtabs { top: calc(var(--header-h) + 14px); }

  /* Reset do estado sidebar-closed no mobile */
  body.sidebar-closed .sidebar      { width: var(--sidebar-w); transform: translateX(-100%); }
  body.sidebar-closed .main-wrapper { margin-left: 0; }
  /* Mobile: restaura labels e footer que foram ocultados */
  body.sidebar-closed .nav-link-label,
  body.sidebar-closed .sidebar-brand-text { display: revert; }
  body.sidebar-closed .sidebar-footer {
    max-height: 80px;
    padding: 12px 16px;
    opacity: 1;
    pointer-events: auto;
    border-top-color: rgba(0,0,0,.07);
  }
  [data-theme="dark"] body.sidebar-closed .sidebar-footer {
    border-top-color: rgba(255,255,255,.07);
  }
}

@media (max-width: 540px) {
  .kpi-grid    { grid-template-columns: 1fr 1fr; gap: 10px; }
  .main-content { padding: 12px 10px 40px; }
  .painel-subtab { padding: 7px 13px; font-size: .78rem; }
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; gap: 10px; }
}
