/* ============================================================
   RoMax Аналітика — дизайн-система v2
   Бренд: жовтий #FAD200 (акцент UI), темний #03001C (сайдбар).
   Кольори серій графіків — валідована категоріальна палітра
   (бренд-жовтий серією не буває).
   ============================================================ */
:root {
  --brand-yellow: #FAD200;
  --brand-yellow-soft: rgba(250, 210, 0, 0.14);
  --brand-dark: #03001C;
  --brand-dark-2: #0a0730;

  --page: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.08);
  --shadow: 0 1px 2px rgba(3, 0, 28, .04), 0 4px 16px rgba(3, 0, 28, .05);
  --shadow-lift: 0 2px 4px rgba(3, 0, 28, .06), 0 12px 32px rgba(3, 0, 28, .10);

  /* серії (light) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* статуси */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --side-w: 250px;
  --radius: 14px;
  --radius-s: 9px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: var(--brand-yellow); color: var(--brand-dark); }

/* ---------- каркас: сайдбар + контент ---------- */
body.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }

aside.side {
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  background: linear-gradient(180deg, var(--brand-dark) 0%, var(--brand-dark-2) 100%);
  color: #cfcede; display: flex; flex-direction: column; z-index: 40;
}
aside.side .neural {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: .5; pointer-events: none;
}
aside.side > * { position: relative; }

