/* ============================================================
   BERTHO AI LAB — FEUILLE DE STYLE MODULAIRE v2.5
   Architecture Réactive : Double Vue, Radar 300ms & Skeletons Ratios
   ============================================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #060911;
  --panel: #0b1120;
  --panel-2: #131d35;
  --border: rgba(56, 189, 248, 0.15);
  --border-active: #00f2fe;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --success: #10b981;
  --cyan: #00f2fe;
  --purple: #a855f7;
  --danger: #ef4444;
  --gold: #fbbf24;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ============================================================
   HEADER & STATUT
   ============================================================ */
header {
  padding: 14px 24px;
  background: rgba(11, 17, 32, 0.95);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h1 span {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 242, 254, 0.15);
  color: var(--cyan);
  border: 1px solid rgba(0, 242, 254, 0.3);
}

.brand p {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 2px;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.5);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  transition: all 0.3s;
}

.dot.online {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

/* ============================================================
   DISPOSITION PRINCIPALE (GRID)
   ============================================================ */
.layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  flex: 1;
  min-height: calc(100vh - 65px);
}

aside {
  background: rgba(8, 12, 22, 0.8);
  border-right: 1px solid var(--border);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 0.65rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.history-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.btn-text-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
}
.btn-text-danger:hover { text-decoration: underline; }

/* BOUTONS D'OUTILS LATÉRAUX */
.tools-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool {
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool:hover {
  background: var(--panel-2);
  border-color: rgba(56, 189, 248, 0.4);
}

.tool.active {
  border-color: var(--border-active);
  background: rgba(0, 242, 254, 0.08);
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.15);
}

.tool strong {
  display: block;
  font-size: 0.82rem;
  color: #fff;
  margin-bottom: 2px;
}

.tool span {
  color: var(--muted);
  font-size: 0.68rem;
}

/* HISTORIQUE */
.history-stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 400px;
}

