/* Noesis Playground — lapis ink on vellum (same language as the Admin). Light by default. */

/* self-hosted fonts (CSP: style-src 'self'; URLs relative to this stylesheet) */
@font-face { font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("vendor/fonts/inter-var.woff2") format("woff2"); }
@font-face { font-family: "Instrument Serif"; font-style: normal; font-weight: 400; font-display: swap; src: url("vendor/fonts/instrument-serif-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("vendor/fonts/ibm-plex-mono-400.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("vendor/fonts/ibm-plex-mono-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 600; font-display: swap; src: url("vendor/fonts/ibm-plex-mono-600.woff2") format("woff2"); }

:root {
  --bg: oklch(0.975 0.006 85);
  --surface: oklch(0.994 0.0035 85);
  --surface-2: oklch(0.958 0.007 85);
  --ink: oklch(0.235 0.018 265);
  --ink-2: oklch(0.335 0.02 265);
  --muted: oklch(0.505 0.018 265);
  --line: oklch(0.905 0.009 85);
  --lapis: oklch(0.44 0.17 268);
  --lapis-2: oklch(0.385 0.165 268);
  --lapis-soft: oklch(0.937 0.028 268);
  --ok: oklch(0.545 0.115 152);
  --danger: oklch(0.55 0.185 33);
  --danger-soft: oklch(0.955 0.025 33);
  --radius: 12px;
  --shadow: 0 1px 1.5px oklch(0.25 0.02 265 / 0.05), 0 6px 18px oklch(0.25 0.02 265 / 0.055);
  --serif: "Instrument Serif", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --col: clamp(720px, 58vw, 1080px); /* conversation column: grows on wide screens */
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); }
button, input, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: .9em; background: var(--lapis-soft); padding: .1em .35em; border-radius: 5px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--lapis); outline-offset: 2px; }

