:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1c1b18; --muted: #6b675e; --line: #e6e3dc;
  --accent: #0f5c56; --accent-ink: #ffffff;
  --ok: #1f7a4d; --ok-bg: #e4f3ea; --warn: #8a5a00; --warn-bg: #fff2d6; --bad: #9b2c2c; --bad-bg: #fbe4e4; --grey: #5b5b5b; --grey-bg: #ecebe7;
  --radius: 10px; --sidebar: 260px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.msg { margin: 8px 0 0; font-size: 13px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: #cfcbc2; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .5; cursor: default; }
.file-btn { display: inline-block; margin-top: 10px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 12px; letter-spacing: .5px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login-card .brand { margin-bottom: 20px; font-size: 17px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.login-card .btn { width: 100%; margin-top: 10px; }

/* shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.search input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
nav { display: flex; flex-direction: column; gap: 2px; }
.nav-heading { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 8px 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; border-radius: 8px; color: var(--ink); }
.nav-item:hover { background: var(--bg); text-decoration: none; }
.nav-item.active { background: #e8f0ef; color: var(--accent); font-weight: 600; }
.pill { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.me { font-weight: 600; }

.main { padding: 32px 40px 80px; max-width: 980px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 14px; margin-bottom: 6px; }
.page-head h1 { margin: 0; font-size: 26px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); margin: 6px 0 22px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 20px; align-items: center; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; letter-spacing: .02em; vertical-align: middle; }
.badge.verified { background: var(--ok-bg); color: var(--ok); }
.badge.unverified, .badge.ai_inferred, .badge.draft { background: var(--grey-bg); color: var(--grey); }
.badge.stale { background: var(--warn-bg); color: var(--warn); }
.badge.pending_review { background: var(--warn-bg); color: var(--warn); }
.badge.rejected, .badge.superseded, .badge.archived { background: var(--bad-bg); color: var(--bad); }
.badge.locked { background: #e9e6ff; color: #4b3fb3; }
/* connection statuses (Settings page) share the same badge shape */
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.error { background: var(--bad-bg); color: var(--bad); }
.badge.revoked { background: var(--grey-bg); color: var(--grey); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.row:hover { border-color: #cfcbc2; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub mark { background: #fff3b0; padding: 0 2px; }
.kind { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); width: 52px; }

.prose { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 30px; }
.prose h1, .prose h2, .prose h3 { margin: 1.2em 0 .5em; }
.prose h1:first-child, .prose h2:first-child { margin-top: 0; }
.prose p { margin: .6em 0; }
.prose code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 90%; }
.prose pre { background: #1c1b18; color: #f6f5f2; padding: 14px; border-radius: 8px; overflow: auto; }
.prose table { border-collapse: collapse; width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.prose a.wikilink { border-bottom: 1px dotted var(--accent); }
.prose a.wikilink.missing { color: var(--muted); border-bottom-style: dashed; }

.facts { margin-top: 14px; }
.fact { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; padding: 10px 0; border-top: 1px solid var(--line); }
.fact:first-of-type { border-top: 0; }
.fact .k { font-weight: 600; }
.fact .v { color: var(--ink); }
.fact .src { font-size: 12.5px; color: var(--muted); }
.fact .actions { display: flex; gap: 6px; align-items: start; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.empty { color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.error { background: var(--bad-bg); color: var(--bad); padding: 12px 14px; border-radius: 8px; }
.rejected-notice { background: var(--bad-bg); color: var(--bad); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px; }
.rev { display: flex; gap: 12px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.rev:first-child { border-top: 0; }
.rev .no { width: 30px; color: var(--muted); }
.rev .grow { flex: 1; }

/* collections (Step 11 — databases) */
.coll-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.coll-table th, .coll-table td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.coll-table th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.coll-table td.row-actions { white-space: nowrap; font-size: 12.5px; }
.coll-table td.row-actions a { margin-right: 10px; }
.link-danger { color: var(--bad); }

/* modals (new page, page settings, conflict, diff) */
.modal-overlay { position: fixed; inset: 0; background: rgba(28,27,24,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--panel); border-radius: 14px; padding: 26px 28px; width: 100%; max-width: 640px; max-height: 86vh; overflow: auto; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; }
.modal textarea { resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; align-items: center; }
.modal-actions .muted { margin-right: auto; }

/* settings / connections form (Settings page) — same field styling as .modal */
.settings-form label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
.settings-form label:first-child { margin-top: 0; }
.settings-form input, .settings-form select { width: 100%; max-width: 420px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; display: block; margin-top: 4px; }
.settings-form button { margin-top: 16px; }

/* diff view */
.diff { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 10px 0; max-height: 320px; overflow: auto; white-space: pre-wrap; }
.diff-line { padding: 1px 4px; border-radius: 3px; }
.diff-line.add { background: var(--ok-bg); color: var(--ok); }
.diff-line.del { background: var(--bad-bg); color: var(--bad); text-decoration: line-through; }

/* editor (build step 6) */
.editor-shell { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.edit-title-label, .edit-summary-label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.edit-title-label input, .edit-summary-label input { display: block; width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; font-size: 15px; }
.editor-toolbar { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.editor-toolbar button { border: 1px solid transparent; background: none; padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; min-width: 30px; }
.editor-toolbar button:hover { background: var(--panel); border-color: var(--line); }
.editor-toolbar button.is-active { background: #e8f0ef; color: var(--accent); }
.tb-sep { width: 1px; background: var(--line); margin: 2px 4px; }
.editor-mount { border: 1px solid var(--line); border-top: none; border-radius: 0 0 8px 8px; padding: 16px 18px; min-height: 260px; }
.editor-mount .ProseMirror { outline: none; min-height: 240px; }
.editor-mount .ProseMirror p { margin: .6em 0; }
.editor-mount .ProseMirror h1, .editor-mount .ProseMirror h2, .editor-mount .ProseMirror h3 { margin: 1em 0 .4em; }
.editor-mount .ProseMirror pre { background: #1c1b18; color: #f6f5f2; padding: 12px; border-radius: 8px; }
.editor-mount .ProseMirror code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.editor-mount .ProseMirror pre code { background: none; padding: 0; }
.editor-mount .ProseMirror blockquote { border-left: 3px solid var(--line); margin: .8em 0; padding-left: 14px; color: var(--muted); }
.editor-mount .ProseMirror hr { border: none; border-top: 1px solid var(--line); margin: 1.4em 0; }
#edit-status { margin-right: auto; }

/* attachments */
.attachment-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.attachment { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.attachment:first-child { border-top: 0; }
.attachment .file-name { font-weight: 600; }
.attachment-preview img { max-width: 160px; max-height: 100px; border-radius: 6px; display: block; }

/* assistant chat (build step 7) */
.chat-fab { position: fixed; right: 22px; bottom: 22px; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #fff; border: none; font-size: 22px; line-height: 52px; padding: 0; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.22); z-index: 90; }
.chat-fab:hover { filter: brightness(1.08); }
.chat-drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 400px; max-width: 100vw; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.1); z-index: 95; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head-title { font-weight: 600; flex: 1; }
.chat-model { border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 12px; max-width: 130px; background: var(--panel); color: var(--ink); }
.chat-history-panel { border-bottom: 1px solid var(--line); max-height: 220px; overflow: auto; }
.chat-history-item { display: flex; justify-content: space-between; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink); }
.chat-history-item:first-child { border-top: 0; }
.chat-history-item:hover { background: var(--bg); text-decoration: none; }
.chat-messages { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty { color: var(--muted); text-align: center; margin-top: 40px; font-size: 13px; padding: 0 12px; }
.chat-msg { max-width: 92%; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; white-space: pre-wrap; }
.chat-msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.chat-msg.assistant p { margin: .4em 0; }
.chat-msg.assistant p:first-child { margin-top: 0; }
.chat-msg.assistant p:last-child { margin-bottom: 0; }
.chat-msg .cite { font-size: 10px; vertical-align: super; color: var(--accent); }
.chat-cursor { display: inline-block; animation: chat-blink 1s steps(2) infinite; }
@keyframes chat-blink { 50% { opacity: 0; } }
.chat-tools { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 4px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; max-height: 120px; font-family: inherit; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 20px 16px 60px; }
  .two-col { grid-template-columns: 1fr; }
  .editor-toolbar button { min-width: 26px; }
  .chat-drawer { width: 100vw; }
}
