/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:           #F0F5FF;
  --surface:      #FFFFFF;
  --surface-2:    #F8FAFD;
  --accent:       #1558D6;
  --accent-dark:  #0F46B8;
  --accent-light: #EEF4FF;
  --ink:          #0F172A;
  --ink-soft:     #475569;
  --ink-muted:    #94A3B8;
  --line:         #E2E8F0;
  --success:      #059669;
  --success-bg:   #ECFDF5;
  --error:        #DC2626;
  --error-bg:     #FEF2F2;
  --warning:      #D97706;
  --warning-bg:   #FFFBEB;
  --radius:       10px;
  --radius-lg:    16px;
  --radius-xl:    24px;
  --shadow:       0 1px 3px rgba(15,23,42,.07), 0 1px 2px rgba(15,23,42,.05);
  --shadow-lg:    0 8px 32px rgba(15,23,42,.12);
  --font:         'Inter', system-ui, -apple-system, sans-serif;
  --header-h:     60px;
  --input-h:      80px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Typography ────────────────────────────────────────────────────────────── */
h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; }
h1 { font-size: 28px; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
p  { color: var(--ink-soft); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-muted); }

.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--ink-soft);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.btn-icon:hover { background: var(--surface-2); border-color: var(--ink-muted); }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 13px 20px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
}
.btn-google:hover {
  background: var(--surface-2);
  border-color: #9CA3AF;
  box-shadow: 0 2px 8px rgba(15,23,42,.08);
  text-decoration: none;
}
.btn-google svg { flex-shrink: 0; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.form-label .optional {
  font-weight: 400;
  color: var(--ink-muted);
  margin-left: 4px;
}
.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21,88,214,.12);
}
.form-input::placeholder { color: var(--ink-muted); }
.form-hint {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.5;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 24px 28px 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

/* ── Status banners ────────────────────────────────────────────────────────── */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.banner-success { background: var(--success-bg); color: var(--success); border: 1px solid #A7F3D0; }
.banner-error   { background: var(--error-bg);   color: var(--error);   border: 1px solid #FECACA; }
.banner-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #FDE68A; }
.banner-info    { background: var(--accent-light); color: var(--accent); border: 1px solid #BFDBFE; }

/* ── App header ────────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  z-index: 100;
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  flex-shrink: 0;
}
.app-logo-text {
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
}
.app-logo-text:hover { text-decoration: none; }
.header-sep {
  width: 1px;
  height: 24px;
  background: var(--line);
  flex-shrink: 0;
}
.header-spacer { flex: 1; }

/* Property selector */
.property-select-wrap {
  position: relative;
  flex: 0 1 320px;
  min-width: 0;
}
.property-select-wrap .form-select {
  padding-right: 36px;
  font-size: 13px;
  font-weight: 500;
  height: 36px;
  padding-top: 0;
  padding-bottom: 0;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394A3B8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  -webkit-appearance: none;
}

/* User avatar */
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Chat layout ───────────────────────────────────────────────────────────── */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-top: var(--header-h);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* ── Welcome screen ────────────────────────────────────────────────────────── */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 24px;
}
.welcome-icon {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.welcome h2 { font-size: 24px; }
.welcome p  { max-width: 400px; font-size: 15px; color: var(--ink-soft); }
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 560px;
}
.prompt-chip {
  padding: 8px 14px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.prompt-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ── Chat messages ─────────────────────────────────────────────────────────── */
.msg-row {
  display: flex;
  gap: 12px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 0;
}
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}
.msg-avatar.diver {
  background: var(--accent);
  color: #fff;
}
.msg-avatar.user-av {
  background: var(--ink);
  color: #fff;
  overflow: hidden;
}
.msg-avatar.user-av img { width: 100%; height: 100%; object-fit: cover; }

.msg-body { flex: 1; min-width: 0; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.65;
  max-width: 100%;
  word-break: break-word;
}
.msg-row.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
  color: var(--ink);
}
.msg-row.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg-row.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }

/* Markdown inside bubbles */
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12.5px;
  background: rgba(15,23,42,.07);
  padding: 2px 5px;
  border-radius: 4px;
}
.msg-row.user .msg-bubble code {
  background: rgba(255,255,255,.2);
}
.msg-bubble pre {
  background: #0F172A;
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code {
  background: none;
  color: #E2E8F0;
  padding: 0;
  font-size: 12.5px;
}
.msg-bubble p { margin: 4px 0; color: inherit; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg-bubble li { margin: 3px 0; }
.msg-bubble br { display: block; content: ''; margin: 2px 0; }
.msg-bubble .table-wrap { overflow-x: auto; margin: 10px 0; }
.msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.msg-bubble th, .msg-bubble td {
  padding: 7px 12px;
  text-align: left;
  border: 1px solid var(--line);
}
.msg-bubble th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--ink);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

/* Loading indicator */
.msg-loading .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.dots { display: flex; gap: 4px; align-items: center; padding: 2px 0; }
.dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: bounce 1.2s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* ── Chat input ────────────────────────────────────────────────────────────── */
.chat-input-area {
  flex-shrink: 0;
  padding: 12px 20px 20px;
  background: var(--bg);
}
.chat-input-inner {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(21,88,214,.1);
}
#chatInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 14.5px;
  color: var(--ink);
  background: transparent;
  line-height: 1.55;
  max-height: 180px;
  overflow-y: auto;
  min-height: 24px;
}
#chatInput::placeholder { color: var(--ink-muted); }

#sendBtn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
#sendBtn:hover { background: var(--accent-dark); }
#sendBtn:active { transform: scale(0.92); }
#sendBtn:disabled { background: var(--ink-muted); cursor: not-allowed; transform: none; }

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, #DBEAFE 0%, var(--bg) 70%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 48px 40px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 32px;
}
.login-logo-text {
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.04em;
}
.login-tagline {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 10px;
}
.login-sub {
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 32px;
  line-height: 1.55;
}
.login-note {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 20px;
  line-height: 1.5;
}
.login-error {
  padding: 11px 14px;
  background: var(--error-bg);
  border: 1px solid #FECACA;
  border-radius: var(--radius);
  color: var(--error);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 20px;
  text-align: left;
}

/* ── Settings page ─────────────────────────────────────────────────────────── */
.settings-page {
  min-height: 100vh;
  padding: var(--header-h) 20px 48px;
}
.settings-inner {
  max-width: 640px;
  margin: 0 auto;
  padding-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.settings-card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.settings-card-header h3 { margin: 0; }
.settings-card-body { padding: 24px; display: flex; flex-direction: column; gap: 18px; }

.provider-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
}
.provider-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.provider-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}
.provider-section { display: none; flex-direction: column; gap: 16px; }
.provider-section.active { display: flex; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.green { background: var(--success); }
.status-dot.red   { background: var(--error); }
.status-dot.grey  { background: var(--ink-muted); }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .property-select-wrap { flex: 0 1 180px; }
  .login-card { padding: 36px 24px 28px; }
  .chat-messages { padding: 20px 12px 12px; }
  .chat-input-area { padding: 8px 12px 16px; }
  .msg-row { max-width: 100%; }
}
