:root {
  --brand: #3b5bdb;
  --bg: #ffffff; --side: #f7f7f8; --surface: #ffffff; --surface-2: #f1f2f4; --border: #e5e6ea;
  --text: #16181d; --muted: #6b7080; --bubble: #f1f2f4;
  --ok: #1f8a4c; --ok-soft: #e4f5ea; --warn: #b26a00; --warn-soft: #fff3dc; --bad: #c92a2a; --bad-soft: #fde8e8;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, var(--surface));
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121; --side: #171717; --surface: #2a2a2a; --surface-2: #303030; --border: #3a3a3a;
    --text: #ececec; --muted: #a3a3a8; --bubble: #303030;
    --ok: #4cc27f; --ok-soft: #15301f; --warn: #f0b04a; --warn-soft: #33270f; --bad: #ff6b6b; --bad-soft: #3a1717;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--brand); }
h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; flex: none; }

/* Signed out: a simple centred card */
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
body.signed-out main.wrap { padding-top: 24px; padding-bottom: 64px; }
.top { border-bottom: 1px solid var(--border); }
.top .wrap { display: flex; align-items: center; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { height: 28px; width: auto; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Signed in: sidebar + main, like ChatGPT */
.app { display: grid; grid-template-columns: 272px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; padding: 12px 10px; gap: 8px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 8px; }
.new-chat { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; border: 1px solid var(--border); background: var(--surface); }
.new-chat:hover { background: var(--surface-2); }
.chats { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 1px; margin: 6px -4px 0; padding: 0 4px; }
.chats a { display: grid; gap: 1px; padding: 8px 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.chats a:hover { background: var(--surface-2); }
.chats a.on { background: var(--brand-soft); }
.chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chats a.unread .chat-title { font-weight: 700; }
.chat-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }
.side-empty { padding: 8px 10px; }
.side-foot { border-top: 1px solid var(--border); padding-top: 8px; display: grid; gap: 2px; }
.side-foot a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text); text-decoration: none; font-size: 14px; }
.side-foot a:hover, .side-foot a.on { background: var(--surface-2); }
.me-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.me-name { flex: 1; min-width: 0; font-size: 14px; display: grid; line-height: 1.3; }
.me-name small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 700; flex: none; background: var(--surface-2); color: var(--text); }
.avatar.me { background: var(--brand); color: #fff; }
.avatar.staff { background: var(--text); color: var(--bg); }
.avatar.ai { background: var(--brand-soft); color: var(--brand); font-size: 15px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; position: relative; }
.only-mobile { display: none !important; }
.topbar { display: none; }
/* Desktop: the sidebar collapses to a slim top bar (remembered per browser). */
@media (min-width: 861px) {
  .side-collapsed .app { grid-template-columns: minmax(0, 1fr); }
  .side-collapsed .side { display: none; }
  .side-collapsed .topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
  .side-collapsed .topbar-title { display: none; }
}
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0; background: none; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

/* A conversation */
.chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--border); }
.chat-head h1 { font-size: 17px; margin: 0; }
.chat-head .meta { margin: 2px 0 0; }
.scroller { flex: 1; overflow-y: auto; min-height: 0; }
.thread { list-style: none; margin: 0 auto; padding: 24px 24px 8px; max-width: 800px; display: grid; gap: 18px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg .bubble { min-width: 0; max-width: 100%; }
.msg.k-client { justify-content: flex-end; }
.msg.k-client .bubble { background: var(--bubble); border-radius: 18px 18px 4px 18px; padding: 10px 16px; max-width: 78%; }
.msg.k-client .who { text-align: right; }
.msg .who { font-size: 13px; font-weight: 600; margin-bottom: 2px; display: flex; gap: 8px; align-items: baseline; }
.msg .who time { font-weight: 400; font-size: 12px; }
.msg.k-client .who { justify-content: flex-end; }
.tag { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }
.body { overflow-wrap: anywhere; }
.body.plain { white-space: pre-wrap; }
.body.md > :first-child { margin-top: 0; }
.body.md > :last-child { margin-bottom: 0; }
.body.md p { margin: 0 0 10px; }
.body.md ul, .body.md ol { margin: 0 0 10px; padding-left: 22px; }
.body.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.body.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.files { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.files img { display: block; max-width: min(100%, 360px); max-height: 280px; border-radius: 12px; margin-bottom: 4px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); text-decoration: none; font-size: 14px; background: var(--surface); }
.file-chip svg { width: 16px; height: 16px; }
.ai-status { display: flex; align-items: center; gap: 12px; max-width: 800px; margin: 0 auto; padding: 4px 24px 12px; color: var(--muted); font-size: 15px; }
.dots::after { content: "…"; display: inline-block; animation: dots 1.2s steps(4, end) infinite; overflow: hidden; vertical-align: bottom; width: 0; }
@keyframes dots { to { width: 1.2em; } }
@media (prefers-reduced-motion: reduce) { .dots::after { animation: none; width: auto; } }

/* The message box */
.composer { width: 100%; max-width: 800px; margin: 0 auto; padding: 8px 24px 16px; }
.box { display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 6px 6px 6px 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }
.box:focus-within { border-color: color-mix(in srgb, var(--brand) 50%, var(--border)); }
.box textarea { flex: 1; border: 0; outline: none; resize: none; background: none; color: var(--text); font: inherit; padding: 8px 4px; max-height: 40vh; min-height: 24px; }
.attach { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--muted); cursor: pointer; flex: none; }
.attach:hover, .attach:focus-within { background: var(--surface-2); color: var(--text); }
.attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; cursor: pointer; flex: none; }
.send:disabled { opacity: .35; cursor: default; }
.composer-hint { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.picked { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.picked span { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); }

/* A new chat */
.welcome { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 24px; text-align: center; gap: 6px; }
.welcome h1 { font-size: 28px; }
.welcome > p { max-width: 560px; }
.welcome .composer { padding: 16px 0 0; text-align: left; }
.starters { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 800px; margin-top: 4px; }
.starter { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.starter:hover { background: var(--surface-2); }

/* Contacts and logins pages */
.page { flex: 1; overflow-y: auto; padding: 28px 24px 64px; }
.page > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 440px; margin: 40px auto; }
.flash { padding: 10px 14px; border-radius: 10px; margin: 12px 24px 0; }
body.signed-out .flash { margin: 0 0 16px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.empty { color: var(--muted); padding: 20px 0; }
.stack { display: grid; gap: 14px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 14px; font-weight: 500; }
label > input, label > textarea, label > select { display: block; margin-top: 6px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%; }
.page input:focus, .page textarea:focus, .card input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.small { padding: 5px 12px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
.link.danger { color: var(--bad); }
.head { margin-bottom: 18px; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 0; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.work { background: var(--brand-soft); color: var(--brand); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list li { border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.title { font-weight: 600; }
.contacts li { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 18px; flex-wrap: wrap; }
.contact { display: grid; gap: 2px; }
.contacts .edit { flex-basis: 100%; }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details.add > summary { display: inline-flex; }
.card.add:not([open]) { background: none; border: 0; padding: 0; }
.login-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.login h2 { margin: 0 0 4px; }
.login .meta { gap: 14px; }
.login .edit { margin-top: 12px; }
.secret { display: grid; gap: 6px; justify-items: end; max-width: 100%; }
.secret code { background: var(--surface-2); padding: 6px 10px; border-radius: 8px; font-size: 15px; overflow-wrap: anywhere; user-select: all; }
.secret .notes { white-space: pre-wrap; max-width: 360px; }
.share { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; margin: 0; }
.share legend { font-size: 14px; font-weight: 600; padding: 0 4px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; margin: 0; }
.picks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; padding-left: 24px; }
.picks > div { display: grid; gap: 4px; align-content: start; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .side-open .side { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .side-open .scrim { opacity: 1; pointer-events: auto; }
  .topbar { display: flex; }
  .only-desktop { display: none !important; }
  .icon-btn.only-mobile { display: inline-grid !important; }
  .scrim.only-mobile { display: block !important; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
  .topbar-title { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
  .chat-head { padding: 10px 16px; }
  .chat-head h1 { display: none; }
  .thread, .ai-status { padding-left: 16px; padding-right: 16px; }
  .composer { padding: 6px 12px max(12px, env(safe-area-inset-bottom)); }
  .msg.k-client .bubble { max-width: 88%; }
  .welcome h1 { font-size: 23px; }
  .page { padding: 20px 16px 48px; }
  .grid, .picks { grid-template-columns: 1fr; }
  .secret { justify-items: start; }
  .flash { margin: 10px 16px 0; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* Chat groups in the sidebar */
.chats .chat { display: grid; }
.group > summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text); }
.group > summary:hover { background: var(--surface-2); }
.group > summary svg { width: 18px; height: 18px; color: var(--muted); }
.group-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-new { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: var(--muted); opacity: 0; }
.group > summary:hover .group-new, .group-new:focus-visible { opacity: 1; }
.group-new:hover { background: var(--border); color: var(--text); }
.group-new svg { width: 16px; height: 16px; }
.group-body { padding-left: 14px; margin-left: 9px; border-left: 1px solid var(--border); display: grid; gap: 1px; }
.group-empty { padding: 4px 10px; margin: 0; }
.group-menu > summary { padding: 4px 10px; opacity: 0; }
.group:hover .group-menu > summary, .group-menu[open] > summary, .group-menu > summary:focus-visible { opacity: 1; }
.group-menu[open] { padding: 0 6px 8px; display: grid; gap: 6px; }
.group-form { display: flex; gap: 6px; }
.group-form input { padding: 6px 10px; font-size: 14px; min-width: 0; }
.chats-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 12px 10px 4px; }
.new-group { margin-top: 8px; }
.new-group > summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; color: var(--muted); }
.new-group > summary:hover { background: var(--surface-2); color: var(--text); }
.new-group > summary svg { width: 18px; height: 18px; }
.new-group[open] > summary { color: var(--text); }
.new-group .group-form { padding: 4px 6px; }
.chat-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.move select { padding: 5px 30px 5px 10px; font-size: 14px; width: auto; max-width: 200px; border-radius: 10px; }
.in-group { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); padding: 4px 12px; border-radius: 99px; background: var(--surface-2); }
.in-group svg { width: 16px; height: 16px; }
@media (max-width: 860px) { .group-new, .group-menu > summary { opacity: 1; } .chat-head { flex-wrap: wrap; } .chat-tools { width: 100%; justify-content: space-between; } }

.archived-chats { margin-top: 8px; }
.archived-chats > summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; color: var(--muted); }
.archived-chats > summary:hover { background: var(--surface-2); color: var(--text); }
.archived-chats > summary svg { width: 18px; height: 18px; }
