/* LHYTE HQ — palette from lhyte.com / admin.lhyte.com */
:root {
  --terracotta: #B85042;
  --olive: #5C7148;
  --sand: #E7E8D1;
  --cream: #FBF7F0;
  --charcoal: #1F1F1F;

  --bg: var(--cream);
  --panel: #F4EFE5;
  --surface: #FFFFFF;
  --text: #1F1F1F;
  --muted: #6B675F;
  --line: #E4DDCF;
  --accent: var(--terracotta);
  --accent-ink: #FFFFFF;
  --user-bubble: #EDE6D8;
  --code-bg: #F1ECE2;
  --ok: var(--olive);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1F1F;
    --panel: #181818;
    --surface: #262624;
    --text: #EFEBE3;
    --muted: #A39E94;
    --line: #34322E;
    --accent: #CF6A5B;
    --user-bubble: #2F2D29;
    --code-bg: #2B2926;
    --ok: #8EA676;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1F1F1F; --panel: #181818; --surface: #262624; --text: #EFEBE3; --muted: #A39E94;
  --line: #34322E; --accent: #CF6A5B; --user-bubble: #2F2D29; --code-bg: #2B2926; --ok: #8EA676; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button { font: inherit; color: inherit; cursor: pointer; }

.wordmark { font-weight: 600; letter-spacing: .22em; font-size: 17px; }
.wordmark span { color: var(--accent); letter-spacing: .12em; font-size: .8em; margin-left: .2em; }
.wordmark.big { font-size: 30px; letter-spacing: .28em; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--line); }
.link-btn { border: 0; background: none; color: var(--muted); padding: 0; text-decoration: underline; font-size: 13px; }
.error { color: var(--accent); min-height: 1.4em; font-size: 14px; margin: 0; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.login-sub { color: var(--muted); margin: -4px 0 12px; }
.login-card input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }

/* Layout */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px; gap: 12px; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; height: 32px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 8px 0; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.list li { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.list li button.item { flex: 1; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.list li.active button.item, .list li button.item:hover { background: var(--line); }
.list li .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 4px 6px; }
.list li:hover .del { opacity: 1; }
.list .kb-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; }
.list .kb-item:hover { background: var(--line); }
.list .kb-item small { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 2px; }
.list .kb-item .lock { color: var(--accent); font-size: 11px; margin-left: 4px; }
.kb-panel { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.kb-filter { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }
.side-foot { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-bottom: 1px solid var(--line); min-height: 56px; }
.chat-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }

.thread { flex: 1; overflow-y: auto; padding: 24px 20px 8px; }
.thread > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; padding-top: 8vh; }
.empty-sub { color: var(--muted); max-width: 460px; margin: 12px auto 28px; }
.starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; }
.starter { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; line-height: 1.4; }
.starter::before { content: attr(data-area); display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; font-weight: 600; }
.starter:hover { border-color: var(--accent); }

.msg { margin: 0 auto 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .who-label { font-size: 12px; letter-spacing: .18em; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.activity { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.live::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }
.sources { margin-top: 10px; font-size: 13px; }
.sources summary { color: var(--muted); cursor: pointer; }
.sources ol { margin: 6px 0 0; padding-left: 20px; }
.sources a { color: var(--text); }
.msg-actions { margin-top: 6px; display: flex; gap: 10px; }
.msg-actions button { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 0; }
.msg .error-box { border: 1px solid var(--accent); color: var(--accent); border-radius: 10px; padding: 8px 12px; font-size: 14px; }

/* Markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol { margin: 0 0 .8em; }
.md h1, .md h2, .md h3 { font-size: 1.05em; margin: 1.2em 0 .5em; }
.md a { color: var(--accent); }
.md code { background: var(--code-bg); padding: .1em .35em; border-radius: 5px; font-size: .92em; }
.md pre { background: var(--code-bg); padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 1em; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--panel); }
.md blockquote { margin: 0 0 1em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.cursor::after { content: "▍"; color: var(--accent); animation: pulse .8s infinite alternate; }

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer > * { max-width: 760px; margin: 0 auto; }
.composer textarea { display: block; width: 100%; resize: none; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 12px 14px; font: inherit; max-height: 40vh; overflow-y: hidden; }
.composer textarea.scroll { overflow-y: auto; }
.composer textarea:focus, .login-card input:focus, .kb-filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.deep { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status { flex: 1; font-size: 12px; color: var(--muted); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Knowledge viewer */
.doc-dialog { width: min(820px, calc(100vw - 32px)); max-height: 85vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; }
.doc-dialog::backdrop { background: rgba(0, 0, 0, .4); }
.doc-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.doc-head h2 { font-size: 16px; margin: 0; }
.doc-body { padding: 16px 18px; font-size: 14px; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 9; }
.only-mobile { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 10; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .thread { padding: 18px 16px 8px; }
  .composer { padding-left: 16px; padding-right: 16px; }
  .starters { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 92%; }
}
