/* ============================================================
   BusinessFlow borrower chat — same design tokens as the ops
   dashboard (brand consistency across the product), laid out as a
   consumer messaging app rather than a data-dense control room:
   more whitespace, larger touch targets, a calmer palette balance.
   ============================================================ */
:root {
  --navy-950: #00111f;
  --navy-900: #001d39;
  --navy-800: #0a4174;
  --blue-600: #49769f;
  --teal-500: #4e8ea2;
  --teal-400: #6ea2b3;
  --sky-300: #7bbde8;
  --sky-100: #bdd8e9;

  --bg-0: #030d18;
  --bg-1: #051c31;
  --surface: rgba(20, 61, 97, 0.38);
  --surface-strong: rgba(28, 78, 122, 0.55);
  --border: rgba(123, 189, 232, 0.14);
  --border-strong: rgba(123, 189, 232, 0.28);

  --text-0: #f2f8fd;
  --text-1: #c7dcee;
  --text-2: #8fadc7;
  --text-3: #5f7f9c;

  --accent: #7bbde8;
  --accent-strong: #bdd8e9;
  --accent-dim: rgba(123, 189, 232, 0.16);

  --success: #4fd8a8;
  --success-dim: rgba(79, 216, 168, 0.14);
  --warning: #f0bd63;
  --warning-dim: rgba(240, 189, 99, 0.14);
  --danger: #f2836f;
  --danger-dim: rgba(242, 131, 111, 0.16);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-lift: 0 20px 60px -20px rgba(0, 8, 20, 0.7);
  --shadow-soft: 0 10px 30px -14px rgba(0, 8, 20, 0.55);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-tight: "Inter Tight", var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text-1);
  background:
    radial-gradient(1100px 700px at 82% -8%, rgba(123, 189, 232, 0.16), transparent 60%),
    radial-gradient(900px 600px at -10% 105%, rgba(78, 142, 162, 0.14), transparent 55%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 55%, var(--bg-0) 100%);
  background-attachment: fixed; min-height: 100%; -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font-family: inherit; }
::selection { background: var(--accent-dim); color: var(--text-0); }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-strong); border-radius: var(--radius-pill); }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-tight); font-weight: 800; font-size: 14px;
  color: var(--navy-950); background: linear-gradient(150deg, var(--sky-100), var(--sky-300) 55%, var(--teal-500));
  box-shadow: 0 6px 18px -6px rgba(123, 189, 232, 0.55); flex-shrink: 0;
}
.brand-name { font-family: var(--font-tight); font-weight: 700; font-size: 16px; color: var(--text-0); }
.brand.small .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 12px; }
.brand.small .brand-name { font-size: 14px; }

/* ============================================================
   Start screen
   ============================================================ */
.start-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.start-screen[hidden] { display: none; }
.start-glow {
  position: absolute; width: 900px; height: 900px; border-radius: 50%;
  background: radial-gradient(circle, rgba(123, 189, 232, 0.16), transparent 60%);
  top: -320px; right: -280px; pointer-events: none;
}
.start-card {
  position: relative; width: 100%; max-width: 400px;
  background: var(--surface); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  padding: 32px 30px 26px; box-shadow: var(--shadow-lift);
  animation: rise 0.5s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.start-card .brand { margin-bottom: 16px; }
.start-tagline { margin: 0 0 22px; font-size: 14px; color: var(--text-1); line-height: 1.5; }

.start-tabs { display: flex; gap: 6px; background: rgba(3, 13, 24, 0.4); border-radius: var(--radius-pill); padding: 4px; margin-bottom: 20px; }
.start-tab {
  flex: 1; border: none; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 600;
  padding: 9px 0; border-radius: var(--radius-pill); cursor: pointer; transition: all 0.2s var(--ease);
}
.start-tab.active { background: var(--accent); color: var(--navy-950); }

.field-label { display: block; font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 6px; }
#start-form input {
  width: 100%; background: rgba(3, 13, 24, 0.55); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 11px 14px; color: var(--text-0); font-size: 14px; margin-bottom: 14px;
}
#start-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.lang-toggle { display: flex; gap: 8px; margin-bottom: 20px; }
.lang-btn {
  flex: 1; border: 1px solid var(--border); background: rgba(3, 13, 24, 0.4); color: var(--text-2);
  font-size: 13px; font-weight: 600; padding: 9px 0; border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s var(--ease);
}
.lang-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text-0); }

