:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --border: #e3e2dd;
  --text: #1a1a18;
  --text-secondary: #52514e;
  --muted: #86857f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #ecebe7;
  --warn-bg: #fff6d6;
  --warn-ink: #7a5600;
  --ok-bg: #e3f4ea;
  --ok-ink: #1d6b3c;
  --danger: #c23b3a;
  --sel: #e8f1fc;
  --block-bg: #eceae4;
  --radius: 10px;
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small, small { font-size: 12px; }
[hidden] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 28px; padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; color: var(--text); }
.brand small { color: var(--muted); font-weight: 400; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 8px 14px; border-radius: 8px; color: var(--text-secondary); }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--sel); color: var(--accent); font-weight: 600; }
.user { margin-left: auto; display: flex; gap: 12px; align-items: center; color: var(--text-secondary); }
.user form { margin: 0; }

main.page { max-width: 1240px; margin: 0 auto; padding: 24px; }
main.page.wide { max-width: none; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  font: inherit; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; border-color: #cfcec8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #256abf; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); padding: 6px 9px; border: 1px solid var(--border);
  border-radius: 7px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid #b7d3f6; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; line-height: 1.45; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--text-secondary); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters label { flex-direction: row; align-items: center; gap: 6px; }
.filters.bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; }
.quick { margin-left: auto; color: var(--muted); }

