:root {
  --green: #3cb878;
  --green-d: #2f9c63;
  --ink: #1f2a24;
  --muted: #6b7a72;
  --line: #e3e9e5;
  --bg: #f5f7f6;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 1px solid var(--line); padding: 12px 22px;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; }
.brand span { color: var(--muted); font-weight: 400; }
nav a { color: var(--ink); text-decoration: none; margin-left: 18px; font-size: 14px; }
nav a:hover { color: var(--green-d); }
nav a.logout { color: #c0392b; }
.wrap { max-width: 900px; margin: 24px auto; padding: 0 18px; }

.head { display: flex; align-items: baseline; justify-content: space-between; }
.head h1 { font-size: 22px; margin: 0 0 4px; }
.stats { color: var(--muted); font-size: 13px; }

.root-add, .tree { background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.root-add { padding: 14px 16px; margin: 16px 0; }
.root-add strong { display: block; margin-bottom: 8px; font-size: 14px; }

ul.tree, ul.children { list-style: none; margin: 0; padding: 0; }
ul.tree { padding: 8px; margin-top: 8px; }
ul.children { margin-left: 22px; border-left: 2px solid var(--line); padding-left: 6px; }
.node { margin: 2px 0; }
.node-row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  border-radius: 8px;
}
.node-row:hover { background: #f0f5f2; }
.node.unpub > .node-row { opacity: .55; }
.node-title { font-weight: 500; }
.is-folder > .node-row > .node-title { font-weight: 600; cursor: pointer; }
.badge { font-size: 14px; }

/* Сворачивание папок */
.node-toggle {
  border: none; background: none; cursor: pointer; line-height: 1;
  font-size: 15px; padding: 2px;
}
.node-toggle::before { content: "📁"; }
.node.is-folder:not(.collapsed) > .node-row .node-toggle::before { content: "📂"; }
.count-chip {
  font-size: 11px; color: var(--muted); background: #eef4f0;
  border-radius: 20px; padding: 1px 7px; min-width: 20px; text-align: center;
}
.node.collapsed > .children,
.node.collapsed > details.add { display: none; }

.tree-toolbar { display: flex; gap: 8px; margin: 14px 0 0; }
.tree-toolbar button {
  font: inherit; font-size: 13px; cursor: pointer; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px;
}
.tree-toolbar button:hover { border-color: var(--green); color: var(--green-d); }

.tag {
  font-size: 11px; color: var(--muted); background: #eef3f0;
  padding: 1px 7px; border-radius: 20px; white-space: nowrap;
}
.tag-ext { background: #fff4e5; color: #b9770e; }
.tag-draft { background: #fdecea; color: #c0392b; }

.actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.pos-form { margin: 0; }
input.pos {
  width: 46px; padding: 3px 5px; text-align: center; font-size: 13px;
  border: 1px solid var(--line); border-radius: 6px; -moz-appearance: textfield;
}
input.pos:focus { border-color: var(--green); outline: none; }
input.pos::-webkit-outer-spin-button, input.pos::-webkit-inner-spin-button { margin: 0; }
.actions form.inline { display: inline; margin: 0; }
.actions button, .pop summary {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  cursor: pointer; font-size: 13px; padding: 3px 7px; line-height: 1;
}
.actions button:hover, .pop summary:hover { border-color: var(--green); }
.actions button.danger:hover { border-color: #e74c3c; }
.pop summary { list-style: none; display: inline-block; }
.pop[open] summary { border-color: var(--green); }

details.pop, details.add { position: relative; }
.edit-form, .add-form {
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
}
details.pop .edit-form {
  position: absolute; right: 0; top: 110%; z-index: 20; width: 320px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
details.add { margin: 4px 0 8px 22px; }
details.add summary {
  cursor: pointer; color: var(--green-d); font-size: 13px; list-style: none;
}
.add-form {
  flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
  background: #f0f5f2; border-radius: 10px; margin-top: 6px;
}
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; }
input, select {
  font: inherit; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff;
}
.add-form input[name=title] { flex: 1; min-width: 160px; }
.add-form .file-only { display: none; gap: 8px; }
.add-form.file-mode .file-only { display: flex; }
button[type=submit] {
  background: var(--green); color: #fff; border: none; border-radius: 7px;
  padding: 8px 16px; font-weight: 600; cursor: pointer;
}
button[type=submit]:hover { background: var(--green-d); }
.empty { color: var(--muted); padding: 20px; text-align: center; }

/* Логин */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: 320px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.06);
}
.login-card .brand { font-size: 20px; text-align: center; }
.login-card .error { background: #fdecea; color: #c0392b; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