.start-submit {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--sky-300), var(--teal-500)); color: var(--navy-950); font-weight: 700;
  font-size: 14.5px; padding: 13px 0; border-radius: var(--radius-md); transition: all 0.15s var(--ease);
}
.start-submit:hover { filter: brightness(1.08); transform: translateY(-1px); }
.start-submit:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.start-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; text-align: center; }
.start-hint { margin: 16px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.5; text-align: center; }

/* ============================================================
   Chat screen
   ============================================================ */
.chat-screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.chat-screen[hidden] { display: none; }

.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px;
  background: rgba(3, 13, 24, 0.72); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-header-right { display: flex; align-items: center; gap: 10px; }
.account-chip { font-size: 12px; font-weight: 600; color: var(--text-1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 5px 12px; }
.account-chip[hidden] { display: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s var(--ease);
}
.icon-btn:hover { color: var(--text-0); border-color: var(--border-strong); }

.message-list {
  flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 14px;
  max-width: 720px; width: 100%; margin: 0 auto;
}

.msg-row { display: flex; flex-direction: column; max-width: 82%; animation: msg-in 0.25s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }
.msg-row.system { align-self: center; max-width: 90%; align-items: center; }

.msg-bubble { padding: 11px 15px; border-radius: 18px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg-row.user .msg-bubble { background: linear-gradient(135deg, var(--sky-300), var(--teal-500)); color: var(--navy-950); border-bottom-right-radius: 5px; font-weight: 500; }
.msg-row.assistant .msg-bubble { background: var(--surface); border: 1px solid var(--border); color: var(--text-0); border-bottom-left-radius: 5px; }
.msg-row.assistant.error .msg-bubble { background: var(--danger-dim); border-color: rgba(242, 131, 111, 0.3); color: var(--text-0); }
.msg-row.system .msg-bubble { background: transparent; border: none; color: var(--text-3); font-size: 12px; text-align: center; padding: 4px 10px; }

.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tool-chip {
  font-size: 10.5px; font-weight: 600; color: var(--success); background: var(--success-dim);
  border: 1px solid rgba(79, 216, 168, 0.25); border-radius: var(--radius-pill); padding: 3px 10px;
  display: inline-flex; align-items: center; gap: 4px;
}

.typing-row { align-self: flex-start; }
.typing-bubble {
  display: flex; align-items: center; gap: 4px; padding: 13px 16px; border-radius: 18px; border-bottom-left-radius: 5px;
  background: var(--surface); border: 1px solid var(--border); width: fit-content;
}
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-2); animation: typing-bounce 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.message-form {
  display: flex; gap: 10px; padding: 16px 20px; max-width: 720px; width: 100%; margin: 0 auto;
  border-top: 1px solid var(--border); flex-shrink: 0; background: rgba(3, 13, 24, 0.4);
}
#message-input {
  flex: 1; min-width: 0; background: rgba(3, 13, 24, 0.55); border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 13px 18px; color: var(--text-0); font-size: 14.5px;
}
#message-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
#message-input:disabled { opacity: 0.6; }
.send-btn {
  width: 46px; height: 46px; flex-shrink: 0; border: none; cursor: pointer; border-radius: 50%;
  background: linear-gradient(135deg, var(--sky-300), var(--teal-500)); color: var(--navy-950);
  display: flex; align-items: center; justify-content: center; transition: all 0.15s var(--ease);
}
.send-btn:hover { filter: brightness(1.08); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

@media (max-width: 520px) {
  .start-card { padding: 26px 20px 20px; }
  .message-list, .message-form { padding-left: 14px; padding-right: 14px; }
  .msg-row { max-width: 90%; }
}
