:root {
  --bg: #0d0e11;
  --panel: #15171c;
  --panel-2: #1b1e25;
  --panel-3: #232731;
  --line: #2a2f3a;
  --line-2: #353b48;
  --text: #e8eaf0;
  --muted: #8d95a5;
  --dim: #636b7b;
  --accent: #4d8dff;
  --accent-2: #3a74e0;
  --accent-soft: rgba(77, 141, 255, .14);
  --ok: #34c77b;
  --ok-soft: rgba(52, 199, 123, .14);
  --warn: #f2b53a;
  --warn-soft: rgba(242, 181, 58, .14);
  --bad: #f05d5e;
  --bad-soft: rgba(240, 93, 94, .14);
  --radius: 10px;
  --radius-s: 7px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; height: 100vh; }
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; letter-spacing: .2px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8a5cff); color: #fff; font-size: 13px; font-weight: 800;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.nav { padding: 4px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s);
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--text); }
.nav a .ico { width: 18px; height: 18px; flex: none; }
.side-title {
  margin: 18px 20px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim);
  display: flex; justify-content: space-between; align-items: center;
}
.side-title button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 16px; line-height: 1; }
.side-title button:hover { color: var(--text); }
.profiles { flex: 1; overflow: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.profiles a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-s); color: var(--text);
}
.profiles a:hover { background: var(--panel-2); text-decoration: none; }
.profiles a.on { background: var(--panel-3); }
.profiles .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 13.5px; }
.side-foot { border-top: 1px solid var(--line); padding: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line);
  background: rgba(13, 14, 17, .85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5; min-height: 60px;
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-width: 0; flex: 1; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs b { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--dim); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.content { flex: 1; overflow: auto; padding: 24px 28px 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: var(--radius-s); border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none !important; font-size: 13.5px;
}
.btn:hover { background: var(--panel-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 30px; padding: 0; height: 30px; }
.btn .ico { width: 16px; height: 16px; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.field small { color: var(--dim); font-size: 12px; }
.input, select.input, textarea.input {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius-s);
  padding: 8px 11px; outline: none; min-height: 36px;
}
textarea.input { resize: vertical; min-height: 80px; font-family: var(--mono); font-size: 12.5px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row-2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.row-3 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr 1fr; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius-s); padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 5px; color: var(--muted); cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--panel-3); color: var(--text); }
.seg button:hover:not(.on) { color: var(--text); }

.switch { position: relative; width: 34px; height: 20px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; background: var(--line-2); border-radius: 20px; cursor: pointer; transition: .15s;
}
.switch span::before {
  content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(14px); }
.switch input:disabled + span { opacity: .5; cursor: wait; }

