/* Bialek AI. "Dusk" palette shared with The Bialek Dispatch; follows the device's light/dark setting. */
:root {
  --bg: #F1EEE8; --card: #F8F6F2; --ink: #2A2C2F; --muted: #85827C; --line: #E0DBD2; --accent: #A8823F; --ph: #E7E2D9;
  --you: #E9E4DA; --danger: #A5473A; --ok: #4F7A52;
  --serif: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, serif;
  --display: Baskerville, "Baskerville Old Face", "Libre Baskerville", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --rail: 272px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1E2124; --card: #25292D; --ink: #D9D6CF; --muted: #8C8A85; --line: #33373B; --accent: #C9A46A; --ph: #2C3034;
          --you: #2B3035; --danger: #D27B6C; --ok: #8DB58F; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- Sign-in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 360px; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 16px; }
.login h1 { font: 400 32px/1.1 var(--display); margin: 18px 0 6px; }
.login p { color: var(--muted); margin: 0 0 22px; font-family: var(--serif); font-style: italic; }
.login .setup { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.login .msg { min-height: 1.5em; margin-top: 14px; color: var(--danger); font-size: 14px; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 14px; line-height: 1.2; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #1E2124; } }
.btn.big { width: 100%; padding: 12px 16px; font-size: 17px; }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); padding: 4px 8px; }
.btn.quiet:hover { color: var(--ink); }
.btn.danger { color: var(--danger); }
.field { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 9px 12px; }
.field:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea.field { resize: vertical; line-height: 1.5; }

/* ---------- App frame ---------- */
.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.rail { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--bg);
  padding: max(18px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) 18px; }
