*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 15px; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
code { font-family: var(--font-mono); font-size: 0.85em; }

.app { display: grid; grid-template-columns: 264px minmax(0, 1fr); height: 100vh; height: 100dvh; }

/* Sidebar */
.sidebar { background: var(--sunken); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 14px 10px 10px; gap: 10px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; min-height: 32px; }
.brand { font-family: var(--font-read); font-weight: 700; font-size: 1.2rem; }
.search input { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.new-btn { width: 100%; }
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-actions .btn { flex: 1; padding: 0 6px; font-size: 0.85rem; }
.tree { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.tree details { margin: 2px 0; }
.tree summary { cursor: pointer; padding: 6px 8px; border-radius: 6px; color: var(--muted); font-size: 0.85rem; font-weight: 600; list-style-position: inside; }
.tree summary:hover { background: var(--bg); }
.tree details > .tree-items { padding-left: 12px; }
.tree a { display: flex; align-items: baseline; gap: 6px; padding: 6px 8px; min-height: 34px; border-radius: 6px; color: var(--ink); text-decoration: none; line-height: 1.35; }
.tree a:hover { background: var(--bg); }
.tree a[aria-current="page"] { background: var(--accent-soft); font-weight: 600; }
.tree .pub { margin-left: auto; font-size: 0.72rem; color: var(--accent); font-weight: 600; flex-shrink: 0; }
.tree .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint { color: var(--muted); padding: 6px 8px; margin: 0; line-height: 1.5; }
.sidebar-foot { margin: 0; padding: 6px 8px 0; color: var(--muted); font-size: 0.78rem; border-top: 1px solid var(--line); }

/* Tombol */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { border-color: var(--ink); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover:not(:disabled) { color: var(--danger); border-color: var(--line); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--surface); font-weight: 600; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }
.icon-btn { width: 36px; height: 36px; border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; font-size: 1.1rem; display: inline-grid; place-items: center; }
.icon-btn:hover { border-color: var(--line); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Topbar */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg); flex-wrap: wrap; }
.path-btn { min-width: 0; max-width: 32ch; height: 36px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; font-family: var(--font-mono); font-size: 0.85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.path-btn:hover:not(:disabled) { border-color: var(--line); color: var(--ink); }
.status { font-size: 0.82rem; color: var(--muted); margin-right: auto; white-space: nowrap; }
.status.error { color: var(--danger); font-weight: 600; cursor: pointer; text-decoration: underline; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { height: 34px; padding: 0 12px; border: 0; background: none; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.banner { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border-bottom: 2px solid var(--danger); color: var(--ink); }
.banner span { flex: 1; }

/* Workspace */
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.workspace[data-mode="split"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.pane { min-height: 0; overflow: auto; }
.pane-edit { display: flex; background: var(--surface); }
.workspace[data-mode="split"] .pane-edit { border-right: 1px solid var(--line); }
#editor { flex: 1; width: 100%; min-height: 100%; resize: none; border: 0; padding: 28px 28px 40vh; background: transparent; font-family: var(--font-mono); font-size: 0.92rem; line-height: 1.7; tab-size: 2; }
#editor:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-soft); }
.pane-read { padding: 32px 32px 30vh; }
.state { grid-column: 1 / -1; display: grid; place-content: center; text-align: center; gap: 12px; padding: 32px 16px; }
.state h2 { font-family: var(--font-read); font-size: 1.6rem; margin: 0; }
.state p { margin: 0; color: var(--muted); max-width: 42ch; line-height: 1.55; }
.state .btn { justify-self: center; }

/* Properti frontmatter di atas preview */
.props { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 auto 1.25rem; max-width: 46rem; font-family: var(--font-ui); font-size: 0.8rem; }
.props span { padding: 3px 8px; border-radius: 4px; background: var(--sunken); color: var(--muted); }
.props span.on { background: var(--accent-soft); color: var(--ink); }
.doc .empty-doc { color: var(--muted); font-style: italic; }

/* Diagram mermaid */
.diagram { margin: 0 0 1.25em; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.diagram-body { padding: 16px; overflow-x: auto; text-align: center; min-height: 48px; }
.diagram-body svg { display: inline-block; }
.diagram-bar { display: flex; gap: 4px; justify-content: flex-end; padding: 4px 6px; border-top: 1px solid var(--line); font-family: var(--font-ui); }
.diagram-bar button { height: 32px; padding: 0 10px; border: 0; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; font-size: 0.8rem; }
.diagram-bar button:hover { background: var(--sunken); color: var(--ink); }
.diagram-error { text-align: left; font-family: var(--font-mono); font-size: 0.8rem; color: var(--danger); white-space: pre-wrap; margin: 0; }
.diagram-loading { color: var(--muted); font-family: var(--font-ui); font-size: 0.85rem; }

/* Slash menu */
.slash { position: fixed; z-index: 30; width: 280px; max-height: 320px; overflow-y: auto; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.16); }
.slash-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.slash-item[aria-selected="true"] { background: var(--accent-soft); }
.slash-item .k { width: 44px; flex-shrink: 0; font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.slash-empty { padding: 10px; color: var(--muted); margin: 0; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 16px 48px rgb(0 0 0 / 0.22); }
dialog.wide { width: min(1100px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog h2 { margin: 0 0 14px; font-family: var(--font-read); font-size: 1.3rem; }
.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; }
.field > span, .field legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 4px; }
.field input:not([type="radio"]) { height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font-family: var(--font-mono); font-size: 0.9rem; }
.field small { color: var(--muted); }
.radio { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; line-height: 1.4; cursor: pointer; }
.radio input { margin-top: 3px; accent-color: var(--accent); }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0 0 8px; font-size: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.diagram-full { overflow: auto; max-height: 72vh; margin-bottom: 14px; text-align: center; }
.diagram-full svg { max-width: none !important; transform-origin: top left; }

.only-mobile { display: none; }
.scrim { display: none; }

/* Menu Lainnya */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 25; min-width: 230px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / 0.16); }
.menu button { display: block; width: 100%; min-height: 38px; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--sunken); }
.menu button.danger { color: var(--danger); }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; }
  .hide-mobile { display: none; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform 0.18s ease-out; }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgb(0 0 0 / 0.35); }
  .topbar { padding: 8px 10px; gap: 6px; }
  .path-btn { max-width: 48vw; }
  .status { order: 5; flex-basis: 100%; margin: 0; }
  .actions .btn { padding: 0 10px; }
  .btn, .icon-btn, .seg button, .path-btn, .tree a, .menu button, .slash-item, .diagram-bar button { min-height: 44px; }
  .icon-btn { width: 44px; }
  .search input { height: 44px; }
  .workspace[data-mode="split"] { grid-template-columns: minmax(0, 1fr); }
  #editor { padding: 18px 16px 40vh; font-size: 16px; }
  .pane-read { padding: 20px 16px 30vh; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
.sidebar-foot a, .sidebar-link { color: var(--accent); }
a.btn { color: var(--ink); text-decoration: none; }

/* Halaman login */
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px 24px 22px; }
.brand-link { display: inline-block; color: var(--ink); text-decoration: none; font-size: 1.15rem; margin-bottom: 18px; }
.brand-link:hover { color: var(--accent); }
.login-title { margin: 0 0 18px; font-family: var(--font-read); font-size: 1.6rem; }
.login-note a { color: var(--accent); font-weight: 600; }
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.login-card .field input { font-family: var(--font-ui); font-size: 1rem; height: 44px; }
.login-submit { width: 100%; height: 44px; }
.login-note { margin: 16px 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

/* Akun di sidebar */
.account { display: grid; gap: 6px; padding: 8px 8px 0; border-top: 1px solid var(--line); font-size: 0.82rem; color: var(--muted); }
.account .who { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .where { line-height: 1.4; overflow-wrap: anywhere; }
.account .where.warn { color: var(--danger); font-weight: 600; }
.account-actions { display: flex; gap: 6px; }
.account-actions .btn { flex: 1; height: 32px; font-size: 0.8rem; padding: 0 6px; }
.account .team-name { color: var(--muted); }

.invite-actions { display: grid; gap: 10px; margin-top: 18px; }
.invite-actions .btn { width: 100%; }

/* Pemilih tim */
.team-wrap { position: relative; }
.team-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; text-align: left; }
.team-btn:hover { border-color: var(--muted); }
.team-btn .tn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.team-btn .tk { flex-shrink: 0; font-size: 0.75rem; color: var(--muted); }
.team-wrap .menu { left: 0; right: 0; min-width: 0; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
.menu button[aria-checked="true"] { font-weight: 700; }
.menu button .sub { display: block; font-size: 0.78rem; color: var(--muted); font-weight: 400; }

/* Dialog tim */
dialog.team-dialog { width: min(640px, calc(100vw - 32px)); }
.td-status { margin: -6px 0 16px; color: var(--muted); }
.td-status.warn { color: var(--danger); font-weight: 600; }
.td-section { border-top: 1px solid var(--line); padding: 14px 0; }
.td-section h3 { margin: 0 0 10px; font-size: 0.95rem; }
.td-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; flex-wrap: wrap; }
.td-row .grow { flex: 1; min-width: 0; }
.td-row .grow small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.td-role { font-size: 0.78rem; color: var(--muted); }
.td-link { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font-family: var(--font-mono); font-size: 0.8rem; }
.td-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.td-table th, .td-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.td-table-wrap { overflow-x: auto; }
.td-note { color: var(--muted); margin: 0 0 10px; line-height: 1.5; }
select.td-select { height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); padding: 0 8px; }
.banner .btn[hidden] { display: none; }
