/* ========================================
   MAIAS CHAT - Estilos principais
   CORRIGIDO v2: Imagem de fundo funcional
   ======================================== */

:root {
  --bg-dark: #0a0d12;
  --bg-panel: #12161d;
  --bg-panel-alt: #161b24;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --text-primary: #e8f1fb;
  --text-secondary: #8ea2b7;
  --text-muted: #5a6a7a;
  --accent: #4da3ff;
  --accent-soft: rgba(77,163,255,0.15);
  --accent-glow: rgba(77,163,255,0.25);
  --bubble-user: #1e2a3a;
  --bubble-bot: #182233;
  --success: #4ade80;
  --warning: #fbbf24;
  --question-bg: rgba(77,163,255,0.08);
  --question-hover: rgba(77,163,255,0.15);
  --question-border: rgba(77,163,255,0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ========================================
   LAYOUT PRINCIPAL
   ======================================== */

.app-container {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr minmax(220px, 280px);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ========================================
   PAINEL ESQUERDO - CENAS
   ======================================== */

.sidebar-left {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.audiocena-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.audiocena-link:hover {
  color: var(--accent);
}

.title-link {
  color: inherit;
  text-decoration: none;
  transition: color 0.2s ease;
}

.title-link:hover {
  color: var(--accent);
}

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.scenes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.scene-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.scene-item:hover {
  background: var(--bg-panel-alt);
  border-color: var(--border);
}

.scene-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.scene-number {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.scene-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.scene-chapter {
  font-size: 12px;
  color: var(--text-secondary);
}

.scene-details {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel-alt);
  max-height: 180px;
  overflow-y: auto;
  flex-shrink: 0;
}

.scene-details-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.scene-details-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.scene-themes {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.theme-tag {
  font-size: 9px;
  padding: 3px 6px;
  background: rgba(77,163,255,0.1);
  color: var(--accent);
  border-radius: 4px;
  border: 1px solid rgba(77,163,255,0.2);
}

/* ========================================
   PAINEL CENTRAL - CHAT
   ======================================== */

.main-panel {
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  /* Fundo base escuro */
  background: var(--bg-dark);
}

/* ============================================
   IMAGEM DE FUNDO DA CENA
   - Usa um div separado criado via CSS
   - Apenas a IMAGEM tem opacidade reduzida
   - O conteúdo fica 100% opaco
   ============================================ */
.main-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* A imagem é definida via JavaScript com --scene-bg */
  background-image: var(--scene-bg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* Opacidade APENAS do pseudo-elemento (imagem) */
  opacity: 0;
  /* Atrás de todo o conteúdo */
  z-index: 0;
  /* Não bloqueia cliques */
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* Quando há imagem de cena, mostrar com opacidade reduzida */
.main-panel.has-scene-bg::before {
  opacity: 0.8; /* Ajusta: 0.2=escuro, 0.5=mais visível */
}

/* Gradiente decorativo no topo (glow azul) */
.main-panel::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-glow), transparent);
  pointer-events: none;
  z-index: 1;
}

/* ========================================
   HEADER DO CHAT
   ======================================== */

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(18,22,29,0.95);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.chat-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-title .character-name {
  color: var(--accent);
}

.chat-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-audiocena {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-audiocena:hover {
  background: var(--accent);
  color: #fff;
}

.model-chip {
  font-size: 10px;
  padding: 4px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

.btn-clear {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear:hover {
  background: var(--bg-panel-alt);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* ========================================
   MENSAGENS DO CHAT
   ======================================== */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  position: relative;
  z-index: 2;
  min-height: 0;
  /* Fundo semi-transparente para deixar ver a imagem */
  background: rgba(10, 13, 18, 0.5);
}

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-start;
  /* Garantir que as mensagens são 100% opacas */
  opacity: 1;
}

.msg.me {
  flex-direction: row-reverse;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.avatar .initial,
.avatar .bars {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.25s ease;
}

.avatar .initial { opacity: 1; }
.avatar .bars {
  opacity: 0;
  padding: 8px;
  grid-template-rows: repeat(5, 1fr);
  gap: 3px;
}

.avatar.speaking .initial { opacity: 0; }
.avatar.speaking .bars { opacity: 1; }

.avatar .bars i {
  height: 3px;
  width: 20%;
  background: var(--accent);
  border-radius: 2px;
  animation: widen 1.4s infinite ease-in-out;
}

.avatar .bars i:nth-child(1) { --min: 20%; --max: 75%; animation-delay: 0s; }
.avatar .bars i:nth-child(2) { --min: 15%; --max: 60%; animation-delay: 0.1s; }
.avatar .bars i:nth-child(3) { --min: 25%; --max: 90%; animation-delay: 0.2s; }
.avatar .bars i:nth-child(4) { --min: 12%; --max: 50%; animation-delay: 0.3s; }
.avatar .bars i:nth-child(5) { --min: 30%; --max: 85%; animation-delay: 0.4s; }

@keyframes widen {
  0%, 100% { width: var(--min); }
  50% { width: var(--max); }
}

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  max-width: 70%;
  white-space: pre-wrap;
  line-height: 1.6;
  /* Garantir opacidade total */
  opacity: 1;
}

.msg.me .bubble {
  background: var(--bubble-user);
  border-color: rgba(77,163,255,0.2);
}

.typing::after {
  content: "▎";
  margin-left: 2px;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* ========================================
   ÁREA DE INPUT
   ======================================== */

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(18,22,29,0.95);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}

.character-select-row {
  margin-bottom: 10px;
}

.character-select-row select {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.character-select-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.character-select-row select:hover {
  border-color: var(--border-hover);
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.input-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.input-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.input-row input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-send:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-send:active {
  transform: translateY(0);
}

.input-hint {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
}

/* ========================================
   PAINEL DIREITO - CONFIGURAÇÕES
   ======================================== */

.sidebar-right {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
}

.settings-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-header h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-list {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.setting-item {
  margin-bottom: 14px;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.setting-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.setting-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-panel-alt);
  border: 1px solid var(--border);
  transition: 0.2s;
  border-radius: 20px;
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: 0.2s;
  border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
  background-color: var(--accent-soft);
  border-color: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
  background-color: var(--accent);
}

/* Mode indicator */
.mode-indicator {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(77,163,255,0.2);
  border-radius: 6px;
  font-size: 10px;
  color: var(--accent);
  display: none;
}

.mode-indicator.active {
  display: block;
}

/* ========================================
   SECÇÃO DE PERGUNTAS SUGERIDAS
   ======================================== */

.questions-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.questions-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.questions-header h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.questions-subtitle {
  font-size: 10px;
  color: var(--text-muted);
}

.questions-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 0;
}

.questions-empty {
  padding: 16px 12px;
  text-align: center;
}

.questions-empty p {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.questions-hint {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}

.questions-category {
  margin-bottom: 12px;
}

.questions-category-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  margin-bottom: 6px;
}

.question-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--question-bg);
  border: 1px solid var(--question-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.question-btn:hover {
  background: var(--question-hover);
  border-color: var(--accent);
  transform: translateX(2px);
}

.question-btn:active {
  transform: translateX(0);
}

.question-theme {
  display: block;
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

.questions-loading {
  padding: 20px;
  text-align: center;
}

.questions-loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 10px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.questions-loading-text {
  font-size: 11px;
  color: var(--text-muted);
}

.questions-notice {
  padding: 12px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.2);
  border-radius: 8px;
  margin-bottom: 10px;
}

.questions-notice p {
  font-size: 11px;
  color: var(--warning);
  margin: 0;
}

/* ========================================
   RESPONSIVO
   ======================================== */

@media (max-width: 1200px) {
  .app-container {
    grid-template-columns: minmax(200px, 240px) 1fr minmax(200px, 260px);
  }
}

@media (max-width: 1000px) {
  .app-container {
    grid-template-columns: 200px 1fr 220px;
  }

  .sidebar-header h2 {
    font-size: 18px;
  }

  .scene-title {
    font-size: 14px;
  }

  .btn-audiocena {
    display: none;
  }
}

@media (max-width: 800px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar-left {
    display: none;
  }

  .sidebar-right {
    display: none;
  }

  .mobile-controls {
    display: flex;
    gap: 8px;
  }
}

.mobile-controls {
  display: none;
}

/* ========================================
   SCROLLBAR
   ======================================== */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

/* ===========================================
   DROPDOWN MENU - TÍTULO
   =========================================== */

.title-dropdown {
  position: relative;
}

.title-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  color: #c9a227;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0;
  transition: color 0.2s ease;
}

.title-trigger:hover {
  color: #dbb84d;
}

.dropdown-arrow {
  font-size: 0.8rem;
  opacity: 0.7;
  transition: transform 0.2s ease;
}

.dropdown-menu.show + .title-trigger .dropdown-arrow,
.title-dropdown:has(.dropdown-menu.show) .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  min-width: 250px;
  background: #1a1a2e;
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 1000;
  overflow: hidden;
}

.dropdown-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  text-decoration: none;
  color: #e0e0e0;
  transition: background 0.15s ease;
  cursor: pointer;
}

.dropdown-item:hover {
  background: rgba(201, 162, 39, 0.1);
}

.dropdown-item.active {
  background: rgba(201, 162, 39, 0.15);
  cursor: default;
}

.dropdown-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #c9a227;
}

.dropdown-item + .dropdown-item {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.dropdown-icon {
  font-size: 1.25rem;
  width: 2rem;
  text-align: center;
}

.dropdown-text {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.dropdown-label {
  font-weight: 500;
  font-size: 0.95rem;
}

.dropdown-desc {
  font-size: 0.75rem;
  color: #888;
}

.dropdown-item:hover .dropdown-desc {
  color: #aaa;
}

.dropdown-item.active .dropdown-label {
  color: #c9a227;
}