/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sage:       #2563EB;
  --sage-light: #DBEAFE;
  --sage-pale:  #EFF6FF;
  --cream:      #F5F8FF;
  --warm-gray:  #64748B;
  --charcoal:   #0F172A;
  --error:      #DC2626;
  --bubble-user: #DBEAFE;
  --bubble-ai:   #ffffff;
  --border:     #E2E8F0;
  --shadow:     0 2px 8px rgba(37,99,235,0.08);
  --radius:     12px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--charcoal);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */
header {
  background: var(--sage);
  color: white;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-brand .logo {
  font-size: 1.6rem;
  line-height: 1;
}

.header-brand h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.header-brand p {
  font-size: 0.78rem;
  opacity: 0.88;
  margin-top: 1px;
}

#status-badge {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  white-space: nowrap;
}

#status-badge.ready   { background: rgba(255,255,255,0.25); }
#status-badge.loading { background: rgba(255,255,0,0.2); }
#status-badge.error   { background: rgba(255,80,80,0.3); }

/* ===== Main Layout ===== */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ===== Chat Panel ===== */
#chat-panel {
  flex: 1 1 60%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--cream);
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Welcome screen */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 30px 20px;
  gap: 16px;
  color: var(--warm-gray);
}

#welcome .welcome-icon { font-size: 3rem; }
#welcome h2 { font-size: 1.15rem; color: var(--charcoal); }
#welcome p { font-size: 0.88rem; max-width: 380px; line-height: 1.6; }

.starter-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.starter-btn {
  font-size: 0.8rem;
  padding: 7px 13px;
  border: 1.5px solid var(--sage);
  border-radius: 20px;
  background: white;
  color: var(--sage);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font);
}

.starter-btn:hover {
  background: var(--sage);
  color: white;
}

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.2s ease;
}

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

.message.user { align-self: flex-end; align-items: flex-end; }
.message.ai   { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.6;
  box-shadow: var(--shadow);
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
  color: var(--charcoal);
}

.message.ai .bubble {
  background: var(--bubble-ai);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message-meta {
  font-size: 0.68rem;
  color: var(--warm-gray);
  margin-top: 3px;
  padding: 0 4px;
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}

.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--sage);
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* Input area */
#input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: white;
}

#user-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--cream);
  color: var(--charcoal);
  min-height: 44px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}

#user-input:focus { border-color: var(--sage); }
#user-input::placeholder { color: #b0a8a0; }

#send-btn {
  width: 44px; height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--sage);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) { background: #6a8e6e; }
#send-btn:disabled { background: var(--sage-light); cursor: not-allowed; }

/* ===== Sidebar ===== */
#sidebar {
  flex: 0 0 38%;
  display: flex;
  flex-direction: column;
  background: var(--sage-pale);
  overflow: hidden;
  min-width: 300px;
  max-width: 460px;
}

/* Tab bar */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: white;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 11px 8px;
  border: none;
  background: transparent;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--warm-gray);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--sage);
  border-bottom-color: var(--sage);
  font-weight: 600;
}

.tab-btn:hover:not(.active) { background: var(--sage-pale); }

/* Tab panels */
.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel.active { display: flex; flex-direction: column; gap: 12px; }

/* Needs profile cards */
.profile-empty {
  text-align: center;
  color: var(--warm-gray);
  font-size: 0.85rem;
  margin-top: 20px;
  line-height: 1.6;
}

.profile-section {
  background: white;
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}

.profile-section h3 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sage);
  margin-bottom: 8px;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: 0.84rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--sage-pale);
  gap: 8px;
}

.profile-row:last-child { border-bottom: none; }
.profile-label { color: var(--warm-gray); flex-shrink: 0; }
.profile-value { font-weight: 500; text-align: right; }

.tag-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.tag {
  font-size: 0.74rem;
  padding: 3px 9px;
  background: var(--sage-pale);
  border-radius: 12px;
  border: 1px solid var(--sage-light);
  color: #4a6b4e;
}

/* Resources panel */
.resources-search {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#city-input {
  flex: 1;
  padding: 9px 13px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: var(--font);
  background: white;
  outline: none;
  transition: border-color 0.15s;
}

