@view-transition { navigation: auto; }
[x-cloak] { display: none !important; }

:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-hover: #eef1f5;
  --border: #e3e6eb;
  --text: #1d2433;
  --muted: #667085;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --warn-bg: #fff7e6;
  --warn-text: #8a5a00;
  --danger: #c4314b;
  --ok: #157f3c;
  --shadow: 0 8px 28px rgba(16, 24, 40, .12);
  --radius: 8px;
  --sidebar: 290px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181e; --bg-soft: #1b1f27; --bg-hover: #242a35; --border: #2c3340;
    --text: #e6e9ef; --muted: #98a2b3; --accent: #6b9bff; --accent-soft: #1f2b47;
    --warn-bg: #3a2e14; --warn-text: #f5c96b; --danger: #ff6b81; --ok: #4ade80;
    --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); }

/* Header */
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.topbar .spacer { flex: 1; }
.search { position: relative; width: min(360px, 40vw); }
.search input { width: 100%; height: 36px; border: 1px solid var(--border); border-radius: 18px; padding: 0 14px; background: var(--bg-soft); }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto; }
.search-results a { display: block; padding: 10px 14px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.search-results a:hover { background: var(--bg-hover); }
.search-results small { display: block; color: var(--muted); font-size: 12px; }
.navlink { color: var(--muted); text-decoration: none; font-size: 14px; }
.navlink:hover { color: var(--text); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; }

/* Tombol */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 14px; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }

/* Layout space */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: calc(100vh - 56px); }
.sidebar { border-right: 1px solid var(--border); background: var(--bg-soft); padding: 16px 8px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; }
.space-head { padding: 0 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.space-key { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 6px; }
.space-name { font-weight: 700; font-size: 16px; margin: 6px 0 2px; }
.side-label { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tree-item { position: relative; display: flex; align-items: center; gap: 2px; min-height: 32px; border-radius: 6px; padding-right: 4px; }
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--accent-soft); }
.tree-item.active .tree-link { color: var(--accent); font-weight: 600; }
.twisty, .twisty-sp { width: 20px; height: 20px; flex: none; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 11px; padding: 0; }
.tree-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; color: var(--text); text-decoration: none; font-size: 14px; padding: 4px 2px; }
.tree-link span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; flex: none; }
.tree-actions { display: flex; gap: 2px; opacity: 0; }
.tree-item:hover .tree-actions, .tree-item.active .tree-actions { opacity: 1; }
.icon-btn { width: 24px; height: 24px; border: 0; border-radius: 4px; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.pop { position: absolute; right: 4px; top: 30px; z-index: 20; min-width: 220px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; }
.pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; cursor: pointer; font-size: 14px; }
.pop button:hover { background: var(--bg-hover); }
.pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.content { min-width: 0; padding: 28px 40px 80px; }
.page-wrap { max-width: 860px; margin: 0 auto; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.page-title { font-size: 32px; line-height: 1.25; margin: 0 0 6px; font-weight: 700; }
.title-input { width: 100%; font-size: 32px; font-weight: 700; border: 0; outline: none; padding: 0; margin: 0 0 6px; background: transparent; }
.meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--bg-hover); color: var(--muted); }
.badge.draft { background: var(--warn-bg); color: var(--warn-text); }
.badge.ai { background: var(--accent-soft); color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 18px; align-items: center; }
.save-state { font-size: 13px; color: var(--muted); }
.banner { border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--warn-bg); color: var(--warn-text); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner .spacer { flex: 1; }

