/* ═══════════════════════════════════════════════════
   FolioTest Studio — CSS Completo
   Layout: Sidebar Hover + 2 Colunas (Chats | Folio)
   Tema: Azul Editorial (moldura azul, centro claro)
   ═══════════════════════════════════════════════════ */

/* ─── RESET & TOKENS ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Cores — Paleta Editorial */
  --bg-primary: #ffffff;
  --bg-secondary: #E8EEF4;
  --bg-tertiary: #dce4ed;
  --bg-card: #ffffff;
  --border-color: #c2d0df;
  --border-accent: #4A6FA5;
  --text-primary: #1A1A1A;
  --text-secondary: #4a4a4a;
  --text-muted: #7a8a9a;

  /* Acentos */
  --accent-primary: #4A6FA5;
  --accent-primary-dim: #3d5d8a;
  --accent-cta: #3B5998;
  --accent-blue: #4A6FA5;
  --accent-green: #5a8a5e;
  --accent-red: #b85450;

  /* Providers */
  --mistral-color: #F97316;
  --claude-color: #8B5CF6;

  /* FolioTest — corpo editorial */
  --foliotest-bg: #ffffff;
  --foliotest-text: #1A1A1A;

  /* Tipografia */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-serif: 'Playfair Display', 'Times New Roman', Times, Georgia, serif;

  /* Espaçamento */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);

  /* Layout */
  --sidebar-width: 300px;
  --topbar-height: 48px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════
   TOP BAR
   ═══════════════════════════════════════════════════ */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 1px 8px rgba(0,0,0,0.04);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #4A6FA5, #3B5998);
  color: #fff;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1rem;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-text {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.brand-dot {
  color: var(--accent-primary);
}

.logo {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-primary);
  white-space: nowrap;
}

.top-bar-center {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  flex: 1;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

  .tb-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    border: 1px solid transparent;
    transition: all 0.18s ease;
  }
  .tb-link:hover {
    color: var(--accent-primary);
    background: rgba(74, 111, 165, 0.08);
    border-color: rgba(74, 111, 165, 0.18);
  }

/* ═══════════════════════════════════════════════════
   SIDEBAR TRIGGER
   ═══════════════════════════════════════════════════ */
.sidebar-trigger {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: 48px;
  height: calc(100vh - var(--topbar-height));
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: width 0.2s ease, background 0.2s ease;
}

.sidebar-trigger:hover {
  width: 52px;
  background: rgba(74,111,165,0.05);
}

.sidebar-trigger-icon {
  font-size: 1.3rem;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.sidebar-trigger:hover .sidebar-trigger-icon {
  color: var(--accent-primary);
}

.sidebar-trigger-label {
  display: none !important;
}

.sidebar-trigger.hidden {
  pointer-events: none;
  opacity: 0;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR — Histórico
   ═══════════════════════════════════════════════════ */
.history-sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.history-sidebar.open {
  transform: translateX(0);
}

.sidebar-trigger:hover ~ .history-sidebar,
.history-sidebar:hover {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-primary);
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.sidebar-close:hover {
  background: rgba(184,84,80,0.1);
  color: var(--accent-red);
}

.sidebar-new-chat {
  margin: 12px 16px;
  padding: 10px 16px;
  background: var(--accent-cta);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.sidebar-new-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59,89,152,0.25);
  background: var(--accent-primary-dim);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-item:hover {
  background: var(--bg-secondary);
}

.session-label {
  font-size: 0.82rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.session-date {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-left: 8px;
  white-space: nowrap;
}

.session-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.session-item:hover .session-delete {
  opacity: 1;
}

.session-delete:hover {
  color: var(--accent-red);
}

.session-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ═══════════════════════════════════════════════════
   WORKSPACE — Layout 2 colunas 50/50
   ═══════════════════════════════════════════════════ */
.workspace {
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border-color);
}

/* ─── Coluna Esquerda: 2 chats empilhados ─── */
.col-chats {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border-color);
  overflow: hidden;
}

/* ─── Chat Panel ─── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
  min-height: 0;
}

/* ═══ Chat Panel Variants — borda lateral colorida ═══ */
.chat-mistral {
  border-left: 3px solid var(--mistral-color);
}

.chat-claude {
  border-left: 3px solid var(--claude-color);
}

/* ─── Chat Header ─── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-btn {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

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

.btn-icon {
  background: none;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.btn-icon:hover {
  background: rgba(74,111,165,0.08);
}

/* ─── Chat Messages — FUNDO BRANCO/CLARO ─── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  min-height: 0;
  background: var(--bg-primary);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgIn 0.25s ease-out;
}

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

.message.assistant { align-self: flex-start; }
.message:not(.assistant) { align-self: flex-end; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.55;
  word-wrap: break-word;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message:not(.assistant) .message-bubble {
  background: linear-gradient(135deg, rgba(74,111,165,0.12), rgba(74,111,165,0.06));
  border: 1px solid rgba(74,111,165,0.2);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.message-meta {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.welcome-msg { opacity: 0.7; }
.welcome-msg .message-bubble { font-style: italic; border-style: dashed; }

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-self: flex-start;
}

.typing-indicator span {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ─── Chat Footer ─── */
.chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  padding: 10px 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  min-height: 42px;
  max-height: 120px;
}

.chat-input:focus {
  border-color: var(--accent-primary);
}

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

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent-cta);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(59,89,152,0.3);
}

.send-btn:active {
  transform: scale(0.95);
}

