/* ========== SCROLLBAR CUSTOMIZADA ==========

/* ===== iPHONE 15 PRO: 393×852pt + Dynamic Island ===== */
@media (max-width: 393px) {
  /* Safe area para Dynamic Island e barra home */
  .mobile-header {
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }

  .main-content {
    padding-top: calc(56px + env(safe-area-inset-top));
    height: 100svh;
    height: -webkit-fill-available;
  }

  .chat-wrapper {
    padding-bottom: 80px;
  }

  .input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    z-index: 100;
    transition: transform 0.1s ease;
  }

  .input-container.centered {
    position: fixed;
    top: auto;
    bottom: 0;
    transform: none;
    border-top: 1px solid var(--border-color);
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .input-disclaimer {
    display: block;
    font-size: 11px;
    padding: 4px 8px 0;
    text-align: center;
    line-height: 1.3;
  }

  /* Sidebar cobre toda a área incluindo Dynamic Island */
  .sidebar {
    width: 85vw;
    max-width: 300px;
    left: -85vw;
    top: 0;
    bottom: 0;
    height: auto;
    padding-top: env(safe-area-inset-top);
  }

  /* Barra inferior de navegação do iOS */
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Mensagens */
  .message {
    font-size: 14px;
    padding: 10px 12px;
  }

  .message-inner {
    max-width: 100%;
  }

  /* Input */
  .input-wrapper {
    padding: 10px 12px;
    gap: 8px;
    border-radius: 26px;
  }

  #messageInput {
    font-size: 16px; /* evita zoom automático no iOS */
  }

  /* Welcome screen */
  .welcome-screen {
    padding-bottom: calc(260px + env(safe-area-inset-bottom));
    padding-left: 12px;
    padding-right: 12px;
  }

  .audit-welcome {
    padding-bottom: calc(260px + env(safe-area-inset-bottom));
  }

  .welcome-screen h1 {
    font-size: 20px;
  }

  .welcome-screen p {
    font-size: 14px;
  }

  /* Suggestion cards em coluna única */
  .suggestion-cards {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 12px;
    margin-top: 130px;
  }

  /* Login */
  .login-box {
    padding: 24px 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    width: 95%;
    border-radius: 12px;
  }

  /* Nav items da sidebar */
  .nav-item {
    font-size: 14px;
    padding: 10px 12px;
  }

  /* Modais */
  .audit-suggestions-modal {
    max-width: 100%;
    border-left: none;
    border-radius: 0;
  }

  .audit-suggestions-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }

  .agente1-modal {
    max-height: 90vh;
    border-radius: 12px;
  }

  .agente1-modal-overlay {
    padding: 12px;
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  /* Aba lateral de sugestões — recuar da barra home */
  .audit-side-tab {
    top: 25%;
    bottom: auto;
    padding: 14px 8px;
    gap: 8px;
    border-radius: 8px 0 0 8px;
  }

  .audit-side-tab-text {
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  .audit-side-tab svg {
    width: 15px;
    height: 15px;
  }
}

/* ===== Samsung S23 Ultra: 384x824 ===== */
@media (max-width: 384px) and (max-height: 824px) {
  .main-content {
    padding-top: calc(56px + env(safe-area-inset-top));
    height: 100svh;
    min-height: 100svh;
    height: -webkit-fill-available;
  }

  .chat-wrapper {
    padding: 12px 0 180px;
    min-height: 0;
  }

  .messages-container,
  .chat-container {
    padding: 12px;
    padding-bottom: calc(180px + env(safe-area-inset-bottom));
    min-height: 0;
  }

  .message-inner {
    max-width: 100%;
  }

  .message {
    padding: 10px 12px;
  }

  .sidebar {
    width: 85vw;
    max-width: 300px;
    left: -85vw;
    top: 0;
    bottom: 0;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar.mobile-open {
    left: 0;
  }

  .welcome-screen {
    padding-bottom: 180px;
    padding-left: 12px;
    padding-right: 12px;
    min-height: 50vh;
  }

  .audit-welcome {
    padding-bottom: 180px;
  }

  .welcome-screen h1 {
    font-size: 20px;
  }

  .welcome-screen p {
    font-size: 14px;
  }

  .suggestion-cards {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0 12px;
    margin-top: 100px;
  }

  .login-box {
    padding: 22px 18px;
    width: 95%;
    border-radius: 12px;
  }

  .input-container {
    padding: 8px 10px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
  }

  .input-container.centered {
    position: fixed;
    top: auto;
    bottom: 0;
    transform: none;
    border-top: 1px solid var(--border-color);
    padding: 8px 10px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .input-wrapper {
    padding: 10px 12px;
    gap: 8px;
    border-radius: 24px;
    width: 100%;
  }

  .send-btn {
    width: 36px;
    height: 36px;
    padding: 8px;
  }
}

/* ===== iOS Safari — iPhone 15 Pro — Correções específicas ===== */
/* @supports (-webkit-touch-callout: none) identifica iOS WebKit (Safari, Chrome iOS, etc.) */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 393px) {
    /* Altura correta: Safari browser tem toolbar que varia,
       height: 100% + min-height fill-available é mais estável */
    html {
      height: -webkit-fill-available;
    }

    .main-content {
      height: 100%;
      min-height: -webkit-fill-available;
    }

    /* Reduz padding-bottom excessivo da welcome screen:
       260px empurrava o conteúdo muito para cima no Safari */
    .welcome-screen {
      padding-bottom: calc(110px + env(safe-area-inset-bottom));
      min-height: auto;
    }

    .audit-welcome {
      padding-bottom: calc(110px + env(safe-area-inset-bottom));
    }

    /* Reduz margin-top dos cards de sugestão para se encaixar na tela menor */
    .suggestion-cards {
      margin-top: 20px;
    }

    /* Chat wrapper com espaço para o input fixo + barra nativa do Safari */
    .chat-wrapper {
      padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    /* Mensagens com padding adequado para não ficar atrás do input fixo */
    .messages-container,
    .chat-container {
      padding-bottom: calc(95px + env(safe-area-inset-bottom));
    }
  }
}

/* ========== SCROLLBAR CUSTOMIZADA ========== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

.sidebar ::-webkit-scrollbar-thumb {
  background: var(--scrollbar-sidebar);
}

.sidebar ::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-sidebar-hover);
}

/* ========== ABA LATERAL DE SUGESTÕES - AUDITORIA ========== */
.audit-side-tab {
  position: fixed;
  right: 0;
  top: 30%;
  transform: translateY(-50%);
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 10px 0 0 10px;
  padding: 18px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 900;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.18);
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease;
  font-family: inherit;
}

/* Cores específicas por seção */
.audit-side-tab.section-suporte {
  background: var(--background-sup);
}

.audit-side-tab.section-suporte:hover {
  background: #0d3a5f;
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.26);
}

