/* ============================================
   BIOFIBERS - CIA TERMINAL STYLESHEET v3.11
   Architecture: Compact UI + Copy Btn + Fixes
   ============================================ */

:root {
  --cia-bg: #0a0d12;
  --cia-panel: #0f1419;
  --cia-border: rgba(110, 231, 255, 0.12);
  --cia-cyan: #6ee7ff;
  --cia-violet: #8b5cf6;
  --cia-rose: #ff6b9d;
  --cia-success: #4ade80;
  --cia-warning: #fbbf24;
  --cia-error: #ef4444;
  --cia-text: #e8eef5;
  --cia-muted: #8891a0;
}

/* ============================================
   ENTRY BUTTON (Header externe)
   ============================================ */
.cia-entry {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  background: linear-gradient(135deg, rgba(110, 231, 255, 0.08), rgba(139, 92, 246, 0.08));
  border: 1px solid var(--cia-border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}
.cia-entry:hover {
  background: linear-gradient(135deg, rgba(110, 231, 255, 0.12), rgba(139, 92, 246, 0.12));
  border-color: rgba(110, 231, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(110, 231, 255, 0.15);
}
.cia-prompt-symbol {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 13px;
  color: var(--cia-cyan);
  letter-spacing: 0.5px;
}
.cia-entry-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--cia-text);
  font-size: 14px;
  min-width: 200px;
}
.cia-entry-input::placeholder { color: var(--cia-muted); opacity: 0.6; }
.cia-kbd-hints { display: flex; gap: 2px; opacity: 0.5; font-size: 11px; }
.cia-kbd {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes vortexPulse { 0%, 100% { opacity: 0.3; stroke-width: 1; } 50% { opacity: 0.8; stroke-width: 2; } }
@keyframes bootFadeIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: translateX(0); } }
@keyframes messageFadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-10px); opacity: 1; } }
@keyframes modePulse { 0%, 100% { box-shadow: 0 0 5px rgba(236, 72, 153, 0.5); } 50% { box-shadow: 0 0 20px rgba(236, 72, 153, 0.8); } }

.cia-vortex { animation: spin 3s linear infinite; }
.cia-vortex circle { fill: none; stroke: var(--cia-cyan); stroke-width: 1.5; opacity: 0.6; }
.cia-vortex circle:nth-child(1) { stroke-dasharray: 62.8; stroke-dashoffset: 0; animation: vortexPulse 2s ease-in-out infinite; }
.cia-vortex circle:nth-child(2) { stroke: var(--cia-violet); stroke-dasharray: 44; stroke-dashoffset: 0; animation: vortexPulse 2s ease-in-out infinite 0.3s; }
.cia-vortex circle:nth-child(3) { stroke: var(--cia-rose); stroke-dasharray: 25.1; stroke-dashoffset: 0; animation: vortexPulse 2s ease-in-out infinite 0.6s; }

/* ============================================
   TERMINAL CONTAINER
   ============================================ */
