@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500&display=swap');

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

:root {
  --navy: #0d1b2a;
  --navy-mid: #1a2e45;
  --navy-light: #243d56;
  --gold: #c9a84c;
  --gold-light: #e4c97a;
  --gold-dim: rgba(201,168,76,0.15);
  --cream: #f7f3ec;
  --cream-mid: #ede8df;
  --cream-dark: #ddd6c9;
  --text-main: #0d1b2a;
  --text-muted: #5a6e80;
  --text-light: #8a9eb0;
  --white: #ffffff;
  --online-color: #1d6e4e;
  --online-bg: #e8f5ef;
  --offline-color: #a05c00;
  --offline-bg: #fef3e2;
  --danger: #8b1c1c;
  --danger-bg: #fbeaea;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --shadow: 0 2px 16px rgba(13,27,42,0.08);
  --shadow-md: 0 4px 24px rgba(13,27,42,0.12);
}

html { font-size: 15px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--text-main);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.55;
}

/* ── HEADER ─────────────────────────────────────────── */
.app-header {
  background: var(--navy);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 10px; }

.logo-mark {
  width: 38px; height: 38px;
  background: var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-mark svg { width: 18px; height: 18px; }

.header-title h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  color: var(--white);
  line-height: 1.1;
}
.header-title p {
  font-size: 0.7rem;
  color: var(--gold-light);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── STATUS BADGE ───────────────────────────────────── */
.status-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.status-badge .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-badge.online {
  background: var(--online-bg);
  color: var(--online-color);
}
.status-badge.online .dot { background: var(--online-color); animation: pulse 2s infinite; }
.status-badge.offline {
  background: var(--offline-bg);
  color: var(--offline-color);
}
.status-badge.offline .dot { background: var(--offline-color); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ── MODE BANNER ────────────────────────────────────── */
.mode-banner {
  padding: 0.65rem 1.25rem;
  font-size: 13px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid transparent;
  transition: all 0.4s ease;
}
.mode-banner.online-mode {
  background: #e8f5ef;
  color: var(--online-color);
  border-color: #c3e6d8;
}
.mode-banner.offline-mode {
  background: var(--offline-bg);
  color: var(--offline-color);
  border-color: #f5deb3;
}
.mode-banner svg { flex-shrink: 0; }

/* ── TABS ───────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: var(--white);
  border-bottom: 1px solid var(--cream-mid);
}
.tab-btn {
  flex: 1;
  padding: 0.85rem 0.5rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab-btn:hover { color: var(--text-main); background: var(--cream); }
.tab-btn.active {
  color: var(--navy);
  border-bottom-color: var(--gold);
  background: var(--cream);
}
.tab-badge {
  font-size: 10px;
  background: var(--gold);
  color: var(--navy);
  border-radius: 99px;
  padding: 1px 6px;
  font-weight: 500;
}

/* ── MAIN CONTENT ───────────────────────────────────── */
.tab-panel { display: none; flex: 1; overflow-y: auto; min-height: 0; }
.tab-panel.active { display: flex; flex-direction: column; flex: 1; }
/* ensure body/layout fills height so tabs are scrollable */
.layout, #tab-form, #tab-results, #tab-ai, #tab-clients { min-height: 0; }

/* ── FORM SECTIONS ──────────────────────────────────── */
.form-wrap { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }

.form-section {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--cream-mid);
  overflow: hidden;
}
.section-header {
  padding: 0.75rem 1rem;
  background: var(--navy);
  display: flex; align-items: center; gap: 8px;
}
.section-header h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 0.95rem;
  color: var(--white);
}
.section-header svg { color: var(--gold); flex-shrink: 0; }

