/* ===== BASE STYLES (Desktop First) ===== */

/* Editorial Section (shows above chat on mobile) */
.editorial-section {
  background: linear-gradient(135deg, rgba(169,203,183,0.08), rgba(255,255,255,1));
  border-radius: 1rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(0,0,0,0.05);
}

.editorial-section h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--graphite);
  margin-bottom: 0.75rem;
}

.editorial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.editorial-card {
  background: white;
  padding: 1rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(0,0,0,0.08);
  cursor: pointer;
  transition: all 0.3s;
}

.editorial-card:hover {
  border-color: var(--sage-mint);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}

.editorial-card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sage-mint);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.editorial-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--graphite);
  line-height: 1.4;
}

/* Mobile toggle for editorial section */
.editorial-toggle { display: none; }

/* The outer wrapper holding sidebar + chat */
.chat-app-wrapper {
  background: white;
  border-radius: 1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.08);
  display: flex;
  border: 1px solid rgba(0,0,0,0.05);
  overflow: hidden;
  min-height: 32rem;
  max-height: 80vh;
  position: relative;
}

/* Sidebar backdrop (hidden on desktop) */
.chat-sidebar-backdrop { display: none; }

/* Sidebar */
.chat-sidebar {
  width: 14rem; /* ~224px */
  background: var(--sandstone);
  border-right: 1px solid rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.chat-sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.chat-new-conv-btn {
  width: 100%;
  background-color: var(--sage-mint);
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  line-height: 1.2;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(0,0,0,0.08);
  transition: all 0.2s;
}

.chat-new-conv-btn:hover {
  background-color: #92b8a3;
  transform: translateY(-1px);
  box-shadow: 0 12px 20px rgba(0,0,0,0.1);
}

.chat-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(43,43,43,0.6);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.conversation-list-item {
  width: 100%;
  text-align: left;
  background: white;
  border: 2px solid transparent;
  border-radius: 0.75rem;
  padding: 0.75rem 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.conversation-list-item:hover {
  border-color: var(--sage-mint);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.conversation-list-item-timestamp {
  font-size: 0.7rem;
  color: rgba(43,43,43,0.6);
  margin-bottom: 0.25rem;
}

.conversation-list-item-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--graphite);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-sidebar-footer {
  border-top: 1px solid rgba(0,0,0,0.05);
  padding: 1rem;
  font-size: 0.7rem;
  line-height: 1.4;
}

.status-label {
  display: inline-block;
  background: rgba(0,0,0,0.7);
  color: white;
  font-weight: 600;
  font-size: 0.7rem;
  line-height: 1.2rem;
  padding: 0.15rem 0.5rem;
  border-radius: 0.4rem;
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--graphite);
  background: radial-gradient(circle at 20% 20%, rgba(255,255,255,0.06) 0%, rgba(0,0,0,0) 60%), var(--graphite);
  color: white;
}

.chat-header {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.25);
  color: white;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  gap: 1rem;
}

.chat-menu-toggle {
  display: none;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 0.5rem;
  padding: 0.5rem;
  cursor: pointer;
  min-width: 2.25rem;
  min-height: 2.25rem;
}

.chat-menu-toggle svg {
  width: 20px; height: 20px;
  stroke: white; stroke-width: 2px;
}

.chat-header-title h3 {
  font-weight: 600;
  color: white;
  line-height: 1.3;
}

.chat-header-title p {
  color: rgba(255,255,255,0.8);
  font-weight: 500;
  font-size: 0.875rem;
  line-height: 1.4;
}

.chat-header-rightcopy {
  font-size: 0.7rem;
  line-height: 1.4;
  color: rgba(255,255,255,0.7);
  max-width: 16rem;
  text-align: right;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--soft-white);
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
}

.chat-message {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.3s ease-in;
}

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

.chat-message.user { flex-direction: row-reverse; }

.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--sage-mint);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white;
  flex-shrink: 0;
}

.chat-message.user .chat-avatar { background: var(--terracotta); }

.chat-bubble {
  max-width: 75%;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  line-height: 1.6;
  font-size: 0.95rem;
}