.page-grid { display: grid; grid-template-columns: 1fr 200px; gap: 32px; }
.toc { position: sticky; top: 80px; align-self: start; font-size: 13px; border-left: 2px solid var(--border); padding-left: 12px; }
.toc b { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.toc a { display: block; color: var(--muted); text-decoration: none; padding: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc a:hover { color: var(--accent); }

/* Dokumen */
.doc { font-size: 16px; line-height: 1.7; word-wrap: break-word; }
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6, .blk-text.h1, .blk-text.h2, .blk-text.h3, .blk-text.h4, .blk-text.h5, .blk-text.h6 { font-weight: 700; line-height: 1.3; margin: 1.4em 0 .4em; scroll-margin-top: 80px; }
.doc h1, .blk-text.h1 { font-size: 28px; }
.doc h2, .blk-text.h2 { font-size: 23px; }
.doc h3, .blk-text.h3 { font-size: 19px; }
.doc h4, .blk-text.h4 { font-size: 17px; }
.doc h5, .blk-text.h5 { font-size: 15px; }
.doc h6, .blk-text.h6 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.doc p, .blk-text.p { margin: .5em 0; }
.doc > :first-child { margin-top: 0; }
.empty-doc { color: var(--muted); font-style: italic; }
.table-wrap, .tbl-wrap { overflow-x: auto; margin: 1em 0; }
.doc table { border-collapse: collapse; min-width: 50%; font-size: 15px; }
.doc td, .doc th { border: 1px solid var(--border); padding: 8px 12px; vertical-align: top; text-align: left; min-width: 80px; }
.doc th, .doc .has-header tr:first-child td { background: var(--bg-soft); font-weight: 600; }

/* Editor */
.editor { padding-left: 34px; margin-left: -34px; }
.blk { position: relative; }
.blk-handle { position: absolute; left: -32px; top: 6px; width: 24px; height: 24px; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; font-size: 12px; letter-spacing: -2px; opacity: 0; }
.blk:hover .blk-handle, .blk:focus-within .blk-handle { opacity: 1; }
.blk-handle:hover { background: var(--bg-hover); }
.blk-text { outline: none; min-height: 1.6em; border-radius: 4px; }
.blk-text:empty:focus::before, .editor .blk:only-child .blk-text:empty::before { content: attr(data-ph); color: var(--muted); opacity: .6; pointer-events: none; }
.cell { outline: none; min-height: 1.5em; }
.blk-table td:focus-within { box-shadow: inset 0 0 0 2px var(--accent); }
.tbl-bar { display: none; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.blk:focus-within .tbl-bar { display: flex; }
.add-block { margin-top: 12px; color: var(--muted); }
.ed-menu { position: absolute; z-index: 50; width: 240px; max-height: 320px; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; }
.ed-menu button { display: flex; width: 100%; justify-content: space-between; gap: 8px; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 5px; cursor: pointer; font-size: 14px; }
.ed-menu button.active, .ed-menu button:hover { background: var(--bg-hover); }
.ed-menu small { color: var(--muted); }
.ed-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.ed-toolbar { position: absolute; z-index: 60; display: none; gap: 2px; background: #1d2433; border-radius: 6px; padding: 3px; box-shadow: var(--shadow); }
.ed-toolbar button { min-width: 30px; height: 30px; border: 0; border-radius: 4px; background: none; color: #fff; cursor: pointer; font-size: 14px; }
.ed-toolbar button:hover, .ed-toolbar button.on { background: rgba(255, 255, 255, .18); }

/* Kartu, modal, panel */
.wrap { max-width: 1040px; margin: 0 auto; padding: 32px 16px 80px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 18px; background: var(--bg); text-decoration: none; color: var(--text); display: block; }
a.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card h3 { margin: 8px 0 4px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.skeleton { background: linear-gradient(90deg, var(--bg-soft), var(--bg-hover), var(--bg-soft)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.modal-bg { position: fixed; inset: 0; z-index: 80; background: rgba(15, 20, 30, .45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); padding: 22px; max-height: 90vh; overflow: auto; }
.modal.wide { width: min(860px, 100%); }
.modal h2 { margin: 0 0 12px; font-size: 19px; }
.field { display: block; margin-bottom: 12px; font-size: 14px; }
.field input, .field textarea, .field select { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }

/* Akun */
.account-form { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; background: var(--bg); }
.notice { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.form-error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.form-ok { color: var(--ok); font-size: 14px; margin: 0 0 12px; }
.user-link { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; border-radius: 18px; padding: 2px 8px 2px 2px; }
.user-link:hover { background: var(--bg-hover); color: var(--text); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.drawer { position: fixed; top: 56px; right: 0; bottom: 0; z-index: 40; width: min(380px, 100%); background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow); padding: 18px; overflow: auto; }
.ver { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.ver:hover { border-color: var(--accent); }
.ver small { color: var(--muted); display: block; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; font-size: 13px; }
.center-card { max-width: 420px; margin: 12vh auto; text-align: center; padding: 32px; border: 1px solid var(--border); border-radius: 14px; }
.muted { color: var(--muted); }
.toast-box { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast { background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; max-width: 90vw; }
.toast.err { background: var(--danger); }
.users-table { width: 100%; border-collapse: collapse; }
.users-table td, .users-table th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }

.menu-toggle { display: none; }
@media (max-width: 900px) {
  .page-grid { grid-template-columns: 1fr; }
  .toc { display: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 56px; left: 0; z-index: 35; width: 86vw; max-width: 320px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-toggle { display: inline-flex; }
  .content { padding: 20px 16px 80px; }
  .search { width: 100%; }
  .topbar .brand-text, .user-chip .uname, .navlink.hide-sm { display: none; }
  .page-title, .title-input { font-size: 26px; }
  .editor { padding-left: 0; margin-left: 0; }
  .blk-handle { left: auto; right: -4px; top: -26px; opacity: 1; }
}
