/* Consultation Form Agent – Dialog UI */

:root {
  --bg-page: #eef1f4;
  --bg-panel: #eef1f4;
  --border: #e0e0dc;
  --text: #1a1a1a;
  --text-muted: #5c5c5c;
  --accent: #00417a;
  --accent-hover: #003461;
  --qdesc-pale-blue: #e8f1f9;
  --agent-bg: #e8ebe8;
  --user-bg: #2f6a46;
  --user-text: #fff;
  /* Primary action green (progress bar end / user bubbles); darker for hover */
  --theme-green: #2e7d32;
  --theme-green-hover: #256b29;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.5;
}

.dialog-container {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}

.dialog-header {
  flex-shrink: 0;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  position: relative;
}

.local-mode-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: #b00020;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
}

.local-mode-badge--on {
  background: var(--theme-green);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  width: 220px;
  height: 56px;
  padding: 10px 14px;
  background: var(--accent);
  border-radius: 12px;
  object-fit: contain;
  object-position: left center;
}

.dialog-header h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.dialog-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.dialog-tip {
  margin: 0.5rem 0 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--agent-bg);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}

.dialog-tip code {
  font-size: 0.7rem;
  background: var(--bg-panel);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
}

.dialog-tip.hidden {
  display: none;
}

.dialog-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--agent-bg);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text);
}

.chat-message {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
}

.chat-message.agent {
  align-self: flex-start;
  background: var(--accent);
  color: var(--user-text);
  border-bottom-left-radius: 4px;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.chat-message-user--editable {
  position: relative;
  outline-offset: 2px;
  transition: filter 0.15s ease, box-shadow 0.15s ease;
}

.chat-message-user--editable:hover,
.chat-message-user--editable:focus {
  filter: brightness(1.08);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.chat-message-user--editable:focus:not(:focus-visible) {
  box-shadow: none;
}

.chat-message-user--editable:focus-visible {
  box-shadow: 0 0 0 2px var(--user-text);
}

.chat-message-edit-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-message-edit-btn:hover {
  filter: brightness(0.95);
}

.chat-message-edit-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chat-message.agent.chat-message--has-description {
  position: relative;
  padding-right: 2.35rem;
}

.chat-message-info-btn {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.35rem;
  height: 1.35rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--accent);
  font-size: 0.75rem;
  font-style: italic;
  font-weight: 700;
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.chat-message-info-btn:hover {
  filter: brightness(0.97);
}

.chat-message-info-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 1px;
}

.question-description-modal[hidden] {
  display: none !important;
}

.question-description-modal {
  position: fixed;
  inset: 0;
  z-index: 1110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  box-sizing: border-box;
}

.question-description-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.question-description-modal-card {
  position: relative;
  z-index: 1;
  width: min(36rem, calc(100% - 2rem));
  max-height: min(85vh, calc(100vh - 2rem));
  margin: 0;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.question-description-modal-header {
  background: var(--accent);
  color: #fff;
  padding: 1rem 1.25rem 1.15rem;
}

.question-description-modal-kicker {
  display: block;
  margin: 0 0 0.4rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.88);
}

.question-description-modal-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.4;
}

.question-description-modal-desc-wrap {
  background: var(--qdesc-pale-blue);
  padding: 1rem 1.25rem 1.1rem;
  border-bottom: 1px solid rgba(0, 65, 122, 0.08);
}

.question-description-modal-body {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
}

.question-description-modal-actions {
  margin: 0;
  padding: 0.85rem 1rem 1rem;
  display: flex;
  justify-content: flex-end;
  background: #fff;
}

.question-description-modal-close {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--user-text);
  cursor: pointer;
  font-size: 0.9rem;
}

.question-description-modal-close:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.quick-reply-btn--explain {
  border-color: var(--accent);
  color: var(--accent);
  background: #fff;
}

.quick-reply-btn--explain:hover {
  background: var(--agent-bg);
}

.answer-edit-modal[hidden] {
  display: none;
}

.answer-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
}

.answer-edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.answer-edit-modal-card {
  position: relative;
  width: min(36rem, calc(100% - 2rem));
  margin: 8vh auto 0;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  padding: 1rem;
}

.answer-edit-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.answer-edit-question {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--text);
}

.answer-edit-input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.answer-edit-input:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}

.answer-edit-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.answer-edit-suggestion-btn {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.answer-edit-suggestion-btn:hover {
  border-color: var(--accent);
  background: var(--agent-bg);
}

.answer-edit-error {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  color: #b00020;
  font-size: 0.85rem;
}

.answer-edit-actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.answer-edit-btn {
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
}

.answer-edit-btn-cancel {
  background: #fff;
  color: var(--text);
}

.answer-edit-btn-update {
  background: var(--accent);
  color: var(--user-text);
  border-color: var(--accent);
}

.chat-message .message-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
  margin-bottom: 0.25rem;
}

.chat-message .message-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.restart-consultation-wrap {
  display: flex;
  justify-content: center;
  margin: 0.35rem 0 0.15rem;
}

