/* Krew Desk — no build step, no external assets. Light/dark via prefers-color-scheme. */
:root {
  /* Krew brand (brand/tokens.json). --brand can be overridden per box (white label: desk.primary_color). */
  --brand: #2563eb;
  --link: color-mix(in srgb, var(--brand) 82%, #000);
  --bg: #f7f6f3;
  --panel: #ffffff;
  --panel-2: #f1f0ec;
  --line: #e3e5e8;
  --text: #111318;
  --muted: #646b76;
  --faint: #8c929b;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --mine: color-mix(in srgb, var(--brand) 10%, var(--panel));
  --shadow: 0 1px 2px rgba(17, 19, 24, .05), 0 1px 3px rgba(17, 19, 24, .07);
  --radius: 10px;
  --sidebar: 264px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --link: color-mix(in srgb, var(--brand) 50%, #fff);
    --bg: #111318;
    --panel: #181b21;
    --panel-2: #20242c;
    --line: #2c313b;
    --text: #ecedef;
    --muted: #a0a7b3;
    --faint: #727985;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #f87171;
    --mine: color-mix(in srgb, var(--brand) 24%, var(--panel));
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
h1, h2, .doc-title, .topbar .title, .brand .name, .login-card h1 { letter-spacing: -.02em; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 10px; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 14px 0 4px; font-size: 24px; font-weight: 400; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }
.error { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 1em; }
.logo { width: 44px; height: 44px; border-radius: 23.4%; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.logo.mark { background: none; }
@media (prefers-color-scheme: dark) { .logo.mark img { box-shadow: 0 0 0 1px #3a404c; } }
.logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 23.4%; }
.wordmark b { font-weight: 700; }
.wordmark span { font-weight: 400; color: var(--muted); margin-left: .28em; }

/* shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.brand .logo { width: 30px; height: 30px; font-size: 14px; }
.brand .name { font-weight: 650; font-size: 16px; }
.brand .sub { font-size: 12px; color: var(--muted); }
.nav { overflow-y: auto; padding: 6px 8px 16px; flex: 1; }
.nav h3 { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); margin: 16px 10px 6px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text); cursor: pointer; text-decoration: none !important; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: color-mix(in srgb, var(--brand) 12%, var(--panel)); }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .meta { font-size: 12px; color: var(--faint); }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 11.5px; padding: 1px 7px; font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sidebar-foot .grow { flex: 1; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 650; font-size: 12px; flex: none; position: relative; }
.avatar.lg { width: 38px; height: 38px; font-size: 14px; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); background: var(--faint); }
.dot.running { background: var(--ok); }
.dot.working { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.offline, .dot.stopped, .dot.disabled { background: var(--faint); }
.dot.crashloop { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
.space-ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--panel-2); color: var(--muted); flex: none; font-size: 13px; font-weight: 600; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 62px; }
.topbar .title { font-weight: 650; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .subtitle { font-size: 13px; color: var(--muted); }
.topbar .grow { flex: 1; min-width: 0; }
.menu-btn { display: none; }
.content { flex: 1; overflow-y: auto; min-height: 0; }
.pad { padding: 20px; max-width: 980px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 18px; color: var(--text); margin-bottom: 6px; font-weight: 600; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.running { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--panel)); }
.pill.working { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, var(--panel)); }

/* chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px 20px 8px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 9px 13px; min-width: 0; max-width: min(620px, 100%); overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .who time { color: var(--faint); margin-left: 6px; }
.msg .ctx { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.day { align-self: center; font-size: 12px; color: var(--faint); margin: 8px 0; }
.working-line { padding: 4px 20px 0; font-size: 13px; color: var(--warn); min-height: 22px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 20px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: none; max-height: 200px; min-height: 42px; }
.composer .btn { height: 42px; }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .5em 0; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1em 0 .4em; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.08em; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--panel-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li.task { list-style: none; margin-left: -1.3em; }
.md table { border-collapse: collapse; margin: .6em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }

/* review card */
.review { border: 1px solid color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--panel); border-radius: 12px; overflow: hidden; width: 100%; max-width: 620px; box-shadow: var(--shadow); }
.review .rh { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: color-mix(in srgb, var(--brand) 8%, var(--panel)); font-weight: 600; }
.review .rh .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review .rb { padding: 10px 14px; max-height: 260px; overflow-y: auto; border-top: 1px solid var(--line); }
.review .rf { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.review .rf .note { color: var(--muted); font-size: 13px; flex: 1; }
.review.full .rb { max-height: none; }

/* spaces & pages */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { flex: 1; min-width: 180px; }
.page-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.page-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); color: var(--text); text-decoration: none !important; }
.page-row:first-child { border-top: 0; }
.page-row:hover { background: var(--panel-2); }
.page-row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.page-row .m { font-size: 12.5px; color: var(--faint); white-space: nowrap; }
.page-ic { color: var(--faint); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }

.editor { display: grid; grid-template-columns: 1fr 340px; height: 100%; min-height: 0; }
.editor.no-chat { grid-template-columns: 1fr; }
.doc { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.doc-head { padding: 16px 24px 8px; display: flex; flex-direction: column; gap: 8px; }
.doc-title { font-size: 26px; font-weight: 700; border: 0; background: transparent; outline: none; width: 100%; padding: 0; }
.doc-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 11px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--panel-2); font-weight: 600; }
.save-state { font-size: 12.5px; color: var(--faint); margin-left: auto; }
.save-state.bad { color: var(--bad); }
.doc-body { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; border-top: 1px solid var(--line); }
.doc-body.edit, .doc-body.view { grid-template-columns: 1fr; }
.doc-body textarea { border: 0; resize: none; padding: 18px 24px; background: var(--panel); outline: none; font: 14px/1.6 var(--mono); min-height: 0; height: 100%; }
.doc-body .preview { padding: 18px 24px; overflow-y: auto; border-left: 1px solid var(--line); min-height: 0; }
.doc-body.view .preview { border-left: 0; max-width: 820px; }
.doc-body.edit .preview, .doc-body.view textarea { display: none; }
.banner { margin: 0 24px 8px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--warn) 14%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.banner .grow { flex: 1; min-width: 200px; }
.side-chat { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side-chat .sc-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; font-weight: 600; }
.side-chat .messages { padding: 12px; }
.side-chat .msg .bubble { max-width: 100%; box-shadow: none; }
.side-chat .composer { padding: 10px 12px 12px; }

/* settings */
.section { margin-bottom: 28px; }
.section h2 { font-size: 16px; margin: 0 0 4px; }
.section p.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
table.matrix { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.matrix th, .matrix td { padding: 8px 10px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
.matrix thead th { background: var(--panel-2); font-weight: 600; border-top: 0; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kv { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); }
.kv:first-child { border-top: 0; }
.kv .grow { flex: 1; min-width: 0; }
.secret { font-family: var(--mono); font-size: 13px; background: var(--panel-2); padding: 8px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; font-size: 14px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.scrim { display: none; }

/* phone */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); z-index: 30; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; min-height: 56px; }
  .pad { padding: 16px; }
  .messages { padding: 14px 16px 8px; }
  .composer { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
  .working-line { padding: 4px 16px 0; }
  .msg .bubble { max-width: 100%; }
  .editor { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side-chat { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .side-chat.collapsed .messages, .side-chat.collapsed .composer { display: none; }
  .doc-body { grid-template-columns: 1fr; }
  .doc-body.split .preview { display: none; }
  .doc-head { padding: 12px 16px 6px; }
  .doc-title { font-size: 21px; }
  .doc-body textarea, .doc-body .preview { padding: 14px 16px; }
  .banner { margin: 0 16px 8px; }
  .page-row .m.opt { display: none; }
}
