/* ==========================================================================
   /start/ — Chat UI styles
   ========================================================================== */

html, body {
  height: 100%;
  overflow-x: hidden;
  max-width: 100vw;
}
@supports (height: 100dvh) {
  body { height: 100dvh; }
}
body {
  background: var(--color-bg-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
}

/* ---- Header ---- */
.chat-header {
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
  flex-shrink: 0;
}
.chat-header__inner {
  max-width: 820px;
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.chat-header__logo {
  font-family: var(--font-logo);
  font-size: 26px;
  color: var(--color-accent);
  text-decoration: none;
}
.chat-header__progress {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 280px;
}
.chat-header__progress-label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
}
.chat-header__progress-label strong {
  color: var(--color-accent);
  font-weight: 700;
}
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--color-accent);
  transition: width 0.4s ease;
}
.chat-header__auth { flex-shrink: 0; }
.chat-header__link {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-light);
  text-decoration: none;
}
.chat-header__link:hover { color: var(--color-text); }

/* ---- Main chat area ---- */
.chat-main {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}
.chat-messages {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-grow: 1;
}

/* ---- Bubble ---- */
.bubble {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: 18px;
  line-height: 1.55;
  font-size: 15px;
  animation: bubble-in 0.28s ease-out;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble--assistant {
  align-self: flex-start;
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 6px;
}
.bubble--user {
  align-self: flex-end;
  background: var(--color-accent);
  color: var(--color-white);
  border-bottom-right-radius: 6px;
}
.bubble__content {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble__content a {
  color: inherit;
  text-decoration: underline;
}

/* ---- Synthesis callout (when phase advances) ---- */
.synthesis {
  align-self: center;
  max-width: 600px;
  background: #fff9ed;
  border: 1px solid #f3dab0;
  border-radius: var(--radius);
  padding: 14px 18px;
  color: #7a5a1a;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  animation: bubble-in 0.4s ease-out;
}
.synthesis__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #a67820;
  margin-bottom: 4px;
  display: block;
}

/* ---- Typing indicator ---- */
.chat-loading {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--color-text-muted);
  font-size: 14px;
}
.chat-loading__dots {
  display: inline-flex;
  gap: 4px;
}
.chat-loading__dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: typing 1.2s infinite ease-in-out;
}
.chat-loading__dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-loading__dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ---- Error ---- */
.chat-error {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 20px;
  color: var(--color-error);
  font-size: 14px;
}

/* ---- Input area ---- */
.chat-input {
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
}
.chat-input__inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 12px;
  position: relative;
}
.chat-input__box {
  display: flex;
  align-items: flex-end;
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  background: var(--color-bg-soft);
  padding: 6px 6px 6px 14px;
  transition: border-color var(--transition);
  gap: 4px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.chat-input__box:focus-within {
  border-color: var(--color-text-muted);
  background: var(--color-white);
}
.chat-input__attach {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  margin-bottom: 2px;
}
.chat-input__attach:not(:disabled):hover {
  color: var(--color-accent);
}
.chat-input__attach:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.chat-input__attach.uploading {
  color: var(--color-accent);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.chat-input__attachments {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 20px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.attach-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 12px;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--color-text);
  max-width: 240px;
}
.attach-pill__icon { font-size: 14px; }
.attach-pill__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-pill__remove {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text);
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 4px;
  transition: background var(--transition);
}
.attach-pill__remove:hover {
  background: var(--color-accent);
  color: var(--color-white);
}
.chat-input__textarea {
  flex-grow: 1;
  padding: 8px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  resize: none;
  min-height: 40px;
  max-height: 160px;
  line-height: 1.5;
  font-size: 15px;
  font-family: inherit;
  overflow-y: auto;
}
.chat-input__textarea:focus { outline: none; }
/* ---- Action button (toggle mic/send) ---- */
.chat-input__action {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  position: relative;
  margin-bottom: 2px;
}
.chat-input__btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
/* Send button — sottile, non invasivo */
.chat-input__btn--send {
  display: none;
  background: var(--color-text);
  color: var(--color-white);
}
.chat-input__btn--send.visible {
  display: flex;
}
.chat-input__btn--send.visible:hover {
  background: var(--color-accent);
}
.chat-input__btn--send svg { width: 16px; height: 16px; margin-left: 1px; }
/* Mic button */
.chat-input__btn--mic {
  display: flex;
  background: transparent;
  color: var(--color-text-muted);
}
.chat-input__btn--mic.hidden {
  display: none;
}
.chat-input__btn--mic:hover {
  color: var(--color-text);
}
.chat-input__btn--mic.recording {
  background: #dc2626;
  color: var(--color-white);
  animation: mic-pulse 1.5s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}
.chat-input__btn--mic.unsupported { display: none !important; }
.chat-input__hint {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px 10px;
  font-size: 11px;
  color: var(--color-text-muted);
}

/* ---- Email collection overlay ---- */
.email-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.2s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.email-overlay__card {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.email-overlay__title { font-size: 22px; margin-bottom: 8px; }
.email-overlay__desc { color: var(--color-text-light); font-size: 14px; margin-bottom: 18px; line-height: 1.5; }

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .chat-header { padding: 0 8px; }
  .chat-header__progress { max-width: none; }
  .chat-messages { padding: 16px 10px 10px; gap: 12px; }
  .bubble { max-width: 94%; font-size: 15px; }
  .chat-input { padding: 0; }
  .chat-input__inner { padding: 6px 6px; }
  .chat-input__box { border-radius: 16px; padding: 6px 6px 6px 12px; }
  .chat-input__hint { display: none; }
  .chat-input__attachments { padding: 6px 6px 0; }
}
