/* ═══════════════════════════════════════════════════════════════
   FundFlow — UI Styles
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables / Theming ─────────────────────────────────── */
:root {
  --bg-primary:    #0f1117;
  --bg-secondary:  #1a1d27;
  --bg-card:       #1e2130;
  --bg-hover:      #252840;
  --bg-input:      #151821;

  --accent-blue:   #3d7fff;
  --accent-blue-h: #5a96ff;
  --accent-green:  #22c55e;
  --accent-yellow: #f59e0b;
  --accent-red:    #ef4444;

  --text-primary:  #e8eaf0;
  --text-secondary:#8b90a8;
  --text-muted:    #555b72;

  --border:        #272b3e;
  --border-subtle: #1e2235;

  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;

  --font-sans:     'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', monospace;

  --sidebar-width: 320px;
  --header-height: 58px;
  --transition:    0.18s ease;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Layout ───────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-brand .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-blue), #6d5aff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.header-brand h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.header-brand .tagline {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.loan-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
}

.loan-selector-wrap label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

#loanSelect {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  min-width: 200px;
}

#loanSelect option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

/* Main Content Area */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Sidebar — Loan Details ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Loan Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}
.status-badge.green  { background: rgba(34,197,94,0.15);  color: #22c55e; }
.status-badge.yellow { background: rgba(245,158,11,0.15); color: #f59e0b; }
.status-badge.blue   { background: rgba(61,127,255,0.15); color: #3d7fff; }
.status-badge.red    { background: rgba(239,68,68,0.15);  color: #ef4444; }

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Borrower Header Card */
.borrower-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}

.borrower-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.loan-id-tag {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 8px;
}

.borrower-meta {
  font-size: 11.5px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Data Sections */
.data-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
}

.data-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
}

.data-row:last-child { border-bottom: none; }

.data-label {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 8px;
}

.data-value {
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
}

.data-value.flag-red    { color: var(--accent-red); }
.data-value.flag-yellow { color: var(--accent-yellow); }
.data-value.flag-green  { color: var(--accent-green); }

/* Missing Docs List */
.doc-list {
  list-style: none;
  padding: 6px 12px 8px;
}

.doc-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
}
.doc-item:last-child { border-bottom: none; }

.doc-item .doc-icon { font-size: 11px; flex-shrink: 0; margin-top: 1px; }
.doc-item.missing .doc-icon { color: var(--accent-yellow); }
.doc-item.ok .doc-icon { color: var(--accent-green); }

.no-items {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--accent-green);
  font-weight: 600;
}

/* ── Right Panel — Chat ───────────────────────────────────────── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* Quick Actions Bar */
.quick-actions-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.qa-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 4px;
  white-space: nowrap;
}

.quick-action-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.quick-action-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-blue);
  color: var(--accent-blue-h);
  transform: translateY(-1px);
}

.quick-action-btn.active {
  background: rgba(61,127,255,0.12);
  border-color: var(--accent-blue);
  color: var(--accent-blue-h);
}

.quick-action-btn .btn-icon-emoji { font-size: 14px; }

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

/* Welcome State */
.welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 40px 24px;
  gap: 12px;
}

.welcome-state .welcome-icon {
  font-size: 48px;
  margin-bottom: 4px;
}

.welcome-state h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.welcome-state p {
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 380px;
  line-height: 1.7;
}

.welcome-hints {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  text-align: left;
  width: 100%;
  max-width: 420px;
}

.hint-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.hint-chip:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue-h);
  background: var(--bg-hover);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.2s ease;
}

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

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

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #3d7fff, #6d5aff);
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, #0f766e, #0891b2);
}

.message-body {
  max-width: 72%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.user .message-body {
  align-items: flex-end;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--accent-blue);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 3px;
}

/* Markdown inside bubbles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  font-size: 13.5px;
  font-weight: 700;
  margin: 10px 0 4px;
  color: var(--text-primary);
}

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child { margin-top: 0; }

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

.message-bubble ul, .message-bubble ol {
  padding-left: 18px;
  margin: 4px 0 6px;
}

.message-bubble li { margin-bottom: 3px; }

.message-bubble strong { color: var(--text-primary); font-weight: 700; }

.message-bubble code {
  background: var(--bg-input);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #a5d6ff;
}

.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.message-meta {
  font-size: 10.5px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  animation: fadeIn 0.2s ease;
}

.typing-dots {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s ease 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.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.typing-label {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Draft Panel (Human-in-the-Loop) ─────────────────────────── */
.draft-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 8px;
  overflow: hidden;
  animation: fadeIn 0.25s ease;
}

.draft-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.draft-panel-header .draft-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent-yellow);
  display: flex;
  align-items: center;
  gap: 6px;
}

.draft-actions {
  display: flex;
  gap: 6px;
}

.btn-approve {
  background: rgba(34,197,94,0.15);
  border: 1px solid rgba(34,197,94,0.4);
  border-radius: var(--radius-sm);
  color: var(--accent-green);
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.btn-approve:hover {
  background: rgba(34,197,94,0.25);
  border-color: var(--accent-green);
}

.btn-edit-draft {
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.35);
  border-radius: var(--radius-sm);
  color: var(--accent-yellow);
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.btn-edit-draft:hover {
  background: rgba(245,158,11,0.22);
  border-color: var(--accent-yellow);
}

.btn-discard {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.btn-discard:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.draft-textarea {
  width: 100%;
  background: var(--bg-input);
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  padding: 14px 16px;
  resize: vertical;
  min-height: 160px;
  outline: none;
}

.draft-approved-badge {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--accent-green);
  font-weight: 600;
  border-top: 1px solid var(--border-subtle);
  background: rgba(34,197,94,0.06);
}

/* ── Chat Input Area ──────────────────────────────────────────── */
.chat-input-area {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.chat-input-box {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  transition: border-color var(--transition);
}

.chat-input-box:focus-within {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(61,127,255,0.12);
}

#chatInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: var(--font-sans);
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 1.5;
  scrollbar-width: thin;
}

#chatInput::placeholder { color: var(--text-muted); }

.send-btn {
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  font-size: 15px;
}

.send-btn:hover { background: var(--accent-blue-h); transform: scale(1.05); }
.send-btn:disabled { background: var(--text-muted); cursor: not-allowed; transform: none; }

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.model-tag {
  font-size: 10.5px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: var(--font-mono);
}

/* ── Toast Notifications ──────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.success { border-color: var(--accent-green); }
.toast.error   { border-color: var(--accent-red);   }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Scrollbar Global ─────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { display: none; }
  .chat-messages { padding: 12px; }
  .chat-input-area { padding: 10px 12px 14px; }
}
