/* ───────── токены ───────── */
:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef1f6; --text: #141821; --muted: #667085;
  --line: #e3e7ee; --accent: #2f6df6; --accent-ink: #ffffff; --accent-soft: #e6eeff;
  --ok: #138a4a; --warn: #b7791f; --danger: #d92d20; --danger-soft: #fdeceb;
  --radius: 16px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 28px rgba(16, 24, 40, .07);
  --shadow-hover: 0 2px 4px rgba(16, 24, 40, .06), 0 18px 40px rgba(16, 24, 40, .13);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1016; --surface: #151922; --surface-2: #1c222d; --text: #e9ecf2; --muted: #8b95a7;
    --line: #262d3a; --accent: #5b8cff; --accent-ink: #0a0f1d; --accent-soft: #1a2542;
    --ok: #3ddc84; --warn: #f0b429; --danger: #ff6b60; --danger-soft: #3a1c1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .4), 0 18px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.grow { flex: 1; }
[hidden] { display: none !important; }
.ic { width: 1.1em; height: 1.1em; vertical-align: -.17em; flex: none; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.container.narrow { max-width: 860px; }
main.container { padding-top: 26px; padding-bottom: 60px; }

/* ───────── шапка ───────── */
.site-head { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.head-in { display: flex; align-items: center; gap: 18px; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #4f8cff, #7a4dff);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 16px; }
.brand-text small { color: var(--muted); font-size: 12px; }

/* ───────── кнопки и поля ───────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: transform .08s, background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.icon-only { padding: 9px 11px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field > span em { font-weight: 400; font-style: normal; opacity: .75; margin-left: 6px; }
input[type=text], input[type=search], input[type=date], input:not([type]), textarea, select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }

/* ───────── панель поиска и теги ───────── */
.toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 22px; }
.toolbar h2 { margin: 0; font-size: 22px; }
.search { position: relative; flex: 1 1 320px; max-width: 460px; }
.search .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; border-radius: 999px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 6px 13px; border-radius: 999px;
  font: inherit; font-size: 13px; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ───────── плитки ───────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 20px; }
.tile {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; color: var(--text); box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s, border-color .18s;
}
.tile:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); text-decoration: none; }
.cover {
  position: relative; aspect-ratio: 16 / 9; overflow: hidden; display: grid; place-items: center;
  background: linear-gradient(135deg, hsl(var(--h1) 72% 56%), hsl(var(--h2) 70% 42%));
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-mark { font-size: 76px; font-weight: 800; color: rgba(255, 255, 255, .28); letter-spacing: -.04em; user-select: none; }
.cover .pill { position: absolute; left: 12px; bottom: 12px; }
.badge-pin { position: absolute; right: 10px; top: 10px; background: rgba(0, 0, 0, .45); color: #ffd66b; border-radius: 999px; padding: 5px 7px; line-height: 0; backdrop-filter: blur(4px); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.pill.ver { background: rgba(0, 0, 0, .5); color: #fff; backdrop-filter: blur(4px); }
.pill.ver.solid { background: var(--accent-soft); color: var(--accent); backdrop-filter: none; font-size: 13px; }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.tile-body { padding: 16px 18px 8px; flex: 1; }
.tile-body h3 { font-size: 17px; margin-bottom: 6px; }
.summary { margin: 0 0 10px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
a.tag:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.tile-foot { display: flex; align-items: center; gap: 14px; padding: 12px 18px 16px; font-size: 13px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.empty.big { padding: 80px 0; }
.empty h2 { color: var(--text); font-size: 22px; margin: 10px 0 6px; }
.empty-ico { font-size: 48px; opacity: .5; } .empty-ico .ic { width: 1em; height: 1em; }
.code { font-size: 72px; font-weight: 800; letter-spacing: -.04em; color: var(--accent); }

/* ───────── страница публикации ───────── */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 14px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; }
.hero { display: grid; grid-template-columns: 300px 1fr; gap: 24px; padding: 0; overflow: hidden; }
.hero-cover { aspect-ratio: auto; min-height: 220px; height: 100%; }
.hero-body { padding: 24px 24px 24px 0; display: flex; flex-direction: column; gap: 12px; }
.hero-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hero h1 { font-size: 28px; }
.lead { margin: 0; font-size: 16px; color: var(--muted); }
.meta-row { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .hero-cover { min-height: 0; aspect-ratio: 16 / 9; }
  .hero-body { padding: 0 20px 22px; }
}
.files { list-style: none; margin: 0; padding: 0; }
.file { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.file:first-child { border-top: 0; padding-top: 0; }
.ext {
  flex: none; width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 11px; font-weight: 800;
  background: var(--accent-soft); color: var(--accent); letter-spacing: .02em;
}
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 700; color: var(--text); word-break: break-all; }
.file-note { color: var(--muted); font-size: 13px; margin-top: 2px; }
.file-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 4px; align-items: center; }
.hash { border: 0; background: var(--surface-2); color: var(--muted); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 8px; border-radius: 6px; cursor: pointer; }
.hash:hover, .hash.copied { background: var(--accent-soft); color: var(--accent); }
.copied { outline: 2px solid var(--ok); }
.file-actions { display: flex; gap: 8px; flex: none; }
@media (max-width: 560px) {
  .file { flex-wrap: wrap; }
  .file-actions { width: 100%; }
  .file-actions .primary { flex: 1; justify-content: center; }
}
.prose { line-height: 1.65; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; } .prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3 { margin: 1.3em 0 .5em; }
.prose h1 { font-size: 20px; } .prose h2 { font-size: 18px; } .prose h3 { font-size: 16px; }
.prose code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.prose pre { background: var(--surface-2); padding: 14px; border-radius: 12px; overflow: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { margin: 1em 0; padding: 2px 16px; border-left: 3px solid var(--accent); color: var(--muted); }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose img { max-width: 100%; border-radius: 10px; }

/* ───────── админка ───────── */
body.admin .head-in { gap: 14px; }
.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a { padding: 8px 14px; border-radius: 10px; color: var(--muted); font-weight: 600; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.user { font-size: 13px; color: var(--muted); padding: 4px 10px; background: var(--surface-2); border-radius: 999px; }
.tile.admin-tile { cursor: default; }
.tile.admin-tile:hover { transform: none; }
.tile-actions { display: flex; gap: 8px; padding: 0 18px 16px; flex-wrap: wrap; }
.cover .pill.state { left: auto; right: 12px; bottom: 12px; background: rgba(0, 0, 0, .55); color: #fff; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .lbl { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .val { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }
.card h3 { font-size: 15px; margin-bottom: 12px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.n, table.t th.n { text-align: right; }
table.t a { cursor: pointer; }
.scroll { overflow-x: auto; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* шторка редактора */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 20, .55); z-index: 40; backdrop-filter: blur(2px); animation: fade .15s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100%); z-index: 41; background: var(--bg);
  display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0, 0, 0, .3); animation: slide .2s ease-out;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-head h3 { font-size: 18px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px; }
.drawer-foot { display: flex; gap: 10px; padding: 14px 22px; background: var(--surface); border-top: 1px solid var(--line); align-items: center; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.block > h4 { margin: 0 0 12px; font-size: 14px; }
.switches { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 6px; }
.switch { display: flex; gap: 10px; align-items: center; cursor: pointer; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.cover-edit { display: flex; gap: 16px; align-items: center; }
.cover-edit .cover { width: 200px; border-radius: 12px; flex: none; }
.cover-edit .cover-mark { font-size: 44px; }
.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted);
  cursor: pointer; transition: all .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.frow { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.frow:first-child { border-top: 0; }
.frow .fname { font-weight: 600; word-break: break-all; }
.frow .fmeta { font-size: 12.5px; color: var(--muted); }
.frow input { grid-column: 1 / -1; font-size: 13px; padding: 7px 10px; }
.queue .q { padding: 8px 0; font-size: 13px; }
.queue .q .top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.queue .q.err .top span:last-child { color: var(--danger); }
.queue .q.ok .top span:last-child { color: var(--ok); }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow-hover); font-weight: 600; animation: fade .15s; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
.callout { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--text); font-size: 13.5px; margin-bottom: 14px; }
.callout.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); }