.mast { display: flex; align-items: center; gap: 10px; padding: 0 4px 14px; border-bottom: 1px solid var(--line); }
.mast img { width: 32px; height: 32px; border-radius: 8px; }
.mast h1 { margin: 0; font: 400 23px/1 var(--display); flex: 1; }
.rail .tools { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px 0 10px; }
.rail .tools .btn { text-align: left; }
.search { padding: 0 0 10px; }
.search input { padding: 7px 11px; font-size: 14px; }
.tree { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; }
.proj { margin-bottom: 8px; }
.proj > header { display: flex; align-items: center; gap: 4px; }
.proj > header button.name { flex: 1; text-align: left; border: 0; background: none; padding: 5px 4px;
  font: 600 11.5px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.proj > header button.name:hover { color: var(--ink); }
.proj > header .mini { border: 0; background: none; color: var(--muted); padding: 2px 6px; font-size: 15px; opacity: .55; }
.proj > header .mini:hover { opacity: 1; color: var(--ink); }
.proj ul { list-style: none; margin: 0; padding: 0; }
.proj li a { display: block; padding: 5px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; font: 15px/1.3 var(--serif);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj li a:hover { background: var(--ph); }
.proj li a.on { background: var(--you); }
.proj .more { font-size: 13px; color: var(--muted); padding: 3px 8px; border: 0; background: none; }
.railfoot { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 2px; }
.railfoot a { display: flex; justify-content: space-between; padding: 5px 6px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.railfoot a:hover { background: var(--ph); }
.railfoot a.on { background: var(--you); }
.railfoot .badge { background: var(--accent); color: #fff; border-radius: 9px; font-size: 12px; padding: 0 7px; line-height: 18px; }
.railfoot .cost { color: var(--muted); font-size: 13px; padding: 6px 6px 0; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 20px 12px; border-bottom: 1px solid var(--line); }
.topbar .menu { display: none; border: 0; background: none; font-size: 22px; padding: 0 6px 0 0; line-height: 1; }
.topbar .title { flex: 1; min-width: 0; font: 500 18px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { font: 13px var(--sans); color: var(--muted); margin-left: 8px; }
.topbar select { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 8px; font-size: 14px; max-width: 46vw; }

.alerts { padding: 0 20px; }
.alert { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; padding: 10px 14px; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 8px; background: var(--card); font-size: 14.5px; }
.alert p { margin: 0; flex: 1 1 280px; }

/* ---------- Conversation ---------- */
.scroll { flex: 1; overflow-y: auto; min-height: 0; }
.thread { max-width: 780px; margin: 0 auto; padding: 22px 20px 30px; }
.empty { text-align: center; color: var(--muted); padding-top: 18vh; font-family: var(--serif); }
.empty h2 { font: 400 30px var(--display); color: var(--ink); margin: 0 0 8px; }
.msg { margin: 0 0 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { max-width: 85%; background: var(--you); border-radius: 14px 14px 4px 14px; padding: 9px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body { font: 17px/1.6 var(--serif); overflow-wrap: anywhere; }
.body > :first-child { margin-top: 0; } .body > :last-child { margin-bottom: 0; }
.body h1, .body h2, .body h3 { font-family: var(--serif); line-height: 1.25; margin: 1.2em 0 .4em; }
.body h1 { font-size: 1.35em; } .body h2 { font-size: 1.2em; } .body h3 { font-size: 1.05em; }
.body code { font: .86em var(--mono); background: var(--ph); padding: .1em .35em; border-radius: 4px; }
.body pre { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; font: 15px/1.4 var(--sans); margin: 1em 0; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.body th { background: var(--card); }
.body blockquote { margin: 1em 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.body img { max-width: 100%; border-radius: 8px; }
.images { display: grid; gap: 10px; margin-top: 10px; }
.images img { width: 100%; max-width: 640px; border-radius: 10px; display: block; }
.foot { margin-top: 8px; font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.foot .err { color: var(--danger); }
.foot .redo { opacity: 0; transition: opacity .15s; }
.msg:hover .foot .redo, .msg:last-child .foot .redo { opacity: 1; }
.foot .redo a { color: var(--muted); }
.foot .redo a:hover { color: var(--accent); }
.sources { margin-top: 10px; font-size: 13.5px; }
.sources summary { color: var(--muted); cursor: pointer; }
.sources ol { margin: 6px 0 0; padding-left: 22px; }
.sources a { word-break: break-all; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--muted); font-style: italic; font-family: var(--serif); }
.suggest { margin-top: 12px; display: grid; gap: 8px; }
.suggest .card { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 9px 12px; border: 1px dashed var(--line); border-radius: 8px; font-size: 14.5px; }
.suggest .card p { margin: 0; flex: 1 1 260px; } .suggest .card b { font-weight: 600; color: var(--accent); }

.composer { padding: 10px 20px max(14px, env(safe-area-inset-bottom)); }
.composer form { max-width: 780px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end;
  border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 8px 8px 8px 14px; }
.composer textarea { flex: 1; border: 0; background: none; resize: none; outline: none; max-height: 40vh; padding: 6px 0; line-height: 1.45; }
.composer .send { border: 0; background: var(--accent); color: #fff; width: 38px; height: 38px; border-radius: 10px; font-size: 18px; flex: none; }
@media (prefers-color-scheme: dark) { .composer .send { color: #1E2124; } }
.composer .send.stop { background: var(--muted); }
.composer .hint { max-width: 780px; margin: 6px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Pages (facts, vault, project, settings) ---------- */
.page { max-width: 780px; margin: 0 auto; padding: 24px 20px 60px; }
.page h2 { font: 400 28px var(--display); margin: 0 0 4px; }
.page .lede { color: var(--muted); margin: 0 0 22px; font-family: var(--serif); font-style: italic; }
.page h3 { font: 600 12px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
.facts { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.facts li { display: flex; gap: 8px; align-items: flex-start; border-bottom: 1px solid var(--line); padding: 8px 0; }
.facts li .text { flex: 1; padding: 4px 2px; border-radius: 6px; outline: none; font-family: var(--serif); font-size: 16.5px; }
.facts li .text:focus { background: var(--card); box-shadow: 0 0 0 1px var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.label { font-size: 13px; color: var(--muted); display: grid; gap: 5px; }
.notelist { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.notelist li a { display: block; padding: 10px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.notelist li a b { font: 500 16.5px var(--serif); display: block; }
.notelist li a span { font-size: 13.5px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notelist li a em { font-style: normal; color: var(--accent); font-size: 12px; margin-left: 6px; }
.results a { display: block; padding: 8px 2px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.results a span { display: block; font-size: 13.5px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px;
  border-radius: 20px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }
.scrim { display: none; }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30; transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.18); }
  .app.open .rail { transform: none; }
  .app.open .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.25); }
  .topbar { padding-left: 14px; padding-right: 14px; }
  .topbar .menu { display: block; }
  .thread, .page { padding-left: 16px; padding-right: 16px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .composer .hint { display: none; }
  .alerts { padding: 0 14px; }
  .msg.assistant .body { font-size: 16.5px; }
}
