:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --border: #dbe2e8;
  --text: #17222c;
  --muted: #5d6b78;
  --primary: #0b7a75;
  --primary-ink: #ffffff;
  --primary-soft: #e0f2f0;
  --danger: #c62828;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #1e7d32;
  --mark: #fff1a8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 10px;
  --sidebar: 300px;
  --top: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151b; --surface: #161e26; --surface-2: #1d2731; --border: #2a3642; --text: #e5ecf2;
    --muted: #93a3b2; --primary: #35b5ab; --primary-ink: #04201e; --primary-soft: #133331;
    --danger: #ff6b6b; --danger-soft: #3a1c1c; --warn: #f0c050; --warn-soft: #3a3016; --ok: #5ccf6b;
    --mark: #5c5216; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f151b; --surface: #161e26; --surface-2: #1d2731; --border: #2a3642; --text: #e5ecf2;
  --muted: #93a3b2; --primary: #35b5ab; --primary-ink: #04201e; --primary-soft: #133331;
  --danger: #ff6b6b; --danger-soft: #3a1c1c; --warn: #f0c050; --warn-soft: #3a3016; --ok: #5ccf6b;
  --mark: #5c5216; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.emergency { background: #c62828; border-color: #c62828; color: #fff; font-weight: 700; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 38px; padding: 0; font-size: 18px; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, select.input, textarea.input {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface);
}
.input:focus, .btn:focus-visible, .editor-area:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; }
.error-text { color: var(--danger); font-size: 14px; min-height: 20px; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top); display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); }
.brand img { width: 30px; height: 30px; border-radius: 7px; }
.search-box { flex: 1; max-width: 560px; position: relative; }
.search-box input { padding-left: 36px; background: var(--surface-2); border-color: transparent; }
.search-box::before { content: "⌕"; position: absolute; left: 12px; top: 7px; font-size: 18px; color: var(--muted); }
.badge-dot {
  position: absolute; top: 3px; right: 3px; min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 17px; text-align: center; font-weight: 700;
}
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: calc(100vh - var(--top)); }
.sidebar {
  position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow: auto;
  border-right: 1px solid var(--border); background: var(--surface); padding: 10px 8px 40px;
}
.main { min-width: 0; padding: 20px clamp(14px, 3vw, 40px) 80px; }
.main-inner { max-width: 920px; margin: 0 auto; }
.offline-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 13px; padding: 4px; }

/* ---------- tree */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 16px; }
.tree-item {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 7px; cursor: pointer;
  text-decoration: none; color: var(--text); font-size: 14px;
}
.tree-item:hover { background: var(--surface-2); }
.tree-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tree-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.tree-item .toggle { width: 16px; text-align: center; color: var(--muted); flex: none; }
.tree-item.emergency { color: var(--danger); font-weight: 600; }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 8px 6px; }

/* ---------- cards & lists */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tile { padding: 14px; display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--text); }
.tile:hover { border-color: var(--primary); }
.tile .ico { font-size: 22px; }
.list { display: flex; flex-direction: column; }
.list-item {
  display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text);
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item .title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.list-item mark { background: var(--mark); color: inherit; border-radius: 2px; }
.pill {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
  background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
}
.pill.new { background: var(--primary); color: var(--primary-ink); }
.pill.updated { background: var(--warn-soft); color: var(--warn); }
.pill.draft { background: var(--warn-soft); color: var(--warn); }
.pill.archived { background: var(--surface-2); color: var(--muted); }
.pill.important { background: var(--danger-soft); color: var(--danger); }
.tag { display: inline-block; padding: 2px 9px; margin: 2px 4px 2px 0; border-radius: 12px; font-size: 13px;
  background: var(--surface-2); color: var(--muted); text-decoration: none; }
.tag:hover { color: var(--primary); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.section-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 10px; }
.section-head h2 { margin: 0; font-size: 18px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }

.emergency-hero {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: var(--radius);
  background: #c62828; color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; box-shadow: var(--shadow);
}
.emergency-hero small { display: block; font-weight: 400; font-size: 13px; opacity: .9; }

