/* ---------------------------------------------------------------------------
   Knowledge Base
   One stylesheet. Tokens first, then layout, then components.
   --------------------------------------------------------------------------- */

:root {
  --bg:            #f6f7f5;
  --surface:       #ffffff;
  --surface-2:     #f0f2ef;
  --surface-3:     #e6e9e4;
  --border:        #dce0d9;
  --border-strong: #c3c9bd;

  --text:          #1d211c;
  --text-muted:    #5d665a;
  --text-faint:    #868f82;

  --accent:        #2f6f4e;
  --accent-hover:  #275c41;
  --accent-soft:   #e6f0ea;
  --accent-text:   #ffffff;

  --danger:        #a3341f;
  --danger-soft:   #fbeae6;
  --warning:       #8a6100;
  --warning-soft:  #fcf3dd;
  --info:          #1f5878;
  --info-soft:     #e4f0f6;

  --radius:        8px;
  --radius-sm:     5px;
  --shadow:        0 1px 2px rgba(20, 30, 20, .06), 0 4px 12px rgba(20, 30, 20, .05);
  --shadow-lg:     0 2px 6px rgba(20, 30, 20, .08), 0 12px 32px rgba(20, 30, 20, .10);

  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-read: Georgia, "Iowan Old Style", "Palatino Linotype", serif;

  --sidebar-w: 260px;
  --header-h:  56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #14171400;
    --bg:            #141714;
    --surface:       #1b1f1b;
    --surface-2:     #232823;
    --surface-3:     #2c322c;
    --border:        #2f352f;
    --border-strong: #444c44;

    --text:          #e6eae4;
    --text-muted:    #a3ad9f;
    --text-faint:    #7d867a;

    --accent:        #6bbd8f;
    --accent-hover:  #85cba2;
    --accent-soft:   #1e2f26;
    --accent-text:   #102016;

    --danger:        #e8836c;
    --danger-soft:   #33201b;
    --warning:       #e0b95c;
    --warning-soft:  #2f2718;
    --info:          #7fbcdc;
    --info-soft:     #1a2831;

    --shadow:        0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-lg:     0 2px 6px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { line-height: 1.25; font-weight: 640; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; letter-spacing: -.015em; }
h2 { font-size: 1.3rem; letter-spacing: -.01em; }
h3 { font-size: 1.08rem; }
h4 { font-size: .98rem; }

p { margin: 0 0 1em; }

code, kbd, pre { font-family: var(--font-mono); font-size: .88em; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

img { max-width: 100%; height: auto; }

::selection { background: var(--accent-soft); }

/* --- Skip link ------------------------------------------------------------ */

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--accent); color: var(--accent-text);
  padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

/* --- Layout --------------------------------------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 680; letter-spacing: -.01em; color: var(--text);
  min-height: var(--header-h);
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  font-size: .78rem; font-weight: 700; flex: none;
}

.sidebar-section { padding: .9rem .7rem .3rem; }
.sidebar-heading {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint); font-weight: 660;
  padding: 0 .45rem .4rem;
}
.sidebar-heading a { color: var(--text-faint); font-size: .95rem; line-height: 1; }
.sidebar-heading a:hover { color: var(--accent); text-decoration: none; }

.nav-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .42rem .5rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .89rem;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 580; }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent); }
.nav-item .count { margin-left: auto; font-size: .74rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.nav-item .icon { width: 16px; text-align: center; flex: none; opacity: .75; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding: .7rem; }

.user-chip {
  display: flex; align-items: center; gap: .6rem;
  padding: .4rem .5rem; border-radius: var(--radius-sm); color: var(--text);
}
.user-chip:hover { background: var(--surface-2); text-decoration: none; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--surface-3); color: var(--text-muted);
  display: grid; place-items: center; font-size: .7rem; font-weight: 660;
}
.user-chip .who { min-width: 0; }
.user-chip .who strong { display: block; font-size: .85rem; font-weight: 580; }
.user-chip .who span { display: block; font-size: .72rem; color: var(--text-faint); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}

.menu-toggle { display: none; }

.searchbox { flex: 1 1 auto; max-width: 460px; position: relative; }
.searchbox input {
  width: 100%; padding: .45rem .75rem .45rem 2rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: .88rem;
}
.searchbox input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.searchbox .glass {
  position: absolute; left: .6rem; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); font-size: .85rem; pointer-events: none;
}

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }

.content { padding: 1.75rem 1.75rem 5rem; width: 100%; }
.content.narrow { max-width: 820px; }
.content.wide   { max-width: 1180px; }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .85rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .86rem; font-weight: 520;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: .25rem .55rem; font-size: .78rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* --- Forms ---------------------------------------------------------------- */

.field { margin-bottom: 1.1rem; }
.field label, .label {
  display: block; font-size: .8rem; font-weight: 600;
  margin-bottom: .3rem; color: var(--text);
}
.field .hint { font-size: .78rem; color: var(--text-faint); margin-top: .3rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=url], select, textarea {
  width: 100%; padding: .48rem .65rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 90px; }

input[type=color] { width: 44px; height: 32px; padding: 2px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); }