.chat-message.assistant .chat-bubble {
  background: white;
  color: var(--graphite);
  border: 1px solid rgba(0,0,0,0.05);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.chat-message.user .chat-bubble {
  background: var(--terracotta);
  color: white;
  text-align: right;
}

.chat-sources {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.chat-sources-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  margin-bottom: 0.5rem;
}

.chat-source-link {
  display: block;
  font-size: 0.75rem;
  color: var(--sage-mint);
  text-decoration: none;
  margin-bottom: 0.25rem;
  transition: color 0.3s;
}

.chat-source-link:hover {
  color: #92b8a3;
  text-decoration: underline;
}

.chat-feedback {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-feedback-label { font-size: 0.75rem; color: #666; }

.chat-feedback-buttons { display: flex; gap: 0.5rem; }

.chat-feedback-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid rgba(43, 43, 43, 0.2);
  background: white;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 1rem;
  display: flex; align-items: center; gap: 0.25rem;
}

.chat-feedback-btn:hover {
  background: rgba(169, 203, 183, 0.1);
  border-color: var(--sage-mint);
  transform: scale(1.1);
}

.chat-feedback-btn.active {
  background: var(--sage-mint);
  border-color: var(--sage-mint);
  color: white;
}

.chat-feedback-btn.active.negative {
  background: #EF4444;
  border-color: #EF4444;
}

.chat-feedback-comment { margin-top: 0.5rem; width: 100%; }

.chat-feedback-textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid rgba(43, 43, 43, 0.2);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

.chat-feedback-textarea:focus { outline: none; border-color: var(--sage-mint); }

.chat-feedback-submit {
  margin-top: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--sage-mint);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.3s;
}

.chat-feedback-submit:hover { background: #92b8a3; }

.chat-feedback-thanks {
  font-size: 0.75rem;
  color: #10B981;
  font-style: italic;
}

/* Typing indicator */
.chat-typing {
  padding: 1rem 1.25rem;
  background: white;
  border-radius: 1rem;
  display: inline-flex;
  gap: 0.25rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.chat-typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--sage-mint);
  animation: typing 1.4s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* Input container */
.chat-input-container {
  background: var(--graphite);
  background: radial-gradient(circle at 80% 80%, rgba(255,255,255,0.04) 0%, rgba(0,0,0,0) 50%), var(--graphite);
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.chat-input-wrapper { display: flex; gap: 0.75rem; align-items: center; }

#chat-input {
  flex: 1;
  padding: 0.875rem 1.25rem;
  border: 2px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.08);
  border-radius: 1.5rem;
  font-size: 0.95rem;
  color: white;
  outline: none;
  transition: all 0.3s;
}

#chat-input::placeholder { color: rgba(255,255,255,0.5); }

#chat-input:focus {
  border-color: var(--sage-mint);
  background: rgba(255,255,255,0.12);
}

#chat-send-btn {
  background: var(--sage-mint);
  border: none;
  border-radius: 50%;
  padding: 0.875rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#chat-send-btn:hover { background: #92b8a3; transform: scale(1.05); }

#chat-send-btn svg { width: 24px; height: 24px; stroke: white; }

#chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Welcome screen */
.chat-welcome { text-align: center; padding: 2rem; color: #666; }

.chat-welcome h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--graphite);
  margin-bottom: 0.5rem;
}

.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.chat-suggestion {
  padding: 0.75rem 1rem;
  background: white;
  border: 2px solid var(--mist-silver);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 0.875rem;
  text-align: left;
}

.chat-suggestion:hover {
  border-color: var(--sage-mint);
  background: rgba(169, 203, 183, 0.05);
  transform: translateY(-2px);
}

/* Special suggestion for personal plan - FULL WIDTH */
.chat-suggestion-special {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--sage-mint), var(--muted-olive));
  color: white;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transition: all 0.3s;
  grid-column: 1 / -1;
}

.chat-suggestion-special:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}

/* Assessment blocks */
.assessment-block h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--graphite);
}

.assessment-desc {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 1rem;
}

.assessment-row { margin-bottom: 1rem; }

.assessment-label {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--graphite);
}

.assessment-input,
.assessment-select {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--mist-silver);
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.assessment-input:focus,
.assessment-select:focus { outline: none; border-color: var(--sage-mint); }

.assessment-option-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.assessment-option-btn {
  padding: 0.6rem 1rem;
  background: white;
  border: 2px solid var(--mist-silver);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s;
}

.assessment-option-btn.selected {
  background: var(--sage-mint);
  color: white;
  border-color: var(--sage-mint);
}

.assessment-option-btn:hover { border-color: var(--sage-mint); }

.assessment-next-btn {
  margin-top: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--sage-mint);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 0.9rem;
}