.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px; min-height: 72px;
}
.side-head img { height: 34px; display: block; filter: drop-shadow(0 0 6px rgba(250,210,0,.25)); }
.typewriter {
  color: var(--brand-yellow); font-weight: 700; font-size: 16.5px;
  letter-spacing: .02em; white-space: nowrap; min-height: 22px;
}
.typewriter::after {
  content: ""; display: inline-block; width: 2px; height: 1em;
  background: var(--brand-yellow); margin-left: 2px; vertical-align: -2px;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

nav.side-nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
nav.side-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 13px; border-radius: 10px; text-decoration: none;
  color: #b9b8cc; font-weight: 500; font-size: 14.5px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
nav.side-nav a svg { width: 19px; height: 19px; flex: none; opacity: .85; }
nav.side-nav a:hover { color: #fff; background: rgba(255, 255, 255, .07); transform: translateX(2px); }
nav.side-nav a.active {
  color: var(--brand-dark); background: var(--brand-yellow); font-weight: 700;
  box-shadow: 0 4px 14px rgba(250, 210, 0, .3);
}
nav.side-nav a.active svg { opacity: 1; }
nav.side-nav .sep {
  margin: 10px 13px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .09em; color: #6d6b85;
}

.side-foot { padding: 14px 18px 18px; font-size: 12.5px; color: #8f8da6; }
.side-foot .out {
  display: flex; align-items: center; gap: 8px; color: #b9b8cc;
  text-decoration: none; padding: 8px 10px; border-radius: 9px; margin: 0 -10px 6px;
}
.side-foot .out:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-foot .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.dot.ok { background: var(--good); box-shadow: 0 0 6px var(--good); }
.dot.fail { background: var(--critical); box-shadow: 0 0 6px var(--critical); }

/* ---------- топбар ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; min-height: 64px;
  background: rgba(247, 247, 244, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.01em; }
.burger {
  display: none; border: 0; background: none; cursor: pointer; padding: 6px;
  color: var(--ink);
}

main.content { padding: 22px 28px 56px; max-width: 1420px; }
.side-overlay { display: none; }

/* ---------- фільтри (один рядок над контентом) ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 14px; margin-bottom: 18px;
}
.filters .preset {
  text-decoration: none; padding: 6px 13px; border-radius: 9px; font-size: 13px;
  color: var(--ink-2); border: 1px solid transparent; transition: all .15s ease;
}
.filters .preset.on { background: var(--brand-dark); color: #fff; }
.filters .preset:hover:not(.on) { border-color: var(--grid); background: var(--surface-2); }
.filters input, .filters select {
  padding: 7px 10px; border: 1px solid var(--grid); border-radius: 9px;
  font: inherit; font-size: 13px; background: #fff; color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--brand-dark);
  box-shadow: 0 0 0 3px var(--brand-yellow-soft);
}
.filters label.f {
  display: flex; flex-direction: column; gap: 3px; font-size: 11px;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.filters .spacer { flex: 1; }
.filters button, .btn {
  padding: 8px 15px; border: 0; border-radius: 9px; font: inherit; font-size: 13px;
  font-weight: 600; background: var(--brand-dark); color: #fff; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 7px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.filters button:hover, .btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.btn.accent { background: var(--brand-yellow); color: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--grid); font-weight: 500; }
.btn.ghost:hover { box-shadow: none; background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- KPI-плитки ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.tile::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand-yellow); opacity: 0; transition: opacity .2s ease;
}
.tile:hover::before { opacity: 1; }
.tile .v { font-size: 27px; font-weight: 700; margin-top: 3px; letter-spacing: -.02em; }
.tile .l { font-size: 12.5px; color: var(--ink-2); }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* дельта до попереднього періоду */
.delta { display: inline-block; font-size: 12px; font-weight: 700; margin-left: 6px;
         padding: 1px 7px; border-radius: 12px; vertical-align: 3px; }
.delta.up { background: #e2f4e2; color: var(--good-text); }
.delta.down { background: #fbe4e4; color: #8f1f1f; }
.delta.flat { background: #f0efec; color: var(--ink-2); }

/* ---------- сітки і картки ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.grid32 { display: grid; grid-template-columns: 3fr 2fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 1100px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) { .grid2, .grid3, .grid32 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
  min-width: 0;
}
.card h2 { font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 0 0 12px; }
.card h2 .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.card .chart-wrap { position: relative; height: 260px; }
.card .chart-wrap canvas { cursor: crosshair; }
.card .chart-wrap.tall { height: 320px; }
.card .chart-wrap.short { height: 210px; }

/* поява секцій */
.reveal { opacity: 0; transform: translateY(14px); }
.reveal.in { opacity: 1; transform: none; transition: opacity .5s ease, transform .5s ease; }
@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
  html { scroll-behavior: auto; }
  .typewriter::after { animation: none; }
  .login-card { animation: none; }
  .tile, .btn, .filters button, nav.side-nav a { transition: none; }
}

/* ---------- таблиці ---------- */
.table-scroll { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table.data {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.table-scroll table.data { box-shadow: none; }
table.data th, table.data td {
  text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--grid); font-size: 13.8px;
}
table.data th {
  color: var(--ink-2); font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; background: var(--surface-2); position: sticky; top: 0;
  white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th.sorted-a::after { content: " ↑"; color: var(--brand-dark); }
table.data th.sorted-d::after { content: " ↓"; color: var(--brand-dark); }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: #fbfaf5; }
table.data td.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
table.data a.camp-link { text-decoration: none; font-weight: 500; }
table.data a.camp-link:hover { color: var(--series-1); text-decoration: underline; }
tr.incomplete td { background: #fff8e0; }

/* міні-бар усередині клітинки (частка від максимуму) */
.cellbar { position: relative; min-width: 90px; }
.cellbar .bg {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 16px;
  background: var(--brand-yellow-soft); border-radius: 4px; z-index: 0;
  transition: width .6s cubic-bezier(.2,.7,.3,1);
}
.cellbar span { position: relative; z-index: 1; }

/* ---------- бейджі і вердикти ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.active { background: #e2f4e2; color: var(--good-text); }
.badge.paused { background: #f0efec; color: var(--ink-2); }
.badge.other { background: #eceaf7; color: var(--series-7); }
.badge.v-bad { background: #fbe4e4; color: #8f1f1f; }
.badge.v-warn { background: #fdf1d8; color: #7a5200; }
.badge.v-scale { background: #e2f4e2; color: var(--good-text); }
.badge.v-ok { background: #f0efec; color: var(--ink-2); }
.badge.v-info { background: #e4eefb; color: #123f77; }

.rec {
  display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 8px;
}
.rec .ic { flex: none; width: 34px; height: 34px; border-radius: 9px; display: flex;
  align-items: center; justify-content: center; font-size: 16px; }
.rec.v-bad .ic { background: #fbe4e4; }
.rec.v-warn .ic { background: #fdf1d8; }
.rec.v-scale .ic { background: #e2f4e2; }
.rec.v-info .ic { background: #e4eefb; }
.rec b { display: block; font-size: 14px; margin-bottom: 2px; }
.rec p { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.rec .grow { flex: 1; }
.rec .acts { flex: none; display: flex; gap: 6px; align-items: flex-start; }
.rec .acts button {
  border: 1px solid var(--grid); background: #fff; border-radius: 8px;
  font: inherit; font-size: 12px; padding: 4px 10px; cursor: pointer;
  transition: all .15s ease;
}
.rec .acts button:hover { border-color: var(--brand-dark); }
.rec .acts button.on-done { background: #e2f4e2; border-color: #bce3bc; color: var(--good-text); }
.rec .acts button.on-rej { background: #f0efec; color: var(--ink-2); }
.rec.acted { opacity: .65; }

/* мініатюри креативів */
.thumb {
  width: 52px; height: 52px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); display: block; background: var(--surface-2);
}
.thumb-lg { width: 72px; height: 72px; }

/* ---------- сторінка кампанії ---------- */
.camp-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.camp-head .back {
  flex: none; width: 38px; height: 38px; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.camp-head .back:hover { transform: translateX(-2px); }
.camp-head .t h1 { margin: 0 0 4px; font-size: 20px; }
.camp-head .t .sub { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }

.kv { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; }
.kv .row { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--grid); }
.kv .row:last-child { border-bottom: 0; padding-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 600; text-align: right; }

/* ---------- сповіщення ---------- */
.note { color: var(--muted); font-size: 12.5px; margin: 8px 0; }
.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 15px;
  border-radius: var(--radius-s); font-size: 13.5px; margin-bottom: 14px;
  border: 1px solid;
}
.alert.warn { background: #fdf6e3; border-color: #f0dfae; color: #6b4e00; }
.alert.info { background: #eaf2fc; border-color: #c8ddf5; color: #123f77; }
.sync-ok { color: var(--good-text); } .sync-fail { color: var(--critical); }

.empty {
  padding: 34px 20px; text-align: center; color: var(--muted); font-size: 14px;
  background: var(--surface-2); border: 1px dashed var(--grid); border-radius: var(--radius);
}

/* ---------- логін ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--brand-dark), var(--brand-dark-2));
  position: relative; overflow: hidden;
}
.login-wrap .neural { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .6; }
.login-card {
  position: relative; background: var(--surface); border-radius: 18px; padding: 36px;
  width: 360px; box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
  animation: loginIn .5s cubic-bezier(.2,.7,.3,1);
}
@keyframes loginIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }
.login-card img { height: 38px; margin-bottom: 6px; }
.login-card .tw-line { margin-bottom: 20px; }
.login-card .tw-line .typewriter { font-size: 18px; color: var(--brand-dark); }
.login-card input {
  width: 100%; margin-bottom: 10px; padding: 11px 13px;
  border: 1px solid var(--grid); border-radius: 10px; font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--brand-dark); box-shadow: 0 0 0 3px var(--brand-yellow-soft); }
.login-card button {
  width: 100%; padding: 11px; border: 0; border-radius: 10px;
  background: var(--brand-yellow); color: var(--brand-dark);
  font-weight: 700; font-size: 15px; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(250,210,0,.35); }
.login-card .err { color: var(--critical); font-size: 13px; margin-bottom: 10px; }

/* ---------- гайд ---------- */
.guide { max-width: 860px; }
.guide .card { margin-bottom: 14px; }
.guide h2 { font-size: 16px; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.guide h2 .n {
  flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--brand-yellow);
  color: var(--brand-dark); font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.guide p, .guide li { font-size: 14px; color: var(--ink-2); line-height: 1.55; }
.guide b { color: var(--ink); }
.guide code {
  background: var(--surface-2); border: 1px solid var(--grid); border-radius: 5px;
  padding: 1px 6px; font-size: 12.5px;
}

/* ---------- скролбар ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfcec6; border-radius: 6px; border: 2px solid var(--page); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- мобільна версія ---------- */
@media (max-width: 860px) {
  body.app { grid-template-columns: 1fr; }
  aside.side {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--side-w);
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 60px rgba(0,0,0,.4);
  }
  body.side-open aside.side { transform: none; }
  .burger { display: block; }
  .topbar { padding: 12px 16px; }
  main.content { padding: 16px 16px 48px; }
  body.side-open .side-overlay {
    display: block; position: fixed; inset: 0; background: rgba(3,0,28,.45); z-index: 35;
  }
}