.check { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.check input { width: auto; }

.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; min-width: 0; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin: 0 0 1.2rem; }
legend { font-size: .78rem; font-weight: 660; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); padding: 0 .4rem; }

/* --- Cards, panels -------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
}
.card + .card { margin-top: 1rem; }
.card-title { font-size: .95rem; font-weight: 640; margin: 0 0 .75rem; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  padding: .7rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2); font-size: .82rem; font-weight: 640;
  display: flex; align-items: center; gap: .6rem;
}
.panel-body { padding: 1rem; }

.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

/* --- Page header ---------------------------------------------------------- */

.page-head { margin-bottom: 1.5rem; }
.page-head .eyebrow {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint); font-weight: 640; margin-bottom: .35rem;
}
.page-head h1 { margin-bottom: .3rem; }
.page-head .lede { color: var(--text-muted); font-size: .95rem; margin: 0; max-width: 62ch; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.breadcrumb { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--text-faint); margin-bottom: .6rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { opacity: .5; }

/* --- Space cards ---------------------------------------------------------- */

.space-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem; color: var(--text);
  border-left: 3px solid var(--accent);
}
.space-card:hover { text-decoration: none; box-shadow: var(--shadow); border-color: var(--border-strong); }
.space-card h3 { margin: 0 0 .3rem; font-size: 1rem; }
.space-card p { color: var(--text-muted); font-size: .85rem; margin: 0 0 .7rem; }
.space-card .meta { display: flex; gap: .8rem; font-size: .75rem; color: var(--text-faint); }

/* --- Article list --------------------------------------------------------- */

.article-list { list-style: none; margin: 0; padding: 0; }
.article-list li { border-bottom: 1px solid var(--border); }
.article-list li:last-child { border-bottom: 0; }
.article-list a.row-link {
  display: flex; align-items: baseline; gap: .7rem;
  padding: .6rem .3rem; color: var(--text);
}
.article-list a.row-link:hover { text-decoration: none; background: var(--surface-2); }
.article-list .title { font-weight: 540; }
.article-list .summary { color: var(--text-faint); font-size: .82rem; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-list .when { margin-left: auto; font-size: .75rem; color: var(--text-faint); white-space: nowrap; }

.category-block { margin-bottom: 1.6rem; }
.category-block > h2 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); font-weight: 660;
  padding-bottom: .4rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem;
  display: flex; align-items: center; gap: .5rem;
}
.category-block > h2 .desc { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-faint); font-size: .78rem; }

/* --- Badges --------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .08rem .42rem; border-radius: 20px;
  font-size: .7rem; font-weight: 600; line-height: 1.5;
  background: var(--surface-3); color: var(--text-muted);
  white-space: nowrap;
}
.badge-draft   { background: var(--warning-soft); color: var(--warning); }
.badge-public  { background: var(--info-soft);    color: var(--info); }
.badge-archived{ background: var(--surface-3);    color: var(--text-faint); }
.badge-live    { background: var(--accent-soft);  color: var(--accent); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }

.tag {
  display: inline-block; padding: .1rem .5rem; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .75rem; color: var(--text-muted);
}
.tag:hover { text-decoration: none; border-color: var(--border-strong); }

/* --- Flash messages ------------------------------------------------------- */