/* ---------- article */
.article-head h1 { margin: 6px 0 6px; font-size: clamp(22px, 3vw, 30px); }
.article-body { position: relative; font-size: 16px; line-height: 1.65; overflow-wrap: break-word; }
.article-body img, .article-body video { max-width: 100%; height: auto; border-radius: 8px; }
.article-body table, .editor-area table { border-collapse: collapse; width: 100%; margin: 12px 0; display: block; overflow-x: auto; }
.article-body th, .article-body td, .editor-area th, .editor-area td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; min-width: 60px; }
.article-body th, .editor-area th { background: var(--surface-2); }
.article-body blockquote, .editor-area blockquote { margin: 12px 0; padding: 8px 14px; border-left: 4px solid var(--primary); background: var(--primary-soft); border-radius: 0 8px 8px 0; }
.article-body mark, .editor-area mark { background: var(--mark); color: inherit; padding: 0 2px; }
.article-body pre, .editor-area pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; }
.article-body a[data-file], .editor-area a[data-file] {
  display: inline-flex; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; margin: 4px 0;
}
.no-copy { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.watermark { position: absolute; inset: 0; pointer-events: none; z-index: 2; opacity: .22; background-repeat: repeat; }
.attachments a { display: flex; gap: 8px; padding: 8px 0; }

/* ---------- overlays */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 16, 22, .55);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow: auto;
}
.modal { width: 100%; max-width: 520px; padding: 20px; }
.modal.wide { max-width: 860px; }
.modal h3 { margin-top: 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.toast-wrap { pointer-events: none; position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
.menu { position: absolute; right: 8px; top: calc(var(--top) - 4px); z-index: 50; min-width: 240px; padding: 6px; }
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- auth / lock */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-card .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-card .logo img { width: 44px; height: 44px; border-radius: 10px; }
.lock-screen { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--primary); }
.pin-dots i.on { background: var(--primary); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.pin-pad button { height: 64px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: 24px; cursor: pointer; }
.pin-pad button:active { background: var(--primary-soft); }

/* ---------- admin */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
table.data tr:hover td { background: var(--surface-2); }
.cat-admin li > .tree-item { border: 1px dashed transparent; cursor: grab; }
.cat-admin .drop-inside > .tree-item { border-color: var(--primary); background: var(--primary-soft); }
.cat-admin .drop-before > .tree-item { box-shadow: inset 0 3px 0 var(--primary); }
.cat-admin .drop-after > .tree-item { box-shadow: inset 0 -3px 0 var(--primary); }
.cat-admin .dragging { opacity: .4; }
.roles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 12px; }
.secret-box { font: 600 20px/1.3 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .06em; background: var(--surface-2); padding: 12px; border-radius: 8px; text-align: center; -webkit-user-select: all; user-select: all; }

/* ---------- editor */
.editor-toolbar {
  position: sticky; top: var(--top); z-index: 10; display: flex; flex-wrap: wrap; gap: 2px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-bottom: 0; border-radius: 8px 8px 0 0;
}
.editor-toolbar button, .editor-toolbar select { min-width: 34px; height: 32px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; padding: 0 7px; }
.editor-toolbar button:hover { background: var(--surface); }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 4px 4px; }
.editor-area { min-height: 380px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 8px 8px; line-height: 1.6; font-size: 16px; overflow-wrap: break-word; }
.editor-area img, .editor-area video { max-width: 100%; }
.editor-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.edit-grid { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.diff-box { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }

.mobile-only { display: none; }
.side-shade { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: var(--top); width: min(86vw, 340px); transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  body.side-open .sidebar { transform: none; }
  body.side-open .side-shade { display: block; }
  .side-shade { display: none; position: fixed; inset: var(--top) 0 0 0; background: rgba(0,0,0,.35); z-index: 35; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .brand span { display: none; }
  .edit-grid { grid-template-columns: 1fr; }
  .main { padding-top: 14px; }
}
@media (max-width: 860px) {
  /* таблицы управления на телефоне: каждая строка — карточка, без горизонтальной прокрутки */
  .table-wrap > table.data thead { display: none; }
  .table-wrap > table.data, .table-wrap > table.data tbody, .table-wrap > table.data tr, .table-wrap > table.data td { display: block; width: auto; }
  .table-wrap > table.data tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table-wrap > table.data tr:last-child { border-bottom: 0; }
  .table-wrap > table.data td { border: 0; padding: 3px 0; max-width: none !important; }
  .table-wrap > table.data td:empty { display: none; }
  body.vl-claude .brand { display: none; }
}
@media print {
  .topbar, .sidebar, .no-print { display: none !important; }
  .layout { display: block; }
}