.assessment-next-btn:hover { background: #92b8a3; }

.assessment-error {
  margin-top: 0.5rem;
  color: #EF4444;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Conversation History Modal */
.chat-history-modal {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  padding: 2rem;
  overflow-y: auto;
}

.chat-history-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-history-content {
  background: white;
  border-radius: 1rem;
  padding: 2rem;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.chat-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.chat-history-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--graphite);
}

.chat-history-message {
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 0.75rem;
  background: var(--soft-white);
}

.chat-history-message.user { background: rgba(169, 203, 183, 0.1); }

.chat-history-message-role {
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  color: var(--sage-mint);
}

.chat-history-message.user .chat-history-message-role { color: var(--terracotta); }

/* Fullscreen toggle default (hidden on desktop) */
.chat-fullscreen-toggle { display: none; }

/* ===== MOBILE STYLES (max-width: 768px) — CONSOLIDATED ===== */
@media (max-width: 768px) {
  /* Editorial section - collapsible on mobile */
  .editorial-section { border-radius: 0.5rem; margin-bottom: 1rem; padding: 1rem; }
  .editorial-section.collapsed { padding: 0.75rem 1rem; }
  .editorial-section.collapsed .editorial-content { display: none; }
  .editorial-toggle {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; background: none; border: none; padding: 0; cursor: pointer;
    color: var(--graphite); font-weight: 600; font-size: 0.95rem;
  }
  .editorial-toggle svg { width: 20px; height: 20px; transition: transform 0.3s; }
  .editorial-section.collapsed .editorial-toggle svg { transform: rotate(180deg); }
  .editorial-grid { grid-template-columns: 1fr; gap: 0.75rem; }

  /* Sidebar backdrop */
  .chat-sidebar-backdrop {
    display: block; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5); z-index: 999; opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .chat-sidebar-backdrop.active { opacity: 1; pointer-events: auto; }

  /* App wrapper - FIXED HEIGHT for proper scrolling */
  .chat-app-wrapper {
    border-radius: 0.5rem;
    height: 600px; min-height: 600px; max-height: none;
    flex-direction: column;
  }

  /* Sidebar becomes a drawer */
  .chat-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px; max-width: 80%;
    box-shadow: 8px 0 24px rgba(0,0,0,0.12);
    z-index: 1000;
    transform: translateX(-100%);
  }
  .chat-sidebar.open { transform: translateX(0); }

  /* Main chat area */
  .chat-main {
    flex: 1; width: 100%; position: relative; z-index: 0;
    border-radius: 0.5rem; min-height: 0; display: flex; flex-direction: column;
  }

  /* Header */
  .chat-header { padding: 0.75rem 1rem; gap: 0.75rem; flex-shrink: 0; }
  .chat-header-title h3 { font-size: 1rem; }
  .chat-header-title p { font-size: 0.75rem; }
  .chat-header-rightcopy { display: none; }

  /* Show menu + fullscreen toggle buttons */
  .chat-menu-toggle,
  .chat-fullscreen-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 0.5rem; padding: 0.5rem; margin-left: 0.25rem;
    min-width: 2.25rem; min-height: 2.25rem; cursor: pointer;
  }
  .chat-fullscreen-toggle svg { stroke: #fff; }

  .chat-avatar { width: 32px; height: 32px; font-size: 0.875rem; }

  /* Messages area - THE KEY FIX */
  .chat-messages {
    background: var(--soft-white);
    border-top-left-radius: 0.5rem; border-top-right-radius: 0.5rem;
    flex: 1; overflow-y: auto; overflow-x: hidden; padding: 1rem;
    -webkit-overflow-scrolling: touch; min-height: 0; /* Critical for flexbox scrolling */
    overscroll-behavior: contain; touch-action: pan-y;
  }

  /* Chat bubbles - wider on mobile */
  .chat-bubble { max-width: 90%; padding: 0.875rem 1rem; font-size: 0.9rem; }

  /* Welcome message adjustments */
  .chat-welcome { padding: 1.5rem 1rem; }
  .chat-welcome h3 { font-size: 1.1rem; }
  .chat-suggestions { grid-template-columns: 1fr; gap: 0.65rem; margin-top: 1rem; }
  .chat-suggestion { padding: 0.875rem; font-size: 0.85rem; }
  .chat-suggestion-special { padding: 1rem; font-size: 0.9rem; }

  /* Input container */
  .chat-input-container {
    padding: 0.75rem 1rem; flex-shrink: 0;
    /* Add safe area padding for iPhone notch */
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
  .chat-input-wrapper { gap: 0.5rem; }

  /* Input field */
  #chat-input { font-size: 0.9rem; padding: 0.75rem 1rem; border-radius: 1.25rem; }

  /* Send button - proper touch target */
  #chat-send-btn { padding: 0.75rem; min-width: 44px; min-height: 44px; flex-shrink: 0; }
  #chat-send-btn svg { width: 20px; height: 20px; }

  /* Assessment blocks on mobile */
  .assessment-block { padding: 1rem; }
  .assessment-option-buttons { flex-direction: column; }
  .assessment-option-btn { width: 100%; text-align: left; }

  /* === Full-screen chat (mobile) === */
  body.chat-fullscreen { overflow: hidden; height: 100dvh; }
  body.chat-fullscreen header,
  body.chat-fullscreen footer,
  body.chat-fullscreen .editorial-section { display: none !important; }
  body.chat-fullscreen main { padding: 0 !important; }
  body.chat-fullscreen .chat-app-wrapper {
    position: fixed; inset: 0;
    height: 100dvh; min-height: 100dvh; max-height: none;
    border-radius: 0; box-shadow: none; z-index: 1001;
  }
  body.chat-fullscreen .chat-main { border-radius: 0; }
  body.chat-fullscreen .chat-sidebar { top: 0; bottom: 0; }
}

/* ===== VERY SMALL SCREENS (max-width: 375px) ===== */
@media (max-width: 375px) {
  .chat-header { padding: 0.65rem 0.75rem; }
  .chat-header-title h3 { font-size: 0.9rem; }
  .chat-header-title p { font-size: 0.7rem; }
  .chat-messages { padding: 0.75rem; }
  .chat-bubble { padding: 0.75rem 0.875rem; font-size: 0.875rem; }
  #chat-input { font-size: 0.875rem; padding: 0.65rem 0.875rem; }
  #chat-send-btn { padding: 0.65rem; min-width: 40px; min-height: 40px; }
}
