/* ==========================================================================
   Text-to-SQL Agent with Self-Correction — enterprise SaaS UI (light theme)
   Shares the design language of the sibling RAG projects:
     deep violet #2F004F · plum #722268 · coral #E85F5C
     amber #F5AB00 · teal #0E7C86 · off-white #F7F7F9 · ink #221331
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --violet-950: #22003b;
  --violet-900: #2f004f;
  --violet-800: #3d0f63;
  --violet-100: #efe6f7;
  --plum: #722268;
  --coral: #e85f5c;
  --coral-dark: #d14b48;
  --coral-soft: #fdeeed;
  --amber: #f5ab00;
  --amber-soft: #fdf3da;
  --teal: #0e7c86;
  --teal-soft: #e2f4f5;
  --indigo: #4f46b5;
  --indigo-soft: #ecebfa;
  --bg: #f7f7f9;
  --surface: #ffffff;
  --ink: #221331;
  --muted: #6f677e;
  --border: #e7e3ee;
  --border-strong: #d8d2e2;
  --success: #1e9e6a;
  --success-soft: #e4f5ee;
  --danger: #c43d3b;
  --danger-soft: #fbe9e9;
  --radius: 12px;
  --radius-sm: 8px;
  --rail-w: 244px;
  --topbar-h: 60px;
  --shadow-sm: 0 1px 2px rgba(34, 0, 59, 0.06), 0 1px 3px rgba(34, 0, 59, 0.08);
  --shadow-md: 0 4px 16px rgba(34, 0, 59, 0.10);
  --shadow-lg: 0 12px 40px rgba(34, 0, 59, 0.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
code, pre, .mono { font-family: 'JetBrains Mono', monospace; font-size: 0.85em; }
code { background: var(--violet-100); color: var(--violet-900); padding: 0.1em 0.4em; border-radius: 5px; }
h1, h2, h3, h4 { margin: 0 0 0.5rem 0; font-weight: 700; color: var(--ink); }
p { margin: 0 0 0.5rem 0; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--plum); }
::selection { background: var(--coral); color: #fff; }

/* ==========================================================================
   Shell: nav rail + main column
   ========================================================================== */

.app-shell { display: flex; min-height: 100vh; }

.nav-rail {
  width: var(--rail-w);
  background: linear-gradient(180deg, var(--violet-900) 0%, var(--violet-950) 100%);
  color: #efe9f6;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  transform: translateX(-100%);
  transition: transform 0.24s ease;
}
.nav-rail.open { transform: translateX(0); box-shadow: var(--shadow-lg); }