.messages { margin-bottom: 16px; display: grid; gap: 8px; }
.msg { padding: 10px 14px; border-radius: 8px; background: var(--sel); color: var(--text); }
.msg.error { background: #fde8e8; color: #8a1f1f; }
.msg.success { background: var(--ok-bg); color: var(--ok-ink); }
.msg.warning { background: var(--warn-bg); color: var(--warn-ink); }

/* tables */
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.grid td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.grid tr:hover td { background: var(--surface-2); }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid.compact td { padding: 6px 10px; }
/* ячейка остаётся table-cell (иначе её нижняя граница не стыкуется с соседними), флекс — внутри */
.grid .actions { white-space: nowrap; }
.grid .actions .act-wrap { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.grid .actions form { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; background: var(--bg); font-size: 12px; color: var(--text-secondary); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* upload */
.upload { margin-bottom: 18px; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border: 2px dashed #c9d9ee; border-radius: var(--radius); background: var(--surface); padding: 34px; cursor: pointer;
  text-align: center; color: var(--text-secondary); transition: background .15s, border-color .15s; }
.drop strong { font-size: 16px; color: var(--text); }
.drop input { display: none; }
.drop.hover { background: var(--sel); border-color: var(--accent); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop.busy strong::after { content: " — загружаю…"; }

/* login */
.login-card { max-width: 380px; margin: 80px auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px; display: grid; gap: 14px; }
.login-card form { display: grid; gap: 14px; }

/* editor */
.editor-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }
.editor-head .meta { display: flex; gap: 12px; flex-wrap: wrap; }
.save-area { display: flex; align-items: center; gap: 10px; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 460px; gap: 14px; align-items: start; }
.rows { padding: 0; overflow: hidden; }
.toolbar { display: flex; gap: 6px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.toolbar .spacer { flex: 1; }
.check { flex-direction: row; align-items: center; gap: 6px; }
.rows-head, .row { display: grid; grid-template-columns: 22px 30px minmax(0, 1fr) 130px 140px 140px 110px 24px;
  gap: 8px; align-items: center; padding: 7px 12px; }
.rows-head { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  border-bottom: 1px solid var(--border); background: var(--surface-2); }
.row { border-bottom: 1px solid var(--grid); cursor: pointer; font-size: 13px; }
.row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .t { white-space: normal; font-weight: 500; }
.row .t small.w { display: block; color: var(--warn-ink); font-weight: 400; }
.row:hover { background: var(--surface-2); }
.row.sel { background: var(--sel); box-shadow: inset 3px 0 0 var(--accent); }
.row.warn { background: var(--warn-bg); }
.row.warn.sel { background: #fdeebd; }
.row .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.row .handle { cursor: grab; color: #b9b8b2; user-select: none; }
.row .rm { color: #c9c8c2; text-align: center; }
.row .rm:hover { color: var(--danger); }
.row.kind-ad .t { color: var(--danger); }
.row.kind-block { background: var(--block-bg); }
.row.kind-block .blk { grid-column: 2 / -1; font-weight: 700; letter-spacing: .08em; font-size: 12px; text-align: center; }
.row .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; margin-left: 4px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--bg); font-size: 12px; color: var(--text-secondary); }
.sortable-ghost { opacity: .4; }
.hint { color: var(--muted); font-size: 12px; padding: 8px 12px; margin: 0; }

.panel { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.panel-empty { color: var(--muted); text-align: center; padding: 60px 10px; }
.panel-form { display: grid; gap: 12px; }
.panel-top { display: flex; justify-content: space-between; align-items: center; }
.panel-top h3 { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f-story { display: grid; gap: 12px; }

/* analytics */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--text-secondary); font-size: 12px; }
.kpi b { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.charts .span2 { grid-column: 1 / -1; }
.ch { position: relative; height: 260px; }
.ch.tall { height: 280px; }
.ch.short { height: 180px; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .charts { grid-template-columns: 1fr; }
  .rows-head, .row { grid-template-columns: 22px 30px minmax(0, 1fr) 110px 100px 24px; }
  .rows-head span:nth-child(6), .rows-head span:nth-child(7), .row > span:nth-child(6), .row > span:nth-child(7) { display: none; }
}

/* утверждение */
.btn.approve { border-color: #1baf7a; color: #0f7a53; }
.btn.approve:hover { background: var(--ok-bg); }
.approved-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 24px; background: var(--ok-bg); color: var(--ok-ink); border-top: 1px solid #b9e2c8; font-size: 14px; }
.approved-bar .check-ico { width: 22px; height: 22px; border-radius: 50%; background: #1d6b3c; color: #fff;
  display: grid; place-items: center; font-size: 13px; }
.approved-bar .muted { color: #4d8a64; }
.approved-bar #btn-unapprove { margin-left: auto; color: var(--ok-ink); }
body.is-locked main { padding-bottom: 70px; }
body.is-locked .row .handle, body.is-locked .row .rm { visibility: hidden; }
body.is-locked .row { cursor: default; }
body.is-locked #panel-form textarea, body.is-locked #panel-form input, body.is-locked #panel-form select,
body.is-locked .editor-head input, body.is-locked .editor-head select { background: var(--surface-2); color: var(--text); }
.pill.appr { background: var(--ok-bg); color: var(--ok-ink); }
.row .t { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.approved-bar.view { background: #eef3fb; color: #1c4f8f; border-top-color: #cfe0f5; }
.approved-bar.view .check-ico { background: #2a78d6; }
.approved-bar.view .muted { color: #5b7ea8; }
.user .pill { margin-left: 4px; }

/* ================================================================= mobile */
.mob, .meta-toggle, .sheet-back { display: none; }
.panel-top { gap: 8px; }
.panel-top h3 { flex: 1; }
.move { display: inline-flex; gap: 4px; }

@media (max-width: 760px) {
  :root { font-size: 15px; }
  .desk { display: none; }
  .mob { display: inline; }
  input, select, textarea { font-size: 16px; }              /* iOS не зумит поля */
  .btn { padding: 9px 14px; }
  .btn.small { padding: 7px 11px; }

  /* шапка */
  .topbar { height: auto; flex-wrap: wrap; gap: 6px 12px; padding: 10px 14px 0; }
  .brand small { display: none; }
  .user { margin-left: auto; font-size: 13px; gap: 8px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 8px; }
  .topbar nav a { padding: 7px 12px; white-space: nowrap; }
  main.page { padding: 12px; }

  /* список выпусков — карточки */
  .drop { padding: 18px; }
  .drop span { display: none; }
  .card { padding: 14px; }
  .card-head { flex-direction: column; align-items: stretch; }
  .filters { gap: 6px; }
  .filters input, .filters select { flex: 1 1 130px; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 2px;
    border-bottom: 1px solid var(--border); }
  table.cards td { display: block; padding: 0; border: 0; }
  table.cards tr:hover td { background: none; }
  table.cards .c-date { font-size: 16px; font-weight: 600; }
  table.cards .c-date a::after { content: ""; }
  table.cards .c-time { grid-column: 2; grid-row: 1; font-size: 16px; font-weight: 600; text-align: right; }
  table.cards .c-lang, table.cards .c-tpl, table.cards .c-n, table.cards .c-w { display: inline; color: var(--text-secondary); font-size: 13px; }
  table.cards .c-lang { grid-column: 1; }
  table.cards .c-tpl { grid-column: 2; text-align: right; }
  table.cards .c-n { grid-column: 1; text-align: left; }
  table.cards .c-n::after { content: " материалов"; }
  table.cards .c-w { grid-column: 2; text-align: right; }
  table.cards .c-w .muted { display: none; }
  table.cards .c-st { grid-column: 1 / -1; margin-top: 4px; }
  table.cards .c-by { grid-column: 1 / -1; font-size: 12px; }
  table.cards .c-by br { display: none; }
  table.cards .c-act { grid-column: 1 / -1; margin-top: 8px; }
  table.cards .c-act .act-wrap { justify-content: flex-start; }
  table.cards .empty { display: block; }

  /* редактор */
  .editor-head { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 12px; }
  .meta-toggle { display: flex; justify-content: space-between; width: 100%; background: none; border: 0; padding: 4px 0;
    font: inherit; font-weight: 600; color: var(--text); cursor: pointer; }
  .meta-toggle::after { content: "▾"; color: var(--muted); }
  .editor-head.meta-open .meta-toggle::after { content: "▴"; }
  #meta-sum { color: var(--muted); font-weight: 400; margin-left: auto; margin-right: 8px; }
  .editor-head .meta { display: none; }
  .editor-head.meta-open .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .editor-head .meta label input, .editor-head .meta label select { width: 100%; }
  .save-area { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface);
    border-top: 1px solid var(--border); padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    display: flex; gap: 8px; flex-wrap: wrap; }
  .save-area #state { width: 100%; font-size: 12px; }
  .save-area .btn { flex: 1; justify-content: center; }
  .save-area #state:empty { display: none; }
  main.page.wide { padding-bottom: 96px; }

  .editor { display: block; }
  .rows { border-radius: var(--radius); }
  .toolbar { flex-wrap: wrap; }
  .toolbar .btn { flex: 1 1 auto; }
  .toolbar .spacer { display: none; }
  .toolbar .check { width: 100%; font-size: 13px; }
  .rows-head { display: none; }
  .row { display: flex !important; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; padding: 12px; }
  .row[hidden] { display: none !important; }
  .row .handle, .row .rm { display: none !important; }
  .row .n { flex: 0 0 22px; }
  .row .t { flex: 1 1 calc(100% - 34px); font-size: 15px; }
  .row > span:nth-child(n+4):not(.rm):not(:empty) { flex: 0 0 auto; font-size: 12px; color: var(--text-secondary);
    white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .row > span:nth-child(4) { margin-left: 30px; font-weight: 600; color: var(--text) !important; }
  .row > span:nth-child(5):not(:empty)::before, .row > span:nth-child(6):not(:empty)::before { content: "· "; color: var(--muted); }
  .row > span:empty { display: none; }
  .row.kind-block .blk { flex: 1; }
  .hint { display: none; }

  /* панель правки — полноэкранный лист */
  .panel { display: none; }
  body.sheet-open .panel { display: block; position: fixed; inset: 0; z-index: 30; max-height: none; border-radius: 0;
    border: 0; padding: 12px 14px calc(96px + env(safe-area-inset-bottom)); overflow: auto; }
  body.sheet-open { overflow: hidden; }
  .sheet-back { display: inline-flex; }
  .panel-top { position: sticky; top: -12px; background: var(--surface); padding: 8px 0; z-index: 1; flex-wrap: wrap; }
  .panel-top h3 { font-size: 16px; }
  .two { grid-template-columns: 1fr; }
  #f-body { min-height: 45vh; }

  /* полоса утверждения — над панелью действий */
  .approved-bar { bottom: 58px; padding: 8px 12px; font-size: 13px; flex-wrap: wrap; }
  body.is-locked .approved-bar { bottom: 58px; }
  body.is-locked main.page.wide { padding-bottom: 150px; }
  .approved-bar #bar-note { display: none; }

  /* аналитика */
  .filters.bar { padding: 10px; }
  .filters.bar label { flex: 1 1 45%; }
  .quick { margin-left: 0; width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi b { font-size: 22px; }
  .charts { grid-template-columns: 1fr; gap: 10px; }
  .ch { height: 220px; }

  /* вход */
  .login-card { margin: 30px auto; padding: 22px; }
}

@media (max-width: 760px) {
  body.no-actions .save-area { display: none; }
  body.no-actions .approved-bar { bottom: 0; }
  body.no-actions main.page.wide { padding-bottom: 80px; }
}
@media (max-width: 760px) {
  table.cards .c-by small::before { content: " · "; }
  .meta-toggle { text-align: left; }
}

/* скрытый текст сюжета */
.row .t small.nb { display: block; color: var(--muted); font-style: italic; }
.f-hide { margin: 4px 0 2px; }
.f-hidden-note { margin: 0 0 8px; }

/* выделение автора в тексте */
.author-pop { position: fixed; z-index: 50; display: flex; gap: 6px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,.14); }
.author-pop .btn { white-space: nowrap; }
.f-body.peek textarea { background: var(--surface-2); color: var(--text-secondary); }
#f-author.flash { animation: author-flash 1.2s ease-out; }
@keyframes author-flash { 0% { background: var(--ok-bg); border-color: #1baf7a; } 100% { background: inherit; } }
@media (max-width: 760px) {
  .author-pop { flex-direction: column; }
}

/* всплывающее уведомление с отменой */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius);
  background: #1f1f1d; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 14px; }
.toast .btn { background: transparent; color: #8fc1ff; border-color: transparent; font-weight: 600; }
.toast .btn:hover { background: rgba(255,255,255,.08); }
.toast .muted { color: #a9a8a3; }
body.is-locked .toast { display: none; }
@media (max-width: 760px) { .toast { bottom: 84px; } }
