/* ========== LAYOUT VARIABLES ==========
   Cores, tipografia e espaçamento vêm de global.css (fonte única).
   Aqui ficam só variáveis específicas de layout/estrutura. */
:root {
  --sidebar-width-expanded: 280px;
  --sidebar-width-collapsed: 72px;
  --header-height: 64px;
}

/* ===== ABAS TIPO .tab-item (usadas em Agendamento e Gestão Estratégica) =====
   Regra global — precisa funcionar em qualquer largura de tela, não só desktop. */
.tab-item {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 14px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--green); border-bottom-color: var(--green); }

@media (max-width: 768px) {
  .tab-item { padding: 10px 10px; font-size: 12.5px; }
}

/* ========== SHELL LAYOUT ========== */
.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width-expanded);
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 16px;
  gap: 24px;
  overflow-y: auto;
  transition: width var(--transition-slow) ease, padding var(--transition-slow) ease;
}

/* DESKTOP: Sidebar recolhida (padrão) */
@media (min-width: 769px) {
  .sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    padding: 16px 8px;
    align-items: center;
    gap: 12px;
    overflow-y: hidden;
  }

  .sidebar.collapsed .brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-bottom: 8px;
  }

  .sidebar.collapsed .brand-text {
    display: none;
  }

  .sidebar.collapsed .muted {
    display: none !important;
  }

  .sidebar.collapsed .nav {
    gap: 12px;
    width: 100%;
  }

  .sidebar.collapsed .nav-item {
    padding: 0;
    justify-content: center;
    width: 48px;
    height: 48px;
    display: flex !important;
    align-items: center;
    font-size: 20px;
    border-radius: 8px;
    margin: 0 auto;
    background: transparent;
    border: none;
    color: var(--muted);
  }

  .sidebar.collapsed .nav-text {
    display: none;
  }

  .sidebar.collapsed .nav-icon {
    font-size: 24px;
  }

  .sidebar.collapsed .nav-item.active {
    background: var(--green);
    color: var(--bg);
  }

  .sidebar.collapsed .sidebar-footer {
    width: 100%;
    margin-top: auto;
    flex-direction: column;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .sidebar.collapsed .sidebar-footer .btn {
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar.collapsed .btn-text {
    display: none;
  }

  .sidebar.collapsed .btn-icon {
    font-size: 20px;
  }

  .sidebar.toggle-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    margin-bottom: 24px;
    border-radius: 8px;
  }

  .sidebar.toggle-btn:hover {
    color: var(--green);
    background: var(--panel);
  }
}

.sidebar-toggle-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 8px;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  color: var(--green);
  background: var(--panel);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
}
/* ========== HEADER (MOBILE) ========== */
.header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 100;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.menu-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  width: auto;
  height: auto;
  display: inline-block;
  visibility: visible;
}
.menu-btn:hover {
  color: var(--green);
}
.header-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== NAVBAR DESKTOP ========== */
.navbar-desktop {
  display: none;
  position: fixed;
  top: 16px;
  right: 24px;
  z-index: 50;
}