.nav-brand {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 1.15rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 800; font-size: 1rem; color: #ffffff; letter-spacing: 0.01em; }
.brand-sub { font-size: 0.68rem; color: #b9a8cd; font-weight: 500; }

.nav-menu { padding: 0.9rem 0.7rem; display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  width: 100%;
  background: transparent; border: none;
  color: #cbbcdc;
  font-size: 0.9rem; font-weight: 600;
  padding: 0.68rem 0.85rem;
  border-radius: 9px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #ffffff; }
.nav-item.active { background: rgba(255, 255, 255, 0.11); color: #ffffff; }
.nav-item.active::before {
  content: ""; position: absolute; left: -0.7rem; top: 20%; bottom: 20%;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--coral);
}

.nav-foot {
  margin-top: auto;
  padding: 1rem 1.1rem 1.2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}
.nav-pipeline { font-size: 0.68rem; line-height: 1.7; color: #a893be; font-weight: 500; }
.nav-pipeline b { color: #d9c9ea; font-weight: 700; }

.backdrop {
  position: fixed; inset: 0; background: rgba(34, 0, 59, 0.45);
  z-index: 55; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0 1.1rem;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.page-title { font-size: 1.08rem; font-weight: 800; margin: 0; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem; font-weight: 600;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}
.chip-model { max-width: 220px; overflow: hidden; text-overflow: ellipsis; display: inline-block; line-height: 1.5; }
#roChip { color: var(--teal); border-color: var(--teal-soft); background: var(--teal-soft); }

.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--ink);
  border-radius: var(--radius-sm); width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
}
.only-mobile { display: inline-flex; }

/* ==========================================================================
   Content area
   ========================================================================== */

.content { flex: 1; padding: 1.25rem 1.1rem 2rem; width: 100%; max-width: 1120px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.page-lede { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 0.95rem; font-weight: 800; margin-bottom: 0.85rem; display: flex; align-items: center; gap: 0.5rem; }
.card-title svg { color: var(--plum); flex-shrink: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.grid-2.tight { gap: 0.35rem 1.2rem; margin-bottom: 0.3rem; }
.span-2 { grid-column: 1 / -1; }

/* ---------- forms ---------- */

.field { display: block; margin-bottom: 0.8rem; min-width: 0; }
.field > span { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 0.35rem; }
.field .val { color: var(--plum); font-weight: 800; }
.field .guard {
  font-style: normal; font-weight: 700; color: var(--coral);
  text-transform: uppercase; font-size: 0.6rem; letter-spacing: 0.05em;
  background: var(--coral-soft); border-radius: 5px; padding: 0.05rem 0.35rem; margin-left: 0.25rem;
}
.optional { font-style: normal; font-weight: 500; color: var(--border-strong); text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.05em; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.58rem 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--plum);
  box-shadow: 0 0 0 3px rgba(114, 34, 104, 0.13);
}
textarea { resize: vertical; min-height: 2.4rem; line-height: 1.45; }
::placeholder { color: #b3abc1; }
select { cursor: pointer; }

input[type="range"] { width: 100%; accent-color: var(--coral); height: 24px; }

.hint { font-size: 0.76rem; color: var(--muted); line-height: 1.5; }
.form-error { color: var(--danger); font-size: 0.8rem; font-weight: 600; margin: 0.2rem 0 0.6rem; }
.key-status { font-weight: 700; color: var(--success); }

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 0.62rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  min-height: 42px;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { border-color: var(--plum); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--coral); border-color: var(--coral); color: #fff; }
.btn-primary:hover { background: var(--coral-dark); border-color: var(--coral-dark); }
.btn-secondary { background: var(--violet-100); border-color: var(--violet-100); color: var(--violet-900); }
.btn-secondary:hover { border-color: var(--plum); }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-ghost-danger:hover { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- toasts ---------- */

.toast-container {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 0.5rem; align-items: center;
  width: min(92vw, 430px);
}
.toast {
  width: 100%; border-radius: var(--radius-sm); padding: 0.68rem 0.95rem;
  font-size: 0.83rem; font-weight: 600; box-shadow: var(--shadow-md);
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  animation: toast-in 0.2s ease;
}
.toast.success { border-color: var(--success); background: var(--success-soft); color: #0f6b46; }
.toast.error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   Database view
   ========================================================================== */

.db-picker { display: flex; gap: 0.5rem; align-items: center; }
.db-picker select { flex: 1; }
.db-picker .btn { flex-shrink: 0; min-height: 42px; padding: 0.62rem 0.85rem; }

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: pointer;
}
.dropzone:hover { border-color: var(--plum); }
.dropzone.drag-over { border-color: var(--coral); background: var(--coral-soft); }
.dropzone-inner svg { color: var(--plum); margin-bottom: 0.3rem; }
.link-text { color: var(--coral); font-weight: 700; text-decoration: underline; cursor: pointer; }

.schema-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }
.schema-head .card-title { margin-bottom: 0; }
.schema-stats { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.schema-stat {
  font-size: 0.7rem; font-weight: 700; color: var(--violet-900);
  background: var(--violet-100); border-radius: 999px; padding: 0.2rem 0.6rem;
}

.table-grid { display: grid; grid-template-columns: 1fr; gap: 0.7rem; margin-top: 1rem; }
.table-card { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden; }
.table-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.8rem; background: var(--violet-100);
  border-bottom: 1px solid var(--border);
}
.tc-name { font-weight: 800; font-size: 0.85rem; color: var(--violet-900); font-family: 'JetBrains Mono', monospace; }
.tc-count { font-size: 0.68rem; font-weight: 700; color: var(--plum); }
.tc-cols { padding: 0.6rem 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.tc-col { display: flex; align-items: baseline; gap: 0.45rem; font-size: 0.78rem; }
.tc-col .cn { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--ink); }
.tc-col .ct { font-size: 0.66rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.tc-col .badge-pk { font-size: 0.58rem; font-weight: 800; color: var(--amber); background: var(--amber-soft); border-radius: 4px; padding: 0.02rem 0.3rem; text-transform: uppercase; }
.tc-col .badge-fk { font-size: 0.58rem; font-weight: 800; color: var(--teal); background: var(--teal-soft); border-radius: 4px; padding: 0.02rem 0.3rem; text-transform: uppercase; }
.tc-enum { font-size: 0.68rem; color: var(--muted); font-family: 'JetBrains Mono', monospace; padding-left: 0.2rem; }
.tc-enum b { color: var(--plum); font-weight: 600; }

.empty-hint { color: var(--muted); font-size: 0.88rem; padding: 0.8rem 0.2rem; }

/* ==========================================================================
   Ask view — conversation pane + ask column
   ========================================================================== */

.kb-banner {
  display: flex; align-items: center; gap: 0.55rem;
  background: var(--amber-soft); border: 1px solid var(--amber);
  color: #7a5600; font-size: 0.8rem; font-weight: 600;
  border-radius: var(--radius-sm); padding: 0.6rem 0.85rem; margin-bottom: 0.9rem;
}
.kb-banner svg { flex-shrink: 0; color: #b07d00; }

.chat-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  height: calc(100vh - var(--topbar-h) - 120px);
  min-height: 480px;
}

.thread-pane { display: flex; flex-direction: column; gap: 0.7rem; min-height: 0; }
.new-thread-btn { flex-shrink: 0; }
.thread-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.35rem; padding-right: 2px; }
.thread-item {
  display: flex; align-items: stretch; gap: 0.2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); overflow: hidden;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.thread-item:hover { border-color: var(--border-strong); }
.thread-item.active { border-color: var(--plum); background: var(--violet-100); }
.thread-open {
  flex: 1; min-width: 0; text-align: left; background: transparent; border: none;
  padding: 0.55rem 0.65rem; display: flex; flex-direction: column; gap: 0.15rem;
}
.thread-title {
  font-size: 0.82rem; font-weight: 700; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item.active .thread-title { color: var(--violet-900); }
.thread-meta { font-size: 0.68rem; font-weight: 600; color: var(--muted); }
.thread-del {
  flex-shrink: 0; background: transparent; border: none; color: var(--muted);
  padding: 0 0.55rem; font-size: 0.8rem; line-height: 1;
}
.thread-del:hover { color: var(--danger); background: var(--danger-soft); }
.thread-empty { font-size: 0.78rem; color: var(--muted); padding: 0.6rem 0.3rem; }
.thread-hint { font-size: 0.68rem; color: var(--muted); line-height: 1.5; flex-shrink: 0; margin: 0; }

.chat-main { display: flex; flex-direction: column; min-height: 0; }

.ask-bar {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  margin-bottom: 0.8rem; flex-shrink: 0;
}
.ask-bar-db {
  font-size: 0.72rem; font-weight: 700; color: var(--violet-900);
  background: var(--violet-100); border-radius: 999px; padding: 0.3rem 0.7rem;
  white-space: nowrap; font-family: 'JetBrains Mono', monospace;
}
.example-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; min-width: 0; }
.example-chip {
  font-size: 0.72rem; font-weight: 600; color: var(--plum);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 0.28rem 0.7rem; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.example-chip:hover { border-color: var(--plum); background: var(--violet-100); }

.chat-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 0.25rem 0.1rem 1rem; display: flex; flex-direction: column; gap: 0.9rem; }

.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }
.bubble {
  max-width: 92%;
  border-radius: var(--radius);
  padding: 0.8rem 0.95rem;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: break-word;
}
.msg-user .bubble { background: var(--violet-900); color: #fff; border-bottom-right-radius: 4px; }
.msg-assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; width: 100%; box-shadow: var(--shadow-sm); }

.answer-text { white-space: pre-wrap; }
.answer-text.streaming::after {
  content: "▌"; display: inline-block; margin-left: 1px;
  animation: blink 1s step-start infinite; color: var(--coral);
}
@keyframes blink { 50% { opacity: 0; } }
.error-text { color: var(--danger); font-weight: 600; }

.stage-line { font-size: 0.78rem; font-weight: 700; color: var(--plum); margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.45rem; }
.stage-line .spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--violet-100); border-top-color: var(--plum);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Self-correction trajectory — vertical timeline
   ========================================================================== */

.graph-trace {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem 0.85rem 0.5rem; margin-bottom: 0.8rem;
}
.trace-title {
  font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); margin-bottom: 0.7rem;
}
.gt-steps { display: flex; flex-direction: column; }

.gt-step {
  display: grid; grid-template-columns: 26px 1fr; gap: 0.55rem;
  position: relative; padding-bottom: 0.7rem;
}
.gt-step:last-child { padding-bottom: 0.15rem; }
.gt-step:not(:last-child)::before {
  content: ""; position: absolute; left: 12.5px; top: 24px; bottom: -2px;
  width: 2px; background: var(--border-strong);
}
.gt-dot {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0; z-index: 1; box-shadow: var(--shadow-sm);
}
.gt-dot svg { width: 14px; height: 14px; }
.gt-dot.plan     { background: var(--indigo); }
.gt-dot.generate { background: var(--violet-900); }
.gt-dot.guard    { background: var(--teal); }
.gt-dot.dryrun   { background: var(--plum); }
.gt-dot.execute  { background: var(--coral); }
.gt-dot.repair   { background: var(--amber); color: #6b4b00; }
.gt-dot.verify   { background: var(--success); }
.gt-dot.fail     { background: var(--danger); }
.gt-dot.running  { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(114,34,104,0.0); } 50% { box-shadow: 0 0 0 4px rgba(114,34,104,0.16); } }

.gt-body { min-width: 0; padding-top: 0.15rem; }
.gt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.gt-title { font-size: 0.82rem; font-weight: 700; color: var(--ink); }
.gt-badge {
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase;
  border-radius: 6px; padding: 0.08rem 0.4rem;
}
.gt-badge.kb     { background: var(--violet-100); color: var(--violet-900); }
.gt-badge.info   { background: var(--indigo-soft); color: var(--indigo); }
.gt-badge.warn   { background: var(--amber-soft); color: #8a6100; }
.gt-badge.ok     { background: var(--success-soft); color: var(--success); }
.gt-badge.bad    { background: var(--danger-soft); color: var(--danger); }
.gt-detail { font-size: 0.76rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.5; word-break: break-word; }
.gt-detail .q { font-style: italic; color: var(--ink); }
.gt-detail code { font-size: 0.72rem; }
.gt-detail .err { color: var(--danger); font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; }

.gt-tables { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.45rem; }
.gt-tchip {
  font-size: 0.68rem; font-weight: 700; border-radius: 999px; padding: 0.12rem 0.5rem;
  background: var(--violet-100); color: var(--violet-900); font-family: 'JetBrains Mono', monospace;
}

/* ==========================================================================
   SQL block + result table
   ========================================================================== */

.sql-block { margin-bottom: 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.sql-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.35rem 0.6rem; background: var(--violet-950);
}
.sql-tag { font-size: 0.62rem; font-weight: 800; letter-spacing: 0.08em; color: var(--amber); text-transform: uppercase; }
.sql-copy {
  background: rgba(255,255,255,0.1); border: none; color: #e9def5;
  font-size: 0.68rem; font-weight: 700; border-radius: 5px; padding: 0.2rem 0.55rem;
}
.sql-copy:hover { background: rgba(255,255,255,0.2); }
.sql-code {
  margin: 0; padding: 0.7rem 0.8rem; background: #1a0b2b; color: #e9def5;
  font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
}
.sql-code .kw { color: #f5ab00; font-weight: 600; }
.sql-code .fn { color: #6fd3dd; }
.sql-code .str { color: #7fe0a3; }
.sql-code .num { color: #e88; }
.sql-code .cmt { color: #8a7ba3; font-style: italic; }

.result-block { margin-bottom: 0.8rem; }
.result-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.result-caption { font-size: 0.72rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.result-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.result-table { border-collapse: collapse; width: 100%; font-size: 0.78rem; }
.result-table thead th {
  position: sticky; top: 0; background: var(--violet-100); color: var(--violet-900);
  font-weight: 800; text-align: left; padding: 0.45rem 0.7rem; white-space: nowrap;
  font-family: 'JetBrains Mono', monospace; font-size: 0.72rem;
  border-bottom: 1px solid var(--border-strong);
}
.result-table tbody td {
  padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.result-table tbody tr:nth-child(even) { background: var(--bg); }
.result-table tbody tr:hover { background: var(--violet-100); }
.result-table td.null { color: var(--border-strong); font-style: italic; }
.result-empty { padding: 0.9rem; text-align: center; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.result-more { font-size: 0.7rem; color: var(--muted); padding: 0.35rem 0.7rem; font-weight: 600; }

.usage-caption { margin-top: 0.6rem; font-size: 0.72rem; font-weight: 600; color: var(--muted); }

.chat-input-bar {
  display: flex; align-items: flex-end; gap: 0.6rem;
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius); padding: 0.55rem 0.6rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  padding-bottom: calc(0.55rem + env(safe-area-inset-bottom));
}
.chat-input-bar textarea { border: none; background: transparent; resize: none; max-height: 140px; padding: 0.35rem 0.3rem; }
.chat-input-bar textarea:focus { box-shadow: none; }
.send-btn {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--coral); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease;
}
.send-btn:hover { background: var(--coral-dark); }
.send-btn:disabled { opacity: 0.5; }

/* ==========================================================================
   Settings view
   ========================================================================== */

.lock-wrap { display: flex; justify-content: center; padding: 2.5rem 0; }
.lock-card { width: min(100%, 400px); text-align: center; padding: 1.8rem 1.6rem; }
.lock-icon {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--violet-100); color: var(--violet-900);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 0.9rem;
}
.lock-card h3 { font-size: 1.05rem; }
.lock-card .field > span { text-align: left; }
.lock-card form { margin-top: 1rem; text-align: left; }

.settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.settings-head-text { min-width: 0; }
.settings-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 0.2rem; }
.settings-head .page-lede { margin-bottom: 0; }
.settings-head .btn { flex-shrink: 0; }

.config-summary {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem;
  margin-bottom: 1rem;
}
.cfg-item {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.7rem 0.85rem; box-shadow: var(--shadow-sm);
}
.cfg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.cfg-dot.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.cfg-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.cfg-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.cfg-label { font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.cfg-value { font-size: 0.82rem; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 0.3rem; }
.conn-result { font-size: 0.78rem; font-weight: 700; }
.conn-result.testing { color: var(--muted); }
.conn-result.ok { color: var(--success); }
.conn-result.err { color: var(--danger); }

.input-wrap { position: relative; display: block; }
.input-wrap input { padding-right: 2.6rem; }
.pw-toggle {
  position: absolute; top: 50%; right: 0.5rem; transform: translateY(-50%);
  background: transparent; border: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px; padding: 0;
}
.pw-toggle:hover { color: var(--plum); background: var(--violet-100); }
.pw-toggle.on { color: var(--plum); }

.footer { text-align: center; font-size: 0.72rem; color: var(--muted); padding: 1.1rem 1rem 1.4rem; }

/* ==========================================================================
   Responsive breakpoints
   ========================================================================== */

@media (min-width: 900px) {
  .only-mobile { display: none; }
  .nav-rail { transform: none; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
  .backdrop { display: none; }
  .content { padding: 1.6rem 2rem 2.4rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .config-summary { grid-template-columns: repeat(4, 1fr); }
  .table-grid { grid-template-columns: repeat(2, 1fr); }
  .chat-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .bubble { max-width: 74%; }
  .msg-assistant .bubble { max-width: 94%; }
}

@media (min-width: 1280px) {
  .content { max-width: 1200px; }
  .table-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 899px) {
  .chat-layout { height: auto; display: block; }
  .thread-pane { max-height: 240px; margin-bottom: 1rem; }
  .thread-hint { display: none; }
  .chat-main { height: calc(100vh - var(--topbar-h) - 340px); min-height: 380px; }
}

@media (max-width: 480px) {
  .chip-model, #dbChip { display: none; }
  .page-title { font-size: 0.98rem; }
  .content { padding: 1rem 0.85rem 1.6rem; }
}
