/* ==============================================
   SDF Legal Resource Assistant — Meridian Design
   Fonts: Inter / Instrument Serif
   Palette: #4A7FAF blue · #111318 ink · #FAF9F7 warm
   ============================================== */

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

:root {
  --blue:       #4A7FAF;
  --blue-dark:  #2C5F8A;
  --blue-light: #EBF3FB;
  --blue-mid:   #C8DDEF;
  --ink:        #111318;
  --ink-80:     #2A2F3A;
  --ink-50:     #717990;
  --ink-20:     #D4D8E0;
  --ink-08:     #F2F4F7;
  --white:      #FFFFFF;
  --warm:       #FAF9F7;
  --gold:       #C8A048;
  --nav-h:      68px;
  --font:       'Inter', sans-serif;
  --font-serif: 'Instrument Serif', serif;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
  /* Use dynamic viewport height so mobile browser chrome is accounted for */
  height: 100dvh;
}

body {
  font-family: var(--font);
  background: var(--warm);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  height: 100dvh; /* dynamic viewport: accounts for mobile browser bars */
  display: flex;
  flex-direction: column;
  overflow: clip; /* stops body scroll but lets .messages scroll */
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-dark); }

/* ─── Nav ─── */
nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: var(--nav-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--ink-20);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 5vw, 72px);
  transition: box-shadow .3s;
}

.nav-logo {
  text-decoration: none;
  display: flex;
  align-items: center;
}

.nav-logo img {
  height: 24px;
  width: auto;
  filter: brightness(0) saturate(100%) invert(15%) sepia(10%) saturate(500%) hue-rotate(180deg);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-50);
}

.nav-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-20);
  flex-shrink: 0;
  transition: background 0.3s;
}

.nav-status-dot--loading {
  background: var(--blue);
  animation: pulse 1.4s ease-in-out infinite;
}

.nav-status-dot--ready { background: #22c55e; }
.nav-status-dot--error { background: #ef4444; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.85); }
  50%      { opacity: 1;   transform: scale(1.15); }
}

.nav-cta {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--white);
  background: var(--blue);
  padding: 10px 22px;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .2s, transform .15s;
}

.nav-cta:hover {
  background: var(--blue-dark);
  color: var(--white);
  transform: translateY(-1px);
}

/* ─── Chat page layout ─── */
.chat-page {
  margin-top: var(--nav-h);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* ─── Welcome state ─── */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(32px, 6vw, 80px) 24px;
  overflow-y: auto;
}

.welcome-inner {
  max-width: 640px;
  width: 100%;
  text-align: center;
}

.welcome-tag {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 24px;
}

.welcome-tag::before {
  content: '';
  width: 20px;
  height: 2px;
  background: var(--blue);
}

.welcome-tag::after {
  content: '';
  width: 20px;
  height: 2px;
  background: var(--blue);
}

.welcome-heading {
  font-family: var(--font-serif);
  font-size: clamp(36px, 5.5vw, 64px);
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
  margin-bottom: 20px;
}

.welcome-heading em {
  font-style: italic;
  color: var(--blue);
}

.welcome-sub {
  font-size: 16px;
  font-weight: 300;
  line-height: 1.75;
  color: var(--ink-50);
  max-width: 520px;
  margin: 0 auto 40px;
}

.welcome-disclaimer {
  font-size: 12px;
  color: var(--ink-50);
  line-height: 1.5;
  margin-top: 32px;
  opacity: 0.7;
}

.welcome-disclaimer a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ─── Welcome hidden ─── */
.welcome--hidden {
  display: none;
}

/* ─── Suggestions ─── */
.suggestions {
  max-width: 520px;
  margin: 0 auto;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.suggestion-btn {
  background: var(--white);
  border: 1.5px solid var(--ink-20);
  border-radius: 10px;
  padding: 16px 18px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-80);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.suggestion-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.suggestion-btn:not(:disabled):hover {
  border-color: var(--blue);
  background: var(--blue-light);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(74, 127, 175, 0.12);
}

.suggestion-btn svg {
  color: var(--blue);
  flex-shrink: 0;
  margin-top: 2px;
}

/* ─── Messages ─── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 24px;
  display: none;
  flex-direction: column;
  gap: 28px;
  scroll-behavior: smooth;
}

.messages--active {
  display: flex;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--ink-20); border-radius: 2px; }

.message-row {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  animation: msg-in 0.3s ease both;
}

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

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

/* Avatar */
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message-avatar--bot {
  background: var(--blue);
  color: var(--white);
}

.message-avatar--user {
  background: var(--ink);
  color: var(--white);
}

/* Bubble */
.message-bubble {
  max-width: 640px;
  font-size: 15px;
  line-height: 1.75;
}

.message-bubble--user {
  background: var(--ink);
  color: var(--white);
  padding: 14px 20px;
  border-radius: 16px 4px 16px 16px;
  font-size: 15px;
  line-height: 1.6;
}

.message-bubble--bot {
  background: var(--white);
  border: 1px solid var(--ink-20);
  color: var(--ink);
  padding: 20px 24px;
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

/* Bot bubble content */
.message-bubble--bot p {
  margin: 0 0 12px;
}

.message-bubble--bot p:last-child { margin-bottom: 0; }

.message-bubble--bot a {
  color: var(--blue);
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid rgba(74, 127, 175, 0.3);
  transition: all 0.15s;
  padding-bottom: 1px;
}

.message-bubble--bot a:hover {
  color: var(--blue-dark);
  border-bottom-color: var(--blue-dark);
}

/* Related articles heading */
.bot-articles-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--blue);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 12px;
}