@media (min-width: 769px) {
  .navbar-desktop {
    display: flex;
  }
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-alt);
  border: 1.5px solid var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--green);
  font-weight: 800;
  font-size: 14px;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.user-unit {
  font-size: 12px;
  color: var(--muted);
}
/* ========== BRAND ========== */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  background: var(--green);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  font-weight: 800;
  overflow: hidden;
}
.brand-mark:has(img) { background: transparent !important; }
.brand-mark img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.brand-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.muted {
  font-size: 12px;
  color: var(--muted);
  padding: 12px;
  background: var(--panel);
  border-radius: 6px;
}
/* ========== NAVIGATION ========== */
.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.nav-item {
  padding: 12px 16px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-item:hover {
  background: var(--panel);
  color: var(--text);
}
.nav-item.active {
  background: var(--green);
  color: var(--bg);
  font-weight: 600;
}
/* ========== BUTTONS ========== */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--panel);
  color: var(--text);
}
.btn:hover {
  background: var(--line);
}
.btn-primary {
  background: var(--green);
  color: var(--bg);
}
.btn-primary:hover {
  background: #16a34a;
}
.btn-danger {
  background: #ef4444;
  color: white;
}
.btn-danger:hover {
  background: #dc2626;
}
/* ========== SIDEBAR FOOTER ========== */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
/* ========== RESPONSIVE: MOBILE ========== */
@media (max-width: 768px) {
  /* Gráficos e containers responsivos */
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
  .dashboard-cards {
    grid-template-columns: 1fr;
  }
  .dashboard-charts {
    grid-template-columns: 1fr;
  }

  /* ===== NOVO SHELL MOBILE: mega menu tela cheia + bottom sheet ===== */
  .shell-mobile {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* corrige barra de endereço do navegador comendo altura no mobile */
    overflow: hidden;
    position: relative;
  }

  .topbar-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    flex-shrink: 0;
    position: relative;
    z-index: 60;
  }

  .user-dropdown {
    position: absolute;
    top: 56px;
    right: 12px;
    left: 12px;
    max-width: 280px;
    margin-left: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 70;
  }

  .user-dropdown.active {
    display: flex;
  }

  .user-dropdown-header {
    padding: 10px 12px 12px 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 6px;
  }

  .user-dropdown-name {
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
  }

  .user-dropdown-unit {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
  }

  .user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
  }

  .user-dropdown-danger {
    color: #ef4444;
  }

  .menu-btn-mobile {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
  }

  .brand-mobile {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 1;
  }

  .brand-mobile .brand-mark {
    width: 28px;
    height: 28px;
    background: var(--green);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    font-weight: 800;
    font-size: 13px;
    flex-shrink: 0;
  }

  .brand-mobile-text {
    color: var(--green);
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-avatar-btn-mobile {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--surface-alt);
    border: 1.5px solid var(--green);
    color: var(--green);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .user-avatar-btn-mobile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* ===== SELETOR DE SEÇÃO (substitui as abas roláveis) ===== */
  .section-picker {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-alt);
    flex-shrink: 0;
    cursor: pointer;
  }

  .section-picker .sp-current {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
  }

  .section-picker .sp-current .sp-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
  }

  .section-picker .sp-chevron {
    color: var(--muted);
    font-size: 11px;
    transition: transform 0.2s ease;
  }

  .section-picker.open .sp-chevron {
    transform: rotate(180deg);
  }

  .section-list {
    display: none;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
  }

  .section-list.open {
    display: block;
  }

  .section-list .sp-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--line);
  }

  .section-list .sp-option:last-child {
    border-bottom: none;
  }

  .section-list .sp-option.active {
    color: var(--green);
    font-weight: 700;
    background: rgba(34, 197, 94, 0.06);
  }

  .section-list .sp-option .sp-check {
    color: var(--green);
    font-size: 12px;
  }

  .main-mobile {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .main-mobile #view {
    padding: 16px;
  }

  /* ===== MEGA MENU TELA CHEIA ===== */
  .mega-menu-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 200;
    padding: 20px 16px;
    overflow-y: auto;
  }

  .mega-menu-mobile-overlay.active {
    display: block;
  }

  .mega-menu-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
  }

  .mega-menu-mobile-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
  }

  .mega-menu-mobile-close {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--muted);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    font-size: 16px;
  }

  .mega-card-mobile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 0 4px;
    overflow-y: auto;
  }

  .mega-card-mobile-grid-item {
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
  }

  .mega-card-mobile-grid-item.active {
    border-color: var(--green);
    background: rgba(34, 197, 94, 0.12);
  }

  .mega-card-mobile-icon {
    font-size: 18px;
    flex-shrink: 0;
    color: var(--muted);
  }

  .mega-card-mobile-grid-item.active .mega-card-mobile-icon {
    color: var(--green);
  }

  .mega-card-mobile-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.25;
  }

  .mega-card-mobile-grid-item.active .mega-card-mobile-title {
    color: var(--green);
  }

  /* ===== BOTTOM SHEET DO USUÁRIO ===== */
  .user-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: flex-end;
  }

  .user-sheet-overlay.active {
    display: flex;
  }

  .user-sheet {
    width: 100%;
    background: var(--panel);
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    padding: 10px 18px 28px 18px;
  }

  .sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--line);
    border-radius: 4px;
    margin: 6px auto 16px auto;
  }

  .sheet-header {
    padding-bottom: 14px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
  }

  .sheet-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
  }

  .sheet-unit {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
  }

  .sheet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 14px 6px;
    font-size: 14px;
    color: var(--text);
    border-bottom: 1px solid var(--line);
  }

  .sheet-item:last-child {
    border-bottom: none;
  }

  .sheet-item.sheet-danger {
    color: #ef4444;
  }
}
/* ========== DESKTOP: MEGA MENU + ABAS (novo shell) ========== */
@media (min-width: 769px) {
  .shell-desktop {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .topbar-desktop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    position: relative;
    z-index: 60;
  }

  .topbar-desktop .menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .topbar-desktop .menu-btn:hover {
    border-color: var(--green);
    color: var(--green);
  }

  .topbar-desktop .header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--green);
    font-size: 16px;
  }

  .topbar-desktop .header-brand .brand-mark {
    width: 32px;
    height: 32px;
    background: var(--green);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    font-weight: 800;
  }

  /* ===== MENU DO USUÁRIO (dropdown no ícone) ===== */
  .user-menu-wrapper {
    position: relative;
  }

  .user-avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-alt);
    border: 1.5px solid var(--green);
    color: var(--green);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  .user-avatar-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 240px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 70;
  }

  .user-dropdown.active {
    display: flex;
  }

  .user-dropdown-header {
    padding: 10px 12px 12px 12px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 6px;
  }

  .user-dropdown-name {
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
  }

  .user-dropdown-unit {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
  }

  .user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    text-align: left;
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
    width: 100%;
  }

  .user-dropdown-item:hover {
    background: var(--surface-alt);
  }

  .user-dropdown-danger {
    color: #ef4444;
  }

  /* ===== MEGA MENU (Agendamentos / Configurações) ===== */
  .mega-menu-overlay {
    display: none;
    position: absolute;
    top: 100%;
    left: 24px;
    z-index: 65;
  }

  .mega-menu-overlay.active {
    display: block;
  }

  .mega-menu-panel {
    margin-top: 10px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
    padding: 16px;
    max-width: min(860px, calc(100vw - 48px));
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    overflow-x: hidden;
  }

  /* Scroll fino no mesmo padrão do .perm-tree-box, com hover verde — só aqui,
     não mexe na regra global que esconde scrollbar no resto do app. */
  .mega-menu-panel::-webkit-scrollbar { width: 6px; display: block; }
  .mega-menu-panel::-webkit-scrollbar-track { background: transparent; }
  .mega-menu-panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; transition: background 0.15s; }
  .mega-menu-panel::-webkit-scrollbar-thumb:hover { background: var(--green); }
  .mega-menu-panel { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

  .mega-menu-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  /* Telas bem estreitas: reduz pra 4 colunas e encolhe cards/ícone/fonte
     em vez de depender só do scroll. */
  @media (max-width: 480px) {
    .mega-menu-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
    .mega-menu-card { padding: 10px 4px; font-size: 9px; gap: 4px; }
    .mega-menu-icon { font-size: 14px; }
  }

  .mega-menu-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 8px;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
    transition: all 0.2s ease;
  }

  .mega-menu-card:hover,
  .mega-menu-card.active {
    border-color: var(--green);
    background: rgba(34, 197, 94, 0.1);
    color: var(--green);
  }

  .mega-menu-card.not-implemented {
    opacity: 0.7;
  }

  .mega-menu-card.not-implemented:hover {
    border-color: var(--line);
    background: var(--surface-alt);
    color: var(--text);
    opacity: 1;
  }

  .mega-menu-icon {
    font-size: 18px;
  }

  /* ===== ABAS HORIZONTAIS (dentro de Agendamentos) ===== */
  .schedule-tabs {
    display: flex;
    gap: 4px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    flex-shrink: 0;
  }

  .main-desktop {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ===== CONFIGURAÇÕES: sidebar fixa (padrão mockup) ===== */
  .settings-desktop-body {
    display: flex;
    flex: 1;
    overflow: hidden;
  }

  .settings-side {
    width: 190px;
    flex-shrink: 0;
    border-right: 1px solid var(--line);
    padding: 16px 0;
    overflow-y: auto;
  }

  .settings-side-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 9px 20px;
    font-size: 12.5px;
    color: var(--muted);
    border-left: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .settings-side-item:hover {
    color: var(--text);
  }

  .settings-side-item.active {
    color: var(--text);
    border-left-color: var(--green);
    background: rgba(34, 197, 94, 0.06);
  }

  .settings-main {
    flex: 1;
    overflow-y: auto;
  }

  /* Navegação agora é pela sidebar — botões "voltar" internos ficam redundantes */
  #lookupBackBtn,
  #userBackBtn,
  #groupBackBtn {
    display: none;
  }
}