.audit-side-tab.section-financeiro {
  background: var(--background-fin);
}

.audit-side-tab.section-financeiro:hover {
  background: #d4b363;
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.26);
}

.audit-side-tab.section-auditoria {
  background: var(--background-comp);
}

.audit-side-tab.section-auditoria:hover {
  background: #8a4445;
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.26);
}

.audit-side-tab:hover {
  background: var(--accent-hover);
  box-shadow: -6px 0 20px rgba(0, 0, 0, 0.26);
}

.audit-side-tab-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* ========== MODAL DE SUGESTÕES DE AUDITORIA ========== */
.audit-suggestions-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  z-index: 3000;
  animation: fadeInOverlay 0.22s ease;
}

@keyframes fadeInOverlay {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.audit-suggestions-modal {
  background: var(--bg-primary);
  border-left: 1px solid var(--border-color);
  border-radius: 0;
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.2);
  animation: slideInFromRight 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overflow: hidden;
}

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
    opacity: 0.6;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.audit-suggestions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.audit-suggestions-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.audit-suggestions-title svg {
  color: var(--accent-primary);
}

/* Cores do header do modal por seção */
.audit-suggestions-modal.section-suporte .audit-suggestions-title svg {
  color: var(--background-sup);
}

.audit-suggestions-modal.section-financeiro .audit-suggestions-title svg {
  color: var(--background-fin);
}

.audit-suggestions-modal.section-auditoria .audit-suggestions-title svg {
  color: var(--background-comp);
}

.audit-suggestions-close {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.audit-suggestions-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.audit-suggestions-subtitle {
  padding: 10px 24px 0;
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.audit-suggestions-body {
  overflow-y: auto;
  padding: 16px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.audit-suggestions-body::-webkit-scrollbar {
  width: 6px;
}
.audit-suggestions-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* Categorias */
.audit-category {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audit-category-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-primary);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}

.audit-questions-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.audit-question-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all 0.18s ease;
  line-height: 1.4;
}

.audit-question-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(16, 163, 127, 0.12);
}