.restart-consultation-btn {
  padding: 0.6rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.restart-consultation-btn:hover {
  background: var(--agent-bg);
}

.form-type-choices {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 0;
}

.form-type-choice-btn {
  width: 100%;
  max-width: 20rem;
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.form-type-choice-btn:hover {
  background: var(--agent-bg);
  border-color: var(--accent);
}

.form-type-choice-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.quick-replies {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0 1.5rem 0.5rem;
}

.quick-reply-btn {
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.quick-reply-btn:hover {
  background: var(--agent-bg);
  border-color: var(--accent);
}

.quick-reply-btn--selected {
  background: var(--accent);
  color: var(--user-text);
  border-color: var(--accent);
}

.quick-reply-btn--send {
  margin-left: auto;
  background: var(--accent);
  color: var(--user-text);
  border-color: var(--accent);
}

.quick-reply-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-input-area {
  flex-shrink: 0;
  padding: 0.75rem 1.5rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.5rem 0;
  width: 100%;
}

.progress-row[hidden] {
  display: none;
}

.progress-bar {
  flex: 1;
  min-width: 0;
  height: 4px;
  background: var(--border);
  overflow: hidden;
}

.progress-count {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #c62828, #2e7d32);
  transition: width 0.25s ease-out;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.user-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}

.user-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.user-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--accent);
  color: var(--user-text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.powered-by {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 36px;
}

.powered-by-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.powered-by-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.powered-by-link {
  display: inline-flex;
  align-items: center;
}

/* Submit step */
.chat-message.submit-prompt .submit-btn {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--accent);
  color: var(--user-text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.chat-message.submit-prompt .submit-btn:hover {
  background: var(--accent-hover);
}

.chat-message.submit-prompt .submit-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.submit-bar {
  margin-top: 0.25rem;
  display: grid;
  gap: 0.5rem;
}

.submit-bar[hidden] {
  display: none;
}

.submit-bar .submit-btn {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.9rem 1.25rem;
  min-height: 3rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--theme-green);
  color: var(--user-text);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(46, 125, 50, 0.35);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.submit-bar .submit-btn:hover {
  background: var(--theme-green-hover);
  box-shadow: 0 3px 10px rgba(46, 125, 50, 0.45);
}

.submit-bar .submit-btn:focus {
  outline: 2px solid var(--theme-green);
  outline-offset: 3px;
}

.submit-bar .submit-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
}

.submit-upload-label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.75rem;
  opacity: 0.95;
}

.submit-upload-input {
  width: 100%;
  font-size: 0.75rem;
  color: var(--text);
}

.submit-review {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
}

.submit-review-title {
  margin: 0 0 0.4rem 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.submit-review-list {
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  gap: 0.35rem;
}

.submit-review-item {
  display: grid;
  gap: 0.1rem;
}

.submit-review-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.submit-review-value {
  font-size: 0.8rem;
  color: var(--text);
  word-break: break-word;
}

.hp-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Loading / status */
.chat-message.status {
  align-self: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Typing indicator — shown while AI call is in flight */
.chat-message.agent-typing {
  padding: 0.5rem 0.75rem;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 1.25rem;
  padding: 0.1rem 0;
}
.typing-dots span {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--agent-bubble-text, #fff);
  opacity: 0.4;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dots span { animation: none; opacity: 0.7; }
}

/* BriefChat — section-complete motivation (confetti + phrase) */
.briefchat-celebration {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  opacity: 0;
  animation: briefchat-celebration-fade-in 1s ease forwards;
}

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

@keyframes briefchat-celebration-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.briefchat-celebration-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.35);
  backdrop-filter: blur(2px);
  transition: background 0.35s ease;
}

.briefchat-celebration[data-briefchat-style='fireworks'] .briefchat-celebration-backdrop {
  background: rgba(12, 20, 40, 0.42);
}

.briefchat-celebration[data-briefchat-style='rain'] .briefchat-celebration-backdrop {
  background: rgba(30, 40, 55, 0.38);
}

.briefchat-celebration[data-briefchat-style='sparkles'] .briefchat-celebration-backdrop {
  background: rgba(40, 35, 50, 0.32);
}

.briefchat-celebration[data-briefchat-style='stars'] .briefchat-celebration-backdrop {
  background: rgba(25, 35, 55, 0.36);
}

.briefchat-celebration-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.briefchat-celebration-card {
  position: relative;
  z-index: 2;
  max-width: min(92vw, 26rem);
  margin: 1rem;
  padding: 1.25rem 1.5rem;
  background: #fff9e6;
  border-radius: var(--radius-md, 12px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  text-align: center;
  border: 1px solid rgba(0, 65, 122, 0.12);
}

.briefchat-celebration-phrase {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--accent);
}

.briefchat-motivation-toast {
  align-self: center;
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 1rem;
  max-width: 90%;
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  color: var(--accent);
  background: #fff9e6;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 65, 122, 0.1);
}

@media (max-width: 480px) {
  .dialog-container {
    max-width: 100%;
  }

  .chat-message {
    max-width: 92%;
  }

  .dialog-header,
  .chat-messages,
  .chat-input-area {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
