@import url('tokens.css');

/* ==========================================================================
   PHM IA — DESIGN SYSTEM & STYLESHEET (v1.0)
   Ambiente de Inteligência Artificial Educacional & Tecnológica
   ========================================================================== */

:root {
  --ia-bg: #060b17;
  --ia-surface: #0a1224;
  --ia-surface-card: #0e172a;
  --ia-surface-hover: #162444;
  --ia-line: rgba(255, 255, 255, 0.10);
  --ia-line-active: #0d9488;
  --ia-cyan: #0d9488;
  --ia-cyan-light: #2dd4bf;
  --ia-cyan-glow: rgba(13, 148, 136, 0.20);
  --ia-purple: #8b5cf6;
  --ia-purple-glow: rgba(139, 92, 246, 0.20);
  --ia-green: #10b981;
  --ia-green-glow: rgba(16, 185, 129, 0.20);
  --ia-gold: #d4a853;
  --ia-rose: #f43f5e;
  --ia-text: #f8fafc;
  --ia-text-muted: #94a3b8;
  --ia-text-subtle: #64748b;
  --ia-font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --ia-font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --ia-radius-xs: 2px;
  --ia-radius-sm: 4px;
  --ia-radius-md: 6px;
}

[data-theme="light"] {
  --ia-bg: #f8fafc;
  --ia-surface: #ffffff;
  --ia-surface-card: #f1f5f9;
  --ia-surface-hover: #e2e8f0;
  --ia-line: #e2e8f0;
  --ia-line-active: #0d9488;
  --ia-cyan: #0d9488;
  --ia-cyan-light: #0f766e;
  --ia-cyan-glow: rgba(13, 148, 136, 0.15);
  --ia-text: #0b1e3d;
  --ia-text-muted: #334155;
  --ia-text-subtle: #64748b;
}

[data-theme="sepia"] {
  --ia-bg: #f5eee1;
  --ia-surface: #fbf7ee;
  --ia-surface-card: #eae1cf;
  --ia-surface-hover: #ded2bd;
  --ia-line: #dfd4bf;
  --ia-line-active: #b45309;
  --ia-cyan: #b45309;
  --ia-cyan-light: #d97706;
  --ia-cyan-glow: rgba(180, 83, 9, 0.15);
  --ia-text: #2e2116;
  --ia-text-muted: #463425;
  --ia-text-subtle: #75604e;
}

* {
  box-sizing: border-box;
}

