:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --text: #1d2129;
  --muted: #6b7280;
  --line: #e4e6eb;
  --accent: #ff6a1a;
  --accent-soft: #fff1e8;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e8efff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--info); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer; white-space: nowrap; font-weight: 500; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: #c9ccd3; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(0.95); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.danger-text { color: var(--bad); }

input[type='text'], input[type='search'], input[type='date'], input[type='number'], input[type='password'], select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, .editor:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.03em; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.page { max-width: 1100px; margin: 24px auto; padding: 0 20px; display: grid; gap: 20px; }
.page h2 { font-size: 18px; margin-bottom: 12px; }
.page p { line-height: 1.5; }

/* ---------- Посты ---------- */
.posts-layout { display: grid; grid-template-columns: 270px 1fr; gap: 20px; padding: 20px; align-items: start; }
.filters { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.filters .panel { padding: 16px; }
.filters .row { flex-direction: column; align-items: stretch; gap: 0; }
.filters h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 12px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tab {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-weight: 500; color: var(--muted);
}
.tab b { color: var(--text); margin-left: 4px; font-weight: 600; }
.tab.active { background: var(--text); border-color: var(--text); color: #fff; }
.tab.active b { color: #fff; }

.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; margin-bottom: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.toolbar .spacer { flex: 1; }
.toolbar select { width: auto; height: 30px; }
.toolbar.bulk { background: var(--text); color: #fff; border-color: var(--text); }
.toolbar.bulk .btn { height: 30px; }
.toolbar.bulk select { color: var(--text); }

.list { display: grid; gap: 10px; }
.card {
  display: grid; grid-template-columns: 28px 196px 1fr auto; gap: 14px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: opacity 0.15s, border-color 0.15s;
  border-left: 4px solid var(--line);
}
.card.st-approved { border-left-color: var(--ok); }
.card.st-rejected { border-left-color: var(--bad); }
.card.st-new { border-left-color: #cbd0d8; }
.card.focused { outline: 2px solid var(--accent); outline-offset: -1px; }
.card.selected { background: #fffaf5; }
.card.gone { opacity: 0.45; }
.card .check { display: flex; align-items: flex-start; padding-top: 4px; }
.card .check input { width: 16px; height: 16px; cursor: pointer; }

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; align-content: start; cursor: pointer; }
.thumbs.one { grid-template-columns: 1fr; }
.thumbs.two { grid-template-columns: 1fr 1fr; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: #e9ebef;
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px;
}
.thumbs.one .thumb { aspect-ratio: 4 / 3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play {
  position: absolute; inset: auto 6px 6px auto; padding: 2px 6px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 11px;
}
.thumb .more {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.5); color: #fff; font-weight: 600; font-size: 15px;
}
.thumbs-empty { height: 100%; min-height: 60px; border: 1px dashed var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }

.card .content { min-width: 0; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.meta .reacts { color: var(--text); }
.card h3 { font-size: 15px; line-height: 1.35; margin-bottom: 4px; cursor: pointer; }
.card h3:hover { color: var(--accent); }
.excerpt { margin: 0; color: #3c4250; line-height: 1.45; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--bg); color: var(--muted); font-size: 12px; border: 1px solid transparent;
}
.chip.type { background: var(--info-soft); color: var(--info); }
.chip.rubric { background: var(--accent-soft); color: #c2410c; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.tag { cursor: pointer; }
.chip.tag:hover { border-color: var(--line); }

.card .actions { display: flex; flex-direction: column; gap: 6px; }
.act {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; font-size: 17px; display: flex; align-items: center; justify-content: center;
}
.act.approve:hover, .st-approved .act.approve { background: var(--ok); border-color: var(--ok); color: #fff; }
.act.reject:hover, .st-rejected .act.reject { background: var(--bad); border-color: var(--bad); color: #fff; }
.act.edit:hover { background: var(--bg); }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 20px 0 40px; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.7; }
kbd { display: inline-block; min-width: 20px; padding: 0 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: #fff; font-size: 11px; text-align: center; font-family: inherit; }

/* ---------- Модальное окно ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 18, 25, 0.55); display: flex; align-items: flex-start; justify-content: center; padding: 3vh 2vw; overflow: auto; }
.modal { width: min(1280px, 100%); background: var(--panel); border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; max-height: 94vh; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; flex: 1; }
.modal-body { display: grid; grid-template-columns: 1fr 1.15fr; gap: 0; overflow: hidden; flex: 1; min-height: 0; }
.modal-body > div { overflow: auto; padding: 20px; }
.modal-body > div:first-child { border-right: 1px solid var(--line); background: #fafbfc; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.modal-foot .spacer { flex: 1; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gitem { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.gitem.excluded { opacity: 0.4; }
.gitem.cover { outline: 3px solid var(--accent); }
.gitem .gmedia { aspect-ratio: 1; background: #e9ebef; display: flex; align-items: center; justify-content: center; cursor: zoom-in; position: relative; }
.gitem .gmedia img { width: 100%; height: 100%; object-fit: cover; }
.gitem .gbar { display: flex; gap: 4px; padding: 6px; }
.gitem .gbar button { flex: 1; height: 26px; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.gitem .gbar button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.seg button.on { background: var(--info); border-color: var(--info); color: #fff; }
.seg.rubrics button.on { background: var(--accent); border-color: var(--accent); }

.editor-tools { display: flex; gap: 4px; margin-bottom: 6px; flex-wrap: wrap; }
.editor-tools button { height: 28px; min-width: 30px; padding: 0 8px; border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer; }
.editor {
  min-height: 220px; max-height: 46vh; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 8px;
  line-height: 1.55; background: #fff;
}
.editor blockquote, .orig blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); }
.orig { padding: 12px; border: 1px dashed var(--line); border-radius: 8px; line-height: 1.55; background: #fafbfc; margin-top: 8px; font-size: 13px; }
.spoiler { background: #e5e7eb; border-radius: 3px; }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.9); display: flex; align-items: center; justify-content: center; }
.lightbox img, .lightbox video { max-width: 92vw; max-height: 90vh; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.15); color: #fff; font-size: 22px; cursor: pointer; }
.lightbox .lb-prev { left: 20px; }
.lightbox .lb-next { right: 20px; }
.lightbox .lb-count { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); color: #fff; }

/* ---------- Таблицы ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.tbl input { height: 30px; }
.tbl td.num { text-align: right; width: 70px; }
.tbl td.act-cell { width: 1%; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.stat b { display: block; font-size: 24px; margin-top: 4px; }
.progress { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; margin: 10px 0; }
.progress div { height: 100%; background: var(--accent); transition: width 0.3s; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px; overflow: auto; font-size: 12px; line-height: 1.5; }
.tagcloud { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Уведомления ---------- */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; padding: 10px 16px; border-radius: 8px; background: var(--text); color: #fff; box-shadow: var(--shadow); }
.toast.error { background: var(--bad); }

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login form { width: 340px; }
.login h1 { font-size: 20px; margin-bottom: 16px; }
.login .error { color: var(--bad); margin: 8px 0; min-height: 18px; }

@media (max-width: 1200px) {
  .posts-layout { grid-template-columns: 230px 1fr; gap: 14px; padding: 14px; }
  .card { grid-template-columns: 24px 150px 1fr auto; gap: 12px; }
}

@media (max-width: 820px) {
  .posts-layout { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; }
  .card { grid-template-columns: 24px 120px 1fr; }
  .card .actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .modal-body { grid-template-columns: 1fr; overflow: auto; }
}