.bot-articles-heading::before {
  content: '';
  width: 16px;
  height: 2px;
  background: var(--blue);
}

.bot-article-item {
  display: flex;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 8px;
  line-height: 1.55;
  font-weight: 400;
}

.bot-article-item::before {
  content: '→';
  color: var(--blue);
  flex-shrink: 0;
  font-weight: 500;
}

.bot-disclaimer {
  font-size: 13px;
  color: var(--ink-50);
  font-style: italic;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--ink-20);
  font-weight: 300;
}

/* ─── Loading indicator ─── */
.loading-row {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  animation: msg-in 0.3s ease both;
}

.loading-bubble {
  background: var(--white);
  border: 1px solid var(--ink-20);
  border-radius: 4px 16px 16px 16px;
  padding: 20px 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.loading-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 20px;
}

.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  animation: pulse 1.4s ease-in-out infinite;
}

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

.loading-label {
  font-size: 12px;
  color: var(--blue);
  font-weight: 500;
  margin-top: 6px;
  letter-spacing: .02em;
}

/* ─── Error ─── */
.error-msg {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 14px;
  color: #b91c1c;
  text-align: center;
  animation: msg-in 0.3s ease both;
}

/* ─── Input area ─── */
.input-area {
  flex-shrink: 0;
  padding: 0 24px 24px;
  background: linear-gradient(to bottom, transparent 0%, var(--warm) 20%);
  position: relative;
  /* Ensure it's always visually above message stream */
  z-index: 10;
}

.input-container {
  max-width: 760px;
  margin: 0 auto;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--white);
  border: 1.5px solid var(--ink-20);
  border-radius: 14px;
  padding: 6px 6px 6px 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-row:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(74, 127, 175, 0.08);
}

.input-field {
  flex: 1;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.5;
  padding: 10px 0;
}

.input-field::placeholder { color: var(--ink-50); font-weight: 300; }
.input-field:disabled { opacity: 0.5; cursor: not-allowed; }

.send-btn {
  width: 44px;
  height: 44px;
  background: var(--ink);
  border: none;
  border-radius: 10px;
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  font-size: 11px;
  color: var(--ink-50);
  text-align: center;
  margin-top: 8px;
  opacity: 0.6;
  font-weight: 300;
}

/* ─── Footer ─── */
footer {
  background: #0C0E13;
  flex-shrink: 0;
  padding: 16px clamp(20px, 5vw, 72px);
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

footer p {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1.5;
}

.footer-links {
  display: flex;
  gap: 20px;
}

.footer-links a {
  font-size: 12px;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.4);
  text-decoration: none;
  transition: color .2s;
}

.footer-links a:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  :root { --nav-h: 56px; }

  .nav-logo img { height: 20px; }
  .nav-cta { display: none; }
  .nav-status { font-size: 11px; }

  /* Top-align welcome so heading is never clipped above the scroll origin */
  .welcome {
    align-items: flex-start;
    justify-content: flex-start;
    padding: 36px 20px 24px;
  }

  .welcome-inner {
    text-align: left;
  }

  .welcome-tag {
    justify-content: flex-start;
  }

  .welcome-sub,
  .suggestions,
  .welcome-disclaimer {
    margin-left: 0;
    max-width: 100%;
  }

  .welcome-heading {
    font-size: clamp(32px, 8vw, 48px);
  }

  .welcome-sub { font-size: 15px; }

  .suggestions-grid {
    grid-template-columns: 1fr;
  }

  .messages {
    padding: 20px 16px;
    gap: 20px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 9px;
  }

  .message-bubble { max-width: 100%; font-size: 14px; }

  .message-bubble--bot {
    padding: 16px 18px;
  }

  .message-bubble--user {
    padding: 12px 16px;
  }

  .input-area {
    padding: 10px 12px calc(16px + env(safe-area-inset-bottom, 0px));
    /* Solid background so it never looks like a message bubble */
    background: var(--warm);
    border-top: 1px solid var(--ink-20);
  }

  .input-row {
    border-radius: 12px;
    padding: 4px 4px 4px 16px;
  }

  .input-hint { display: none; }

  footer { padding: 12px 16px; }

  .footer-inner {
    flex-direction: column;
    text-align: center;
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .message-row--user .message-avatar,
  .message-row:not(.message-row--user) .message-avatar {
    display: none;
  }

  .message-row { gap: 0; }

  .message-bubble--user { border-radius: 14px 4px 14px 14px; }
  .message-bubble--bot  { border-radius: 4px 14px 14px 14px; }
}
