:root {
  /* Paleta de Cores Refinada (Tech/Professional) */
  --brand-primary: #2563eb;       /* Azul Royal Moderno */
  --brand-secondary: #1e40af;     /* Azul Escuro Profundo */
  --brand-accent: #3b82f6;        /* Azul Brilhante */
  
  --surface-primary: #ffffff;
  --surface-secondary: #f8fafc;   /* Cinza muito claro, quase branco */
  --surface-tertiary: #f1f5f9;    /* Cinza suave para containers */

  --text-primary: #0f172a;        /* Quase preto, alto contraste */
  --text-secondary: #475569;      /* Cinza médio para suporte */
  --text-tertiary: #94a3b8;       /* Cinza claro para placeholders */
  --text-light: #ffffff;

  --status-success: #10b981;
  --status-warning: #f59e0b;
  --status-error: #ef4444;

  /* Efeitos Visuais */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05);
  --shadow-glow: 0 0 20px rgba(37, 99, 235, 0.2);

  --border-radius: 12px;
  --max-width: 48rem; /* Aprox 768px */

  --transition-base: 200ms ease-in-out;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--surface-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  /* Garante que o corpo ocupe 100% da altura para o flex funcionar */
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#root {
  display: flex;
  flex-direction: column;
  height: 100%; /* Ocupa 100% do body */
  width: 100%;
  overflow: hidden; /* Evita scroll duplo */
}

/* --- Header Moderno --- */
header {
  background: var(--surface-primary);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-bottom: 1px solid var(--surface-tertiary);
  width: 100%;
  flex-shrink: 0; /* Header nunca encolhe */
  z-index: 20;
}

header h1 {
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}

.sophia-highlight {
  color: var(--brand-primary);
  font-weight: 700;
}

/* --- Timer Discreto --- */
.timer {
  background: var(--surface-tertiary);
  color: var(--text-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 500;
  margin: 0.5rem auto 0;
  display: none; /* JS controla visibilidade */
  align-items: center;
  border: 1px solid transparent;
}

.timer.warning {
  color: #b45309;
  background: #fffbeb;
  border-color: #fcd34d;
}

.timer.danger {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fca5a5;
  animation: pulse-red 2s infinite;
}

/* --- Container de Vídeo Introdutório (YouTube) --- */
#video-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.video-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
  background: #000;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

.video-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.primary-button {
  background: var(--brand-primary);
  color: white;
  padding: 1rem 2.5rem;
  border-radius: 99px; 
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
}

.primary-button:hover {
  background: var(--brand-secondary);
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.4);
}

/* --- Área Principal (Chat e Conteúdo) --- */
main {
  flex: 1; /* Ocupa todo o espaço restante entre Header e Footer */
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  background: var(--surface-primary);
  position: relative;
  overflow: hidden; /* Importante: o scroll deve ser interno nos filhos */
  border-left: 1px solid var(--surface-tertiary);
  border-right: 1px solid var(--surface-tertiary);
}

/* Chat Container - CRÍTICO PARA O REALTIME */
#chat-container {
  flex: 1; /* Força o chat a ocupar todo o espaço vertical disponível */
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Prepara para o filho ter scroll */
  position: relative;
  background: var(--surface-primary);
  min-height: 0; /* Correção para flexbox scroll */
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Espaço para garantir que a última mensagem não fique escondida atrás de nada */
  padding-bottom: 1rem; 
}

.message {
  max-width: 85%;
  padding: 0.875rem 1.25rem;
  border-radius: 1rem;
  font-size: 0.95rem;
  line-height: 1.5;
  position: relative;
  animation: fade-in 0.3s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.bot-message {
  background: var(--surface-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.user-message {
  background: var(--brand-primary);
  color: var(--text-light);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

/* --- GRAVAÇÃO DE VÍDEO (CORRIGIDO PARA NÃO QUEBRAR TELA) --- */

#video-recording-container {
  /* Flex Column força itens um embaixo do outro, resolvendo o problema lateral */
  display: flex; 
  flex-direction: column; 
  align-items: center;
  justify-content: flex-start;
  gap: 1.5rem;
  background: var(--surface-primary);
  width: 100%;
  height: 100%; /* Ocupa toda a main */
  padding: 1.5rem;
  overflow-y: auto; /* Permite rolar se a tela for muito pequena */
}

.video-question {
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
    margin: 0;
    width: 100%;
}

.video-preview-wrapper {
    position: relative;
    width: 100%;
    /* Max-width impede que estoure em desktops, width 100% segura no mobile */
    max-width: 100%; 
    aspect-ratio: 16 / 9; /* Mantém a proporção retangular */
    background: #000;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* Impede que o vídeo seja esmagado */
}

#video-preview {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Cobre a área sem distorcer */
    transform: scaleX(-1); /* Espelho */
}

.video-timer-display {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-light);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 10;
}

.video-instructions {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 0;
    line-height: 1.4;
}

.video-controls {
    display: flex;
    flex-direction: row; /* Botões lado a lado */
    gap: 1rem;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap; /* Se a tela for minúscula, quebra linha */
}

/* --- REALTIME VISUALIZER UI (CORRIGIDO) --- */
/* Fixo no rodapé da Main, permitindo ver o chat acima */

#realtime-visualizer-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Gradiente sutil para diferenciar do chat */
    background: linear-gradient(to bottom, #ffffff, #f1f5f9);
    
    width: 100%;
    /* Altura fixa para ser um painel de controle estável */
    height: 240px; 
    
    border-top: 1px solid #cbd5e1;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
    z-index: 10;
    flex-shrink: 0; /* Não deixa encolher */
    padding: 1rem 0;
}

.visualizer-container {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

/* Núcleo da IA */
.ai-core {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--brand-accent), var(--brand-secondary));
    border-radius: 50%;
    position: relative;
    z-index: 10;
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.4);
    animation: core-breathe 4s infinite ease-in-out;
}