.shell { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; padding: 18px 16px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 4px 6px; }
.mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--lapis); color: #fff; font: 600 21px/1 var(--serif); letter-spacing: -.02em; }
.wordmark { font: 600 21px/1.1 var(--serif); letter-spacing: .02em; }
.tagline { color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-title { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.panel-head .panel-title { margin: 0; }
#keyForm { display: flex; gap: 6px; }
#keyForm input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--surface); font-family: var(--mono); font-size: 13px; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.error { margin: 8px 0 0; color: var(--danger); font-size: 13px; }
.tenant { margin-bottom: 8px; min-width: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(31, 138, 91, .15); margin-right: 8px; vertical-align: middle; }
.tenant-name { font-weight: 600; margin-bottom: 2px; }
.tenant-meta { color: var(--muted); font-size: 12px; font-family: var(--mono); padding-left: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list { list-style: none; margin: 0 -4px; padding: 0; overflow-y: auto; flex: 1; min-height: 60px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 8px; padding: 2px 4px; }
.conv:hover, .conv.active { background: var(--lapis-soft); }
.conv-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 4px; cursor: pointer; }
.conv-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv.active .conv-name { font-weight: 600; color: var(--lapis-2); }
.conv-sub { display: block; color: var(--muted); font-size: 11.5px; }
.conv-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.conv:hover .conv-actions, .conv:focus-within .conv-actions, .conv.active .conv-actions { opacity: 1; }
.conv-rename-input { width: 100%; border: 1px solid var(--lapis); border-radius: 6px; padding: 4px 6px; font-size: 14px; }
.empty { color: var(--muted); font-size: 13px; margin: 8px 0; }
.conv-footer { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; font-size: 13px; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--danger); }
.usage { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.docs-link { color: var(--lapis); text-decoration: none; font-size: 13px; padding: 0 4px; }
.docs-link:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #cfd5e1; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.primary { background: var(--lapis); border-color: var(--lapis); color: #fff; }
.btn.primary:hover { background: var(--lapis-2); }
.btn.primary:disabled { background: #b8bfdf; border-color: #b8bfdf; cursor: not-allowed; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--lapis-soft); }
.danger-text { color: var(--danger) !important; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); border-radius: 6px; width: 28px; height: 28px; display: grid; place-items: center; font-size: 14px; }
.icon-btn:hover { background: #e3e7f5; color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(244, 246, 249, .9); }
.conv-title { font: 600 16px/1.2 var(--serif); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { flex: 1; overflow-y: auto; padding: 28px 22px 12px; }
.thread > * { max-width: var(--col); margin-left: auto; margin-right: auto; }

.welcome { text-align: center; padding: 8vh 0 0; color: var(--ink-2); }
.welcome-mark { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 16px; background: var(--lapis); color: #fff; font: 600 34px/1 var(--serif); }
.welcome h1 { font: 600 28px/1.2 var(--serif); color: var(--ink); margin: 0 0 10px; }
.welcome p { max-width: 520px; margin: 0 auto 22px; }
.steps { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 0; margin: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow); }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--lapis-soft); color: var(--lapis); font-size: 12px; font-weight: 700; margin-right: 8px; }

.msg { margin: 0 auto 18px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble { max-width: 100%; border-radius: 14px; padding: 11px 15px; }
.msg.user .bubble { background: var(--lapis); color: #fff; border-bottom-right-radius: 4px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-bottom-left-radius: 4px; overflow-wrap: anywhere; }
.msg.error .bubble { background: var(--danger-soft); border-color: #f1c9c6; color: #7b2320; }
.msg.incomplete .bubble { border-left: 3px solid #d99a2b; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; color: #8a5a0b; background: #fbf1dc; border-radius: 999px; padding: 1px 8px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.meta .btn { padding: 2px 8px; font-size: 12px; }
.cursor::after { content: "▍"; color: var(--lapis); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } }
.thinking { color: var(--muted); font-style: italic; }

/* markdown inside answers */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .55em 0; }
/* prose stays at a readable measure; tables and code may use the full column */
.md p, .md li, .md blockquote, .md h1, .md h2, .md h3, .md h4 { max-width: 78ch; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); line-height: 1.25; margin: 1em 0 .4em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li { margin: .2em 0; }
.md blockquote { margin: .6em 0; padding: .2em .9em; border-left: 3px solid var(--lapis-soft); color: var(--ink-2); }
.md pre { background: #10172b; color: #e6e9f2; border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
.md pre code { background: none; padding: 0; color: inherit; }
.md a { color: var(--lapis); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md .table-wrap { overflow-x: auto; margin: .6em 0; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 50%; overflow-wrap: normal; word-break: normal; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; overflow-wrap: normal; word-break: normal; min-width: 7ch; }
.md th { white-space: nowrap; }
.md th { background: var(--surface-2); font-weight: 600; }

/* composer */
.composer { padding: 10px 22px 16px; border-top: 1px solid var(--line); background: var(--bg); }
.composer > * { max-width: var(--col); margin-left: auto; margin-right: auto; }
.options { margin-bottom: 8px; font-size: 13px; color: var(--ink-2); }
.options summary { cursor: pointer; width: max-content; color: var(--muted); }
.options label { display: block; margin-top: 8px; font-weight: 500; }
.options textarea, .options input { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--surface); font-weight: 400; resize: vertical; }
.muted { color: var(--muted); font-weight: 400; }
.input-row { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; box-shadow: var(--shadow); }
.input-row:focus-within { border-color: #aab4e3; }
#message { flex: 1; border: 0; resize: none; outline: none; padding: 6px 6px; max-height: 220px; background: transparent; }
#message:disabled { cursor: not-allowed; }
.send { height: 36px; }
.composer-hint { color: var(--muted); font-size: 11.5px; margin-top: 6px; text-align: right; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 50; }

.only-mobile { display: none; }

@media (min-width: 1800px) {
  body { font-size: 16px; }
  .shell { grid-template-columns: 320px 1fr; }
}

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 40; box-shadow: 0 0 40px rgba(22, 33, 58, .25); transform: translateX(-105%); transition: transform .18s; }
  .sidebar.open { transform: none; }
  .only-mobile { display: grid; }
  .brand .only-mobile { margin-left: auto; }
  .topbar, .thread, .composer { padding-left: 14px; padding-right: 14px; }
  .conv-actions { opacity: 1; }
  .welcome { padding-top: 4vh; }
  .welcome h1 { font-size: 23px; }
  .msg.user .bubble { max-width: 92%; }
}