/* ═══════════════════════════════════════════════════
   COLUNA DIREITA — PAINEL FOLIO
   ═══════════════════════════════════════════════════ */
.col-folio {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
}

.folio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.folio-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.ft-tab {
  padding: 5px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.ft-tab:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.ft-tab.active {
  background: rgba(74,111,165,0.12);
  color: var(--accent-primary);
  border-color: rgba(74,111,165,0.25);
  font-weight: 600;
}

.folio-header-actions {
  display: flex;
  gap: 4px;
}

/* ─── Corpo do FolioTest ─── */
.folio-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

#foliotestContent {
  padding: 32px 28px;
  background: var(--foliotest-bg);
  color: var(--foliotest-text);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.85;
  min-height: 100%;
}

#foliotestContent h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #111;
  letter-spacing: -0.5px;
}

#foliotestContent h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.8rem;
  color: #222;
}

#foliotestContent h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
  color: #333;
}

#foliotestContent p {
  margin-bottom: 1rem;
  text-align: justify;
  hyphens: auto;
}

#foliotestContent p:first-of-type::first-letter {
  font-family: var(--font-serif);
  font-size: 3.2em;
  float: left;
  line-height: 0.85;
  margin-right: 8px;
  margin-top: 4px;
  color: var(--accent-primary);
  font-weight: 700;
}

#foliotestContent blockquote {
  border-left: 3px solid var(--accent-primary);
  margin: 1.5rem 0;
  padding: 12px 20px;
  font-style: italic;
  background: rgba(74,111,165,0.04);
  color: #444;
}

#foliotestContent hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
}

#foliotestContent a {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ft-empty {
  padding: 40px 28px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.7;
}

.ft-empty code {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85rem;
}

.ft-meta {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ─── Editor Direto ─── */
.folio-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--bg-primary);
}

.edit-textarea {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 14px;
  resize: none;
  outline: none;
  min-height: 200px;
}

.edit-textarea:focus {
  border-color: var(--accent-primary);
}

.editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}

.btn-save, .btn-cancel {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-save {
  background: var(--accent-green);
  color: #fff;
}

.btn-save:hover { background: #4a7a4e; }

.btn-cancel {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-cancel:hover {
  background: rgba(184,84,80,0.08);
  color: var(--accent-red);
  border-color: rgba(184,84,80,0.25);
}

/* ═══════════════════════════════════════════════════
   FOLIO WELCOME
   ═══════════════════════════════════════════════════ */
.folio-welcome h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  margin-bottom: 1rem;
  color: var(--accent-primary);
}

.folio-welcome p {
  margin-bottom: 0.8rem;
  font-family: var(--font-serif);
  color: var(--text-secondary);
}

.folio-welcome blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 10px 20px;
  margin-top: 1.5rem;
  font-style: italic;
  color: #666;
}

/* ═══════════════════════════════════════════════════
   GIPGAP — Modos visuais
   ═══════════════════════════════════════════════════ */
:root {
  --gipgap-borda-leitura: rgba(74,111,165,0.5);
  --gipgap-borda-edicao: rgba(90,138,94,0.5);
  --gipgap-borda-vinculacao: rgba(200,150,60,0.5);
  --gipgap-shadow-leitura: inset 0 0 0 1px rgba(74,111,165,0.12);
  --gipgap-shadow-edicao: inset 0 0 0 1px rgba(90,138,94,0.12);
  --gipgap-shadow-vinculacao: inset 0 0 0 1px rgba(200,150,60,0.12);
  --gipgap-transition: background-color 0.3s ease, border-left 0.3s ease, box-shadow 0.3s ease;
}

.reading-mode {
  background-color: rgba(200,218,240,0.35) !important;
  border-left: 3px solid var(--gipgap-borda-leitura);
  box-shadow: var(--gipgap-shadow-leitura);
  border-radius: 4px;
  transition: var(--gipgap-transition);
  cursor: pointer;
}

.vinculacao-mode {
  background-color: rgba(255,240,200,0.4) !important;
  border-left: 3px solid var(--gipgap-borda-vinculacao);
  box-shadow: var(--gipgap-shadow-vinculacao);
  border-radius: 4px;
  transition: var(--gipgap-transition);
  cursor: crosshair;
}

.edicao-mode {
  background-color: rgba(210,240,210,0.45) !important;
  border-left: 3px solid var(--gipgap-borda-edicao);
  box-shadow: var(--gipgap-shadow-edicao);
  border-radius: 4px;
  transition: var(--gipgap-transition);
}

.hint {
  display: none;
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 0.75rem;
  opacity: 0.7;
  animation: pulseLink 1.5s ease-in-out infinite;
}

@keyframes pulseLink {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.15); }
}

/* ═══════════════════════════════════════════════════
   GIPGAP TOAST
   ═══════════════════════════════════════════════════ */
.gipgap-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(50,50,50,0.88);
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  backdrop-filter: blur(6px);
}

.gipgap-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.gipgap-action-btn { position: relative; }

.gipgap-action-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: rgba(40,40,40,0.92);
  color: #fff;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 0.72rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.gipgap-action-btn:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ═══════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════════════════════════════════════════════════
   RESPONSIVO
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .col-chats { flex-direction: column; }
  .sidebar-trigger { width: 40px; }
  .history-sidebar { width: 85vw; }
  #foliotestContent { padding: 20px 16px; }
}

.show { display: block !important; }