.cia-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 13, 18, 0.85);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.cia-overlay.active { opacity: 1; pointer-events: auto; }
.cia-terminal {
  width: 95vw; max-width: 1400px; height: 90vh; max-height: 900px;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1a1f2e 0%, #0f1419 100%);
  border-radius: 16px; border: 1px solid rgba(110, 231, 255, 0.15);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden; transform: scale(0.95) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cia-overlay.active .cia-terminal { transform: scale(1) translateY(0); }

/* ============================================
   HEADER
   ============================================ */
.cia-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; /* Header plus compact */
  background: linear-gradient(180deg, rgba(26, 31, 46, 0.95), rgba(15, 20, 25, 0.8));
  border-bottom: 1px solid rgba(110, 231, 255, 0.12); flex-shrink: 0;
}
.cia-header-left, .cia-header-right { display: flex; align-items: center; gap: 14px; }
.cia-traffic-lights { display: flex; gap: 8px; }
.cia-traffic-light { width: 12px; height: 12px; border-radius: 50%; border: none; cursor: pointer; transition: all 0.2s ease; }
.cia-traffic-light.close { background: linear-gradient(135deg, #ff5f57, #e63946); }
.cia-traffic-light.minimize { background: linear-gradient(135deg, #ffbd2e, #f4a261); }
.cia-traffic-light.maximize { background: linear-gradient(135deg, #28c840, #2a9d8f); }
.cia-traffic-light:hover { transform: scale(1.15); filter: brightness(1.2); }
.cia-title {
  margin: 0; font-size: 13px; font-weight: 600; color: var(--cia-text);
  letter-spacing: 0.5px; text-transform: uppercase;
  background: linear-gradient(135deg, var(--cia-cyan), var(--cia-violet));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.cia-header-btn {
  background: transparent; border: none; color: var(--cia-muted);
  cursor: pointer; padding: 4px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease; margin-right: 8px;
}
.cia-header-btn:hover { color: var(--cia-cyan); background: rgba(110, 231, 255, 0.1); }
.cia-status { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--cia-muted); }
.cia-status-dot { width: 8px; height: 8px; border-radius: 50%; animation: pulse 2s ease-in-out infinite; }
.cia-status-dot.online { background: var(--cia-success); box-shadow: 0 0 12px rgba(74, 222, 128, 0.6); }
.cia-status-dot.processing { background: var(--cia-warning); box-shadow: 0 0 12px rgba(251, 191, 36, 0.6); animation: blink 0.8s ease-in-out infinite; }
.cia-status-dot.error { background: var(--cia-error); box-shadow: 0 0 12px rgba(239, 68, 68, 0.6); }

/* ============================================
   BODY
   ============================================ */
.cia-body {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px;
  min-height: 0; scrollbar-width: thin;
  scrollbar-color: rgba(110, 231, 255, 0.3) transparent;
}
.cia-body::-webkit-scrollbar { width: 8px; }
.cia-body::-webkit-scrollbar-track { background: transparent; }
.cia-body::-webkit-scrollbar-thumb { background: rgba(110, 231, 255, 0.2); border-radius: 4px; }
.cia-body::-webkit-scrollbar-thumb:hover { background: rgba(110, 231, 255, 0.4); }

.cia-boot { font-family: ui-monospace, 'Courier New', monospace; font-size: 12px; line-height: 1.5; color: var(--cia-muted); }
.cia-ascii { color: var(--cia-cyan); font-size: 9px; line-height: 1.1; margin-bottom: 20px; text-shadow: 0 0 10px rgba(110, 231, 255, 0.5); }
.cia-boot-line { margin: 2px 0; animation: bootFadeIn 0.3s ease; white-space: pre; font-family: monospace; }
.cia-boot-line.success { color: var(--cia-success); }
.cia-boot-line.info { color: var(--cia-cyan); }
.cia-boot-line.highlight { color: var(--cia-violet); font-weight: 600; }
.cia-boot-line .check { color: var(--cia-success); margin-right: 8px; }
.cia-boot-line .arrow { color: var(--cia-cyan); margin-right: 8px; }

/* ============================================
   CHAT MESSAGES (Compact UI)
   ============================================ */
.cia-chat { display: flex; flex-direction: column; gap: 14px; min-height: min-content; padding-bottom: 10px; }
.cia-message {
  display: flex; gap: 10px; animation: messageFadeIn 0.4s ease;
  position: relative; padding-right: 24px; /* Place pour le bouton copier */
}
.cia-message:hover .cia-copy-msg-btn { opacity: 1; }

.cia-message-avatar {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11px; margin-top: 2px;
}
.cia-message.user .cia-message-avatar { background: linear-gradient(135deg, var(--cia-violet), var(--cia-rose)); color: white; }
.cia-message.assistant .cia-message-avatar { background: linear-gradient(135deg, var(--cia-cyan), var(--cia-violet)); color: white; }

.cia-message-content {
  flex: 1; padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px; color: var(--cia-text);
  line-height: 1.45; font-size: 13px; /* Police compacte */
}
.cia-message.user .cia-message-content { background: rgba(139, 92, 246, 0.08); border-color: rgba(139, 92, 246, 0.15); }

/* --- Bouton Copier --- */
.cia-copy-msg-btn {
  position: absolute; top: 0; right: 0;
  background: transparent; border: none; color: var(--cia-muted);
  cursor: pointer; opacity: 0; transition: all 0.2s ease;
  padding: 4px;
}
.cia-copy-msg-btn:hover { color: var(--cia-cyan); transform: scale(1.1); }

/* --- Typographie Compacte --- */
.cia-message-content h1, .cia-message-content h2, .cia-message-content h3, .cia-message-content h4 {
  margin-top: 12px; margin-bottom: 6px; line-height: 1.3;
  color: var(--cia-cyan); font-weight: 600;
}
/* On écrase les styles par défaut pour éviter l'effet "énorme" */
.cia-message-content h1 { font-size: 14px; text-transform: uppercase; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 2px; }
.cia-message-content h2 { font-size: 13px; color: var(--cia-violet); }
.cia-message-content h3 { font-size: 13px; font-weight: 700; color: #fff; }
.cia-message-content h4 { font-size: 12px; font-style: italic; opacity: 0.9; }
.cia-message-content p { margin-bottom: 6px; }
.cia-message-content ul, .cia-message-content ol { margin: 4px 0 8px 16px; padding: 0; }
.cia-message-content li { margin-bottom: 2px; }
.cia-message-content > *:first-child { margin-top: 0; }

/* --- Tables Compactes --- */
.cia-message-content table {
  width: 100%; border-collapse: collapse; margin: 8px 0;
  font-size: 10px; font-family: 'JetBrains Mono', monospace;
  background: rgba(0, 0, 0, 0.2); border-radius: 4px;
  overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.1);
}
.cia-message-content th {
  background: rgba(110, 231, 255, 0.08); color: var(--cia-cyan);
  font-weight: 600; text-align: left; padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.cia-message-content td { padding: 4px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); color: var(--cia-text); }
.cia-message-content td:nth-child(n+3), .cia-message-content th:nth-child(n+3) { text-align: right; }

.cia-message.system { justify-content: center; padding: 8px 0; }
.cia-system-message { background: rgba(100, 100, 255, 0.1); border: 1px solid rgba(100, 100, 255, 0.2); border-radius: 8px; padding: 6px 12px; font-size: 11px; color: rgba(150, 150, 255, 0.9); text-align: center; }

/* ============================================
   TYPING & INPUT
   ============================================ */
.cia-typing { display: flex; gap: 4px; padding: 4px 0; }
.cia-typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cia-cyan); animation: typingBounce 1.4s ease-in-out infinite; }
.cia-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cia-typing-dot:nth-child(3) { animation-delay: 0.4s; }

.cia-input-area {
  flex-shrink: 0; padding: 12px 16px;
  border-top: 1px solid rgba(110, 231, 255, 0.12);
  background: rgba(10, 13, 18, 0.9); backdrop-filter: blur(10px);
}
.cia-input-container { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.cia-prompt { display: flex; align-items: center; gap: 6px; font-family: ui-monospace, monospace; font-size: 12px; color: var(--cia-cyan); flex-shrink: 0; padding-top: 8px; }
.cia-input-wrapper { flex: 1; position: relative; }
.cia-input {
  width: 100%; min-height: 38px; max-height: 150px; padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(110, 231, 255, 0.15);
  border-radius: 8px; color: var(--cia-text); font-family: inherit; font-size: 13px;
  line-height: 1.4; resize: none; outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.cia-input:focus { border-color: rgba(110, 231, 255, 0.4); box-shadow: 0 0 0 3px rgba(110, 231, 255, 0.1); }
.cia-send-btn {
  flex-shrink: 0; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--cia-cyan), var(--cia-violet));
  border: none; border-radius: 8px; cursor: pointer; transition: all 0.2s ease;
}
.cia-send-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(110, 231, 255, 0.4); }
.cia-send-btn svg { width: 18px; height: 18px; fill: white; }

/* ============================================
   FOOTER (Modes, Debug, Timer, Cost)
   ============================================ */
.cia-mode-indicator { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-size: 11px; color: var(--cia-muted); flex-wrap: wrap; gap: 12px; }
.cia-mode { display: flex; align-items: center; gap: 8px; }
#ciaModeHint { color: rgba(255, 255, 255, 0.4); font-size: 10px; }
.cia-mode-toggle { background: transparent; border: 1px solid var(--cia-border); border-radius: 6px; padding: 2px; cursor: pointer; transition: all 0.2s ease; }
.cia-mode-toggle:hover { border-color: var(--cia-cyan); box-shadow: 0 0 10px rgba(110, 231, 255, 0.3); }
.cia-mode-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-weight: 600; font-size: 10px; letter-spacing: 0.5px; transition: all 0.3s ease; }
.cia-mode-badge.light { background: linear-gradient(135deg, #4ade80, #22c55e); color: #000; }
.cia-mode-badge.full { background: linear-gradient(135deg, #f472b6, #ec4899); color: #fff; animation: modePulse 2s ease-in-out infinite; }

.cia-debug-toggle { display: flex; align-items: center; }
.cia-debug-btn { display: flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 6px; padding: 3px 8px; color: rgba(255, 255, 255, 0.5); font-size: 10px; cursor: pointer; transition: all 0.2s ease; }
.cia-debug-btn:hover { background: rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.8); }
.cia-debug-btn.active { background: rgba(234, 179, 8, 0.2); border-color: rgba(234, 179, 8, 0.5); color: #eab308; }

.cia-debug-panel { position: fixed; bottom: 20px; right: 20px; width: 500px; max-height: 400px; background: rgba(0, 0, 0, 0.95); border: 1px solid rgba(234, 179, 8, 0.3); border-radius: 12px; z-index: 10001; overflow: hidden; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.cia-debug-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: rgba(234, 179, 8, 0.1); border-bottom: 1px solid rgba(234, 179, 8, 0.2); color: #eab308; font-size: 11px; font-weight: 600; }
.cia-debug-content { padding: 10px; margin: 0; max-height: 340px; overflow: auto; font-family: 'JetBrains Mono', monospace; font-size: 10px; color: #a3e635; background: transparent; white-space: pre-wrap; word-break: break-all; }

.cia-timer-container { display: flex; align-items: center; gap: 6px; padding: 3px 8px; background: rgba(0, 0, 0, 0.2); border: 1px solid rgba(255, 255, 255, 0.05); border-radius: 6px; color: var(--cia-muted); font-family: 'JetBrains Mono', monospace; font-size: 11px; transition: all 0.3s ease; }
.cia-timer-container svg { opacity: 0.5; }
.cia-timer-container.active { color: var(--cia-success); border-color: rgba(74, 222, 128, 0.2); }
.cia-timer-container.active svg { opacity: 1; animation: spin 10s linear infinite; }
.cia-timer-container.warning { color: var(--cia-warning); border-color: rgba(251, 191, 36, 0.3); animation: pulse 1s infinite; }
.cia-timer-container.expired { color: var(--cia-error); opacity: 0.7; }

.cia-cost-wrapper { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; gap: 1px; padding: 3px 8px; background: rgba(0, 0, 0, 0.3); border-left: 1px solid var(--cia-border); font-family: 'JetBrains Mono', monospace; font-size: 10px; min-width: 80px; }
.cia-cost-row { display: flex; align-items: center; gap: 6px; width: 100%; justify-content: space-between; }
.cia-cost-label { color: var(--cia-muted); font-weight: bold; opacity: 0.7; }
.cia-cost-value { color: var(--cia-cyan); font-weight: 600; }
#ciaCostMonthly { color: var(--cia-violet); }

/* Responsive & Utilities */
@media (max-width: 768px) {
  .cia-terminal { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
  .cia-header { padding: 10px 12px; }
  .cia-body { padding: 12px; }
  .cia-input-area { padding: 10px 12px; }
  .cia-entry-input { min-width: 120px; }
  .cia-kbd-hints, #ciaModeHint { display: none; }
  .cia-debug-panel { width: calc(100vw - 40px); left: 20px; right: 20px; bottom: 10px; max-height: 300px; }
  .cia-mode-indicator { flex-direction: column; align-items: flex-start; gap: 8px; }
}
.hidden { display: none !important; }
.no-scroll { overflow: hidden; }