.flash {
  padding: .65rem .9rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: .88rem; border: 1px solid transparent;
  display: flex; align-items: flex-start; gap: .55rem;
}
.flash-success { background: var(--accent-soft); color: var(--accent);  border-color: currentColor; }
.flash-error   { background: var(--danger-soft); color: var(--danger);  border-color: currentColor; }
.flash-info    { background: var(--info-soft);   color: var(--info);    border-color: currentColor; }

/* --- Tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th, table.data td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 660; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.right, table.data th.right { text-align: right; }
table.data .nowrap { white-space: nowrap; }

/* --- Empty state ---------------------------------------------------------- */

.empty {
  text-align: center; padding: 3rem 1.5rem; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
.empty h3 { color: var(--text); margin-bottom: .4rem; }
.empty p { max-width: 46ch; margin: 0 auto 1.1rem; font-size: .9rem; }

/* ---------------------------------------------------------------------------
   Article page
   --------------------------------------------------------------------------- */

.article-layout { display: flex; gap: 2.5rem; align-items: flex-start; }
.article-main { flex: 1 1 auto; min-width: 0; max-width: 780px; }
.article-aside { flex: 0 0 200px; position: sticky; top: calc(var(--header-h) + 1.5rem); }

.toc { font-size: .82rem; }
.toc-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); font-weight: 660; margin-bottom: .5rem; }
.toc a { display: block; padding: .22rem 0 .22rem .7rem; color: var(--text-muted); border-left: 2px solid var(--border); }
.toc a:hover { color: var(--accent); border-left-color: var(--border-strong); text-decoration: none; }
.toc a.is-current { color: var(--accent); border-left-color: var(--accent); font-weight: 560; }
.toc a.lvl-3 { padding-left: 1.35rem; font-size: .78rem; }
.toc a.lvl-4 { padding-left: 2rem; font-size: .76rem; }

.article-meta {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  font-size: .78rem; color: var(--text-faint);
  padding-bottom: 1rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border);
}

/* The rendered body. Kept separate from app chrome so article HTML can never
   restyle the interface around it. */
.prose {
  font-size: 1rem;
  line-height: 1.68;
  color: var(--text);
  overflow-wrap: break-word;
}
.prose > *:first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 2rem 0 .7rem; scroll-margin-top: calc(var(--header-h) + 1rem);
}
.prose h1 { font-size: 1.55rem; }
.prose h2 { font-size: 1.28rem; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.08rem; }
.prose h4 { font-size: .96rem; color: var(--text-muted); }
.prose p  { margin: 0 0 1.1rem; }
.prose ul, .prose ol { margin: 0 0 1.1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: .35rem; }
.prose li > ul, .prose li > ol { margin-top: .35rem; margin-bottom: .35rem; }
.prose li input[type=checkbox] { margin-right: .35rem; }
.prose blockquote {
  margin: 0 0 1.1rem; padding: .1rem 0 .1rem 1rem;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}
.prose img { border-radius: var(--radius); border: 1px solid var(--border); display: block; margin: 1.2rem 0; }
.prose a { text-decoration: underline; text-underline-offset: 2px; }

.prose code {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .08em .35em; border-radius: 4px; font-size: .86em;
}
.prose pre.kb-code {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem;
  overflow-x: auto; margin: 0 0 1.2rem; line-height: 1.5;
}
.prose pre.kb-code code { background: none; border: 0; padding: 0; font-size: .84rem; }

.prose .kb-table-wrap { overflow-x: auto; margin: 0 0 1.2rem; }
.prose table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: .45rem .65rem; }
.prose th { background: var(--surface-2); font-weight: 640; }

.prose .kb-anchor {
  opacity: 0; margin-left: .4rem; color: var(--text-faint);
  text-decoration: none; font-weight: 400;
}
.prose h1:hover .kb-anchor, .prose h2:hover .kb-anchor,
.prose h3:hover .kb-anchor, .prose h4:hover .kb-anchor { opacity: 1; }

