:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --brand: #111827; --accent: #2563eb; --accent-soft: #e8f0fe; --ok: #127a3d; --ok-soft: #e6f4ea;
  --warn: #8a5a00; --warn-soft: #fff4d6; --err: #b42318; --err-soft: #fdecea; --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; } .right { text-align: right; }
.inline { display: inline; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--brand); color: #fff; }
.brand { color: inherit; font-weight: 600; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand.big { font-size: 18px; color: var(--ink); justify-content: center; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: #fff; color: var(--brand); font-weight: 800; }
.brand.big .logo { background: var(--brand); color: #fff; }
.search { flex: 1; max-width: 520px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 6px; border: 0; }
.topnav { display: flex; align-items: center; gap: 14px; margin-left: auto; }
.topnav a, .topnav .link { color: #d7dbe3; }
.topnav a.btn.primary { color: #fff; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 52px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 16px 10px; overflow-y: auto; }
.side-title { margin: 16px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-link, .tree a { display: block; padding: 5px 8px; border-radius: 6px; color: var(--ink); }
.side-link.active, .tree a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree .tree { padding-left: 14px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

.page-head { margin-bottom: 18px; }
.page-head.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.btn { display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font: inherit; }
.btn:hover { text-decoration: none; border-color: #c8ccd6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.link.danger { color: var(--err); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.card.login { width: 360px; text-align: center; }
.card.login form { text-align: left; margin-top: 16px; }
.card.narrow { max-width: 520px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid2 > .panel { margin-top: 18px; }

label { display: block; font-weight: 500; margin-bottom: 12px; }
input, select { font: inherit; }
label input:not([type=checkbox]), label select, .stack input, .row-form input, .row-form select, .share-form select, .share-form input, .copy-row input {
  display: block; width: 100%; margin-top: 4px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.stack > label { margin: 0; }
.form-wide { max-width: 560px; }
.row-form, .share-form, .copy-row, .inline-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row-form input, .row-form select, .share-form select, .share-form input, .copy-row input, .inline-actions select { width: auto; flex: 1; margin: 0; }
.inline-actions { justify-content: flex-end; margin: 0; }
.inline-actions select { flex: 0 1 auto; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; }
.row-form.wrap { flex-wrap: wrap; }
fieldset.checks { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
fieldset.checks label { font-weight: 400; margin: 4px 0; }

table { width: 100%; border-collapse: collapse; }
table.docs { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.grants td, .versions td { padding: 8px 6px; }
.versions tr.current td { background: var(--accent-soft); }
.doc-title { font-weight: 600; color: var(--ink); }
.snippet { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kind { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: #eef0f4; color: #4a5263; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #eef0f4; color: #4a5263; white-space: nowrap; }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.published { background: var(--ok-soft); color: var(--ok); }
.badge.archived { background: #eceef2; color: #6b7385; }
.empty { padding: 30px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--err-soft); color: var(--err); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.subfolders { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 6px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); }

.viewer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.viewer iframe { display: block; width: 100%; height: 78vh; border: 0; background: #fff; }
.viewer img { display: block; max-width: 100%; margin: 0 auto; }
.viewer pre.plain { margin: 0; padding: 18px; white-space: pre-wrap; max-height: 78vh; overflow: auto; }
.markdown { padding: 24px 32px; line-height: 1.6; max-width: 900px; }
.markdown table { border: 1px solid var(--line); margin: 12px 0; }
.markdown td, .markdown th { border: 1px solid var(--line); }
.markdown img { max-width: 100%; }
.markdown pre { background: #f3f4f6; padding: 12px; border-radius: 6px; overflow: auto; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 6px; overflow: auto; font-size: 12px; }

.groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 14px; }
.group { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.group h3 { margin-top: 0; }
.members { list-style: none; padding: 0; margin: 0 0 8px; }
.members li { padding: 3px 0; display: flex; gap: 6px; align-items: baseline; }
.members form { margin-left: auto; }
.audit td { font-size: 12px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .topnav a:not(.btn) { display: none; }
}