/* Camadas de Brilho */
.ai-glow-1, .ai-glow-2 {
    position: absolute;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.1);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.ai-glow-1 {
    width: 80px;
    height: 80px;
    animation: glow-pulse 3s infinite ease-in-out;
}

.ai-glow-2 {
    width: 110px;
    height: 110px;
    animation: glow-pulse 3s infinite ease-in-out 1s;
}

/* Status e Feedback */
.realtime-status-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

#realtime-status-text {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

/* Ondas de áudio mini */
.audio-waves-mini {
    display: flex;
    gap: 4px;
    height: 16px;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.audio-waves-mini span {
    width: 3px;
    height: 100%;
    background-color: var(--brand-accent);
    border-radius: 2px;
    animation: sound-wave 1s infinite ease-in-out;
}

.audio-waves-mini span:nth-child(2) { animation-delay: 0.1s; height: 80%; }
.audio-waves-mini span:nth-child(3) { animation-delay: 0.2s; height: 60%; }
.audio-waves-mini span:nth-child(4) { animation-delay: 0.3s; height: 40%; }

/* ESTADOS DA IA */
#realtime-visualizer-ui.mode-speaking .ai-core {
    background: linear-gradient(135deg, #a855f7, #6366f1);
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.5);
    animation: core-speak 0.8s infinite alternate;
}
#realtime-visualizer-ui.mode-speaking .ai-glow-1 { background: rgba(168, 85, 247, 0.15); }
#realtime-visualizer-ui.mode-speaking .realtime-status-container .audio-waves-mini { opacity: 1; }
#realtime-visualizer-ui.mode-speaking .audio-waves-mini span { background-color: #a855f7; }

#realtime-visualizer-ui.mode-listening .ai-core {
    transform: scale(1.1);
    background: linear-gradient(135deg, #10b981, #0ea5e9);
    box-shadow: 0 0 40px rgba(16, 185, 129, 0.4);
    animation: none;
}
#realtime-visualizer-ui.mode-listening .ai-glow-1 {
    width: 100px;
    height: 100px;
    background: rgba(16, 185, 129, 0.1);
    animation: ripple-out 2s infinite linear;
}

/* ANIMAÇÕES */
@keyframes core-breathe { 0% { transform: scale(1); opacity: 0.9; } 50% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1); opacity: 0.9; } }
@keyframes core-speak { 0% { transform: scale(0.95); } 100% { transform: scale(1.1); } }
@keyframes glow-pulse { 0% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.3; } 50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.6; } 100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.3; } }
@keyframes ripple-out { 0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.8; } 100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; } }
@keyframes sound-wave { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@keyframes pulse-red { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }

/* --- INPUTS E FORMULÁRIOS --- */
form#user-input-form {
    padding: 1rem;
    background: var(--surface-primary);
    border-top: 1px solid var(--surface-tertiary);
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.input-group {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    position: relative;
}

input#user-input {
    flex: 1;
    padding: 0.875rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 99px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--surface-secondary);
    min-width: 0;
}

input#user-input:focus {
    border-color: var(--brand-primary);
    background: #fff;
}

button[type="submit"] {
    background: var(--brand-primary);
    color: white;
    border: none;
    padding: 0 1.5rem;
    border-radius: 99px;
    font-weight: 600;
    cursor: pointer;
}

button[type="submit"]:disabled { background: var(--text-tertiary); cursor: not-allowed; }

#mic-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mic-btn.recording {
    color: var(--status-error);
    background: #fee2e2;
    animation: pulse-red 1.5s infinite;
}

/* Upload e Footer */
#resume-upload-form { padding: 2rem; display: flex; justify-content: center; flex-shrink: 0; }
.upload-container { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1rem; }
.file-input { padding: 0.5rem; border: 1px dashed var(--text-tertiary); border-radius: var(--border-radius); background: var(--surface-secondary); width: 100%; }
.upload-button { background: var(--brand-primary); color: white; padding: 0.875rem; border: none; border-radius: var(--border-radius); font-weight: 600; cursor: pointer; }

footer {
    padding: 1rem;
    text-align: center;
    background: var(--surface-primary);
    border-top: 1px solid var(--surface-tertiary);
    flex-shrink: 0;
    z-index: 30;
}
footer p { font-size: 0.8rem; color: var(--text-secondary); margin: 0.25rem 0; }
footer a { color: var(--brand-primary); text-decoration: none; font-weight: 500; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.audio-player { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; background: rgba(255,255,255,0.1); padding: 0.5rem; border-radius: 99px; }
.play-pause-btn { width: 28px; height: 28px; border-radius: 50%; border: none; background: white; color: var(--brand-primary); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.progress-bar-container { flex: 1; height: 4px; background: rgba(255,255,255,0.3); border-radius: 2px; cursor: pointer; }
.progress-bar { height: 100%; background: white; width: 0%; border-radius: 2px; }

/* Botão de Perigo */
.danger-button {
    background-color: var(--status-error);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    font-weight: 600;
    cursor: pointer;
}
.danger-button:hover { background-color: #b91c1c; }

/* Ajuste Mobile */
@media (max-width: 600px) {
    #realtime-visualizer-ui { height: 200px; }
    .visualizer-container { width: 100px; height: 100px; }
    .ai-core { width: 40px; height: 40px; }
    .ai-glow-1 { width: 60px; height: 60px; }
    .ai-glow-2 { width: 80px; height: 80px; }
}
