/* ============================================================
 * Widget prod Poux Experts — design tokens client adoptés
 * Surface : iframe injectée par embed.js sur pouxexperts.fr
 * ============================================================ */

:root {
  --color-accent: #17a3af;
  --color-accent-dark: #128390;
  --color-accent-soft: #e6f7f8;
  --color-text: #333333;
  --color-text-muted: #7a7a7a;
  --color-surface: #ffffff;
  --color-surface-alt: #f7f9fa;
  --color-border: #e6eaec;

  --radius-sm: 12px;
  --radius-pill: 24px;
  --radius-circle: 50%;

  --shadow-soft: 0 5px 10px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lifted: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 6px rgba(0, 0, 0, 0.05);

  --motion-fast: 200ms ease;
  --motion-normal: 300ms ease;

  --font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: transparent;
  font-family: var(--font-family);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

.widget-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Container ---------- */

.widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-surface);
}

/* ---------- Header ---------- */

.widget-header {
  position: relative;
  background: var(--color-accent);
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatars {
  display: flex;
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-circle);
  border: 2px solid var(--color-accent);
  background-size: cover;
  background-position: center;
  background-color: #ffffff;
}

.avatar-1 {
  background-image: url("/static/img/pouxface-1.jpg");
  background-color: #e6f7f8;
}

.avatar-2 {
  margin-left: -10px;
  background-image: url("/static/img/pouxface-2.jpg");
  background-color: #128390;
}

.header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-title {
  font-size: 15px;
  font-weight: 500;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 12px;
  margin: 2px 0 0 0;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-circle);
  background: #5be584;
  box-shadow: 0 0 0 2px rgba(91, 229, 132, 0.25);
  display: inline-block;
}

.header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-circle);
  color: inherit;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.15); }
.icon-btn:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

/* ---------- Kebab menu ---------- */

.kebab-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 14px;
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lifted);
  min-width: 220px;
  padding: 6px;
  z-index: 10;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  font: inherit;
  font-size: 14px;
  color: var(--color-text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.menu-item:hover { background: var(--color-surface-alt); }
.menu-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

/* ---------- Greeting card ---------- */

.greeting-card {
  background: linear-gradient(180deg, var(--color-accent-soft) 0%, transparent 100%);
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  transition: max-height var(--motion-normal), padding var(--motion-normal), opacity var(--motion-normal);
  max-height: 200px;
  overflow: hidden;
}

.greeting-card.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  border-bottom: none;
}

.greeting-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--color-accent-dark);
  margin: 0 0 6px 0;
}

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

/* ---------- Messages ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

.msg {
  display: flex;
  max-width: 85%;
  animation: fadeIn var(--motion-fast);
}

.msg-user { align-self: flex-end; }
.msg-bot  { align-self: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-user .bubble {
  background: var(--color-accent);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.msg-bot .bubble {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.bubble.loading {
  color: var(--color-text-muted);
  font-style: italic;
}

.bubble a {
  color: var(--color-accent-dark);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bubble a:hover { color: var(--color-accent); }

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

/* ---------- Composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  font: inherit;
  font-size: 14px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
  resize: none;
  max-height: 120px;
  background: var(--color-surface-alt);
  transition: border-color var(--motion-fast), background var(--motion-fast);
  font-family: var(--font-family);
}

.composer-input:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--color-surface);
}

.composer-send {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-circle);
  border: none;
  background: var(--color-accent);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--motion-fast), transform var(--motion-fast);
}

.composer-send:hover { background: var(--color-accent-dark); }
.composer-send:active { transform: scale(0.95); }
.composer-send:disabled {
  background: var(--color-border);
  cursor: not-allowed;
}
.composer-send:focus-visible {
  outline: 2px solid var(--color-accent-dark);
  outline-offset: 2px;
}

/* ---------- Feedback modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn var(--motion-fast);
}

/* L'attribut HTML `hidden` doit gagner sur `display: flex` ci-dessus,
   sinon $feedbackModal.hidden = true ne ferme rien (la modale reste
   visible). Override explicite. */
.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: 90%;
  max-width: 360px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 20px;
  box-shadow: var(--shadow-lifted);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text);
  margin: 0;
}

.modal-header .icon-btn {
  color: var(--color-text-muted);
}

.modal-text {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 14px 0;
  line-height: 1.45;
}

.modal-rating {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.rating-btn {
  flex: 1;
  padding: 12px;
  font-size: 22px;
  background: var(--color-surface-alt);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--motion-fast);
}

.rating-btn:hover { background: var(--color-accent-soft); }
.rating-btn.selected {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}

.modal-textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-family);
  margin-bottom: 12px;
}

.modal-textarea:focus {
  outline: none;
  border-color: var(--color-accent);
}

.modal-submit {
  width: 100%;
  padding: 11px;
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--motion-fast);
}

.modal-submit:hover { background: var(--color-accent-dark); }
.modal-submit:disabled {
  background: var(--color-border);
  cursor: not-allowed;
}

.modal-status {
  font-size: 12px;
  text-align: center;
  margin: 8px 0 0 0;
  color: var(--color-text-muted);
  min-height: 16px;
}

.modal-status.success { color: var(--color-accent-dark); }
.modal-status.error   { color: #c93838; }
