/*
 * Tokens sémantiques — la palette Atelier Moka (référence figée) sert de défaut.
 * `--accent` est surchargé au runtime depuis resolve.brand.themeAccent (thème
 * client). Les teintes douces d'accent sont dérivées par color-mix, ce qui rend
 * les badges thématisables sans token supplémentaire. L'écran « lien inconnu »
 * ignore toujours ces tokens de marque.
 */
:root {
  --bg: #f7f3ee;
  --surface: #fcfaf7;
  --text: #241812;
  --muted: #8c7b6e;
  --line: #eadfd2;
  --accent: #a85c2e; /* défaut Atelier Moka ; surchargé par themeAccent */
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* le corps ne scrolle jamais horizontalement */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 16px; /* piège iOS : jamais sous 16px sur les champs */
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.brand-header,
.composer-wrap {
  flex: none;
}

svg {
  display: block;
}

/* --- BrandHeader --------------------------------------------------------- */

.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

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

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
}

.brand-logo.mono {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.verified {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.verified svg {
  width: 15px;
  height: 15px;
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: -10px -10px -10px 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.menu-btn svg {
  width: 20px;
  height: 20px;
}

/* --- Arrival / ProductIdentity ------------------------------------------ */

.arrival {
  padding: 18px 18px 28px;
}

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

.product-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent);
}

.product-icon svg {
  width: 24px;
  height: 24px;
}

.product-text {
  min-width: 0; /* laisse le texte se tronquer/wrapper au lieu de déborder */
}

.product-category {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.product-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.product-brand {
  font-size: 13px;
  color: var(--muted);
}

/* Vignette PHOTO (bouton) — même gabarit 48×48 que le slot icône, pour que le
   bloc ne saute pas entre l'état photo et l'état repli-icône. */
.product-photo {
  flex: none;
  position: relative;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--surface));
  border-radius: 13px;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  cursor: zoom-in;
  display: block;
}

.product-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-expand {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: rgba(20, 14, 10, 0.5);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.product-expand svg {
  width: 9px;
  height: 9px;
}

/* Lightbox d'agrandissement — overlay plein écran. */
.zoom-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 12, 8, 0.74);
  animation: zoom-fade 0.2s ease both;
}

.zoom-figure {
  position: relative;
  margin: 0;
  width: 100%;
  max-width: 460px;
  animation: zoom-in 0.24s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.zoom-figure img {
  width: 100%;
  height: auto;
  border-radius: 18px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5);
  display: block;
}

.zoom-figure figcaption {
  margin-top: 12px;
  text-align: center;
}

.zoom-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.zoom-brand {
  display: block;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;
}

.zoom-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(20, 14, 10, 0.55);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (prefers-reduced-motion: reduce) {
  .zoom-backdrop,
  .zoom-figure {
    animation: none;
  }
}

@keyframes zoom-fade {
  from {
    opacity: 0;
  }
}

@keyframes zoom-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

.intro {
  margin: 20px 0 14px;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
}

.transparency {
  display: flex;
  gap: 8px;
  margin: 0 0 24px;
  font-size: 13px;
  color: var(--muted);
}

.transparency > span:last-child {
  min-width: 0;
}

.transparency-icon {
  flex: none;
  color: var(--muted);
}

.transparency-icon svg {
  width: 15px;
  height: 15px;
  margin-top: 1px;
}

.conf-link {
  color: var(--accent);
  text-decoration: underline;
}

/* --- Suggestions initiales ---------------------------------------------- */

.suggestions-label {
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.init-suggestions {
  display: grid;
  gap: 10px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s ease, transform 0.05s ease;
}

.chip:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.chip:active {
  transform: scale(0.995);
}

.chip-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent);
}

.chip-icon svg {
  width: 20px;
  height: 20px;
}

.chip-label {
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

/* --- Conversation (fil éphémère) ---------------------------------------- */

.msg {
  margin-top: 16px;
}

.msg-user {
  display: flex;
  justify-content: flex-end;
}

.msg-user .bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-right-radius: 6px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--text);
  font-weight: 600;
}

