/* Атрибут hidden должен скрывать элемент даже там, где задан display (label, flex-строки). */
[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2481cc; --accent-text: #fff; --hover: #f0f3f7;
  --green: #1f9d55; --green-bg: #e3f6ea; --amber: #b7791f; --amber-bg: #fdf3dc;
  --red: #d64545; --red-bg: #fde8e8; --blue: #2b6cb0; --blue-bg: #e4effa; --gray-bg: #eceef2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #9099ab; --line: #2b313d;
    --accent: #3d9be9; --hover: #232a35;
    --green: #4cc38a; --green-bg: #173326; --amber: #e0b04f; --amber-bg: #3a2f16;
    --red: #f07a7a; --red-bg: #3d1e1e; --blue: #7ab3ef; --blue-bg: #1b2c40; --gray-bg: #2a303b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 12px; }
main { padding: 20px; max-width: 1600px; margin: 0 auto; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.r { text-align: right; white-space: nowrap; }

.top { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); }
.top nav a.on, .top nav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.cur-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.cur-switch a { padding: 3px 9px; font-size: 13px; color: var(--muted); }
.cur-switch a + a { border-left: 1px solid var(--line); }
.cur-switch a.on { background: var(--accent); color: var(--accent-text); }
.cur-switch a:hover { text-decoration: none; background: var(--hover); }
.cur-switch a.on:hover { background: var(--accent); }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
.banner { background: var(--blue-bg); color: var(--blue); padding: 8px 20px; font-size: 13px; }
.banner.warn { background: var(--amber-bg); color: var(--amber); }
.banner.err { background: var(--red-bg); color: var(--red); }
.inline { display: inline; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; display: inline-block; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .6; cursor: progress; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card.empty, td.empty { text-align: center; padding: 30px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--green-bg); color: var(--green); }
.flash.err { background: var(--red-bg); color: var(--red); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); }
.kpi.link:hover { border-color: var(--accent); text-decoration: none; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; }

/* Таблица прокручивается внутри своей рамки (и по горизонтали, и по вертикали) — тогда шапка и строка
   «Итого» залипают у её краёв. Высота — почти весь экран; меню сервиса поэтому не закреплено, чтобы не
   перекрывать шапку таблицы. */
.table-wrap { overflow: auto; max-height: calc(100vh - 24px); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; z-index: 2;
     background: var(--card); box-shadow: inset 0 -1px 0 var(--line), 0 2px 4px -2px rgba(0, 0, 0, .15); }