.prose .kb-callout {
  border: 1px solid var(--border); border-left: 3px solid var(--text-faint);
  background: var(--surface-2); border-radius: var(--radius);
  padding: .85rem 1rem .1rem; margin: 0 0 1.2rem;
}
.prose .kb-callout-label {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  font-weight: 700; margin-bottom: .4rem;
}
.prose .kb-callout-note      { border-left-color: var(--info);    background: var(--info-soft); }
.prose .kb-callout-note .kb-callout-label { color: var(--info); }
.prose .kb-callout-tip       { border-left-color: var(--accent);  background: var(--accent-soft); }
.prose .kb-callout-tip .kb-callout-label { color: var(--accent); }
.prose .kb-callout-important { border-left-color: var(--accent);  background: var(--accent-soft); }
.prose .kb-callout-important .kb-callout-label { color: var(--accent); }
.prose .kb-callout-warning,
.prose .kb-callout-caution   { border-left-color: var(--danger);  background: var(--danger-soft); }
.prose .kb-callout-warning .kb-callout-label,
.prose .kb-callout-caution .kb-callout-label { color: var(--danger); }

.prose mark { background: var(--warning-soft); color: inherit; padding: .05em .2em; border-radius: 3px; }

.article-footer-nav { display: flex; gap: 1rem; margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--border); }
.article-footer-nav a { flex: 1 1 0; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.article-footer-nav a:hover { text-decoration: none; border-color: var(--border-strong); background: var(--surface); }
.article-footer-nav .dir { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin-bottom: .15rem; }
.article-footer-nav .next { text-align: right; }

/* ---------------------------------------------------------------------------
   Editor
   --------------------------------------------------------------------------- */

.editor-shell { display: flex; flex-direction: column; gap: 1rem; }

.editor-toolbar {
  display: flex; align-items: center; gap: .3rem; flex-wrap: wrap;
  padding: .4rem; background: var(--surface-2);
  border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}
.editor-toolbar .sep { width: 1px; height: 20px; background: var(--border-strong); margin: 0 .25rem; }
.editor-toolbar .toolbar-right {
  margin-left: auto; display: inline-flex; align-items: center; gap: .35rem;
}
.editor-toolbar .toolbar-right label { margin: 0; }
.editor-toolbar .toolbar-right select { width: auto; padding: .2rem 1.4rem .2rem .4rem; font-size: .8rem; }
.tool-btn {
  border: 0; background: transparent; color: var(--text-muted);
  padding: .28rem .5rem; border-radius: var(--radius-sm);
  font: inherit; font-size: .8rem; cursor: pointer; min-width: 30px;
}
.tool-btn:hover { background: var(--surface-3); color: var(--text); }
.tool-btn.is-on { background: var(--accent-soft); color: var(--accent); }
.tool-btn strong, .tool-btn em { font-size: .85rem; }

.editor-panes { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; background: var(--surface); }
.editor-panes.split .editor-pane { width: 50%; }
.editor-panes.split .preview-pane { display: block; }
.preview-pane { display: none; width: 50%; border-left: 1px solid var(--border); overflow-y: auto; padding: 1.2rem 1.4rem; background: var(--surface); }
.editor-pane { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

#body-markdown {
  border: 0; border-radius: 0; resize: none;
  font-family: var(--font-mono); font-size: .875rem; line-height: 1.65;
  padding: 1.2rem 1.4rem; min-height: 520px; height: 100%;
  background: var(--surface); color: var(--text);
  tab-size: 2;
}
#body-markdown:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

.rich-editor {
  min-height: 520px; padding: 1.2rem 1.4rem; overflow-y: auto;
  background: var(--surface); color: var(--text);
}
.rich-editor:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--text-faint); }

.editor-status {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  font-size: .76rem; color: var(--text-faint);
}
.editor-status .spacer { margin-left: auto; }

.drop-hint {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(47, 111, 78, .12); border: 3px dashed var(--accent);
  display: none; place-items: center; pointer-events: none;
  font-size: 1.1rem; font-weight: 600; color: var(--accent);
}
.drop-hint.is-on { display: grid; }

