/* Krin-Assist — design « hero » : bandeau sombre + mascotte, accent configurable.
   Réutilise les IDs/classes attendus par chat.js (#chat-area, .msg, #chat-form,
   #message-input, #send-btn, #typing). Les couleurs viennent de variables posées
   en ligne dans le template (--accent, --hero, --hero-2). */

:root {
  --accent: #14A8E4;
  --hero: #0A0C10;
  --hero-2: #0A0C10;
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #16202A;
  --text-muted: #6E8290;
  --border: #DCE8F0;
  --chip-border: #CFE0EA;
  --chip-text: #22404E;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  color-scheme: light;  /* design clair fixe : pas d'inversion en mode sombre OS */
}

body { display: flex; flex-direction: column; }

/* --- En-tête héro : ciel étoilé animé + mascotte auréolée --- */
.hero {
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  background:
    radial-gradient(1px 1px at 12% 25%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 60%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 45% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 62% 75%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 35%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 65%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 15% 85%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 95% 15%, #fff 50%, transparent 51%),
    linear-gradient(180deg, var(--hero-2) 0%, var(--hero) 85%);
  background-repeat: repeat, repeat, repeat, repeat, repeat, repeat, repeat, repeat, no-repeat;
  background-size: 260px 260px, 260px 260px, 260px 260px, 260px 260px, 260px 260px, 260px 260px, 260px 260px, 260px 260px, 100% 100%;
  animation: stardrift 140s linear infinite;
  padding: calc(24px + env(safe-area-inset-top)) 16px 0;
}
@keyframes stardrift {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: -260px -130px, 260px -180px, -180px 260px, 220px 180px, -220px -220px, 180px -140px, -140px 220px, 240px -240px, 0 0; }
}

.hero-media {
  position: relative;
  height: 160px;
  overflow: visible;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.hero-media::before {
  /* Auréole lumineuse pulsante derrière la mascotte */
  content: "";
  position: absolute;
  top: 8px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 55%, transparent) 0%, transparent 68%);
  filter: blur(4px);
  animation: aura-pulse 3.2s ease-in-out infinite;
}

@keyframes aura-pulse {
  0%, 100% { transform: scale(0.94); opacity: 0.75; }
  50% { transform: scale(1.05); opacity: 1; }
}

.hero-img {
  position: relative;
  width: 210px;
  height: 210px;
  object-fit: cover;
  object-position: 50% 24%;  /* cadre le visage de la mascotte */
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--accent) 65%, transparent));
}

.call-btn {
  position: absolute;
  top: calc(30px + env(safe-area-inset-top));
  right: 14px;
  border: 1px solid rgba(20, 168, 228, 0.6);
  color: #7FD4F5;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
}

.hero-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 46px;
  background: linear-gradient(180deg, transparent 0%, var(--hero) 78%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding-bottom: 8px;
}

.hero-name {
  font-family: "Orbitron", "Space Grotesk", system-ui, sans-serif;
  color: #ffffff;
  font-weight: 700;
  font-size: 20px;
  line-height: 1;
  letter-spacing: .04em;
  text-shadow: 0 0 14px color-mix(in srgb, var(--accent) 70%, transparent);
}

.hero-tagline {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #7FD4F5;
  font-size: 12px;
  line-height: 1;
  padding-bottom: 2px;
}

.hero-tagline::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px 1px var(--accent);
  animation: status-blink 1.8s ease-in-out infinite;
}

@keyframes status-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* --- Zone chat --- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  padding: 12px 15px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border: 1px solid #EDF2F6;   /* définit la bulle sur fond blanc */
  border-radius: 20px 20px 20px 6px;
  box-shadow: 0 2px 6px rgba(11, 50, 72, 0.06);
}

.msg.user {
  align-self: flex-end;
  background: var(--hero);
  color: #ffffff;
  border-radius: 20px 20px 6px 20px;
}

.msg.system-note {
  align-self: center;
  background: rgba(20, 168, 228, 0.12);
  color: #0B7FB0;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  padding: 6px 14px;
}

