/* CSS UNIFICADO E CORRIGIDO */
:root {
  --bg: radial-gradient(circle at top left, #e0f2fe 0, #f4f4fb 45%, #f9fafb 100%);
  --glass: rgba(255, 255, 255, 0.65);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --border-glass: rgba(148, 163, 184, 0.45);
  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.18);
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --ink: #0f172a;
  --ink-soft: #6b7280;
  --danger: #dc2626;
  --danger-soft: rgba(248, 113, 113, 0.1);
}

*, *::before, *::after { box-sizing: border-box; }

/* ===== ESTRUTURA PRINCIPAL (ENQUADRAMENTO) ===== */
html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  background-attachment: fixed; /* Fixa o fundo para melhorar o efeito glass */
  overscroll-behavior: none; /* Evita efeito elástico no iOS */
}

/* Aplica overflow:hidden apenas em páginas que NÃO são a landing page (ex: o painel de chat) */
/*html:not(.landing-page), body:not(.landing-page) {
    overflow: hidden;*/ /* Impede o scroll da página inteira */
    /* Correção: baseia o bloqueio do body na classe do HTML pai */
html:not(.landing-page), 
html:not(.landing-page) body {
    overflow: hidden; /* Impede o scroll apenas se NÃO for landing page */
}

.app-shell {
  height: 100dvh; /* Ocupa a altura dinâmica da tela (mobile friendly) */
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0; /* Não encolhe */
}
.app-title { font-size: 18px; font-weight: 600; }
.app-subtitle { font-size: 12px; color: var(--ink-soft); }
.app-header-right { font-size: 12px; color: var(--ink-soft); }

.app-main {
  flex: 1; /* Ocupa todo o espaço vertical restante */
  display: flex; /* Usamos flex para controlar as colunas */
  gap: 16px;
  min-height: 0; /* Truque para o scroll interno funcionar em um container flex */
  position: relative; /* Necessário para a responsividade mobile */
  overflow: hidden;
}

/* ===== Cartões glass ===== */
.card-glass {
  border-radius: 18px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  display: flex;
  flex-direction: column; /* Essencial para o layout interno */
}

.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15); /* Reforço visual do título */
}
.card-header-title { font-weight: 600; }

/* ===== Sidebar / fila ===== */
.sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-box {
  padding: 8px 14px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  flex-shrink: 0;
}
.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.55);
  background: var(--glass-strong);
}
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
}
.conversation-list {
  flex: 1; /* Ocupa o espaço restante no sidebar */
  overflow-y: auto; /* Adiciona o scroll vertical QUANDO necessário */
  padding: 6px 0;
}
.sidebar-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Filter Pills */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  flex-shrink: 0;
}
.filter-pill {
  flex: 1;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px; /* Borda suave */
  border: 1px solid transparent;
  background: rgba(236, 239, 241, 0.5);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.2s ease;
}
.filter-pill:hover {
  background: rgba(224, 227, 230, 0.8);
  color: var(--ink);
}
.filter-pill.active {
  background: #fff;
  color: var(--accent);
  border-color: rgba(79, 70, 229, 0.4);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
  font-weight: 600;
}

