/**
 * SaaS (super_admin / tenant): não há endbar no HTML, mas o Materialy reserva
 * --bs-endbar-width (~270px) em .topbar, .page-title-box e .page-wrapper .page-content.
 * O tema só zera margin-right do conteúdo em viewports < 1200px; em desktop o espaço
 * vazio permanece até estes overrides (depois de app.min.css, com !important).
 *
 * app.js (Materialy) define data-sidebar-size=collapsed entre 310px e 1440px; o tema
 * põe .logo-lg com width:0 mas o <img> ainda desenhava fora da caixa — dois logos.
 */

body.layout-app-saas .startbar .brand .logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-decoration: none;
}

body.layout-app-saas .startbar .brand .logo .logo-lg {
  overflow: hidden;
}

body.layout-app-saas .startbar .brand .logo .brand-site-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--bs-menu-link-hover-color, #fff);
}

/* Sidebar estreita (ícones): o botão largo «Novo agendamento» quebra o layout — esconde até hover expandir a barra */
body.layout-app-saas[data-sidebar-size="collapsed"] .startbar:not(:hover) li.tenant-startbar-new-appt {
  display: none !important;
}

@media (min-width: 1200px) {
  body.layout-app-saas[data-sidebar-size="collapsed"] .startbar:not(:hover) .brand .logo .brand-site-name {
    display: none;
  }

  body.layout-app-saas .topbar {
    width: auto !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    left: var(--bs-startbar-width) !important;
    right: 0 !important;
  }

  body.layout-app-saas[data-sidebar-size="collapsed"] .topbar {
    left: var(--bs-startbar-collapsed-width) !important;
  }

  body.layout-app-saas .page-title-box {
    width: calc(100% - var(--bs-startbar-width)) !important;
    margin-left: var(--bs-startbar-width) !important;
    margin-right: 0 !important;
    max-width: none !important;
  }

  body.layout-app-saas[data-sidebar-size="collapsed"] .page-title-box {
    width: calc(100% - var(--bs-startbar-collapsed-width)) !important;
    margin-left: var(--bs-startbar-collapsed-width) !important;
  }
}

body.layout-app-saas .page-wrapper .page-content {
  margin-right: 0 !important;
  padding-left: clamp(0.75rem, 2vw, 1.25rem);
  padding-right: clamp(0.75rem, 2vw, 1.25rem);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 70px);
}

body.layout-app-saas .page-wrapper .page-content > .container-fluid {
  flex-grow: 1;
}

body.layout-app-saas .footer {
  margin-top: auto;
}

/* Reserva pública: sem sidebar — o tema aplica margin-left da startbar ao .page-content */
body.layout-public-booking .page-wrapper .page-content {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Reserva pública: neutraliza topbar/layout fixo do Materialy (evita sobreposição/encavalamento). */
body.layout-public-booking .topbar {
  position: static !important;
  inset: auto !important;
  width: 100% !important;
  margin: 0 !important;
  height: auto !important;
  min-height: 92px !important;
  padding: 0 !important;
}

body.layout-public-booking .page-wrapper {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 92px);
}

body.layout-public-booking .page-wrapper .page-content {
  margin-top: 0 !important;
  min-height: auto !important;
  display: flex;
  flex-direction: column;
  flex: 1;
}

body.layout-public-booking .page-wrapper .page-content .container-fluid {
  flex: 1;
}

body.layout-public-booking .footer {
  margin-top: auto !important;
}

/* Tenant — WhatsApp ligado: destaque legível em tema claro/escuro */
body.layout-app-saas .whatsapp-connected-hero {
  border: 1px solid rgba(25, 135, 84, 0.35);
  background: linear-gradient(
    145deg,
    rgba(25, 135, 84, 0.12) 0%,
    rgba(25, 135, 84, 0.04) 100%
  );
}

body.layout-app-saas .whatsapp-connected-icon svg {
  filter: drop-shadow(0 2px 8px rgba(25, 135, 84, 0.35));
}

/*
 * Super admin → Configurações: o Symfony exige um único <form> para Identidade + Trial.
 * O Bootstrap esconde painéis com .tab-content > .tab-pane (filho directo). Aqui os dois
 * primeiros .tab-pane estão dentro do form → ficam todos display:block e empilham altura.
 */
body.layout-app-saas .settings-tabs-root > form.settings-general-form > .tab-pane:not(.show) {
  display: none !important;
}

body.layout-app-saas .settings-tabs-root > form.settings-general-form > .tab-pane.show {
  display: block !important;
}

/* Billing: seleção de plano */
body.layout-app-saas .billing-plan-card--pickable {
  cursor: pointer;
  user-select: none;
}

