/* ═══════════════════════════════════════════════════════
   THE3 Finance — Sidebar v3
   ═══════════════════════════════════════════════════════ */

:root {
  --sb-w:      240px;
  --sb-w-mini: 68px;
}

/* ══════════════════════
   BRAND
   ══════════════════════ */
.sb-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .85rem 1rem .85rem 1.25rem;
  border-bottom: 1px solid var(--border-light, #f0f2f5);
  flex-shrink: 0;
  min-height: 58px;
}
.sb-logo-full { height: 30px; width: auto; object-fit: contain; }
.sb-logo-mini { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; display: none !important; }

.sb-brand-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .25rem;
}

/* Botão fechar — mobile */
.sb-close-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: none; border: none; cursor: pointer;
  color: #94a3b8; border-radius: 6px;
  transition: background .15s, color .15s;
}
.sb-close-btn:hover { background: #fee2e2; color: #dc2626; }
.sb-close-btn svg { width: 16px; height: 16px; display: block; }

/* Botão recolher — desktop */
.sb-collapse-btn {
  display: flex;
  align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px; cursor: pointer;
  color: #94a3b8;
  transition: all .15s;
  flex-shrink: 0;
}
.sb-collapse-btn:hover { border-color: var(--blue); color: var(--blue); background: #eff6ff; }
.sb-collapse-btn svg { width: 13px; height: 13px; display: block; transition: transform .3s; }

/* ══════════════════════
   NAV (scroll)
   ══════════════════════ */
.sb-nav {
  flex: 1;
  padding: .4rem .6rem;
  overflow-y: auto;
  overflow-x: hidden;
}
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

/* ── Label — oculto no mini ── */
.sb-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ══════════════════════
   GRUPOS
   ══════════════════════ */
.sb-group { margin-bottom: .1rem; }

/* Cabeçalho do grupo */
.sb-group-header {
  display: flex !important;
  align-items: center !important;
  gap: .65rem;
  width: 100%;
  padding: .48rem .8rem;
  border: none; border-radius: 8px;
  background: none;
  color: #64748b;
  font-family: var(--font-body);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}
.sb-group-header > svg:first-child {
  width: 16px !important; height: 16px !important;
  flex-shrink: 0;
}
.sb-group-header:hover { background: #f1f5f9; color: var(--navy, #0F2A44); }

/* Seta do grupo */
.sb-chevron {
  margin-left: auto;
  flex-shrink: 0;
  width: 13px !important; height: 13px !important;
  color: #94a3b8;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.sb-group.open > .sb-group-header .sb-chevron { transform: rotate(180deg); }

/* Container dos subitens */
.sb-group-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s cubic-bezier(.4,0,.2,1);
}
.sb-group.open > .sb-group-items { max-height: 500px; }

/* Subitem — FIX #1: especificidade maior que .sb-item */
.sb-group-items .sb-item {
  padding: .5rem .8rem .5rem 2rem !important;
  font-size: .845rem !important;
}
.sb-group-items .sb-item svg {
  width: 15px !important; height: 15px !important;
}

/* ══════════════════════
   MODO MINI (desktop)
   ══════════════════════ */
.sidebar.mini {
  width: var(--sb-w-mini) !important;
  min-width: var(--sb-w-mini) !important;
}
.main-area.mini-offset { margin-left: var(--sb-w-mini) !important; }

/* Brand no mini — FIX #2: logo + botão sempre visíveis */
.sidebar.mini .sb-brand {
  padding: .75rem .55rem;
  justify-content: center;
  flex-direction: column;
  gap: .5rem;
  min-height: auto;
}
.sidebar.mini .sb-logo-full { display: none !important; }
.sidebar.mini .sb-logo-mini { display: block !important; }
.sidebar.mini .sb-brand-actions { margin-left: 0; }
.sidebar.mini .sb-collapse-btn {
  display: flex !important;
  width: 32px !important;
  height: 32px !important;
}
.sidebar.mini .sb-collapse-btn svg { transform: rotate(180deg); }

/* Nav no mini */
.sidebar.mini .sb-nav { padding: .4rem .3rem; }

/* Oculta labels e chevrons */
.sidebar.mini .sb-label { display: none !important; }
.sidebar.mini .sb-chevron { display: none !important; }
.sidebar.mini .sb-badge { display: none !important; }

/* Header dos grupos centralizado */
.sidebar.mini .sb-group-header {
  justify-content: center !important;
  padding: .6rem .4rem !important;
  gap: 0 !important;
}

/* sb-item direto (dashboard) centralizado */
.sidebar.mini .sb-nav > .sb-item {
  justify-content: center !important;
  padding: .6rem .4rem !important;
  gap: 0 !important;
}
.sidebar.mini .sb-nav > .sb-item.active::before { display: none; }

/* Subitens ocultos no mini */
.sidebar.mini .sb-group-items { max-height: 0 !important; }

/* User no mini */
.sidebar.mini .sb-user-info { display: none !important; }
.sidebar.mini .sb-user {
  justify-content: center;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  padding: .75rem .4rem;
}
.sidebar.mini .sb-logout {
  padding: .3rem !important;
}

/* Tooltip no mini — FIX posicionamento com position:fixed */
.sidebar.mini .sb-group-header,
.sidebar.mini .sb-nav > .sb-item { position: relative; }

.sidebar.mini .sb-group-header:hover::after,
.sidebar.mini .sb-nav > .sb-item:hover::after {
  content: attr(title);
  position: fixed;
  left: calc(var(--sb-w-mini) + 10px);
  top: auto;
  background: #0F2A44;
  color: #fff;
  padding: .3rem .8rem;
  border-radius: 6px;
  font-size: .76rem;
  font-weight: 500;
  white-space: nowrap;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}

/* ══════════════════════
   MOBILE
   ══════════════════════ */
@media (max-width: 768px) {
  .sb-close-btn    { display: flex !important; }
  .sb-collapse-btn { display: none !important; }

  /* Sidebar: coluna flex com altura total e scroll interno */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1), box-shadow .3s;
    width: var(--sb-w) !important;
    min-width: var(--sb-w) !important;
    /* 100dvh = altura real excluindo barra do Safari/Chrome mobile */
    height: 100dvh !important;
    height: 100vh !important; /* fallback para browsers sem suporte */
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    /* JS vai sobrescrever com a altura real via --real-vh */
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,.25);
  }

  /* Nav: cresce e tem scroll — min-height:0 é essencial */
  .sidebar .sb-nav {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Usuário: fixo no rodapé, nunca encolhe */
  .sidebar .sb-user {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    border-top: 1px solid var(--border-light, #f0f2f5) !important;
    padding: .85rem 1rem !important;
    display: flex !important;
    min-height: 64px !important;
  }

  .main-area { margin-left: 0 !important; }

  /* Cancela mini no mobile */
  .sidebar.mini { width: var(--sb-w) !important; min-width: var(--sb-w) !important; }
  .sidebar.mini .sb-brand { padding: .85rem 1rem .85rem 1.25rem; justify-content: flex-start; }
  .sidebar.mini .sb-logo-full { display: block !important; }
  .sidebar.mini .sb-logo-mini { display: none !important; }
  .sidebar.mini .sb-label { display: block !important; }
  .sidebar.mini .sb-chevron { display: block !important; }
  .sidebar.mini .sb-badge { display: inline-flex !important; }
  .sidebar.mini .sb-user-info { display: block !important; }
  .sidebar.mini .sb-user { justify-content: flex-start; }
  .sidebar.mini .sb-group-header { justify-content: flex-start !important; padding: .48rem .8rem !important; gap: .65rem !important; }
  .sidebar.mini .sb-nav > .sb-item { justify-content: flex-start !important; padding: .55rem .8rem !important; gap: .65rem !important; }
  .sidebar.mini .sb-group-items { max-height: 0; }
  .sidebar.mini .sb-group.open > .sb-group-items { max-height: 500px; }
  .sidebar.mini .sb-group-header:hover::after,
  .sidebar.mini .sb-nav > .sb-item:hover::after { display: none; }
}