#city-input:focus { border-color: var(--sage); }

#search-btn {
  padding: 9px 16px;
  background: var(--sage);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

#search-btn:hover:not(:disabled) { background: #6a8e6e; }
#search-btn:disabled { background: var(--sage-light); cursor: not-allowed; }

#resources-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.resource-card {
  background: white;
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}

.resource-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.resource-icon { font-size: 1rem; }

.resource-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--sage);
}

.resource-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--charcoal);
  text-decoration: none;
  line-height: 1.3;
}

.resource-title:hover { color: var(--sage); text-decoration: underline; }

.resource-snippet {
  font-size: 0.8rem;
  color: var(--warm-gray);
  margin-top: 4px;
  line-height: 1.5;
}

.resource-loading {
  text-align: center;
  color: var(--warm-gray);
  font-size: 0.85rem;
  padding: 20px;
}

/* Disclaimer */
.disclaimer {
  font-size: 0.72rem;
  color: var(--warm-gray);
  background: white;
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.5;
  border-left: 3px solid var(--sage-light);
  flex-shrink: 0;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sage-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--sage); }

/* ===== Responsive ===== */
@media (max-width: 700px) {
  main { flex-direction: column; }
  #chat-panel { flex: 0 0 55%; border-right: none; border-bottom: 1px solid var(--border); }
  #sidebar { flex: 0 0 45%; min-width: unset; max-width: unset; }
}

/* ===== Protected Intake ===== */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-actions label {
  font-size: 0.72rem;
  opacity: 0.9;
}

#role-select {
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 8px;
  padding: 5px 8px;
  color: white;
  background: rgba(255,255,255,0.16);
  font-family: var(--font);
}

#role-select option { color: var(--charcoal); }

.protected-banner {
  background: #fff7e6;
  border: 1px solid #f2d39b;
  border-left: 4px solid #d99a2b;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #5f4214;
}

.intake-card {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.form-heading h2 {
  font-size: 0.95rem;
  color: var(--charcoal);
  margin-bottom: 3px;
}

.form-heading p {
  font-size: 0.76rem;
  color: var(--warm-gray);
  line-height: 1.5;
}

.intake-card label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--charcoal);
}

.intake-card input,
.intake-card select,
.intake-card textarea {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 0.84rem;
  background: var(--cream);
}

.intake-card textarea {
  min-height: 58px;
  resize: vertical;
  line-height: 1.45;
}

.intake-card textarea.large-text { min-height: 110px; }

.skip-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--warm-gray);
  font-size: 0.74rem;
  font-weight: 500;
}

.skip-row input { width: auto; }

.file-label { font-weight: 600 !important; }

.primary-action {
  border: none;
  border-radius: 9px;
  background: var(--sage);
  color: white;
  padding: 10px 14px;
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
}

.primary-action:hover { background: #6a8e6e; }

.intake-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.intake-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--cream);
  padding: 10px;
  cursor: pointer;
  font-family: var(--font);
}

.intake-row.active,
.intake-row:hover {
  border-color: var(--sage);
  background: var(--sage-pale);
}

.intake-row span,
.intake-row small,
.intake-row em {
  display: block;
}

.intake-row small {
  margin-top: 2px;
  color: var(--warm-gray);
  font-size: 0.72rem;
}

.intake-row em {
  color: var(--sage);
  font-size: 0.74rem;
  font-style: normal;
  font-weight: 700;
  text-align: right;
}

.intake-detail { margin-top: 4px; }

.raw-detail,
.restricted-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--cream);
  padding: 12px;
}

.raw-detail h3,
.restricted-card h3 {
  color: var(--sage);
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.privacy-note,
.restricted-card p {
  color: var(--warm-gray);
  font-size: 0.78rem;
  line-height: 1.5;
  margin-bottom: 10px;
}

.raw-row {
  border-top: 1px solid var(--border);
  padding: 8px 0;
}

.raw-row strong {
  display: block;
  color: var(--charcoal);
  font-size: 0.76rem;
  margin-bottom: 3px;
}

.raw-row p {
  white-space: pre-wrap;
  color: #4b4742;
  font-size: 0.82rem;
  line-height: 1.45;
}