/* --- Carte de confirmation de rendez-vous --- */
.confirm-card {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 92%;
  margin: 4px 0;
  padding: 14px 18px;
  background: #ecfdf3;
  border: 1px solid #a6f4c5;
  border-radius: 16px;
  animation: confirm-pop .35s ease-out;
}
.confirm-check {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #12b76a;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-title { font-weight: 700; font-size: 15px; color: #027a48; }
.confirm-sub { font-size: 13px; color: #039855; margin-top: 2px; }
@keyframes confirm-pop {
  0% { transform: scale(.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Chips de suggestions --- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.chips[hidden] { display: none; }

.chip {
  background: var(--surface);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  border-radius: 999px;
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(11, 50, 72, 0.06);
}
.chip.primary {
  background: var(--hero);
  border-color: var(--hero);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
}
.chip:active { transform: translateY(1px); }

/* --- Indicateur de frappe --- */
.typing { display: flex; gap: 4px; padding: 2px 22px 8px; }
.typing[hidden] { display: none; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* --- Saisie --- */
.chat-input {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
}

#chat-form { display: flex; gap: 8px; align-items: center; }

#message-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 13px 18px;
  font-size: 16px; /* 16px min : évite le zoom auto iOS */
  background: #ffffff;              /* toujours blanc, même en thème sombre du navigateur */
  color: #16202A;                  /* texte foncé lisible (jamais noir sur noir) */
  color-scheme: light;             /* empêche le navigateur d'assombrir le champ */
  outline: none;
}
#message-input:focus { border-color: var(--accent); }
#message-input::placeholder { color: var(--text-muted); }

#send-btn {
  border: none;
  background: var(--accent);
  color: #05131C;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 55%, transparent);
}
#send-btn:disabled { opacity: .5; }

#mic-btn {
  border: 1px solid var(--border);
  background: #ffffff;
  color: #16202A;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
#mic-btn:disabled { opacity: .5; }
#mic-btn.listening {
  background: #d92d20;
  border-color: #d92d20;
  color: #fff;
  animation: mic-pulse 1.2s infinite;
}
@keyframes mic-pulse { 50% { opacity: .55; } }

.powered {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}
.powered img { height: 15px; border-radius: 3px; }
.powered a { color: var(--text-muted); text-decoration: none; }

/* ============================================================
   Avatar Krin interactif : colonne gauche (grand écran) + états réactifs
   ============================================================ */

/* Le wrapper est transparent au layout sur mobile : la colonne flex du body
   reste identique à avant (hero en haut, messages, chips, saisie). */
.conversation { display: contents; }

/* --- Disposition « colonne gauche » sur grand écran --- */
@media (min-width: 900px) {
  body { flex-direction: row; }
  .hero {
    width: 340px;
    flex-shrink: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px 20px;
  }
  .hero-media { height: auto; margin-bottom: 20px; }
  .hero-img { width: 240px; height: 240px; }
  .hero-media::before { width: 224px; height: 224px; top: 6px; }
  /* nom + tagline : passent du « fade » absolu à un bloc statique centré */
  .hero-fade {
    position: static;
    height: auto;
    background: none;
    flex-direction: column;
    gap: 6px;
    padding: 0;
  }
  .hero-name { font-size: 26px; }
  /* La conversation redevient une vraie colonne flex (scroll + saisie épinglée) */
  .conversation {
    display: flex;
    flex: 1;
    min-width: 0;
    height: 100dvh;
    flex-direction: column;
  }
}

/* --- Repos : flottement doux (le halo garde son aura-pulse de base) --- */
@keyframes avatar-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.hero-img { animation: avatar-float 5s ease-in-out infinite; }

/* --- Écoute (micro actif) : halo rouge, pulsation rapide --- */
body[data-avatar-state="listening"] .hero-media::before {
  background: radial-gradient(circle, rgba(217, 45, 32, .6) 0%, transparent 68%);
  animation: aura-pulse 1.4s ease-in-out infinite;
}

/* --- Réflexion (Claude génère, avant le 1er mot) : léger balancement + halo scintillant --- */
@keyframes avatar-think { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
body[data-avatar-state="thinking"] .hero-img { animation: avatar-think 1.7s ease-in-out infinite; }
body[data-avatar-state="thinking"] .hero-media::before { animation: aura-pulse 1s ease-in-out infinite; }

/* --- Parole (streaming de la réponse) : bounce + onde sonore + halo intensifié --- */
@keyframes avatar-speak { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.035); } }
body[data-avatar-state="speaking"] .hero-img { animation: avatar-speak .5s ease-in-out infinite; }
body[data-avatar-state="speaking"] .hero-media::before { opacity: 1; animation: aura-pulse 1.2s ease-in-out infinite; }
@keyframes sonar { 0% { transform: scale(.72); opacity: .7; } 100% { transform: scale(1.28); opacity: 0; } }
body[data-avatar-state="speaking"] .hero-media::after {
  content: "";
  position: absolute;
  top: 8px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  z-index: -1;
  animation: sonar 1.4s ease-out infinite;
}
@media (min-width: 900px) {
  body[data-avatar-state="speaking"] .hero-media::after { width: 224px; height: 224px; }
}

/* --- Accessibilité : mouvement réduit --- */
@media (prefers-reduced-motion: reduce) {
  .hero,
  .hero-img,
  .hero-media::before,
  body[data-avatar-state] .hero-img,
  body[data-avatar-state] .hero-media::before { animation: none !important; }
  body[data-avatar-state="speaking"] .hero-media::after { display: none; }
}
