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

:root {
  --bg: #efede8;
  --bg-hover: #e4e1da;
  --foreground: #1A1A18;
  --muted: #6B6A68;
  --accent: #e6453e;
  --accent-hover: #f05a53;
  --user-bubble: #e0ddd6;
  --composer-bg: #FFFFFF;
  --sidebar-bg: #e4e1da;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 0.25rem 1.25rem rgba(0, 0, 0, 0.035);
  --content-max: 48rem;
  --radius: 1rem;
  --transition: 300ms cubic-bezier(0.165, 0.85, 0.45, 1);

  --font-sans: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: 'Jost', ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  background: var(--bg);
  color: var(--foreground);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Layout
   ============================================ */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================================
   Sidebar (left, Claude-style)
   ============================================ */

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), opacity var(--transition);
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 160px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--foreground);
  white-space: nowrap;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.sidebar-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-icon-btn:hover {
  background: var(--border);
  color: var(--foreground);
}

.sidebar-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 16px 16px 8px;
}

.lender-search-wrapper {
  position: relative;
  padding: 0 10px 8px;
}

.lender-search-icon {
  position: absolute;
  left: 20px;
  top: 8px;
  color: var(--muted);
  pointer-events: none;
}

.lender-search {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--foreground);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.lender-search::placeholder {
  color: var(--muted);
}

.lender-search:focus {
  border-color: rgba(0, 0, 0, 0.2);
  background: var(--composer-bg);
}

.lender-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}

.lender-item {
  padding: 7px 10px;
  font-size: 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lender-item:hover {
  background: var(--bg);
}

.lender-no-results {
  padding: 10px 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ============================================
   Main chat area
   ============================================ */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Top bar with toggle + title */
.chat-topbar {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  display: none;
  align-items: center;
  justify-content: center;
}

.topbar-toggle:hover {
  background: var(--border);
  color: var(--foreground);
}

.topbar-new-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.topbar-new-btn:hover {
  background: var(--bg-hover);
  color: var(--foreground);
  border-color: rgba(0, 0, 0, 0.15);
}

.topbar-logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-logout-btn:hover {
  background: var(--border);
  color: var(--foreground);
}

.sidebar.collapsed ~ .chat-main .topbar-toggle {
  display: flex;
}

.topbar-title {
  font-size: 0.92rem;
  color: var(--muted);
}

/* ============================================
   Messages area
   ============================================ */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 32px;
  scroll-behavior: smooth;
}

.messages-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Single message block */
.message {
  padding: 14px 0;
}

.message + .message {
  border-top: 1px solid var(--border);
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.message.user .msg-avatar {
  background: var(--user-bubble);
  color: var(--foreground);
}

.message.assistant .msg-avatar {
  background: var(--accent);
  color: white;
}

.msg-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--foreground);
}

/* Message content */
.msg-content {
  line-height: 1.5;
  font-size: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* User messages: sans-serif, shown in a bubble */
.message.user .msg-content {
  background: var(--user-bubble);
  padding: 12px 16px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  display: inline-block;
  max-width: 85%;
  font-family: var(--font-sans);
}

/* Assistant messages: serif, no bubble, full width */
.message.assistant .msg-content {
  font-family: var(--font-serif);
  color: var(--foreground);
}

/* Markdown elements inside assistant messages */
.msg-content ul,
.msg-content ol {
  margin: 2px 0 4px 20px;
  padding: 0;
  list-style-position: outside;
}

.msg-content li {
  margin: 0;
  padding: 0;
  line-height: 1.4;
}

.msg-content strong {
  font-weight: 600;
}

.msg-content p {
  margin: 0 0 4px;
}

.msg-content p:last-child {
  margin-bottom: 0;
}

/* Tighten spacing between adjacent block elements */
.msg-content p + ul,
.msg-content p + ol {
  margin-top: 0;
}

.msg-content ul + p,
.msg-content ol + p {
  margin-top: 4px;
}

.msg-content h1,
.msg-content h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 12px 0 3px;
  font-family: var(--font-sans);
}

.msg-content h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 10px 0 3px;
  font-family: var(--font-sans);
}

.msg-content h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 8px 0 2px;
  font-family: var(--font-sans);
}

/* Sources */
.sources {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--font-sans);
}

.sources summary {
  cursor: pointer;
  font-weight: 500;
  padding: 6px 0;
  user-select: none;
}

.sources summary:hover {
  color: var(--foreground);
}

.sources ul {
  margin: 6px 0 0 18px;
  list-style: disc;
}

.sources li {
  margin-bottom: 3px;
  line-height: 1.4;
}

/* ============================================
   Typing indicator
   ============================================ */

.typing-indicator {
  padding: 14px 0;
  max-width: var(--content-max);
  margin: 0 auto;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 10px;
}

.typing-dots .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.dots {
  display: flex;
  gap: 4px;
}

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: dotPulse 1.4s ease-in-out infinite;
}

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

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

/* ============================================
   Streaming cursor
   ============================================ */

