/* Elio design-PWA — chat UI. Mobile-first. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, sans-serif;
  background: #FAFAF8;
  color: #1F2937;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: contain;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  background: #fff;
}

/* ─── States ────────────────────────────────────────────────── */

.screen-fill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.loader {
  text-align: center;
  color: #6B7280;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #E5E7EB;
  border-top-color: #FF6B2B;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loader-text { font-size: 14px; }

.err-card {
  max-width: 320px;
  text-align: center;
  padding: 24px;
}
.err-icon { font-size: 40px; margin-bottom: 12px; }
.err-card div:last-child { color: #DC2626; font-size: 15px; }

/* ─── Intake form (shown before chat starts) ────────────────── */

.intake-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.intake-header {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 24px 20px 12px;
  padding-top: max(24px, env(safe-area-inset-top));
}

.intake-headtext { flex: 1; min-width: 0; }
.intake-greet { font-size: 16px; font-weight: 600; color: #111827; line-height: 1.35; }
.intake-greet span { color: #FF6B2B; }
.intake-sub { font-size: 13px; color: #6B7280; margin-top: 4px; line-height: 1.4; }

.intake-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px 20px max(28px, env(safe-area-inset-bottom));
}

.intake-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: #374151;
  font-weight: 500;
}
.intake-label.half { flex: 1; min-width: 0; }

.intake-row { display: flex; gap: 10px; }

.intake-form input,
.intake-form select {
  height: 44px;
  padding: 0 12px;
  border: 1.5px solid #E5E7EB;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: #F9FAFB;
  color: #111827;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.intake-form input:focus,
.intake-form select:focus {
  border-color: #FF6B2B;
  background: #fff;
}
.intake-form select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23999' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.intake-submit {
  margin-top: 8px;
  height: 50px;
  border: none;
  border-radius: 12px;
  background: #FF6B2B;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.intake-submit:disabled { opacity: 0.6; cursor: wait; }

.intake-skip {
  background: transparent;
  border: none;
  color: #6B7280;
  font-size: 14px;
  padding: 8px;
  cursor: pointer;
  align-self: center;
}

/* ─── Chat shell ────────────────────────────────────────────── */

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;  /* allow children to scroll */
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #E5E7EB;
  padding-top: max(12px, env(safe-area-inset-top));
}

.contractor-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #FF6B2B;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.contractor-info { flex: 1; min-width: 0; }
.contractor-name { font-size: 15px; font-weight: 600; color: #111827; }
.contractor-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6B7280;
  margin-top: 1px;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10B981;
  display: inline-block;
}

/* ─── Messages ──────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  font-size: 15.5px;
  line-height: 1.4;
  border-radius: 18px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fade-in 0.2s ease-out;
}

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

.bubble-user {
  background: #FF6B2B;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  background: #F3F4F6;
  color: #111827;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.bubble strong { font-weight: 600; }

/* Image inside a chat bubble */
.bubble-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
  margin-bottom: 6px;
  object-fit: cover;
}
.bubble-user .bubble-image {
  background: rgba(255, 255, 255, 0.15);
}

.timestamp {
  font-size: 11px;
  color: #9CA3AF;
  margin: 4px 8px 0;
}

.timestamp-user { align-self: flex-end; }
.timestamp-assistant { align-self: flex-start; }

/* ─── Typing indicator ──────────────────────────────────────── */

.typing-indicator {
  padding: 0 16px 4px;
}

.typing {
  padding: 12px 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: auto;
  max-width: none;
}

.typing span {
  width: 7px;
  height: 7px;
  background: #9CA3AF;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

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

/* ─── Composer ──────────────────────────────────────────────── */

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #E5E7EB;
}

/* Attach (camera) button — left of the input */
#attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #6B7280;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
#attach-btn:active:not(:disabled) {
  transform: scale(0.95);
}
#attach-btn:disabled {
  color: #D1D5DB;
  cursor: not-allowed;
}

/* Preview strip above the composer when a photo is queued */
.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #FAFAF8;
  border-top: 1px solid #E5E7EB;
}
.image-preview img {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
}
.image-preview button {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #E5E7EB;
  color: #374151;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.composer input {
  flex: 1;
  height: 44px;
  padding: 0 16px;
  border: 1.5px solid #E5E7EB;
  border-radius: 22px;
  font-size: 16px;
  font-family: inherit;
  background: #F9FAFB;
  color: #111827;
  outline: none;
  transition: border-color 0.15s;
}

.composer input:focus {
  border-color: #FF6B2B;
  background: #fff;
}

.composer button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #FF6B2B;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}

.composer button:disabled {
  background: #D1D5DB;
  cursor: not-allowed;
}

.composer button:active:not(:disabled) {
  transform: scale(0.95);
}

/* Hint when session is finalized */
.session-ended {
  align-self: center;
  margin: 24px auto;
  padding: 12px 18px;
  background: #FEF3C7;
  border-radius: 12px;
  color: #92400E;
  font-size: 13px;
  text-align: center;
  max-width: 80%;
}
