/* The web app's own chrome (`00-OpenDocWeb.md §3.4`). Colours are tokens,
   redefined for dark mode, so the page and the editor agree. */
:root {
  --fg: #1c1c1e; --bg: #ffffff; --muted: #6b6b70; --rule: #d8d8dc;
  --header-bg: #f2f2f7; --accent: #0a84ff; --panel: #f7f7f9; --danger: #d70015;
  --ok: #248a3d; --warn-bg: #fff4d6; --warn-fg: #6a4a00; --bubble: #e9f2ff;
  --sans: -apple-system, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f2f2f7; --bg: #1c1c1e; --muted: #98989f; --rule: #3a3a3c;
    --header-bg: #2c2c2e; --panel: #232325; --warn-bg: #3a300f; --warn-fg: #ffd98a; --bubble: #173152;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 14px; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--header-bg); border: 1px solid var(--rule); border-radius: 7px;
  padding: 4px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
select, input[type=text], input[type=password], textarea {
  background: var(--bg); border: 1px solid var(--rule); border-radius: 7px; padding: 4px 8px;
}
a { color: var(--accent); }

#app { display: flex; flex-direction: column; height: 100%; }
#app > main { flex: 1; }
header.bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  border-bottom: 1px solid var(--rule); background: var(--panel); min-width: 0;
}
header.bar .brand { font-weight: 700; letter-spacing: 0.2px; }
header.bar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
header.bar .state { color: var(--muted); font-size: 12px; white-space: nowrap; }
header.bar .spacer { flex: 1; }
.banner { padding: 8px 12px; background: var(--warn-bg); color: var(--warn-fg); border-bottom: 1px solid var(--rule); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner:empty { display: none; }

main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
main.no-chat { grid-template-columns: minmax(0, 1fr); }
main.no-chat #chat { display: none; }
#docpane { overflow: auto; min-height: 0; position: relative; }
#editor { max-width: 860px; margin: 0 auto; min-height: 100%; }
#source { display: none; width: 100%; height: 100%; border: none; border-radius: 0; padding: 20px 24px; font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: none; }
#docpane.source #editor { display: none; }
#docpane.source #source { display: block; }
.locked .ProseMirror { opacity: 0.75; }

#welcome { max-width: 640px; margin: 48px auto; padding: 0 20px; line-height: 1.55; }
#welcome h1 { font-size: 28px; margin-bottom: 4px; }
#welcome .lead { color: var(--muted); margin-top: 0; }
#welcome .actions { display: flex; gap: 10px; margin: 20px 0; flex-wrap: wrap; }
#welcome .fine { color: var(--muted); font-size: 12.5px; }

#chat { border-left: 1px solid var(--rule); display: grid; grid-template-rows: auto auto 1fr auto auto; min-height: 0; background: var(--panel); }
#chat .row { display: flex; gap: 6px; align-items: center; padding: 8px 10px 0; flex-wrap: wrap; }
#chat .row select { max-width: 100%; }
#chat #sessions { flex: 1; min-width: 0; }
#transcript { overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.msg { padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.user { background: var(--bubble); align-self: flex-end; max-width: 88%; }
.msg.assistant { background: var(--bg); border: 1px solid var(--rule); }
.msg.notice { color: var(--muted); font-size: 12px; text-align: center; background: none; padding: 2px; }
.msg.error { color: var(--danger); background: none; border: 1px solid var(--danger); }
.tool { font-size: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--bg); }
.tool summary { cursor: pointer; padding: 5px 8px; color: var(--muted); }
.tool summary b { color: var(--fg); font-weight: 600; }
.tool.error summary b { color: var(--danger); }
.tool pre { margin: 0; padding: 6px 8px; border-top: 1px solid var(--rule); white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 11.5px; max-height: 260px; overflow: auto; }
.ask { border: 1px solid var(--accent); border-radius: 8px; padding: 8px; background: var(--bg); font-size: 12.5px; }
.ask .buttons { display: flex; gap: 6px; margin-top: 6px; }
#composer { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--rule); }
#composer textarea { flex: 1; resize: none; height: 64px; }
#status { padding: 0 10px 8px; font-size: 12px; color: var(--muted); min-height: 1.5em; }

dialog { border: 1px solid var(--rule); border-radius: 12px; padding: 0; background: var(--bg); color: var(--fg); width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog .head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
dialog .head h2 { font-size: 16px; margin: 0; flex: 1; }
dialog .body { padding: 12px 16px; overflow: auto; max-height: calc(100dvh - 160px); }
dialog .foot { padding: 10px 16px; border-top: 1px solid var(--rule); display: flex; gap: 8px; justify-content: flex-end; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; word-break: break-all; }
.crumbs button { font-size: 12.5px; }
ul.files { list-style: none; margin: 0; padding: 0; }
ul.files li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--rule); cursor: pointer; }
ul.files li:hover { background: var(--header-bg); }
ul.files li .icon { width: 1.4em; text-align: center; }
ul.files li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ul.files li.doc .name { font-weight: 600; }
ul.files li .kind { color: var(--muted); font-size: 12px; }
.setting { border-bottom: 1px solid var(--rule); padding: 10px 0; }
.setting:last-child { border-bottom: none; }
.setting h3 { margin: 0 0 4px; font-size: 14px; }
.setting p { margin: 4px 0; color: var(--muted); font-size: 12.5px; }
.setting .line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.setting .line input { flex: 1; min-width: 180px; }
.setting .result { font-size: 12.5px; margin-top: 4px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 10; max-width: calc(100vw - 32px); }
.od-image-missing { display: block; padding: 12px; color: var(--muted); border: 1px dashed var(--rule); border-radius: 8px; }

@media (max-width: 820px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  main.no-chat { grid-template-rows: minmax(0, 1fr); }
  #chat { border-left: none; border-top: 1px solid var(--rule); }
  header.bar { flex-wrap: wrap; row-gap: 6px; }
  header.bar .state { display: none; }
  header.bar .title { flex: 1 1 40%; }
  header.bar .spacer { display: none; }
  header.bar button { padding: 3px 8px; }
}