.upload-list { list-style: none; padding: 0; margin: .6rem 0 0; font-size: .8rem; }
.upload-list li { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; color: var(--text-muted); }
.upload-list .ok { color: var(--accent); }
.upload-list .bad { color: var(--danger); }

/* --- Editor sidebar ------------------------------------------------------- */

.editor-layout { display: flex; gap: 1.5rem; align-items: flex-start; }
.editor-layout > .editor-shell { flex: 1 1 auto; min-width: 0; }
.editor-side { flex: 0 0 280px; }

/* --- Diff ----------------------------------------------------------------- */

.diff { font-family: var(--font-mono); font-size: .8rem; line-height: 1.5; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.diff div { padding: .1rem .7rem; white-space: pre-wrap; word-break: break-word; }
.diff .same    { color: var(--text-muted); }
.diff .added   { background: var(--accent-soft); color: var(--accent); }
.diff .removed { background: var(--danger-soft); color: var(--danger); }
.diff .added::before   { content: '+ '; opacity: .6; }
.diff .removed::before { content: '- '; opacity: .6; }
.diff .same::before    { content: '  '; }

/* --- Share panel ---------------------------------------------------------- */

.share-url {
  display: flex; gap: .5rem; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .35rem .35rem .35rem .7rem;
}
.share-url input {
  border: 0; background: transparent; padding: 0; font-family: var(--font-mono);
  font-size: .78rem; flex: 1 1 auto; min-width: 0;
}
.share-url input:focus { outline: none; }

.token-value {
  font-family: var(--font-mono); font-size: .8rem; word-break: break-all;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: .55rem .7rem; margin: .5rem 0;
}

/* ---------------------------------------------------------------------------
   Sign-in and other bare pages
   --------------------------------------------------------------------------- */

.centred-page { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.centred-card { width: 100%; max-width: 380px; }
.centred-card .brand { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-bottom: 1.5rem; font-size: 1.15rem; font-weight: 680; }
.centred-card .brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: .85rem; }

/* ---------------------------------------------------------------------------
   Public share page
   --------------------------------------------------------------------------- */

.public-page { max-width: 780px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.public-header {
  border-bottom: 1px solid var(--border); padding-bottom: 1.2rem; margin-bottom: 2rem;
}
.public-header .space-name { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); font-weight: 660; }
.public-header h1 { margin: .4rem 0 .5rem; font-size: 1.9rem; }
.public-header .lede { color: var(--text-muted); margin: 0; }
.public-footer {
  margin-top: 4rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--text-faint);
  display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
}

/* ---------------------------------------------------------------------------
   Print
   --------------------------------------------------------------------------- */

@media print {
  .sidebar, .topbar, .article-aside, .page-actions, .no-print, .article-footer-nav { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .content, .article-main, .public-page { max-width: none; padding: 0; }
  .prose a { color: #000; text-decoration: underline; }
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; color: #555; }
  .prose pre.kb-code, .prose .kb-callout { background: #f7f7f7; border: 1px solid #ccc; }
  .prose h2, .prose h3 { break-after: avoid; }
  .prose pre, .prose table, .prose img { break-inside: avoid; }
}

.print-page { max-width: 720px; margin: 0 auto; padding: 2rem; }
.print-head { border-bottom: 2px solid var(--text); padding-bottom: .8rem; margin-bottom: 2rem; }

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .article-aside { display: none; }
  .editor-side { flex-basis: 240px; }
}

@media (max-width: 900px) {
  .editor-layout { flex-direction: column; }
  .editor-side { flex: 1 1 auto; width: 100%; }
  .editor-panes.split .editor-pane { width: 100%; }
  .editor-panes.split .preview-pane { display: none; }
}

@media (max-width: 780px) {
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .content { padding: 1.25rem 1rem 4rem; }
  .topbar { padding: 0 1rem; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Utilities ------------------------------------------------------------ */

.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.small  { font-size: .82rem; }
.mono   { font-family: var(--font-mono); }
.stack  { display: flex; flex-direction: column; gap: .6rem; }
.inline { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.75rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.75rem; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