/* ---------- cards / panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); gap: 12px; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-body { padding: 18px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; color: var(--text);
}
a.card:hover { border-color: var(--line-2); background: var(--panel-2); text-decoration: none; }
.card-top { display: flex; gap: 12px; align-items: center; }
.card-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { color: var(--muted); font-size: 12.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--dim); font-size: 12px; margin-top: 2px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--panel-3); flex: none; object-fit: cover;
  display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 13px; overflow: hidden;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.lg { width: 64px; height: 64px; font-size: 20px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 500; background: var(--panel-3); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.gap-l { gap: 16px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.hidden { display: none !important; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .count { color: var(--dim); font-weight: 400; margin-left: 4px; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.t th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 1; white-space: nowrap; cursor: default;
}
.t th.sortable { cursor: pointer; }
.t th.sortable:hover { color: var(--text); }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--panel-2); }
.t tfoot td { background: var(--panel-2); font-weight: 600; border-top: 1px solid var(--line-2); border-bottom: 0; }
.t td.num, .t th.num { text-align: right; white-space: nowrap; }
.t .name-cell { min-width: 240px; max-width: 420px; }
.t .name-cell a, .t .name-cell .nm { color: var(--text); font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t .name-cell a:hover { color: var(--accent); }
.t .sub { color: var(--dim); font-size: 11.5px; font-family: var(--mono); }
.t .issue { color: var(--warn); font-size: 12px; margin-top: 3px; white-space: normal; }
.t .actions { white-space: nowrap; text-align: right; }
.t .actions .btn { opacity: .75; }
.t tr:hover .actions .btn { opacity: 1; }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--panel-3); flex: none; }

.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.loading { padding: 50px; display: grid; place-items: center; color: var(--muted); gap: 12px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .7s linear infinite; }

.error-box {
  border: 1px solid rgba(240, 93, 94, .35); background: var(--bad-soft); border-radius: var(--radius); padding: 14px 16px; color: var(--text);
}
.error-box b { color: var(--bad); }
.error-box .det { color: var(--muted); font-size: 12.5px; margin-top: 6px; font-family: var(--mono); word-break: break-word; }
.note {
  border: 1px solid var(--line-2); background: var(--panel-2); border-radius: var(--radius); padding: 12px 14px; color: var(--muted); font-size: 13px;
}
.note b { color: var(--text); }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(5, 6, 8, .72); display: grid; place-items: center; z-index: 50;
  padding: 20px; animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow);
  width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
}
.modal.wide { width: min(780px, 100%); }
.modal-head { padding: 18px 20px 6px; display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 12px 20px; overflow: auto; }
.modal-foot { padding: 14px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: 420px; }
.toast {
  background: var(--panel-3); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); padding: 11px 14px;
  border-radius: var(--radius-s); box-shadow: var(--shadow); font-size: 13.5px; animation: fade .15s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.toast small { display: block; color: var(--muted); margin-top: 3px; font-family: var(--mono); font-size: 11.5px; word-break: break-word; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(77, 141, 255, .12), transparent); }
.login { width: min(380px, 100%); }
.login .brand { padding: 0 0 22px; justify-content: center; font-size: 18px; }

/* ---------- chart ---------- */
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { fill: var(--dim); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }

/* ---------- launch wizard ---------- */
.wizard { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.wizard .panel { margin-bottom: 16px; }
.wizard .summary { position: sticky; top: 0; max-height: calc(100vh - 110px); overflow: auto; }
.step-num {
  width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); font-size: 12px; font-weight: 700; margin-right: 8px;
}
.dropzone {
  border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 12px; }
.media-item { border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: var(--bg); position: relative; }
.media-item img, .media-item video { width: 100%; height: 110px; object-fit: cover; display: block; background: #000; }
.media-item .cap { padding: 6px 8px; font-size: 11.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.media-item .cap span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-item .progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width .2s; }
.media-item .rm { position: absolute; top: 5px; right: 5px; background: rgba(0, 0, 0, .65); border: 0; color: #fff; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-3); border-radius: 12px; padding: 2px 4px 2px 9px; font-size: 12.5px; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; }
.suggest { position: relative; }
.suggest-list {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px; background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-s); max-height: 240px; overflow: auto; z-index: 10; box-shadow: var(--shadow);
}
.suggest-list div { padding: 7px 11px; cursor: pointer; font-size: 13px; }
.suggest-list div:hover, .suggest-list div.on { background: var(--panel-3); }
.steps-report { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.steps-report div { display: flex; gap: 8px; align-items: baseline; }
.ad-preview { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.ad-preview .hd { display: flex; gap: 8px; align-items: center; padding: 10px; font-size: 13px; font-weight: 600; }
.ad-preview .tx { padding: 0 10px 10px; font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: hidden; }
.ad-preview .im { aspect-ratio: 4 / 3; background: var(--panel-3); display: grid; place-items: center; color: var(--dim); }
.ad-preview .im img, .ad-preview .im video { width: 100%; height: 100%; object-fit: cover; }
.ad-preview .ft { display: flex; justify-content: space-between; align-items: center; padding: 10px; gap: 10px; background: var(--panel-2); }
.ad-preview .ft b { display: block; font-size: 13px; }
.ad-preview .ft small { color: var(--muted); font-size: 11.5px; }

/* ---------- узкие экраны: временно, полноценная мобильная версия будет отдельно ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .side { position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .profiles { max-height: 160px; }
  .content { padding: 16px; }
  .top { padding: 12px 16px; }
  .wizard { grid-template-columns: 1fr; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
}