body.phm-ia-body {
  margin: 0;
  padding: 0;
  background-color: var(--ia-bg);
  color: var(--ia-text);
  font-family: var(--ia-font);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   BANNER DE CONHECIMENTO ABERTO / APOIO (GLOBAL)
   ========================================================================== */
.phm-support-banner {
  display: block;
  width: 100%;
  flex-shrink: 0;
  background: #2dd4bf;
  color: #0b1120;
  border-bottom: 1px solid rgba(11, 17, 32, 0.12);
  position: relative;
  z-index: 1000;
  box-sizing: border-box;
}

.phm-support-banner__link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 2.25rem;
  padding: 0.42rem 1rem;
  color: #0b1120 !important;
  text-decoration: none !important;
  font-family: var(--ia-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  text-align: center;
  line-height: 1.35;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.phm-support-banner__link:hover,
.phm-support-banner__link:focus-visible {
  background-color: #26c6b2;
  color: #040812 !important;
  text-decoration: none !important;
}

.phm-support-banner__link:focus-visible {
  outline: 2px solid #0b1120;
  outline-offset: -2px;
}

.phm-support-banner__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0.25rem rgba(11, 17, 32, 0.16);
  flex-shrink: 0;
  display: inline-block;
}

.phm-support-banner__text strong {
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.phm-support-banner__arrow {
  flex-shrink: 0;
  transition: transform 0.2s ease;
  display: inline-block;
  vertical-align: middle;
}

.phm-support-banner__link:hover .phm-support-banner__arrow,
.phm-support-banner__link:focus-visible .phm-support-banner__arrow {
  transform: translateX(3px);
}

@media (max-width: 48rem) {
  .phm-support-banner__link {
    font-size: 0.76rem;
    padding: 0.4rem 0.75rem;
    gap: 0.45rem;
  }
}

/* ==========================================================================
   LAYOUT GERAL: APP CONTAINER
   ========================================================================== */
.ia-app-container {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  overflow: hidden;
  position: relative;
}

/* ==========================================================================
   SIDEBAR LATERAL (HISTÓRICO & CONFIGURAÇÕES)
   ========================================================================== */
.ia-sidebar {
  width: clamp(190px, 16vw, 260px);
  background: var(--ia-surface);
  border-right: 1px solid var(--ia-line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease, width 0.3s ease;
  z-index: 50;
}

.ia-sidebar.collapsed {
  transform: translateX(-100%);
  position: absolute;
  height: 100%;
}

.ia-sidebar-header {
  padding: 0.75rem 1rem;
  height: 54px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--ia-line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ia-logo-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--ia-text);
}

.ia-logo-badge {
  background: rgba(13, 148, 136, 0.12);
  border: 1px solid var(--ia-cyan);
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ia-logo-text h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ia-text);
}

.ia-logo-text p {
  margin: 0;
  font-family: var(--ia-font-mono);
  font-size: 0.68rem;
  color: var(--ia-text-subtle);
  letter-spacing: 0.02em;
}

.ia-btn-new-chat {
  margin: 0.85rem 1rem;
  background: #0d9488;
  color: #ffffff;
  border: 1px solid #0f766e;
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.65rem 1rem;
  font-family: var(--ia-font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(13, 148, 136, 0.2);
}

.ia-btn-new-chat:hover {
  background: #0f766e;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(13, 148, 136, 0.3);
}

.ia-sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.ia-history-section-title {
  font-family: var(--ia-font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ia-text-subtle);
  padding: 0.6rem 0.5rem 0.3rem 0.5rem;
}

.ia-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.7rem;
  border-radius: var(--ia-radius-sm, 4px);
  color: var(--ia-text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  margin-bottom: 0.25rem;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.ia-history-item:hover {
  background: var(--ia-surface-hover);
  color: var(--ia-text);
  border-color: var(--ia-line);
}

.ia-history-item.active {
  background: rgba(13, 148, 136, 0.12);
  color: var(--ia-cyan-light, #2dd4bf);
  border-color: rgba(13, 148, 136, 0.35);
  font-weight: 600;
}

.ia-history-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.ia-history-item-del {
  background: none;
  border: none;
  color: var(--ia-text-subtle);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--ia-radius-xs, 2px);
  display: none;
}

.ia-history-item:hover .ia-history-item-del {
  display: block;
}

.ia-history-item-del:hover {
  color: var(--ia-rose);
}

.ia-sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--ia-line);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.45rem;
  box-sizing: border-box;
  flex-shrink: 0;
}

.ia-footer-btn {
  background: transparent;
  border: 1px solid var(--ia-line);
  color: var(--ia-text-muted);
  font-family: var(--ia-font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: var(--ia-radius-sm, 4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  text-decoration: none;
}

.ia-footer-btn:hover {
  background: var(--ia-surface-hover);
  color: var(--ia-text);
  border-color: var(--ia-line-active);
}

/* ==========================================================================
   ÁREA PRINCIPAL DO CHAT
   ========================================================================== */
.ia-chat-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--ia-bg);
  position: relative;
}

.ia-chat-topbar {
  padding: 0.75rem 1.5rem;
  height: 54px;
  box-sizing: border-box;
  border-bottom: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  backdrop-filter: none;
  z-index: 10;
}

.ia-topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.ia-btn-toggle-sidebar {
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  color: var(--ia-text);
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ia-btn-toggle-sidebar:hover {
  background: var(--ia-surface-hover);
  border-color: var(--ia-line-active);
}

.ia-persona-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(13, 148, 136, 0.12);
  border: 1px solid var(--ia-cyan);
  color: var(--ia-cyan-light, #2dd4bf);
  padding: 0.25rem 0.65rem;
  border-radius: var(--ia-radius-sm, 4px);
  font-family: var(--ia-font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ia-status-indicator {
  font-family: var(--ia-font-mono);
  font-size: 0.72rem;
  color: var(--ia-green);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.ia-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ia-green);
  box-shadow: 0 0 6px var(--ia-green-glow);
}

.ia-topbar-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  color: var(--ia-text-muted);
  padding: 0.38rem 0.75rem;
  border-radius: var(--ia-radius-sm, 4px);
  font-family: var(--ia-font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.2s ease;
}

.ia-topbar-back-btn:hover {
  background: var(--ia-surface-hover);
  color: var(--ia-cyan-light, #2dd4bf);
  border-color: var(--ia-cyan);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.ia-topbar-back-btn svg {
  color: var(--ia-cyan);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.ia-topbar-back-btn:hover svg {
  transform: translateX(-2px);
}

/* ==========================================================================
   FEED DE MENSAGENS
   ========================================================================== */
.ia-messages-stream {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

/* TELA DE BOAS-VINDAS / ESTADO VAZIO */
.ia-welcome-box {
  margin: auto;
  text-align: center;
  max-width: 720px;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ia-welcome-icon {
  width: 48px;
  height: 48px;
  background: rgba(13, 148, 136, 0.12);
  border: 1px solid var(--ia-cyan);
  border-radius: var(--ia-radius-sm, 4px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  margin-bottom: 1.25rem;
}

.ia-welcome-box h2 {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem 0;
  color: var(--ia-text);
}

.ia-welcome-box p {
  color: var(--ia-text-muted);
  font-size: 0.98rem;
  line-height: 1.6;
  margin: 0 0 1.75rem 0;
}

/* SELETOR DE MODOS / PERSONAS */
.ia-modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  width: 100%;
  margin-bottom: 2rem;
}

.ia-mode-card {
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  padding: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ia-mode-card:hover {
  background: var(--ia-surface-hover);
  border-color: var(--ia-cyan);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ia-mode-card.selected {
  border-color: var(--ia-cyan);
  background: rgba(13, 148, 136, 0.08);
  box-shadow: 0 0 12px rgba(13, 148, 136, 0.2);
}

.ia-mode-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--ia-text);
  margin-bottom: 0.35rem;
}

.ia-mode-card-desc {
  font-size: 0.78rem;
  color: var(--ia-text-subtle);
  line-height: 1.4;
}

/* SUGESTÕES DE PROMPTS DE 1 CLIQUE */
.ia-prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.ia-prompt-chip-btn {
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  padding: 0.85rem 1rem;
  color: var(--ia-text-muted);
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  transition: all 0.2s ease;
  line-height: 1.45;
}

.ia-prompt-chip-btn:hover {
  background: var(--ia-surface-hover);
  color: var(--ia-text);
  border-color: var(--ia-cyan);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   CARDS DE MENSAGENS (USER & ASSISTANT)
   ========================================================================== */
.ia-message-row {
  display: flex;
  gap: 0.85rem;
  width: 100%;
  animation: fadeInMsg 0.25s ease-out;
}

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

.ia-message-row.user {
  justify-content: flex-end;
}

.ia-avatar-box {
  width: 32px;
  height: 32px;
  border-radius: var(--ia-radius-sm, 4px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ia-message-row.assistant .ia-avatar-box {
  background: rgba(13, 148, 136, 0.15);
  border: 1px solid var(--ia-cyan);
}

.ia-message-row.user .ia-avatar-box {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid var(--ia-purple);
}

.ia-message-bubble {
  max-width: 85%;
  border-radius: var(--ia-radius-md, 6px);
  padding: 1rem 1.25rem;
  line-height: 1.7;
  font-size: 0.95rem;
  color: var(--ia-text);
  position: relative;
}

.ia-message-row.user .ia-message-bubble {
  background: var(--ia-surface-card);
  color: var(--ia-text) !important;
  border: 1px solid var(--ia-line);
  border-top-right-radius: var(--ia-radius-xs, 2px);
}

.ia-message-row.assistant .ia-message-bubble {
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-top-left-radius: var(--ia-radius-xs, 2px);
  width: 100%;
}

/* FORMATOS MARKDOWN DENTRO DAS RESPOSTAS */
.ia-message-bubble h1, 
.ia-message-bubble h2, 
.ia-message-bubble h3, 
.ia-message-bubble h4 {
  color: var(--ia-text);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  font-weight: 800;
}

.ia-message-bubble h1:first-child,
.ia-message-bubble h2:first-child,
.ia-message-bubble h3:first-child {
  margin-top: 0;
}

.ia-message-bubble h1 { font-size: 1.35rem; color: var(--ia-cyan); }
.ia-message-bubble h2 { font-size: 1.2rem; color: var(--ia-gold); }
.ia-message-bubble h3 { font-size: 1.05rem; color: var(--ia-cyan-light, #2dd4bf); }

.ia-message-bubble p {
  margin: 0 0 0.85rem 0;
}

.ia-message-bubble p:last-child {
  margin-bottom: 0;
}

.ia-message-bubble ul, 
.ia-message-bubble ol {
  margin: 0.4rem 0 0.85rem 1.4rem;
  padding: 0;
  color: var(--ia-text);
}

.ia-message-bubble li {
  margin-bottom: 0.35rem;
}

.ia-message-bubble blockquote {
  border-left: 3px solid var(--ia-cyan);
  background: rgba(13, 148, 136, 0.08);
  margin: 0.85rem 0;
  padding: 0.65rem 1rem;
  border-radius: 0 var(--ia-radius-sm, 4px) var(--ia-radius-sm, 4px) 0;
  color: var(--ia-text);
}

.ia-message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
}

.ia-message-bubble th, 
.ia-message-bubble td {
  border: 1px solid var(--ia-line);
  padding: 0.55rem 0.85rem;
  text-align: left;
}

.ia-message-bubble th {
  background: rgba(0, 0, 0, 0.4);
  color: var(--ia-cyan);
  font-weight: 800;
}

.ia-message-bubble td {
  background: rgba(0, 0, 0, 0.2);
}

/* BLOCOS DE CÓDIGO & SYNTAX HIGHLIGHT */
.ia-code-block-wrapper {
  background: #020617;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  margin: 0.85rem 0;
  overflow: hidden;
}

.ia-code-block-header {
  background: #0f172a;
  padding: 0.4rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.75rem;
  color: var(--ia-text-subtle);
  font-family: var(--ia-font-mono);
}

.ia-btn-copy-code {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ia-text-muted);
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.ia-btn-copy-code:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.ia-code-block-wrapper pre {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--ia-font-mono);
  font-size: 0.86rem;
  line-height: 1.5;
  color: #38bdf8;
}

.ia-inline-code {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-family: var(--ia-font-mono);
  font-size: 0.86em;
  border: 1px solid rgba(56, 189, 248, 0.25);
}

/* ==========================================================================
   BARRA DE ENTRADA / INPUT BAR
   ========================================================================== */
.ia-input-container {
  padding: 0.85rem 1.5rem 1.25rem 1.5rem;
  background: transparent;
  border-top: none;
  backdrop-filter: none;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
  width: 100%;
}

.ia-input-wrapper {
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.ia-input-wrapper:focus-within {
  border-color: var(--ia-cyan);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.25);
}

.ia-textarea {
  background: transparent;
  border: none;
  color: var(--ia-text);
  font-family: var(--ia-font);
  font-size: 0.95rem;
  resize: none;
  min-height: 24px;
  max-height: 180px;
  outline: none;
  line-height: 1.5;
  padding: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}

.ia-textarea::placeholder {
  color: var(--ia-text-subtle);
}

.ia-input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.ia-persona-quick-selector {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  color: var(--ia-text-muted);
}

.ia-persona-select {
  background: transparent;
  border: none;
  color: var(--ia-cyan);
  font-weight: 700;
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
}

.ia-persona-select option {
  background: var(--ia-surface);
  color: var(--ia-text);
}

.ia-btn-send {
  background: #0d9488;
  color: #ffffff;
  border: 1px solid #0f766e;
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.55rem 1.15rem;
  font-family: var(--ia-font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s ease;
}

.ia-btn-send:hover {
  background: #0f766e;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

.ia-btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.ia-input-footer-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ia-text-subtle);
  margin-top: 0.5rem;
}

/* ==========================================================================
   MODAL DE CONFIGURAÇÕES & CHAVE DE API
   ========================================================================== */
.ia-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.ia-modal-content {
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  padding: 1.75rem;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.ia-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--ia-line);
  padding-bottom: 0.85rem;
  margin-bottom: 1.25rem;
}

.ia-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ia-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ia-modal-close {
  background: transparent;
  border: none;
  color: var(--ia-text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--ia-radius-xs, 2px);
}

.ia-modal-close:hover {
  color: var(--ia-text);
}

.ia-form-group {
  margin-bottom: 1.25rem;
}

.ia-form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ia-cyan);
  margin-bottom: 0.4rem;
}

.ia-form-input, .ia-form-select {
  width: 100%;
  background: var(--ia-surface-card);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-sm, 4px);
  padding: 0.65rem 0.8rem;
  color: var(--ia-text);
  font-size: 0.88rem;
  box-sizing: border-box;
}

.ia-form-input:focus, .ia-form-select:focus {
  border-color: var(--ia-cyan);
  outline: 2px solid rgba(13, 148, 136, 0.25);
}

.ia-form-help {
  font-size: 0.76rem;
  color: var(--ia-text-subtle);
  margin-top: 0.35rem;
  line-height: 1.4;
}

/* ==========================================================================
   DROPDOWN DE EXPORTAÇÃO (WORD .DOCX & MARKDOWN .MD)
   ========================================================================== */
.ia-export-dropdown {
  position: relative;
  display: inline-block;
}

.ia-export-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  color: var(--ia-text);
  font-family: var(--ia-font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.38rem 0.75rem;
  border-radius: var(--ia-radius-sm, 4px);
  cursor: pointer;
  transition: all 0.2s ease;
}

.ia-export-trigger-btn:hover,
.ia-export-dropdown.active .ia-export-trigger-btn {
  background: var(--ia-surface-hover);
  border-color: var(--ia-cyan);
  color: var(--ia-text);
}

.ia-export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 270px;
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  padding: 0.45rem;
  z-index: 200;
  animation: iaMenuFadeIn 0.15s ease;
}

@keyframes iaMenuFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ia-export-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem;
  border: none;
  background: transparent;
  border-radius: var(--ia-radius-sm, 4px);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  color: var(--ia-text);
}
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  color: var(--ia-text);
}

.ia-export-item:hover {
  background: var(--ia-surface-hover);
  color: #ffffff;
}

.export-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.export-details {
  display: flex;
  flex-direction: column;
}

.export-details strong {
  font-size: 0.84rem;
  color: #ffffff;
  display: block;
}

.export-details small {
  font-size: 0.72rem;
  color: var(--ia-text-subtle);
  margin-top: 1px;
}

/* ==========================================================================
   RESPONSIVIDADE
   ========================================================================== */
@media (max-width: 768px) {
  .ia-sidebar {
    position: absolute;
    height: 100%;
    z-index: 100;
    box-shadow: 10px 0 30px rgba(0,0,0,0.8);
  }
  
  .ia-modes-grid {
    grid-template-columns: 1fr;
  }
  
  .ia-prompts-grid {
    grid-template-columns: 1fr;
  }
  
  .ia-message-bubble {
    max-width: 92%;
  }
}

/* Correções de responsividade mobile: evita clipping horizontal e altura fixa. */
@media (max-width: 768px) {
  html, body.phm-ia-body { min-height: 100dvh; height: 100dvh; }
  body.phm-ia-body { overflow: hidden; }
  .ia-app-container { height: 100dvh; min-height: 0; }
  .ia-sidebar { width: min(280px, calc(100vw - 32px)); }
  .ia-chat-main { height: 100%; min-width: 0; }
  .ia-chat-topbar { height: auto; min-height: 54px; padding: .55rem .75rem; gap: .5rem; }
  .ia-chat-topbar > div:last-child { min-width: 0; gap: .4rem !important; }
  .ia-topbar-left, .ia-topbar-left + div { min-width: 0; }
  .ia-status-indicator { white-space: nowrap; }
  .ia-messages-stream { min-width: 0; padding: .9rem .7rem; gap: .9rem; }
  .ia-welcome-box { width: 100%; max-width: 100%; padding: 1rem .35rem; }
  .ia-welcome-box h2 { font-size: 1.45rem; }
  .ia-welcome-box p { font-size: .9rem; }
  .ia-modes-grid, .ia-prompts-grid { min-width: 0; }
  .ia-input-container { padding: .65rem .7rem .8rem; }
  .ia-input-wrapper { min-width: 0; }
  .ia-textarea { min-width: 0; font-size: .92rem; }
}

@media (max-width: 480px) {
  .ia-export-trigger-btn span,
  .ia-topbar-back-btn span { display: none; }
  .ia-export-trigger-btn, .ia-topbar-back-btn { padding: .5rem; min-width: 38px; justify-content: center; }
  .ia-status-indicator { font-size: .72rem; }
  .ia-welcome-icon { width: 54px; height: 54px; }
  .ia-welcome-box h2 { font-size: 1.28rem; }
  .ia-welcome-pill { font-size: .7rem; padding: .3rem .55rem; }
  .ia-prompt-card, .ia-prompt-chip-btn { padding: .75rem; }
  .ia-btn-send { min-height: 42px; padding-inline: .85rem; }
}


/* ==========================================================================
   MELHORIAS DE DESIGN & NAVEGAÇÃO DO PHM IA
   ========================================================================== */

.ia-btn-portal-back {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--ia-surface);
  border: 1px solid var(--ia-line);
  color: var(--ia-text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--ia-radius-sm, 4px);
  font-family: var(--ia-font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
  transition: all 0.2s ease;
}

.ia-btn-portal-back:hover {
  background: var(--ia-surface-hover);
  border-color: var(--ia-cyan);
  color: var(--ia-text);
  transform: translateY(-1px);
}

.ia-welcome-pills {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.ia-welcome-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--ia-surface-card);
  border: 1px solid var(--ia-line);
  color: var(--ia-text-muted);
  padding: 0.3rem 0.65rem;
  border-radius: var(--ia-radius-sm, 4px);
  font-family: var(--ia-font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ia-welcome-pill svg {
  color: var(--ia-cyan);
  flex-shrink: 0;
}

.ia-prompts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
  width: 100%;
}

.ia-prompt-card {
  background: var(--ia-surface-card);
  border: 1px solid var(--ia-line);
  border-radius: var(--ia-radius-md, 6px);
  padding: 1rem 1.15rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ia-prompt-card:hover {
  background: var(--ia-surface-hover);
  border-color: var(--ia-cyan);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 15px rgba(56, 189, 248, 0.15);
}

.ia-prompt-card-cat {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ia-cyan);
  margin-bottom: 0.35rem;
}

.ia-prompt-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 0.35rem;
}

.ia-prompt-card-text {
  font-size: 0.78rem;
  color: var(--ia-text-subtle);
  line-height: 1.4;
}

/* Efeito de pulsação na luz de status */
@keyframes iaPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
  70% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.ia-status-dot {
  animation: iaPulse 2s infinite;
}
.ia-logo-badge {
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}
.ia-logo-group:hover .ia-logo-badge {
  transform: rotate(-10deg) scale(1.08);
}

/* Override final de responsividade (mantido no fim para vencer estilos legados). */
@media (max-width: 768px) {
  .ia-sidebar {
    width: 220px;
    max-width: 80vw;
    min-width: 0;
    overflow-x: hidden;
  }

  .ia-chat-main,
  .ia-messages-stream,
  .ia-input-container { overflow-x: hidden; }
  .ia-app-container { overflow-x: hidden; }

  .ia-chat-topbar { min-width: 0; width: 100%; }
  .ia-chat-topbar > div:last-child { flex: 0 1 auto; overflow: hidden; }
  .ia-export-dropdown { flex-shrink: 0; }
  .ia-topbar-back-btn { flex-shrink: 0; }
  .ia-welcome-box, .ia-prompts-grid, .ia-modes-grid { overflow-wrap: anywhere; max-width: 100%; }
  .ia-prompts-grid > *, .ia-modes-grid > * { min-width: 0; max-width: 100%; }
  .ia-prompts-grid, .ia-modes-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (max-width: 360px) {
  .ia-sidebar { width: 68vw; min-width: 0; }
  .ia-chat-topbar { padding-inline: .5rem; }
  .ia-status-indicator { display: none; }
}

/* Janelas estreitas em desktop podem ter escala física reduzida, mas viewport
   CSS acima de 768 px. Este breakpoint evita que a sidebar volte a 280 px. */
@media (min-width: 769px) and (max-width: 1100px) {
  .ia-sidebar { width: 220px; }
  .ia-chat-topbar { padding-inline: .8rem; }
  .ia-chat-topbar > div:last-child { gap: .45rem !important; }
  .ia-messages-stream { max-width: 100%; padding-inline: .8rem; }
  .ia-prompts-grid, .ia-modes-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .ia-chat-main, .ia-messages-stream, .ia-input-container { overflow-x: hidden; }
}
