:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --sidebar-bg: #ffffff;
  --hover: #f1f5f9;
  --active-bg: #eff6ff;
  --active-fg: #2563eb;
  --accent: #2563eb;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(0,0,0,0.08);
}
[data-theme="dark"] {
  --bg: #0b1220;
  --fg: #e5e7eb;
  --muted: #94a3b8;
  --border: #1f2937;
  --sidebar-bg: #0f172a;
  --hover: #111827;
  --active-bg: #1e293b;
  --active-fg: #60a5fa;
  --accent: #60a5fa;
  --card: #0f172a;
  --shadow: 0 10px 30px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.logo {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #1e293b, #334155);
  color: #fff; display: grid; place-items: center; font-size: 16px;
}
.top-links { display: flex; align-items: center; gap: 18px; }
.top-link { color: var(--fg); text-decoration: none; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.top-link:hover { color: var(--accent); }
.ico { width: 18px; height: 18px; display: inline-block; vertical-align: middle; }
.ico-sm { width: 12px; height: 12px; display: inline-block; opacity: 0.6; }
.icon-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--fg); width: 34px; height: 34px; border-radius: 8px;
  cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--hover); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 240px;
  max-width: 1400px; margin: 0 auto;
}
.sidebar {
  border-right: 1px solid var(--border);
  padding: 20px 12px; min-height: calc(100vh - 63px);
  background: var(--sidebar-bg);
}
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list li {
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
  font-size: 14px; color: var(--fg); display: flex; justify-content: space-between;
  align-items: center;
}
.side-list li:hover { background: var(--hover); }
.side-list li.active { background: var(--active-bg); color: var(--active-fg); font-weight: 600; }
.side-list li.section { font-weight: 600; color: var(--muted); font-size: 13px; text-transform: none; margin-top: 8px; cursor: default; }
.side-list li.section:hover { background: transparent; }

.content { padding: 28px 40px; min-width: 0; }
.breadcrumbs { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.breadcrumbs .ico { width: 14px; height: 14px; }
#article h2 .ico { width: 24px; height: 24px; color: var(--accent); }
.btn .ico { width: 16px; height: 16px; margin-right: 4px; }
.crumb { background: var(--active-bg); color: var(--active-fg); padding: 3px 10px; border-radius: 999px; }
#article h1 { font-size: 40px; margin: 10px 0 20px; }
#article h2 { font-size: 26px; margin-top: 36px; display: flex; align-items: center; gap: 10px; }
#article p { color: var(--fg); }
#article ul { padding-left: 22px; }
#article li { margin: 6px 0; }

.toc {
  border-left: 1px solid var(--border);
  padding: 28px 20px;
  font-size: 13px;
}
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc li { padding: 6px 0; color: var(--muted); cursor: pointer; }
.toc li:hover, .toc li.active { color: var(--accent); }

/* Staff floating button */
.staff-btn {
  position: fixed; right: 20px; bottom: 20px;
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff;
  font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow); z-index: 100;
}
.staff-btn:hover { transform: translateY(-2px); }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: grid; place-items: center; z-index: 200;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card); color: var(--fg);
  padding: 24px; border-radius: 12px; width: 380px;
  box-shadow: var(--shadow);
}
.modal-card.wide { width: min(880px, 94vw); max-height: 86vh; overflow: auto; }
.modal-card h3 { margin: 0 0 6px; }
.modal-card .muted { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-card input, .modal-card textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  font-size: 14px; font-family: inherit;
  margin-bottom: 10px;
}
.modal-card label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); cursor: pointer; font-size: 14px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { opacity: 0.9; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; margin-top: 6px; }
.error { color: #dc2626; font-size: 13px; margin-bottom: 10px; }
.hidden { display: none !important; }

/* Admin */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.admin-grid h4 { margin: 0 0 12px; }
.admin-list { list-style: none; padding: 0; margin: 0; max-height: 420px; overflow: auto; }
.admin-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
  font-size: 14px;
}
.admin-list button { background: transparent; border: none; color: #dc2626; cursor: pointer; font-size: 13px; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 220px 1fr; }
  .toc { display: none; }
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ============ Staff panel — advanced editor ============ */
.modal-card.xl { max-width: 1100px; width: 95vw; }
.modal-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }

.tabs { display: flex; gap: 4px; margin-left: 8px; flex: 1; }
.tab {
  background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 6px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--fg); background: var(--hover); }
