:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --ink: #1f2937;
  --ink-soft: #475569;
  --line: #e5e7eb;
  --accent: #b8431f;       /* LBAPS warm rust */
  --accent-soft: #fdf1ec;
  --good: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
}

/* SIDEBAR */
#sidebar {
  width: 290px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px 14px;
  overflow-y: auto;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  padding: 0 4px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  letter-spacing: .5px;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 8px 4px 6px 4px;
}
#persona-list { display: flex; flex-direction: column; gap: 4px; }
.persona-btn {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.persona-btn:hover { background: #f4f3f0; }
.persona-btn .pb-tag {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-top: 1px;
  line-height: 1.3;
}
.persona-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.persona-btn.active .pb-tag { color: var(--accent); opacity: .85; }

.kb-link {
  margin-top: 18px;
  padding: 10px;
  background: #fbf6ee;
  border: 1px solid #efe3cf;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}
.kb-link a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.footer-meta {
  margin-top: auto;
  padding-top: 12px;
  font-size: 11px;
  color: var(--ink-soft);
}
.footer-meta code {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 10.5px;
  background: #f4f3f0;
  padding: 1px 5px;
  border-radius: 3px;
}

/* MAIN */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#topbar {
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.banner-label {
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}
.banner-tagline {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 1px;
}

#controls {
  display: flex;
  align-items: end;
  gap: 14px;
}
.control { display: flex; flex-direction: column; gap: 4px; }
.control label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: .5px;
}
.control select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  min-width: 200px;
}
#mode-tabs { display: flex; gap: 2px; background: #f4f3f0; padding: 2px; border-radius: 7px; }
.mode-tab {
  padding: 5px 12px;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
}
.mode-tab.active {
  background: white;
  color: var(--accent);
  box-shadow: var(--shadow);
}
#reset-btn {
  padding: 6px 14px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-soft);
}
#reset-btn:hover { background: #f4f3f0; }

/* CHAT */
#chat-region {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat.empty { display: grid; place-items: center; }
.placeholder { text-align: center; color: var(--ink-soft); max-width: 480px; }
.placeholder h2 { color: var(--ink); font-weight: 600; font-size: 19px; margin-bottom: 16px; }
.placeholder ul { text-align: left; padding-left: 18px; line-height: 1.8; }

.msg {
  max-width: 760px;
  padding: 12px 16px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}
.msg.user {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.msg.assistant {
  background: var(--panel);
  border: 1px solid var(--line);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow);
}
.msg.assistant.streaming::after {
  content: "▍";
  color: var(--accent);
  margin-left: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.usage-pill {
  align-self: flex-start;
  font-size: 11px;
  color: var(--ink-soft);
  background: #eef2f7;
  padding: 3px 8px;
  border-radius: 99px;
  margin-top: -6px;
}

#composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 24px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
#composer-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  line-height: 1.4;
}
#composer-input:focus { border-color: var(--accent); }
#send-btn {
  padding: 10px 22px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#send-btn:hover:not(:disabled) { background: #9a3819; }

/* LOGOUT */
.logout-link {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink-soft);
  text-decoration: none;
  border-radius: 6px;
  text-align: center;
  transition: background .15s, color .15s;
}
.logout-link:hover { background: #f4f3f0; color: var(--accent); }

/* LOGIN PAGE */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #fdf1ec 0%, #faf9f7 40%, #eef2f7 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 40px 36px 36px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
}

.login-card .login-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 28px;
}

.login-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 24px;
}

.login-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-field { display: flex; flex-direction: column; gap: 5px; }
.login-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.login-field input {
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 67, 31, .1);
}
.login-field input::placeholder { color: #94a3b8; }

.login-btn {
  margin-top: 4px;
  padding: 11px 22px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  transition: background .15s;
}
.login-btn:hover { background: #9a3819; }
.login-btn:active { background: #832f14; }