.table-wrap tfoot td { position: sticky; bottom: 0; z-index: 2; background: var(--card); box-shadow: inset 0 1px 0 var(--line); }
th a { color: var(--muted); }
tbody tr:hover { background: var(--hover); }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
table.compact td { padding: 6px 4px; }
table.ads { font-size: 13px; }
.title-cell { min-width: 220px; }
.target { min-width: 180px; max-width: 260px; color: var(--muted); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.err-row { background: var(--red-bg); }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.blue { background: var(--blue-bg); color: var(--blue); }
.pill.gray { background: var(--gray-bg); color: var(--muted); }
.cpa.good { color: var(--green); font-weight: 600; }
.cpa.warn { color: var(--amber); font-weight: 600; }
.cpa.bad { color: var(--red); font-weight: 600; }
.flag { color: var(--amber); cursor: help; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
input[type="search"] { min-width: 260px; }
input[type="checkbox"] { width: 16px; height: 16px; }
.bulkbar { display: flex; gap: 8px; align-items: center; background: var(--blue-bg); padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.bulkbar[hidden] { display: none; }

.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.crumbs { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.row-form { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.ad-preview { background: var(--hover); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; }
.ad-preview p { margin: 0 0 6px; }
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; border-bottom: 1px solid var(--line); }
.bar { flex: 1; height: 100%; position: relative; display: flex; align-items: flex-end; }
.bar .fill { width: 100%; background: var(--accent); opacity: .75; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar:hover .fill { opacity: 1; }
.bar .dot { position: absolute; left: 50%; transform: translate(-50%, -4px); font-size: 10px; color: var(--green); font-weight: 700; }
.chart-legend { display: flex; justify-content: space-between; margin-top: 4px; }

.rec { display: flex; gap: 12px; align-items: flex-start; border-left: 4px solid var(--line); }
.rec.high { border-left-color: var(--red); }
.rec.warn { border-left-color: var(--amber); }
.rec.info { border-left-color: var(--green); }
.rec-body { flex: 1; }
.rec-head { margin-bottom: 4px; }
.rec-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.rec-mini { margin-bottom: 6px; }
.rec-mini:not(.new) { opacity: .6; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tabs a.on { background: var(--card); border: 1px solid var(--line); color: var(--text); }

.form label { display: block; margin-bottom: 12px; font-weight: 500; }
.form label input:not([type="checkbox"]):not([type="radio"]), .form label select, .form label textarea, .form details textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.form label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.form .hint { display: block; color: var(--muted); font-size: 12px; font-weight: 400; margin-top: 2px; }
.form details { margin-bottom: 12px; }
.form summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.counter { float: right; color: var(--muted); font-weight: 400; font-size: 12px; }
.rules-help { padding-left: 18px; }
.progress { height: 10px; background: var(--gray-bg); border-radius: 5px; overflow: hidden; margin-bottom: 10px; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.kpis.compact { margin-bottom: 10px; }
.kpis.compact .kpi { padding: 8px 12px; }
.kpis.compact .value { font-size: 17px; }
.verdict-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.verdict-bar .pill { font-size: 12px; padding: 3px 10px; }
.bulk-tools { margin-bottom: 6px; }
.group h2 { margin: 0; }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.composer-side { position: sticky; top: 12px; }
.btn.wide { width: 100%; margin-top: 8px; }
.tabs-radio { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs-radio label { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-weight: 500; margin: 0; }
.tabs-radio label:has(input:checked) { border-color: var(--accent); background: var(--blue-bg); }
.tabs-radio.small label { font-size: 13px; font-weight: 400; }
.field-title { font-weight: 500; margin-bottom: 4px; }
.pick-box { border: 1px solid var(--line); border-radius: 6px; padding: 6px; margin-bottom: 12px; }
.pick-box .pick-filter { width: 100%; margin-bottom: 6px; }
.pick-list { max-height: 180px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 2px 10px; }
.pick { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 13px; margin: 0; }
.pick[hidden] { display: none; }
.days { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.ad-preview.tg { border-left: 0; background: var(--hover); }
.pv-site { font-weight: 600; margin-bottom: 4px; }
.pv-img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; margin: 6px 0; display: block; }
.pv-video { background: #222; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.pv-img[hidden] { display: none; }
.media-pick { display: grid; grid-template-columns: 160px 1fr; gap: 12px; align-items: start; margin-bottom: 8px; }
.media-current { min-height: 40px; }
.gen-preview { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--gray-bg); display: block; margin-bottom: 8px; }
.composer-side .gen-preview { min-height: 160px; }
#gen .composer-side { width: 100%; }
.composer:has(.gen-preview) { grid-template-columns: minmax(0, 1fr) 440px; }
.cr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cr-card { margin: 0; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.muted-card { opacity: .55; }
.cr-media { position: relative; display: block; }
.cr-media img, .cr-media video { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; display: block; background: var(--gray-bg); }
.cr-badge { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.cr-name input { width: 100%; font-weight: 600; border-color: transparent; padding: 3px 4px; }
.cr-name input:hover, .cr-name input:focus { border-color: var(--line); }
.cr-stats div { margin-bottom: 2px; }
.lib-panel { border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); margin-bottom: 10px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; max-height: 340px; overflow-y: auto; }
.lib-item { border: 2px solid transparent; border-radius: 6px; padding: 2px; cursor: pointer; background: var(--card); font-size: 11px; text-align: left; color: var(--text); font-family: inherit; }
.lib-item.on { border-color: var(--accent); }
.lib-item img, .lib-item .lib-vid { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; display: block; }
.lib-vid { background: #222; color: #fff; display: flex; align-items: center; justify-content: center; }
.lib-item .lib-cap { display: block; padding: 2px 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-thumb { width: 160px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; display: block; }
.pv-text { white-space: pre-wrap; word-break: break-word; }
.pv-button { text-align: center; color: var(--accent); font-weight: 600; font-size: 13px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.picker { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; background: var(--bg); }
.seg-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 14px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pk-tools { margin-bottom: 6px; }
.pk-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.pk-row { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-bottom: 1px solid var(--line); font-weight: 400; margin: 0; cursor: pointer; }
.pk-row:hover { background: var(--hover); }
.pk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-meta { display: flex; gap: 6px; align-items: center; font-size: 12px; white-space: nowrap; }
@media (max-width: 900px) {
  .composer { grid-template-columns: 1fr; }
  .composer-side { position: static; }
}
.rules-help li { margin-bottom: 6px; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card.login { width: 100%; max-width: 360px; }
.card.login h1 { justify-content: center; }
.card.login label { display: block; margin-bottom: 12px; }
.card.login input { display: block; width: 100%; margin-top: 4px; }
.card.login .btn { width: 100%; }

@media (max-width: 700px) {
  main { padding: 12px 16px; }
  .top { position: static; padding: 8px 16px; gap: 8px; }
  .kpi .value { font-size: 18px; }
  .bulkbar { top: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .row3 { grid-template-columns: 1fr; }
  .top-right { margin-left: 0; }
  input[type="search"] { min-width: 0; flex: 1; }
  .rec { flex-wrap: wrap; }
  .rec-body { flex: 1 1 calc(100% - 40px); }
  .rec-actions { width: 100%; justify-content: flex-start; }
  dl.kv { grid-template-columns: 110px 1fr; }
}