.audit-question-btn:active {
  transform: translateY(0);
}

@media (max-width: 384px) {
  .audit-questions-grid {
    grid-template-columns: 1fr;
  }

  .audit-suggestions-modal {
    max-width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
  }

  .audit-suggestions-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }

  .audit-suggestions-header {
    padding: 16px 16px 12px;
  }

  .audit-suggestions-body {
    padding: 12px 16px 20px;
  }

  .audit-side-tab {
    top: 25%;
    bottom: auto;
    padding: 14px 8px;
    gap: 8px;
    border-radius: 8px 0 0 8px;
  }

  .audit-side-tab-text {
    font-size: 11px;
    letter-spacing: 0.04em;
  }

  .audit-side-tab svg {
    width: 15px;
    height: 15px;
  }
}

/* ========== MODAL AGENTE 1 ========== */
.agente1-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  padding: 20px;
  animation: fadeInOverlay 0.2s ease;
}

.agente1-modal {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: agente1SlideUp 0.25s ease;
  animation-fill-mode: both;
  overflow: hidden;
}

@keyframes agente1SlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.agente1-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.agente1-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.agente1-modal-title svg {
  color: var(--accent-primary);
}

.agente1-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.agente1-modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.agente1-modal-meta {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.agente1-modal-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-primary);
  white-space: nowrap;
  margin-top: 1px;
}

.agente1-modal-question {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.agente1-modal-body {
  overflow-y: auto;
  padding: 20px;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.7;
}

.agente1-modal-body::-webkit-scrollbar {
  width: 5px;
}
.agente1-modal-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

.agente1-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 10px 0;
}

@media (max-width: 384px) {
  .agente1-modal {
    max-height: 90vh;
    border-radius: 12px;
  }
  .agente1-modal-overlay {
    padding: 12px;
  }
}

.msg-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  opacity: 0;
  transition: 0.2s;
}

.message:hover .msg-actions {
  opacity: 1;
}

.message {
  position: relative;
}

.confirmation-modal.error .confirmation-content {
  border-color: #ef4444;
}

.alert-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.alert-btn {
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.alert-btn:hover {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

.admin-user-item.active {
  border: 1px solid var(--accent-primary);
  border: 3px solid var(--input-border);
}

.admin-user-item {
  position: relative;
}

.user-select {
  position: absolute;
  top: 50px;
  left: 15px;
  right: 15px;
  transform: translateY(-50%) scale(1.2);
  cursor: pointer;
}

/* .admin-user-header {
  padding-left: 40px;
} */

.confirmation-modal {
  animation: fadeInScale 0.2s ease;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

#deleteConfirmModal {
  z-index: 20000 !important;
}

#deleteConfirmModal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20000 !important;
}

#confirmationModal {
  z-index: 20001 !important;
}

.confirmation-modal {
  backdrop-filter: blur(4px);
}

.confirmation-modal {
  backdrop-filter: blur(4px);
}

/* Modal de confirmação (deve ficar na frente) */
#deleteModal {
  z-index: 2000 !important;
}

/* Modal de listagem */
#userListModal {
  z-index: 1050;
}

/* Backdrop do modal de confirmação */
#deleteModal + .modal-backdrop {
  z-index: 1999 !important;
}

/* ========== CHECKBOX STYLES ========== */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  margin: 0;
}

.admin-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

.admin-checkbox:hover {
  opacity: 0.8;
}

.checkbox-label span {
  user-select: none;
}

/* Checkboxes side-by-side container */
.checkboxes-container {
  display: flex;
  gap: 24px;
  align-items: center;
  /* margin-bottom: 20px; */
}

/* Ajustes genéricos de Modais para Mobile (até 768px) */
@media (max-width: 768px) {
  .audit-suggestions-modal {
    max-width: 100%;
    border-left: none;
    border-top: 1px solid var(--border-color);
    border-radius: 0;
  }

  .audit-suggestions-overlay {
    align-items: flex-end;
    justify-content: stretch;
  }

  .agente1-modal {
    max-height: 90vh;
    max-width: 100%;
    border-radius: 12px;
  }
  
  .agente1-modal-overlay {
    padding: 12px;
  }

  .confirmation-modal {
    padding: 10px;
  }
}