.field-grid { padding: 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid.single { grid-template-columns: 1fr; }
.field-grid.triple { grid-template-columns: 1fr 1fr 1fr; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field.span2 { grid-column: span 2; }
.field label { font-size: 11.5px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.02em; }

.field input, .field select {
  border: 1.5px solid var(--cream-mid);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  color: var(--text-main);
  background: var(--cream);
  transition: border-color 0.15s, background 0.15s;
  outline: none;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus {
  border-color: var(--gold);
  background: var(--white);
}
.field input.error { border-color: #c0392b; }

.input-prefix-wrap { position: relative; }
.input-prefix-wrap .prefix {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 14px; color: var(--text-muted); pointer-events: none;
}
.input-prefix-wrap input { padding-left: 22px; }

/* ── CTA BUTTON ─────────────────────────────────────── */
.cta-wrap { padding: 0 1.25rem 1.25rem; }

.cta-btn {
  width: 100%;
  padding: 1rem;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-family: 'DM Serif Display', serif;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
}
.cta-btn:hover { background: var(--navy-mid); }
.cta-btn:active { transform: scale(0.99); }
.cta-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.cta-btn.gold-btn {
  background: var(--gold);
  color: var(--navy);
}
.cta-btn.gold-btn:hover { background: var(--gold-light); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.gold-btn .spinner { border-color: rgba(13,27,42,0.2); border-top-color: var(--navy); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESULTS PANEL ──────────────────────────────────── */
.results-wrap { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }

.results-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 3rem 1.5rem; gap: 1rem; opacity: 0.65;
}
.results-empty .empty-icon {
  width: 60px; height: 60px;
  background: var(--cream-mid);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.results-empty h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.2rem;
}
.results-empty p { font-size: 13px; color: var(--text-muted); max-width: 260px; line-height: 1.6; }

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric-card {
  background: var(--white);
  border: 1px solid var(--cream-mid);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.metric-card.accent { border-left: 3px solid var(--gold); }
.metric-label { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; font-weight: 500; letter-spacing: 0.02em; text-transform: uppercase; }
.metric-value { font-size: 1.4rem; font-weight: 500; color: var(--text-main); font-family: 'DM Serif Display', serif; }
.metric-value.gold { color: var(--gold); }
.metric-sub { font-size: 11px; color: var(--text-light); margin-top: 2px; }

.breakdown-table {
  background: var(--white);
  border: 1px solid var(--cream-mid);
  border-radius: var(--radius);
  overflow: hidden;
}
.breakdown-table-header {
  padding: 0.65rem 1rem;
  background: var(--cream);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--cream-mid);
}
.breakdown-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--cream);
  font-size: 14px;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row.total {
  background: var(--navy);
  color: var(--white);
  font-weight: 500;
}
.breakdown-row .row-label { color: inherit; }
.breakdown-row .row-val { font-weight: 500; }

.dti-bars { display: flex; flex-direction: column; gap: 10px; }
.dti-bar-wrap {
  background: var(--white);
  border: 1px solid var(--cream-mid);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.dti-bar-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 7px; }
.dti-bar-label .dti-name { color: var(--text-muted); font-weight: 500; }
.dti-bar-label .dti-pct { font-weight: 500; }
.dti-bar-label .dti-pct.ok { color: var(--online-color); }
.dti-bar-label .dti-pct.warn { color: var(--offline-color); }
.dti-bar-label .dti-pct.bad { color: var(--danger); }
.dti-track {
  height: 8px;
  background: var(--cream-mid);
  border-radius: 99px;
  overflow: hidden;
}
.dti-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.6s ease;
}
.dti-fill.ok { background: var(--online-color); }
.dti-fill.warn { background: var(--offline-color); }
.dti-fill.bad { background: var(--danger); }
.dti-limit { font-size: 11px; color: var(--text-light); margin-top: 4px; }

/* ── AI CHAT TAB ────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

.offline-ai-notice {
  margin: 1rem 1.25rem;
  padding: 1rem;
  background: var(--offline-bg);
  border: 1px solid #f5deb3;
  border-radius: var(--radius);
  display: flex; gap: 10px; align-items: flex-start;
}
.offline-ai-notice svg { flex-shrink: 0; color: var(--offline-color); margin-top: 1px; }
.offline-ai-notice p { font-size: 13px; color: var(--offline-color); line-height: 1.6; }
.offline-ai-notice strong { display: block; margin-bottom: 3px; }

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 2rem 1.5rem; gap: 0.85rem; opacity: 0.65;
}
.chat-empty h3 { font-family: 'DM Serif Display', serif; font-size: 1.15rem; }
.chat-empty p { font-size: 13px; color: var(--text-muted); max-width: 240px; line-height: 1.6; }

.quick-prompts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 0.5rem; }
.quick-btn {
  font-size: 12px;
  padding: 5px 12px;
  border: 1px solid var(--cream-dark);
  border-radius: 99px;
  background: var(--white);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
}
.quick-btn:hover { border-color: var(--gold); color: var(--navy); background: var(--gold-dim); }

.msg { display: flex; gap: 8px; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500;
  flex-shrink: 0; margin-top: 2px;
}
.msg.user .msg-avatar { background: var(--navy); color: var(--white); }
.msg.assistant .msg-avatar { background: var(--gold); color: var(--navy); }
.msg-bubble {
  max-width: calc(100% - 40px);
  background: var(--white);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-main);
  border: 1px solid var(--cream-mid);
}
.msg.user .msg-bubble {
  background: var(--navy);
  color: var(--white);
  border-color: transparent;
  border-bottom-right-radius: 3px;
}
.msg.assistant .msg-bubble { border-bottom-left-radius: 3px; }
.msg-bubble strong { font-weight: 500; }
.msg-bubble ul { padding-left: 1.2rem; margin: 0.3rem 0; }
.msg-bubble li { margin-bottom: 2px; }
.msg-bubble p { margin-bottom: 0.4rem; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 0.95rem;
  margin: 0.6rem 0 0.25rem;
  color: var(--navy);
}
.msg-bubble .verdict {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; border-radius: 99px;
  font-size: 13px; font-weight: 500; margin: 0.35rem 0;
}
.verdict.qualify { background: #e8f5ef; color: var(--online-color); }
.verdict.borderline { background: var(--offline-bg); color: var(--offline-color); }
.verdict.disqualify { background: var(--danger-bg); color: var(--danger); }

.typing-bubble { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.dot-bounce {
  width: 6px; height: 6px;
  background: var(--gold);
  border-radius: 50%;
  animation: bounce 1.1s infinite;
}
.dot-bounce:nth-child(2) { animation-delay: 0.18s; }
.dot-bounce:nth-child(3) { animation-delay: 0.36s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

.chat-input-bar {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--cream-mid);
  background: var(--white);
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-textarea {
  flex: 1;
  border: 1.5px solid var(--cream-mid);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  line-height: 1.5;
  background: var(--cream);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s;
}
.chat-textarea:focus { border-color: var(--gold); background: var(--white); }
.chat-textarea:disabled { opacity: 0.5; }

.send-btn {
  width: 40px; height: 40px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.send-btn:hover { background: var(--navy-mid); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-light);
  padding: 0.5rem 1.25rem 1rem;
  line-height: 1.5;
}

/* ── TOAST ──────────────────────────────────────────── */
.toast-wrap {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  z-index: 999; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.toast {
  background: var(--navy);
  color: var(--white);
  padding: 0.6rem 1.25rem;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s ease;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--online-color); }
.toast.warning { background: var(--offline-color); }

/* ── SCROLLBAR ──────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cream-dark); border-radius: 2px; }

/* ── UPLOAD TOOLBAR ─────────────────────────────────────────────── */
.upload-tool-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  font-size: 12px; font-family: 'DM Sans', sans-serif;
  color: var(--text-muted);
  background: var(--white);
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.upload-tool-btn:hover { border-color: var(--gold); color: var(--navy); background: var(--gold-dim); }

/* ── ATTACHMENT PILLS ───────────────────────────────────────────── */
.att-pill {
  display: flex; align-items: center; gap: 5px;
  background: var(--white);
  border: 1px solid var(--cream-dark);
  border-radius: 99px;
  padding: 3px 8px 3px 6px;
  font-size: 12px;
  color: var(--text-main);
  max-width: 200px;
}
.att-icon { font-size: 13px; flex-shrink: 0; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.att-remove {
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: 14px; line-height: 1;
  padding: 0 2px; flex-shrink: 0;
  transition: color 0.1s;
}
.att-remove:hover { color: var(--danger); }

/* ── CLIENT CARDS ───────────────────────────────────────────────── */
.client-card {
  background: var(--white);
  border: 1px solid var(--cream-mid);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.client-card:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.client-card.active { border-color: var(--gold); border-left: 3px solid var(--gold); }
.client-card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.client-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--navy); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; flex-shrink: 0;
  font-family: 'DM Serif Display', serif;
}
.client-info { flex: 1; min-width: 0; }
.client-name { font-weight: 500; font-size: 14px; color: var(--text-main); }
.client-meta { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-last-search { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }
.client-card-actions { display: flex; gap: 6px; }
.client-action-btn {
  font-size: 12px; padding: 4px 10px;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-xs);
  background: var(--cream); color: var(--text-muted);
  cursor: pointer; font-family: 'DM Sans', sans-serif;
  transition: all 0.15s;
}
.client-action-btn:hover { border-color: var(--gold); color: var(--navy); }
.client-action-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
.clients-empty { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); font-size: 14px; line-height: 1.7; }

/* ── HISTORY MODAL ──────────────────────────────────────────────── */
.history-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 500; margin-bottom: 8px; }
.history-item { border: 1px solid var(--cream-mid); border-radius: var(--radius-sm); padding: 0.75rem; margin-bottom: 8px; }
.history-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.history-property { font-weight: 500; font-size: 13px; color: var(--text-main); }
.history-date { font-size: 11px; color: var(--text-light); }
.history-price { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.history-summary { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-top: 6px; border-top: 1px solid var(--cream); padding-top: 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ── EXTRACT BUTTON ─────────────────────────────────────────────── */
.extract-btn {
  background: var(--navy) !important;
  color: var(--white) !important;
  border-color: var(--navy) !important;
  display: flex;
  align-items: center;
  gap: 5px;
}
.extract-btn:hover {
  background: var(--navy-mid) !important;
  color: var(--white) !important;
}
.extract-btn .spinner {
  width: 12px; height: 12px;
  border-width: 2px;
}
