/* ==========================================================================
   VoiceClone Pro — Front utilisateur moderne
   ========================================================================== */

:root {
  --bg-0: #0b0c14;
  --bg-1: #12131f;
  --surface: #1a1c2b;
  --surface-2: #21243a;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef0fb;
  --text-dim: #9497b3;
  --text-faint: #6c6f8a;

  --accent: #7c6bf0;
  --accent-2: #4fd6c8;
  --accent-grad: linear-gradient(135deg, #7c6bf0 0%, #a06bf0 50%, #4fd6c8 130%);
  --accent-soft: rgba(124, 107, 240, 0.16);

  --danger: #f0616b;
  --warn: #f0a94f;
  --success: #4fd68a;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 0 1px rgba(124, 107, 240, 0.25), 0 8px 30px rgba(124, 107, 240, 0.25);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg-0: #fdfaf6;
  --bg-1: #faf4ec;
  --surface: #ffffff;
  --surface-2: #fbf7f1;
  --border: rgba(90, 55, 20, 0.07);
  --text: #2c2013;
  --text-dim: #746452;
  --text-faint: #a89984;

  --accent: #e08a3c;
  --accent-2: #e0567a;
  --accent-grad: linear-gradient(135deg, #e08a3c 0%, #e0567a 55%, #f0b64f 130%);
  --accent-soft: rgba(224, 138, 60, 0.14);
  --shadow-soft: 0 10px 30px rgba(120, 70, 20, 0.10);
  --shadow-glow: 0 0 0 1px rgba(224, 138, 60, 0.25), 0 8px 30px rgba(224, 138, 60, 0.22);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-0);
  color: var(--text);
  overflow: hidden;
  transition: background .3s ease, color .3s ease;
}

/* ---------- Background FX ---------- */
.bg-fx {
  position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background:
    radial-gradient(circle at 15% 20%, var(--bg-1), transparent 55%),
    var(--bg-0);
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: .35;
  animation: float 18s ease-in-out infinite;
}
.orb-a { width: 420px; height: 420px; top: -120px; left: -100px; background: #7c6bf0; }
.orb-b { width: 380px; height: 380px; bottom: -140px; right: -80px; background: #4fd6c8; animation-duration: 22s; animation-delay: -4s; }
.orb-c { width: 260px; height: 260px; bottom: 10%; left: 30%; background: #a06bf0; animation-duration: 26s; animation-delay: -9s; opacity: .2; }

[data-theme="light"] .orb { opacity: .14; }
[data-theme="light"] .orb-a { background: #f0b64f; }
[data-theme="light"] .orb-b { background: #e0567a; }
[data-theme="light"] .orb-c { background: #e08a3c; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.08); }
  66% { transform: translate(-20px, 25px) scale(0.96); }
}

/* ---------- App shell ---------- */
.app {
  position: relative; z-index: 1;
  max-width: 820px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 18px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 4px 16px;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-avatar {
  position: relative;
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; color: #fff;
  box-shadow: var(--shadow-glow);
}

.pulse-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(124, 107, 240, .55);
  animation: pulse 2.4s ease-out infinite;
}
.pulse-ring-delay { animation-delay: 1.2s; }
@keyframes pulse {
  0% { transform: scale(1); opacity: .8; }
  100% { transform: scale(1.7); opacity: 0; }
}

.brand-avatar.audio-playing .pulse-ring { animation-duration: .6s; }
.brand-avatar.audio-playing { animation: soundwave 1s ease-in-out infinite; }
@keyframes soundwave {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.brand-text h1 {
  font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: -0.01em;
}
.brand-text .status {
  margin: 2px 0 0; font-size: .78rem; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.brand-text .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

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

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; cursor: pointer;
  transition: all .18s ease;
}
.icon-btn:hover { transform: translateY(-2px); color: var(--text); border-color: var(--accent); }
.icon-btn:active { transform: translateY(0); }
.icon-btn-accent:hover { color: var(--accent-2); border-color: var(--accent-2); }
.icon-btn-danger:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- Chat area ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 2px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg {
  display: flex; gap: 12px; max-width: 88%;
  animation: rise .35s cubic-bezier(.2,.7,.3,1);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user { margin-left: auto; flex-direction: row-reverse; }

.avatar {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.avatar-agent { background: var(--accent-grad); color: #fff; }
.avatar-user { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }

.msg-body { min-width: 0; }
.msg-user .msg-body { text-align: right; }

.bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  font-size: .95rem;
  line-height: 1.55;
  box-shadow: var(--shadow-soft);
  word-wrap: break-word;
}
.msg-user .bubble {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: 4px;
}

.bubble strong { color: var(--accent-2); font-weight: 600; }
.msg-user .bubble strong { color: #fff; }
.bubble em { color: var(--warn); font-style: normal; }

.msg-time {
  display: block; margin-top: 6px; font-size: .72rem; color: var(--text-faint);
  padding: 0 4px;
}

.msg-actions { display: flex; gap: 6px; margin-top: 8px; }
.demo-chip {
  border: 1px solid var(--accent-2); background: var(--surface);
  color: var(--accent-2); border-radius: 999px; padding: 5px 12px;
  font-size: .78rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  transition: all .15s ease;
}
.demo-chip:hover { background: var(--accent-2); color: #fff; }

/* hors sujet */
.msg-hors-sujet .bubble {
  background: linear-gradient(135deg, rgba(240, 169, 79, .12), rgba(240, 97, 107, .08));
  border-color: rgba(240, 169, 79, .3);
}
.msg-hors-sujet .avatar-agent {
  background: linear-gradient(135deg, var(--warn), var(--danger));
  animation: shake .45s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* quick chips */
.quick-chips {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: .82rem;
  cursor: pointer;
  transition: all .18s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-2); transform: translateY(-1px); }

/* ---------- Lead form ---------- */
.bubble-form { border-top-left-radius: var(--radius-md); }
.bubble-form h3 { margin: 0 0 4px; font-size: 1rem; }
.bubble-form p { margin: 0 0 14px; color: var(--text-dim); font-size: .85rem; }

.field { margin-bottom: 10px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .88rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease;
  resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field input.invalid, .field textarea.invalid { border-color: var(--danger); }
.field-error { display: block; color: var(--danger); font-size: .74rem; margin-top: 4px; min-height: 1em; }

.submit-btn {
  width: 100%; border: none; border-radius: var(--radius-sm);
  background: var(--accent-grad); color: #fff; font-weight: 600;
  padding: 11px; font-size: .9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .15s ease, transform .15s ease;
}
.submit-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.submit-btn:disabled { opacity: .6; cursor: default; transform: none; }

.form-success {
  display: flex; align-items: flex-start; gap: 10px;
  background: rgba(79, 214, 138, .1);
  border: 1px solid rgba(79, 214, 138, .35);
  color: var(--success);
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: .88rem;
}
.form-alert {
  background: rgba(240, 97, 107, .12);
  border: 1px solid rgba(240, 97, 107, .35);
  color: var(--danger);
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: .8rem; margin-bottom: 10px;
}

/* ---------- Status bar ---------- */
.status-bar { flex-shrink: 0; min-height: 26px; padding: 0 4px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--text-dim);
}
.status-pill-audio { color: var(--accent-2); }
.hidden { display: none !important; }

.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.wave { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.wave i {
  width: 3px; background: var(--accent-2); border-radius: 2px;
  animation: wave 1s infinite ease-in-out;
}
.wave i:nth-child(1) { height: 40%; animation-delay: 0s; }
.wave i:nth-child(2) { height: 100%; animation-delay: .15s; }
.wave i:nth-child(3) { height: 65%; animation-delay: .3s; }
.wave i:nth-child(4) { height: 85%; animation-delay: .45s; }
@keyframes wave { 0%, 100% { transform: scaleY(.4); } 50% { transform: scaleY(1); } }

/* ---------- Composer ---------- */
.composer { flex-shrink: 0; padding: 10px 2px 18px; }
#composer-form {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 6px 6px 8px;
  box-shadow: var(--shadow-soft);
}

.mic-btn, .send-btn {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem; transition: all .18s ease;
}
.mic-btn { background: var(--surface-2); color: var(--text-dim); }
.mic-btn:hover { color: var(--accent); }
.mic-btn:disabled { opacity: .45; cursor: not-allowed; }
.mic-btn.mic-blocked { color: var(--danger); }

.mic-notice {
  margin: .5rem 0 0; padding: .5rem .75rem;
  font-size: .82rem; line-height: 1.4; text-align: center;
  color: var(--danger);
  background: rgba(240, 97, 107, .1);
  border: 1px solid rgba(240, 97, 107, .3);
  border-radius: 10px;
}
.mic-btn.recording {
  background: var(--danger); color: #fff;
  animation: pulse-red 1s infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240,97,107,.6); }
  50% { box-shadow: 0 0 0 10px rgba(240,97,107,0); }
}

.send-btn { background: var(--accent-grad); color: #fff; }
.send-btn:hover { filter: brightness(1.1); transform: scale(1.04); }
.send-btn:disabled { opacity: .5; cursor: default; transform: none; }

#user-input {
  flex: 1; border: none; background: transparent; outline: none;
  color: var(--text); font-size: .95rem; font-family: inherit; padding: 8px 4px;
}
#user-input::placeholder { color: var(--text-faint); }

.composer-hint {
  text-align: center; font-size: .72rem; color: var(--text-faint);
  margin: 8px 0 0;
}
.composer-hint i { font-size: .78rem; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .app { padding: 0 12px; }
  .msg { max-width: 96%; }
  .brand-text h1 { font-size: .95rem; }
  .icon-btn { width: 38px; height: 38px; }
}