.history-item {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover {
  background: var(--panel-2);
  border-color: rgba(56, 189, 248, 0.4);
}

.hist-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.hist-meta strong {
  font-size: 0.72rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.hist-meta small {
  color: var(--muted);
  font-size: 0.62rem;
}

.btn-del-item {
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 6px;
}
.btn-del-item:hover { color: var(--danger); }

/* ============================================================
   CONTENU PRINCIPAL & PANNEAUX
   ============================================================ */
main {
  padding: 20px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 900;
  color: #fff;
}

.panel-header p {
  color: var(--muted);
  font-size: 0.76rem;
  margin-top: 2px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

textarea, input, select {
  width: 100%;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #080d1a;
  color: #fff;
  padding: 10px 14px;
  font: inherit;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

/* BOUTONS PRINCIPAUX */
.btn-primary {
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  font-weight: 900;
  font-size: 0.8rem;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.2s ease;
}
.btn-primary:hover { opacity: 0.92; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-green { background: linear-gradient(135deg, #10b981, #059669); }
.btn-cyan { background: linear-gradient(135deg, #00f2fe, #0284c7); color: #000; }
.btn-purple { background: linear-gradient(135deg, #a855f7, #7e22ce); }

/* ============================================================
   ZONE D'UPLOAD D'IMAGE (DRAG & DROP)
   ============================================================ */
.upload-dropzone {
  border: 2px dashed rgba(56, 189, 248, 0.25);
  border-radius: 12px;
  padding: 18px;
  background: rgba(13, 22, 40, 0.5);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: var(--cyan);
  background: rgba(0, 242, 254, 0.05);
}

.dropzone-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.dropzone-text svg { color: var(--cyan); }
.dropzone-text strong { color: #fff; text-decoration: underline; }
.dropzone-text small { font-size: 0.68rem; color: #64748b; }

.dropzone-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.dropzone-preview img {
  max-height: 140px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.btn-remove-preview {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--danger);
  color: #fff;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* ============================================================
   DOUBLE VUE : UTILISATEUR VS TÉLÉMÉTRIE
   ============================================================ */
.result-panel {
  padding: 18px 22px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.view-switcher {
  display: flex;
  gap: 8px;
  background: #060911;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.btn-tab {
  background: none;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-tab.active {
  background: var(--panel-2);
  color: #fff;
  border: 1px solid rgba(0, 242, 254, 0.4);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

.quick-meta {
  display: flex;
  gap: 8px;
}

.badge {
  background: #080d1a;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}
.badge strong { color: #fff; }

/* CONTENEURS DES DEUX VUES */
.view-pane {
  display: none;
}
.view-pane.active {
  display: block;
}

/* 1. VUE RENDU UTILISATEUR RÉEL */
.user-preview-card {
  background: #050811;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  min-height: 220px;
  max-height: 520px;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 10px;
  padding: 40px 20px;
  text-align: center;
  font-size: 0.8rem;
}
.empty-icon { font-size: 2rem; }

/* ============================================================
   RADAR D'ACTION 300 MS & ANIMATIONS SSE EN DIRECT
   ============================================================ */
.agent-live-radar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(14, 27, 49, 0.7);
  border: 1px solid rgba(0, 242, 254, 0.4);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  box-shadow: 0 0 20px rgba(0, 242, 254, 0.1);
  animation: radarFadeIn 0.3s ease;
}

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

.radar-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 242, 254, 0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spinRadar 0.8s linear infinite;
  flex-shrink: 0;
}

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

.radar-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.radar-title {
  font-size: 0.78rem;
  font-weight: 900;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.radar-desc {
  font-size: 0.7rem;
  color: var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   SQUELETTE DE L'IMAGE DYNAMIQUE (CALÉ SUR ASPECT-RATIO)
   ============================================================ */
.image-skeleton-card {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.3);
  background: linear-gradient(90deg, #090e1a 0%, #152238 50%, #090e1a 100%);
  background-size: 200% 100%;
  animation: shimmerSkeleton 1.8s infinite;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  padding: 20px;
  margin: 12px auto;
}

@keyframes shimmerSkeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.image-skeleton-card.ratio-1-1 {
  aspect-ratio: 1 / 1;
  max-width: 380px;
}

.image-skeleton-card.ratio-16-9 {
  aspect-ratio: 16 / 9;
  max-width: 520px;
}

.image-skeleton-card.ratio-9-16 {
  aspect-ratio: 9 / 16;
  max-width: 320px;
  max-height: 480px;
}

.skeleton-text {
  font-size: 0.75rem;
  font-weight: 800;
  color: #e2e8f0;
}

/* BULLES DE CHAT ET RENDU MARKDOWN */
.rendered-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-bubble {
  padding: 16px 20px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 0.88rem;
  max-width: 90%;
}

.chat-bubble.assistant {
  background: rgba(19, 29, 53, 0.7);
  border: 1px solid rgba(56, 189, 248, 0.25);
  align-self: flex-start;
  color: #e2e8f0;
}

.chat-bubble.assistant strong.bubble-author {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.chat-bubble.user {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  align-self: flex-end;
}

/* FORMATAGE DE TEXTE RICHE DANS LES BULLES */
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
  color: #fff;
  margin: 12px 0 6px 0;
  font-size: 0.98rem;
}
.chat-bubble ul, .chat-bubble ol {
  margin-left: 20px;
  margin-bottom: 8px;
}
.chat-bubble code {
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cyan);
}
.chat-bubble pre {
  background: #020408;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  margin: 8px 0;
}

/* 2. VUE TÉLÉMÉTRIE INGÉNIEUR */
.telemetry-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.telem-item {
  background: #070a14;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}
.telem-item strong {
  color: var(--cyan);
  display: block;
  font-size: 0.8rem;
  margin-top: 2px;
}

.raw-json-container {
  background: #03050a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  max-height: 420px;
  overflow-y: auto;
}

.raw-json-container pre {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: #cbd5e1;
  white-space: pre-wrap;
  word-break: break-word;
}

/* CARTE DE PRÉVISUALISATION D'IMAGE */
.rendered-image-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.rendered-image-card img {
  max-width: 100%;
  max-height: 480px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}

.btn-download-hd {
  padding: 10px 20px;
  border-radius: 10px;
  background: var(--success);
  border: none;
  color: #fff;
  font-weight: 900;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-download-hd:hover { opacity: 0.9; }

/* RESPONSIVE */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  aside { border-right: 0; border-bottom: 1px solid var(--border); }
}