.streaming-cursor {
  display: inline;
  color: var(--accent);
  animation: cursorBlink 0.8s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ============================================
   Composer (input area)
   ============================================ */

.composer-wrapper {
  padding: 0 16px 20px;
}

.composer {
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--composer-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 0 1px var(--border);
  display: flex;
  align-items: flex-end;
  padding: 4px 4px 4px 16px;
  transition: box-shadow 0.2s;
}

.composer:focus-within {
  box-shadow: var(--shadow), 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--foreground);
  resize: none;
  padding: 10px 0;
  line-height: 1.5;
  max-height: 150px;
  min-height: 24px;
}

.composer textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
  margin-bottom: 2px;
}

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

.send-btn:active {
  transform: scale(0.96);
}

.send-btn:disabled {
  background: #b5b1a9;
  cursor: not-allowed;
}

.send-btn:disabled:active {
  transform: none;
}

.send-btn svg {
  width: 18px;
  height: 18px;
  fill: white;
}

/* ============================================
   Welcome screen
   ============================================ */

.welcome {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 60px 0 40px;
  text-align: center;
}

.welcome-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  overflow: hidden;
}

.welcome h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--foreground);
  margin-bottom: 8px;
}

.welcome p {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 28px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion {
  padding: 8px 16px;
  background: var(--composer-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--font-sans);
}

.suggestion:hover {
  background: var(--bg-hover);
  border-color: rgba(0, 0, 0, 0.15);
}

/* ============================================
   Auth / PIN overlay
   ============================================ */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.auth-logo {
  width: 180px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  overflow: hidden;
}

.auth-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--foreground);
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 32px;
}

.pin-input-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
}

.pin-digit {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--composer-bg);
  color: var(--foreground);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -moz-appearance: textfield;
}

.pin-digit::-webkit-outer-spin-button,
.pin-digit::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pin-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(230, 69, 62, 0.15);
}

.pin-digit.error {
  border-color: #c0392b;
  animation: pinShake 0.4s ease;
}

.auth-error {
  font-size: 0.82rem;
  color: #c0392b;
  min-height: 1.2em;
  margin-bottom: 16px;
}

.auth-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.auth-submit:hover {
  background: var(--accent-hover);
}

.auth-submit:disabled {
  background: #b5b1a9;
  cursor: not-allowed;
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ============================================
   Sidebar backdrop (mobile overlay)
   ============================================ */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition);
}

.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ============================================
   Responsive — Tablet (≤1024px)
   ============================================ */

@media (max-width: 1024px) {
  .sidebar {
    width: 240px;
  }

  .welcome {
    padding: 40px 16px 32px;
  }

  .welcome h2 {
    font-size: 1.35rem;
  }
}

/* ============================================
   Responsive — Mobile (≤768px)
   ============================================ */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    width: 280px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
    transition: transform var(--transition);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 280px;
  }

  .topbar-toggle {
    display: flex !important;
  }

  .messages {
    padding: 0 12px 24px;
  }

  .message {
    padding: 12px 0;
  }

  .message.user .msg-content {
    max-width: 95%;
  }

  .msg-content {
    font-size: 0.9rem;
  }

  .composer-wrapper {
    padding: 0 12px 16px;
  }

  .composer {
    padding: 4px 4px 4px 12px;
  }

  .composer textarea {
    font-size: 1rem; /* prevent iOS zoom on focus */
  }

  .welcome {
    padding: 32px 16px 24px;
  }

  .welcome h2 {
    font-size: 1.25rem;
  }

  .welcome p {
    font-size: 0.85rem;
    margin-bottom: 20px;
  }

  .suggestions {
    gap: 6px;
  }

  .suggestion {
    font-size: 0.8rem;
    padding: 7px 14px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .topbar-new-btn {
    padding: 6px 10px;
    font-size: 0.78rem;
  }
}

/* ============================================
   Responsive — Small phones (≤480px)
   ============================================ */

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

  .sidebar.collapsed {
    width: 100%;
  }

  .chat-topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .topbar-title {
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .messages {
    padding: 0 8px 20px;
  }

  .message.user .msg-content {
    max-width: 100%;
    padding: 10px 14px;
  }

  .msg-content {
    font-size: 0.88rem;
  }

  .msg-content h1,
  .msg-content h2 {
    font-size: 1rem;
  }

  .msg-content h3 {
    font-size: 0.95rem;
  }

  .composer-wrapper {
    padding: 0 8px 12px;
  }

  .composer textarea {
    font-size: 1rem;
  }

  .welcome {
    padding: 24px 12px 20px;
  }

  .welcome-icon {
    width: 40px;
    height: 40px;
    font-size: 18px;
    margin-bottom: 12px;
  }

  .welcome h2 {
    font-size: 1.1rem;
  }

  .welcome p {
    font-size: 0.82rem;
    margin-bottom: 16px;
  }

  .suggestions {
    flex-direction: column;
    align-items: stretch;
  }

  .suggestion {
    border-radius: 12px;
    text-align: left;
  }

  .sources {
    font-size: 0.75rem;
  }

  .pin-digit {
    width: 42px;
    height: 50px;
    font-size: 1.2rem;
  }

  .pin-input-group {
    gap: 6px;
  }

  .auth-title {
    font-size: 1.25rem;
  }
}