body.layout-app-saas .billing-plan-card--pickable .billing-plan-card__features {
  max-height: none;
}

body.layout-app-saas .billing-plan-card--pickable .billing-plan-card-btn {
  cursor: pointer;
}

/* Versão da app (ficheiro VERSION na raiz) */
body.layout-app-saas .startbar .startbar-collapse > .d-flex {
  min-height: 100%;
}
body.layout-app-saas .startbar-version {
  margin-top: auto;
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Notificações mobile: centralizadas e amplas, e ajustes de responsividade da topbar e layout global */
@media (max-width: 575.98px) {
  body.layout-app-saas #crm-notifications-root .dropdown-menu {
    position: fixed !important;
    top: 65px !important;
    left: 5% !important;
    right: 5% !important;
    width: 90% !important;
    transform: none !important;
    z-index: 1050 !important;
  }

  /* Ajusta o espaçamento do menu superior no mobile */
  #topbar-custom {
    padding: 0 0.25rem !important;
  }
  #topbar-custom ul.topbar-item {
    gap: 0.25rem !important;
  }
  #topbar-custom li.topbar-item, 
  #topbar-custom li.dropdown,
  #topbar-custom li.align-self-center {
    margin: 0 !important;
  }
  #topbar-custom .nav-link {
    padding: 0.35rem !important;
    min-width: 32px !important;
    height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  #topbar-custom .btn-sm {
    padding: 0.25rem 0.4rem !important;
    font-size: 11px !important;
    height: 32px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

/* Ajustes de Responsividade Global para Telas Mobile */
@media (max-width: 767.98px) {
  /* Tabelas responsivas automáticas caso não tenham wrapper */
  .table:not(.table-responsive) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Ajuste no título da página e breadcrumbs */
  .page-title-box {
    padding: 10px 0 !important;
    margin-bottom: 10px !important;
  }
  .page-title-box h4.page-title {
    font-size: 1.1rem !important;
    margin-top: 5px !important;
    margin-bottom: 5px !important;
  }
  
  /* Ajustes gerais de formulários e inputs no mobile */
  .form-control, .form-select {
    font-size: 14px !important;
    padding: 0.5rem 0.75rem !important;
  }
  
  /* Botões mais fáceis de tocar no celular */
  .btn {
    padding: 0.5rem 1rem;
    font-size: 13px;
  }
  
  /* Reduzir margens internas e externas excessivas em cards */
  .card-body {
    padding: 1rem !important;
  }
}

/* Scroll horizontal de planos no mobile (swipe magnético) */
@media (max-width: 767.98px) {
  .billing-plans-container {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 1.25rem !important; /* Espaço para a barra de rolagem */
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    justify-content: flex-start !important;
    scrollbar-width: thin; /* Barra de rolagem discreta em navegadores modernos */
  }
  
  .billing-plans-container::-webkit-scrollbar {
    height: 6px;
  }
  
  .billing-plans-container::-webkit-scrollbar-track {
    background: transparent;
  }
  
  .billing-plans-container::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
  }
  
  .billing-plans-container > div[class*="col-"] {
    flex: 0 0 85% !important; /* Cada card ocupa 85% da tela permitindo ver o início do próximo */
    max-width: 85% !important;
    scroll-snap-align: center !important;
  }
}

/* ==========================================================================
   Ajustes de Acessibilidade, Contraste e Tema Claro da Sidebar
   ========================================================================== */