/* Conversation Item */
.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
.conversation-item.active {
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
}
.conversation-info { flex: 1; min-width: 0; }
.conversation-title-row { display: flex; justify-content: space-between; align-items: center; }
.conversation-title { font-weight: 600; }
.conversation-time { font-size: 11px; color: var(--ink-soft); }
.conversation-meta { display: flex; justify-content: space-between; align-items: center; }
.conversation-last { font-size: 11px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-human { padding: 2px 7px; border-radius: 999px; font-size: 10px; background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.5); }
.badge-ai { padding: 2px 7px; border-radius: 999px; font-size: 10px; background: #e0f2fe; color: #0369a1; border: 1px solid rgba(3, 105, 161, 0.2); }
.conversation-actions { display: flex; align-items: center; }
.btn-xs {
  padding: 4px 8px;
  font-size: 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn-xs:hover { background: #f9fafb; }

/* ===== Chat principal ===== */
.chat {
  flex: 1; /* Ocupa o resto do espaço horizontal */
  min-width: 0; /* Evita que o chat "empurre" o sidebar para fora da tela */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.15); /* Reforço visual do título */
}
.chat-header-info h2 { font-size: 15px; font-weight: 600; margin: 0; }
.chat-header-info small { font-size: 11px; color: var(--ink-soft); }

/* Botão principal do header */
.btn-pill {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 8px; /* Borda suave, igual aos filtros */
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: var(--glass-strong);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-pill.danger {
  border-color: rgba(248, 113, 113, 0.7);
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-pill.primary {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-pill:disabled { opacity: 0.5; cursor: default; }
.btn-back {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0 12px 0 0;
}

/* Histórico de Chat */
.chat-history {
  flex: 1; /* Ocupa o espaço central do chat */
  padding: 16px;
  overflow-y: auto; /* Adiciona o scroll vertical QUANDO necessário */
}
.empty-state {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--ink-soft);
}
.msg-wrapper { display: flex; flex-direction: column; margin-bottom: 12px; }
.msg-wrapper.user { align-items: flex-start; }
.msg-wrapper.agent { align-items: flex-end; }
.msg-bubble { max-width: 75%; padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.5; word-wrap: break-word; }
.msg-bubble.user { background: #fff; border: 1px solid #e5e7eb; color: #374151; border-bottom-left-radius: 4px; }
.msg-bubble.agent { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-meta { font-size: 11px; color: #9ca3af; margin-top: 4px; padding: 0 6px; }

/* Estilos para Mídia dentro do balão */
.msg-bubble img, .msg-bubble video {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 4px;
  display: block;
}
.msg-bubble audio {
  max-width: 100%;
  margin-top: 4px;
}
.msg-bubble a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

/* Input de Chat */
.chat-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  background: var(--glass-strong);
  flex-shrink: 0; /* Garante que o input não seja esmagado */
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  min-height: 42px;
  max-height: 140px;
  outline: none;
}
.chat-input textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.3); }

/* Botões de anexo (ícones) */
.chat-actions-left {
  position: relative;
  display: flex;
  gap: 2px;
  padding-bottom: 4px; /* Alinha visualmente com a base do input */
}
.options-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 10px;
  background: var(--glass-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}
.options-menu.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: rgba(148, 163, 184, 0.2);
  color: var(--accent);
}
.btn-icon.recording {
  color: var(--danger);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.chat-actions-right {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
}

.btn-send {
  height: 42px;
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 500;
  cursor: pointer;
}
.btn-send:disabled { opacity: 0.5; cursor: default; }

/* ===== RESPONSIVIDADE (MOBILE) ===== */
@media (max-width: 900px) {
  .app-shell {
    position: fixed; /* Fixa o app na tela para não rolar com o navegador */
    inset: 0; /* Shorthand moderno para top, right, bottom, left = 0 */
    margin: 0;
    border-radius: 0;
    padding: 0; /* Remove padding do container, vamos aplicar internamente */
  }
  .app-header {
    margin-bottom: 0;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top)); /* Protege contra o Notch */
    border-radius: 0;
  }
  .app-main {
    gap: 0;
  }
  .sidebar, .chat {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease-in-out;
    will-change: transform;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
    border-bottom: 1px solid var(--border-glass);
  }
  .sidebar { transform: translateX(0); z-index: 2; }
  .chat { transform: translateX(100%); z-index: 1; }

  .app-main.chat-view-active .sidebar {
    transform: translateX(-100%);
  }
  .app-main.chat-view-active .chat {
    transform: translateX(0);
    z-index: 3;
  }
  .btn-back {
    display: block; /* Mostra o botão de voltar no mobile */
  }
  
  /* Evita zoom automático no iOS ao focar em inputs (font-size >= 16px) */
  input, textarea, select, button {
    font-size: 16px !important;
  }

  .chat-input {
    padding-bottom: max(12px, env(safe-area-inset-bottom)); /* Garante que o input suba acima da barra do iPhone */
    z-index: 50; /* Garante que fique acima de tudo */
    background: #ffffff; /* Fundo sólido para não misturar */
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== LANDING PAGE ESTILOS ===== */
/*.landing-page {
    overflow-y: auto;
    overflow-x: hidden;
}*/
html.landing-page, 
html.landing-page body {
    overflow-y: auto !important; /* Força a barra de rolagem */
    overflow-x: hidden;
    height: auto !important; /* Permite que a página cresça além de 100vh */
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

.main-header {
    position: fixed;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 100;
    padding: 10px 20px;
    background: var(--glass);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--border-glass);
    border-radius: 18px;
    box-shadow: var(--shadow-soft);
}

.main-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
}

.logo {
    height: 40px;
    width: auto;
    border-radius: 8px;
}

.main-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 25px;
}

.main-nav a {
    text-decoration: none;
    color: var(--ink);
    font-weight: 500;
    transition: color 0.3s;
}

.main-nav a:hover {
    color: var(--accent);
}

.menu-toggle {
    display: none;
    font-size: 28px;
    cursor: pointer;
}

main {
    padding-top: 120px; /* Space for header */
}

.hero {
    text-align: center;
    padding: 80px 0;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--ink);
    line-height: 1.2;
    margin-bottom: 20px;
}

.hero .subtitle {
    font-size: 1.25rem;
    color: var(--ink-soft);
    max-width: 700px;
    margin: 0 auto 30px;
}

.cta-button {
    display: inline-block;
    padding: 14px 30px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: 999px;
    font-weight: 600;
    transition: transform 0.3s;
}

.cta-button:hover {
    transform: scale(1.05);
}

section {
    padding: 60px 0;
}

section h2 {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 40px;
}

.grid {
    display: grid;
    gap: 24px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.card-glass {
    padding: 25px;
}

.card-glass h3 {
    margin-top: 0;
    color: var(--accent);
}

.card-glass ul {
    padding-left: 20px;
    color: var(--ink-soft);
}

.main-footer {
    text-align: center;
    padding: 50px 20px;
    margin-top: 40px;
    background: rgba(255, 255, 255, 0.2);
}

.main-footer h2 {
    font-size: 2rem;
}


@media (max-width: 900px) {
    .main-header {
        top: 0;
        left: 0;
        right: 0;
        border-radius: 0;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: 10px;
    }

    .main-nav {
        display: none;
        position: absolute;
        top: calc(100% + 10px);
        left: 16px;
        right: 16px;
        background: var(--glass-strong);
        border-radius: 12px;
        box-shadow: var(--shadow-soft);
        border: 1px solid var(--border-glass);
    }
    .main-nav.active {
        display: block;
    }
    .main-nav ul {
        flex-direction: column;
        padding: 20px;
        gap: 15px;
        align-items: center;
    }
    .menu-toggle {
        display: block;
    }

    .hero h1 { font-size: 2.5rem; }
    .hero .subtitle { font-size: 1.1rem; }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}
/* No final do arquivo painel.css */

/* ... outros estilos ... */

/* FORÇA BRUTA PARA O SCROLL FUNCIONAR */
html.landing-page, 
html.landing-page body {
    overflow: auto !important;       /* Libera a barra de rolagem */
    overflow-x: hidden !important;   /* Evita rolagem horizontal */
    height: auto !important;         /* Permite que a página cresça */
    min-height: 100vh;               /* Garante altura mínima */
    position: static !important;     /* Remove travamentos de posição */
    overscroll-behavior: auto !important; /* Reativa o bounce nativo */
}

/* Garante que o container principal não trave */
html.landing-page .container {
    height: auto !important;
    overflow: visible !important;
}
