/* Kwik AI – Kwik red on concrete grey / graphite, same family as the other Kwik apps */
:root {
  --red: #e00000;
  --red-strong: #ff0000;
  --red-soft: #fde8e8;
  --bg: #f4f4f2;
  --panel: #ffffff;
  --side: #1c1d1f;
  --side-2: #2a2b2e;
  --side-text: #e8e8e6;
  --side-muted: #9a9b9e;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e2e2de;
  --bubble: #ffffff;
  --code: #f0f0ed;
  --ok: #1f8a3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #161718;
  --panel: #202123;
  --side: #0f1011;
  --side-2: #1d1e20;
  --text: #ececea;
  --muted: #a0a09c;
  --line: #313235;
  --bubble: #2a2b2e;
  --code: #26272a;
  --red-soft: #3a1414;
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161718; --panel: #202123; --side: #0f1011; --side-2: #1d1e20; --text: #ececea; --muted: #a0a09c;
    --line: #313235; --bubble: #2a2b2e; --code: #26272a; --red-soft: #3a1414; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15.5px/1.55 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--red); min-height: 1.2em; }

.btn { display: inline-flex; align-items: center; gap: 8px; justify-content: center; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; background: transparent; border-radius: 10px; color: var(--muted); flex: none; }
.icon-btn:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--red-soft), transparent 60%), var(--bg); }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 40px 32px; width: min(420px, 100%); text-align: center; box-shadow: var(--shadow); display: grid; gap: 14px; justify-items: center; }
.login-logo { width: 64px; height: 64px; }
.login h1 { margin: 0; font-size: 30px; letter-spacing: -0.5px; }
.login h1 span, .brand b { color: var(--red); }
.login-form { width: 100%; display: grid; gap: 12px; text-align: left; }
.login-form label { display: grid; gap: 5px; font-size: 14px; font-weight: 600; }
.login-form label[hidden] { display: none; }
.login-form input { font: inherit; font-weight: 400; font-size: 16px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none; }
.login-form input:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.login-form .btn { padding: 12px 14px; font-size: 16px; margin-top: 4px; }
.login-form .btn:disabled { opacity: 0.6; }
.link-btn { border: 0; background: none; color: var(--red); font: inherit; font-weight: 600; cursor: pointer; padding: 4px; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; gap: 12px; padding: 14px 12px; min-height: 0; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-size: 19px; font-weight: 700; letter-spacing: -0.2px; }
.brand img { width: 30px; height: 30px; }
.sidebar .icon-btn { color: var(--side-muted); }
.sidebar .icon-btn:hover { background: var(--side-2); color: #fff; }
.search { width: 100%; border: 1px solid var(--side-2); background: var(--side-2); color: var(--side-text); border-radius: 10px; padding: 8px 12px; outline: none; }
.search:focus { border-color: #555; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.group-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--side-muted); margin: 14px 8px 4px; }
.chat-item { display: flex; align-items: center; border-radius: 9px; position: relative; }
.chat-item a { flex: 1; min-width: 0; padding: 8px 10px; color: var(--side-text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.chat-item:hover, .chat-item.active { background: var(--side-2); }
.chat-item.active { box-shadow: inset 3px 0 0 var(--red); }
.chat-item .more { opacity: 0; width: 30px; height: 30px; }
.chat-item:hover .more, .chat-item.active .more, .chat-item .more:focus { opacity: 1; }
.side-foot { position: relative; border-top: 1px solid var(--side-2); padding-top: 10px; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; border-radius: 10px; padding: 6px 8px; text-align: left; color: var(--side-text); }
.user-btn:hover { background: var(--side-2); }
.user-btn img { width: 32px; height: 32px; border-radius: 50%; background: var(--red); flex: none; object-fit: cover; }
.user-btn span { flex: 1; min-width: 0; display: grid; }
.user-btn b, .user-btn small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn small { color: var(--side-muted); font-size: 12px; }
.menu { position: absolute; bottom: 58px; left: 0; right: 0; background: var(--side-2); border: 1px solid #3a3b3e; border-radius: 12px; padding: 6px; display: grid; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.menu button { background: none; border: 0; text-align: left; padding: 9px 10px; border-radius: 8px; color: var(--side-text); }
.menu button:hover { background: #3a3b3e; }
.menu.floating { position: fixed; bottom: auto; left: auto; right: auto; width: 180px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); min-height: 56px; }
.chat-title { font-size: 15px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.sources { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; background: var(--panel); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #bbb; }
.chip.on::before { background: var(--ok); }

.scroller { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages { max-width: 820px; margin: 0 auto; padding: 24px 20px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }

/* ---------- empty state ---------- */
.empty { max-width: 760px; margin: 8vh auto 0; padding: 0 20px; text-align: center; }
.empty-logo { width: 56px; height: 56px; }
.empty h1 { font-size: clamp(26px, 4vw, 34px); margin: 12px 0 4px; letter-spacing: -0.5px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-top: 26px; text-align: left; }
.suggestion { text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.suggestion:hover { border-color: var(--red); }
.suggestion b { display: block; font-size: 14px; }
.suggestion span { font-size: 13px; color: var(--muted); }

/* ---------- messages ---------- */
.msg { display: grid; gap: 8px; min-width: 0; }
.msg.user { justify-items: end; }
.msg.user .bubble { background: var(--bubble); border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.att-list { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.att-pill { font-size: 12.5px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 3px 9px; }
.msg.assistant { grid-template-columns: 30px minmax(0, 1fr); column-gap: 12px; align-items: start; }
.msg.assistant > .avatar { width: 30px; height: 30px; grid-row: 1 / span 20; margin-top: 2px; }
.msg.assistant > .body { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 0.7em; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1em 0 0.4em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.05em; }
.md a { color: var(--red); }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--code); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--code); border: 1px solid var(--line); padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 0.7em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md .table-wrap { overflow-x: auto; margin: 0 0 0.8em; border: 1px solid var(--line); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: var(--code); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 1em; background: var(--red); margin-left: 2px; vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.thinking { border-left: 2px solid var(--line); padding-left: 12px; color: var(--muted); font-size: 14px; }
.thinking summary { cursor: pointer; list-style: none; user-select: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "▸ "; }
.thinking[open] summary::before { content: "▾ "; }
.thinking .md { margin-top: 6px; font-size: 13.5px; }

.tool { display: grid; gap: 6px; }
.tool-line { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px 4px 8px; width: fit-content; max-width: 100%; }
.tool-line .ico { width: 16px; height: 16px; flex: none; display: grid; place-items: center; }
.tool-line .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-line .sum { opacity: 0.8; white-space: nowrap; }
.tool.ok .ico { color: var(--ok); }
.tool.fail .ico { color: var(--red); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.web-links { display: flex; flex-wrap: wrap; gap: 6px; }
.web-links a { font-size: 12.5px; color: var(--muted); text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 4px 0 8px; }
.file-card { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 9px 11px; text-decoration: none; color: var(--text); min-width: 0; box-shadow: var(--shadow); }
.file-card:hover { border-color: var(--red); }
.md a.file-card { color: var(--text); text-decoration: none; }
.file-card .ext { width: 38px; height: 38px; border-radius: 8px; background: var(--red-soft); color: var(--red); font-weight: 800; font-size: 11px; display: grid; place-items: center; flex: none; text-transform: uppercase; }
.file-card .meta { min-width: 0; display: grid; }
.file-card .meta b { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .meta small { color: var(--muted); font-size: 12px; }
.file-card .dl { margin-left: auto; color: var(--muted); flex: none; }
.md .files { margin: 6px 0 10px; }

.notice { font-size: 13.5px; color: var(--muted); font-style: italic; }
.err { font-size: 14px; color: var(--red); background: var(--red-soft); border-radius: 10px; padding: 8px 12px; }
.actions { display: flex; gap: 2px; opacity: 0.6; }
.actions:hover { opacity: 1; }
.actions .icon-btn { width: 30px; height: 30px; }

/* ---------- composer ---------- */
.composer { padding: 8px 20px calc(10px + env(safe-area-inset-bottom)); max-width: 860px; width: 100%; margin: 0 auto; }
.composer-box { display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 7px; box-shadow: var(--shadow); }
.composer-box:focus-within { border-color: color-mix(in srgb, var(--red) 60%, var(--line)); }
.composer textarea { flex: 1; border: 0; outline: none; background: transparent; resize: none; font: inherit; color: var(--text); padding: 8px 4px; max-height: 40vh; line-height: 1.45; }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--red); color: #fff; display: grid; place-items: center; flex: none; }
.send:disabled { background: color-mix(in srgb, var(--muted) 40%, transparent); cursor: default; }
.send .i-stop { display: none; }
.busy .send .i-send { display: none; }
.busy .send .i-stop { display: block; }
.busy .send { background: var(--text); color: var(--bg); }
.composer > .tiny { margin: 6px 0 0; }
.attachments { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.attachment { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 4px 4px 4px 8px; }
.attachment img { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; }
.attachment button { border: 0; background: none; color: var(--muted); width: 22px; height: 22px; border-radius: 6px; }
.drop { position: absolute; inset: 10px; border: 2px dashed var(--red); border-radius: 18px; background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--red); z-index: 30; pointer-events: none; }

/* ---------- dialog / toast ---------- */
.dlg { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(860px, 94vw); max-height: 86vh; background: var(--panel); color: var(--text); }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line); margin: 0; }
.dlg-head h3 { margin: 0; font-size: 17px; }
.dlg-body { padding: 16px 20px 22px; overflow: auto; max-height: calc(86vh - 60px); }
.dlg-body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dlg-body th, .dlg-body td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.dlg-body select, .dlg-body input { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 50; }

/* ---------- phones ---------- */
.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .topbar { padding: 8px 10px; }
  .sources { display: none; }
  .messages { padding: 16px 14px 8px; }
  .composer { padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); }
  .msg.assistant { grid-template-columns: minmax(0, 1fr); }
  .msg.assistant > .avatar { display: none; }
  .msg.user .bubble { max-width: 92%; }
  body { font-size: 16px; }
}