/* 1. Sincronização e contraste da Sidebar Clara */
html[data-startbar="light"] body.layout-app-saas .startbar .brand .logo .brand-site-name,
html:not([data-startbar="dark"]) body.layout-app-saas .startbar .brand .logo .brand-site-name {
  color: var(--bs-menu-link-color, #061237) !important;
}

html[data-startbar="light"] body.layout-app-saas .startbar-version,
html:not([data-startbar="dark"]) body.layout-app-saas .startbar-version {
  border-top: 1px solid var(--bs-startbar-e-border-color, #e9ebef) !important;
  color: var(--bs-menu-label-color, #6c7387) !important;
}

/* Ajustes finos nos itens e ícones da Sidebar Clara para máximo contraste */
html[data-startbar="light"] .startbar .startbar-menu .navbar-nav .nav-item .nav-link:not(.active) {
  color: #2c303b !important;
  font-weight: 600 !important;
}

html[data-startbar="light"] .startbar .startbar-menu .navbar-nav .nav-item .nav-link:not(.active) .menu-icon {
  color: #4b5266 !important;
}

html[data-startbar="light"] .startbar .startbar-menu .navbar-nav .menu-label {
  color: #1a1e27 !important;
  font-weight: 700 !important;
  letter-spacing: 0.05em;
}

/* 2. Melhoria de contraste global, fundo neutro e sombras profissionais (no tema claro) */
html[data-bs-theme="light"] {
  --bs-body-color: #212529 !important;
  --bs-secondary-color: #3e4455 !important;
  --bs-text-muted: #3e4455 !important;
}

html[data-bs-theme="light"] body.layout-app-saas {
  background-color: #E5EBF0 !important;
  color: #212529 !important;
  font-weight: 500 !important;
}

html[data-bs-theme="light"] .card {
  background-color: #ffffff !important;
  border: none !important;
  border-radius: 12px !important;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04) !important;
}

html[data-bs-theme="light"] .text-muted,
html[data-bs-theme="light"] .text-secondary {
  color: #3e4455 !important;
  font-weight: 500 !important;
}

html[data-bs-theme="light"] .breadcrumb-item,
html[data-bs-theme="light"] .breadcrumb-item a {
  color: #3e4455 !important;
  font-weight: 600 !important;
}

html[data-bs-theme="light"] .table th,
html[data-bs-theme="light"] thead th {
  color: #11151d !important;
  font-weight: 700 !important;
}

html[data-bs-theme="light"] .table td {
  color: #212529 !important;
  font-weight: 500 !important;
}

html[data-bs-theme="light"] .card-title,
html[data-bs-theme="light"] h1,
html[data-bs-theme="light"] h2,
html[data-bs-theme="light"] h3,
html[data-bs-theme="light"] h4,
html[data-bs-theme="light"] h5,
html[data-bs-theme="light"] h6 {
  color: #11151d !important;
  font-weight: 700 !important;
}

html[data-bs-theme="light"] p {
  color: #212529 !important;
}

html[data-bs-theme="light"] .alert {
  color: #11151d !important;
}

html[data-bs-theme="light"] .alert .text-muted {
  color: #11151d !important;
  font-weight: 500 !important;
}

/* Estilos globais para inputs e labels em todo o sistema (Tema Claro) */
html[data-bs-theme="light"] .form-control,
html[data-bs-theme="light"] .form-select {
  background-color: #ffffff !important;
  border: 2px solid #cbd5e1 !important; /* Borda bem visível e definida */
  color: #1a1e27 !important;
  font-weight: 500 !important;
  border-radius: 8px !important;
  transition: all 0.2s ease-in-out !important;
}

html[data-bs-theme="light"] .form-control:focus,
html[data-bs-theme="light"] .form-select:focus {
  background-color: #ffffff !important;
  border-color: #3f51b5 !important;
  box-shadow: 0 0 0 3px rgba(63, 81, 181, 0.15) !important;
  outline: none !important;
}

html[data-bs-theme="light"] .form-label {
  color: #1a1e27 !important;
  font-weight: 700 !important;
  font-size: 13px !important;
  margin-bottom: 6px !important;
}

html[data-bs-theme="light"] .input-group-text {
  background-color: #f1f5f9 !important;
  border: 2px solid #cbd5e1 !important;
  color: #475569 !important;
  font-weight: 600 !important;
}

/* Ajuste de legibilidade para cabeçalho de autenticação (auth-header-box) */
.auth-header-box,
.auth-header-box.bg-black,
div.auth-header-box {
  background-color: #0b0f19 !important;
  color: #ffffff !important;
}

.auth-header-box h1,
.auth-header-box h2,
.auth-header-box h3,
.auth-header-box h4,
.auth-header-box h5,
.auth-header-box h6,
.auth-header-box a,
.auth-header-box div,
html[data-bs-theme="light"] .auth-header-box h1,
html[data-bs-theme="light"] .auth-header-box h2,
html[data-bs-theme="light"] .auth-header-box h3,
html[data-bs-theme="light"] .auth-header-box h4,
html[data-bs-theme="light"] .auth-header-box h5,
html[data-bs-theme="light"] .auth-header-box h6,
html[data-bs-theme="light"] .card .auth-header-box h4 {
  color: #ffffff !important;
}

.auth-header-box p,
.auth-header-box .text-muted,
.auth-header-box .text-white-50,
.auth-header-box span,
.auth-header-box small,
html[data-bs-theme="light"] .auth-header-box p,
html[data-bs-theme="light"] .auth-header-box .text-muted,
html[data-bs-theme="light"] .auth-header-box .text-white-50,
html[data-bs-theme="light"] .card .auth-header-box p {
  color: rgba(255, 255, 255, 0.8) !important;
}