.msg-assistant {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.msg-icon {
  flex: none;
  margin-top: 2px;
  color: var(--muted);
}

.msg-icon svg {
  width: 20px;
  height: 20px;
}

.msg-body {
  flex: 1;
  min-width: 0;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-body.msg-error {
  color: var(--muted);
}

.msg-body p {
  margin: 0 0 10px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body ul,
.msg-body ol {
  margin: 0 0 10px;
  padding-left: 20px;
}

.msg-body ul:last-child,
.msg-body ol:last-child {
  margin-bottom: 0;
}

.msg-body li {
  margin: 3px 0;
}

.msg-body strong {
  font-weight: 700;
}

.msg-body em {
  font-style: italic;
}

.msg-assistant.streaming .msg-body::after {
  content: "▍";
  margin-left: 1px;
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.interrupted-mark {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.interrupted-mark svg {
  width: 11px;
  height: 11px;
  flex: none;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0 30px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.stop-btn svg {
  width: 12px;
  height: 12px;
}

.msg-content {
  flex: 1;
  min-width: 0;
}

/* Révélation séquentielle du moment signature (réponse → sources → suggestions). */
.reveal {
  animation: reveal-up 0.25s both;
  animation-delay: calc(var(--i, 0) * 150ms);
}

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

@media (prefers-reduced-motion: reduce) {
  .reveal {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .sheet,
  .sheet-backdrop {
    animation: none;
  }

  .chip {
    transition: none;
  }
}

/* SourceList — liste PLATE non interactive (spec §1 ; pas de pilules en v1). */
.source-list {
  margin-top: 14px;
}

.source-label {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.source-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 14px;
  color: var(--text);
}

.source-icon {
  display: flex;
  flex: none;
  color: var(--muted);
}

.source-icon svg {
  width: 15px;
  height: 15px;
}

.source-more {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

/* Mention « Conseil général » — distincte mais discrète (spec §4, jamais un bandeau). */
.general-mention {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.general-icon {
  flex: none;
  color: var(--accent);
}

.general-icon svg {
  width: 15px;
  height: 15px;
  margin-top: 1px;
}

.followups {
  margin-top: 22px;
}

/* --- ChatComposer ------------------------------------------------------- */

.composer-wrap {
  padding: 8px 14px max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 5px 5px 5px 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 7px 0;
  border: none;
  background: none;
  outline: none;
  resize: none;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* piège iOS : jamais sous 16px, sinon zoom au focus */
  line-height: 1.4;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.signature {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}

.signature a {
  color: var(--muted);
  text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
  .msg-assistant.streaming .msg-body::after {
    animation: none;
  }
}

/* --- ContactCard -------------------------------------------------------- */

.contact-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.cc-title {
  margin-bottom: 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.cc-field {
  margin-bottom: 12px;
}

.cc-question,
.cc-email {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* piège iOS : jamais sous 16px */
  line-height: 1.4;
  outline: none;
}

.cc-question {
  resize: vertical;
  min-height: 64px;
}

.cc-question:focus,
.cc-email:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.cc-consent {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 4px 0 6px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}

.cc-consent-box {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--accent);
}

.cc-error {
  display: block;
  margin-top: 5px;
  font-size: 13px;
  color: #a0472b; /* erreur de validation — sobre (le "aucun rouge" vise le quota) */
}

.cc-submit,
.cc-retry {
  margin-top: 10px;
  padding: 11px 18px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.cc-submit[disabled] {
  cursor: default;
  opacity: 0.7;
}

.cc-note {
  margin: 12px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.cc-note-error {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.cc-result {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.cc-check {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--accent);
  font-weight: 700;
}

.cc-info {
  flex: none;
  color: var(--accent);
  font-size: 20px;
  line-height: 1.2;
}

.contact-card.frozen .cc-title {
  margin-bottom: 4px;
}

/* --- FeedbackActions ----------------------------------------------------- */

.feedback-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
}

.fb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.fb-btn:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.fb-btn svg {
  width: 17px;
  height: 17px;
}

.fb-btn.selected {
  color: var(--accent);
}

.fb-copied {
  font-size: 12px;
  color: var(--accent);
}

/* --- InfoSheet (bottom sheet) ------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(36, 24, 18, 0.35);
  animation: sheet-fade 0.2s both;
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 20px max(16px, env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 40px rgba(36, 24, 18, 0.18);
  animation: sheet-up 0.22s ease both;
}

@keyframes sheet-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: none;
  }
}

@keyframes sheet-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}

.sheet-brand {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.sheet-site {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.sheet-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 0;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.sheet-line-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
}

.sheet-line-main svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.sheet-line small {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

.sheet-line .chev {
  flex: none;
  color: var(--muted);
  font-size: 18px;
}

.sheet-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.sheet-label {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
}

.sheet-signature {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.sheet-confirm {
  padding: 12px 4px;
  text-align: center;
}

.sheet-confirm .sheet-line-main {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
}

.sheet-confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.sheet-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.sheet-btn.ghost {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
}

/* --- États limites (désactivé / quota) ---------------------------------- */

.arrival.limit {
  padding-top: 40px;
}

.limit-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.brand-exit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.brand-exit .ext {
  font-size: 0.9em;
}

.privacy-footer {
  flex: none;
  padding: 14px 18px;
  text-align: center;
  font-size: 12px;
}

.privacy-footer a {
  color: var(--muted);
  text-decoration: underline;
}

.cc-in-thread {
  margin-top: 16px;
}

/* Composer désactivé (bascule de canal) — évidemment inactif, pas juste atténué. */
.composer.disabled {
  background: var(--bg);
  border-style: dashed;
}

.composer.disabled textarea {
  color: var(--muted);
  cursor: not-allowed;
}

.composer.disabled .send-btn {
  background: var(--muted);
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- États neutres (lien inconnu / erreur réseau) ----------------------- */

.shell {
  padding: 24px 20px;
}

.app.neutral .shell {
  padding-top: 64px;
}

.muted {
  color: var(--muted);
}