.tab.active { color: var(--accent); background: var(--active-bg); border-color: var(--border); font-weight: 600; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.editor-meta {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;
}
.editor-meta label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.editor-meta input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg); font-size: 14px; }

.toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px; border: 1px solid var(--border); border-bottom: none;
  border-radius: 8px 8px 0 0; background: var(--sidebar-bg);
  flex-wrap: wrap;
}
.tb {
  background: transparent; border: none; color: var(--fg);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.tb:hover { background: var(--hover); color: var(--accent); }
.tb-toggle { width: auto; padding: 0 10px; gap: 6px; font-size: 13px; }
.tb-toggle.active { background: var(--active-bg); color: var(--accent); }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tb-spacer { flex: 1; }

.editor-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
.editor-grid.split { grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-area {
  width: 100%; min-height: 320px; padding: 14px;
  border: 1px solid var(--border); border-radius: 0 0 8px 8px;
  background: var(--bg); color: var(--fg); font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.6;
  resize: vertical;
}
.editor-grid.split .editor-area { border-radius: 0 0 0 8px; }
.editor-area:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.preview-pane {
  border: 1px solid var(--border); border-left: none;
  border-radius: 0 0 8px 0; background: var(--bg); padding: 14px;
  max-height: 520px; overflow: auto;
}
.preview-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; letter-spacing: 0.05em; }
.preview-body h1 { font-size: 22px; margin: 0 0 10px; }
.preview-body h2 { font-size: 17px; margin: 14px 0 6px; }
.preview-body h3 { font-size: 15px; margin: 12px 0 4px; }
.preview-body p { margin: 8px 0; }
.preview-body ul, .preview-body ol { margin: 8px 0; padding-left: 22px; }
.preview-body blockquote { border-left: 3px solid var(--accent); margin: 8px 0; padding: 4px 12px; color: var(--muted); }
.preview-body code { background: var(--hover); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
.preview-body a { color: var(--accent); }
.preview-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.editor-actions {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; justify-content: flex-end;
}
.hint { margin-right: auto; font-size: 13px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.danger { background: #ef4444; color: #fff; border: none; }
.btn.danger:hover { background: #dc2626; }

.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
  background: var(--bg);
}
.admin-list li.empty { justify-content: center; color: var(--muted); }
.ali-actions { display: flex; gap: 6px; }

.cheat { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
.cheat td { padding: 6px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
.cheat td:first-child { width: 220px; }
.cheat code { background: var(--hover); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* Article rendered markdown */
#article blockquote { border-left: 3px solid var(--accent); margin: 12px 0; padding: 6px 14px; color: var(--muted); }
#article code { background: var(--hover); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
#article a { color: var(--accent); }
#article hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

@media (max-width: 800px) {
  .modal-card.xl { width: 98vw; padding: 14px; }
  .editor-meta { grid-template-columns: 1fr; }
  .editor-grid.split { grid-template-columns: 1fr; }
  .preview-pane { border-left: 1px solid var(--border); border-radius: 8px; }
  .tabs { flex-wrap: wrap; }
}

/* ============ Sidebar collapsible groups ============ */
.side-list li.page { padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.side-list li.page.indented { padding-left: 28px; }
.side-list li.page:hover { background: var(--hover); }
.side-list li.page.active { background: var(--active-bg); color: var(--active-fg); font-weight: 600; }

.side-list li.group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 10px; margin-top: 10px;
  font-weight: 600; font-size: 13px; color: var(--fg);
  cursor: pointer; border-radius: 6px;
  text-transform: none;
  user-select: none;
}
.side-list li.group-header:hover { background: var(--hover); }
.side-list li.group-header .grp-toggle {
  display: inline-flex; transition: transform 0.15s ease;
  transform: rotate(90deg);
}
.side-list li.group-header .grp-toggle .ico { width: 14px; height: 14px; }
.side-list li.group-header.collapsed .grp-toggle { transform: rotate(0deg); }
.side-list li.group-header .grp-name { flex: 1; }
.side-list li.group-header .grp-count {
  font-size: 11px; color: var(--muted);
  background: var(--hover); padding: 1px 7px; border-radius: 999px;
  font-weight: 500;
}
.side-list li.group-empty {
  padding: 6px 12px 6px 28px;
  font-size: 12px; color: var(--muted); font-style: italic;
  cursor: default;
}
.side-list li.group-empty:hover { background: transparent; }

/* ============ Groups tab ============ */
.group-create {
  display: flex; gap: 8px; margin-bottom: 14px;
}
.group-create input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--fg); font-size: 14px;
}
.group-create .btn { white-space: nowrap; }

/* Admin list section headers */
.admin-list li.admin-section-head {
  border: none; padding: 12px 4px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700;
  background: transparent;
}
.admin-list li.empty {
  text-align: center; color: var(--muted); font-style: italic;
  border-style: dashed;
}

/* Editor section dropdown */
#slideSection {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); color: var(--fg); font-size: 14px;
  font-family: inherit;
}

.ali-info { flex: 1; }
.ali-actions { display: flex; gap: 6px; }

table.cheat { width: 100%; border-collapse: collapse; margin: 8px 0 16px; font-size: 13px; }
table.cheat td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
table.cheat td:first-child { width: 40%; color: var(--accent); }


/* ============================================================
   CALLOUTS / NOTIFICATION BOXES
   Inline syntax (works anywhere in a page description):
     ::danger[TITLE]{body text with **bold** and [links](url)}
     ::success[TITLE]{body}
     ::info[TITLE]{body}
     ::warning[TITLE]{body}
   ============================================================ */
.callout {
  display: grid;
  grid-template-columns: 22px 1fr;
  column-gap: 12px;
  row-gap: 4px;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 10px;
  border-left: 4px solid var(--cl-border);
  background: var(--cl-bg);
  color: var(--fg);
  line-height: 1.55;
  text-align: left;
}
.callout .cl-icon {
  grid-row: 1 / span 2;
  width: 20px; height: 20px;
  color: var(--cl-border);
  margin-top: 2px;
  flex-shrink: 0;
}
.callout .cl-title {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--fg);
  align-self: center;
}
.callout .cl-body {
  grid-column: 2;
  font-size: 14px;
  color: var(--fg);
}
.callout .cl-body > *:first-child { margin-top: 0; }
.callout .cl-body > *:last-child  { margin-bottom: 0; }
.callout .cl-body a {
  color: var(--cl-border); font-weight: 700; text-decoration: underline;
}
.callout .cl-body code {
  background: color-mix(in oklab, var(--cl-border) 15%, var(--bg));
  padding: 1px 6px; border-radius: 4px; font-size: 0.9em;
}

/* Title-only (no body) — center icon next to title */
.callout.no-body { grid-template-rows: auto; }
.callout.no-body .cl-icon { grid-row: 1; }

/* Variants */
.callout.danger  { --cl-border: #ef4444; --cl-bg: color-mix(in oklab, #ef4444 10%, var(--bg)); }
.callout.success { --cl-border: #10b981; --cl-bg: color-mix(in oklab, #10b981 10%, var(--bg)); }
.callout.info    { --cl-border: #3b82f6; --cl-bg: color-mix(in oklab, #3b82f6 10%, var(--bg)); }
.callout.warning { --cl-border: #f59e0b; --cl-bg: color-mix(in oklab, #f59e0b 12%, var(--bg)); }

/* Slightly stronger background in dark mode for legibility */
[data-theme="dark"] .callout.danger  { --cl-bg: color-mix(in oklab, #ef4444 18%, var(--bg)); }
[data-theme="dark"] .callout.success { --cl-bg: color-mix(in oklab, #10b981 18%, var(--bg)); }
[data-theme="dark"] .callout.info    { --cl-bg: color-mix(in oklab, #3b82f6 18%, var(--bg)); }
[data-theme="dark"] .callout.warning { --cl-bg: color-mix(in oklab, #f59e0b 22%, var(--bg)); }

/* Toolbar callout buttons — colored chips */
.tb.cl-btn { font-weight: 800; font-size: 13px; border: 1px solid transparent; }
.tb.cl-danger  { color: #ef4444; background: color-mix(in oklab, #ef4444 12%, transparent); }
.tb.cl-success { color: #10b981; background: color-mix(in oklab, #10b981 12%, transparent); }
.tb.cl-info    { color: #3b82f6; background: color-mix(in oklab, #3b82f6 12%, transparent); }
.tb.cl-warning { color: #f59e0b; background: color-mix(in oklab, #f59e0b 14%, transparent); }
.tb.cl-btn:hover { filter: brightness(1.05); border-color: currentColor; }
