:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #637083;
  --line: #d9e0e8;
  --panel: #ffffff;
  --paper: #f5f7fa;
  --brand: #156f73;
  --brand-strong: #0d5558;
  --accent: #d64f2a;
  --ok: #237a45;
  --warn: #b15c00;
  --shadow: 0 12px 32px rgba(22, 33, 43, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #f5f7fa 0%, #eef5f3 48%, #f8f1ec 100%); }
.auth-panel { width: min(100%, 460px); display: grid; gap: 16px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 26px; }
.auth-panel h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
.auth-panel p { margin: 0; line-height: 1.5; }
.auth-brand { color: var(--ink); }
.auth-brand svg { color: var(--brand); }
.shell { min-height: 100vh; display: grid; grid-template-columns: 268px 1fr; }
.sidebar { background: #101820; color: #f7fbff; padding: 22px; display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 18px; }
.brand svg { width: 28px; height: 28px; color: #79d5cf; }
.mode-card { border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); border-radius: 8px; padding: 14px; }
.mode-card small { color: #b8c5d1; display: block; margin-top: 4px; line-height: 1.45; }
.nav { display: grid; gap: 8px; }
.nav button { border: 0; border-radius: 8px; color: #d9e7f2; background: transparent; padding: 11px 12px; display: flex; gap: 10px; align-items: center; text-align: left; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav svg, .btn svg, .icon { width: 18px; height: 18px; flex: 0 0 auto; }
.main { min-width: 0; }
.topbar { min-height: 72px; display: flex; justify-content: space-between; align-items: center; padding: 18px 28px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.8); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: 0; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.content { padding: 24px 28px 40px; display: grid; gap: 20px; }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 17px; }
.metric { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.metric strong { font-size: 30px; }
.muted { color: var(--muted); }
.form { display: grid; gap: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: grid; gap: 6px; color: #344252; font-weight: 650; font-size: 13px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 10px 11px; color: var(--ink); min-height: 42px; }
textarea { resize: vertical; min-height: 92px; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(21,111,115,.18); border-color: var(--brand); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 10px 13px; display: inline-flex; gap: 8px; align-items: center; justify-content: center; min-height: 42px; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { border-color: #f0c6ba; color: #92351f; }
.btn.ghost { background: transparent; }
.pill { border-radius: 999px; padding: 5px 9px; background: #e8f3f2; color: var(--brand-strong); font-size: 12px; font-weight: 750; display: inline-flex; align-items: center; gap: 6px; }
.pill.warn { background: #fff2de; color: var(--warn); }
.pill.ok { background: #e7f5eb; color: var(--ok); }
.list { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; display: grid; gap: 8px; }
.item-head { display: flex; gap: 10px; justify-content: space-between; align-items: start; }
.item h4 { margin: 0; font-size: 15px; }
.item p { margin: 0; color: var(--muted); line-height: 1.45; }
.table { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; min-width: 680px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; }
tr:last-child td { border-bottom: 0; }
.chat-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.app-chat { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #edf4f3; }
.app-chat .chat { width: min(100%, 860px); min-height: min(720px, calc(100vh - 40px)); }
.chat { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 560px; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; box-shadow: var(--shadow); }
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.messages { padding: 16px; display: flex; flex-direction: column; gap: 10px; overflow: auto; min-height: 360px; }
.bubble { max-width: min(78%, 620px); padding: 11px 13px; border-radius: 8px; line-height: 1.45; background: #eef4f8; align-self: flex-start; white-space: pre-wrap; }
.bubble.user { background: var(--brand); color: #fff; align-self: flex-end; }
.chat-form { border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px; }
.empty { border: 1px dashed #b9c5d1; border-radius: 8px; padding: 18px; color: var(--muted); background: #fbfcfe; text-align: center; }
.token { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: #f1f5f9; padding: 8px; border-radius: 8px; border: 1px solid var(--line); word-break: break-all; }
.setup-field { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.profile-setup { gap: 16px; }
.setup-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.setup-step { border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 8px; padding: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 750; min-height: 44px; }
.setup-step span { width: 22px; height: 22px; border-radius: 999px; display: inline-grid; place-items: center; background: #eef4f8; color: var(--muted); font-size: 12px; }
.setup-step.active { border-color: var(--brand); color: var(--brand-strong); background: #edf7f6; }
.setup-step.active span { background: var(--brand); color: #fff; }
.setup-panel { display: none; gap: 12px; }
.setup-panel.active { display: grid; }
.step-actions { display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.checklist { display: grid; gap: 8px; }
.checklist { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.check-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; min-height: 42px; }
.test-panel { align-self: start; }
.test-panel textarea { min-height: 118px; }
.qa-result { display: grid; gap: 10px; }
.qa-result p { margin: 0; line-height: 1.45; }
.result-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-summary > div { border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: #fbfcfe; display: grid; gap: 4px; }
.result-summary strong { font-size: 18px; }
.answer-preview { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; display: grid; gap: 6px; }
.match-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.match-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; display: grid; gap: 9px; align-content: start; }
.match-card .btn { width: 100%; }
.matched { color: var(--muted); }
.train-exact { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fbfcfe; }
.unanswered-group > .answer-form { border-color: #eef2f6; background: #fbfcfe; }
.toast { position: fixed; right: 18px; bottom: 18px; background: #101820; color: #fff; padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow); z-index: 20; }
.hide { display: none !important; }
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid, .chat-wrap { grid-template-columns: 1fr; }
  .span-4, .span-5, .span-6, .span-7, .span-8, .span-12 { grid-column: span 1; }
}
@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 16px; }
  .content { padding: 16px; }
  .row, .setup-field, .chat-form, .setup-steps { grid-template-columns: 1fr; }
  .step-actions { flex-direction: column-reverse; }
  .bubble { max-width: 94%; }
}
