:root {
  --bg: #0e1014;
  --surface: #161920;
  --surface-2: #1c2029;
  --surface-3: #232834;
  --border: #272c38;
  --border-strong: #353c4c;
  --text: #e7e9ee;
  --muted: #8d95a6;
  --blue: #6aa5ff;
  --violet: #9b8cff;
  --amber: #f2b25c;
  --red: #ff6f86;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Noto Sans Arabic', 'Geeza Pro', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* ---------- каркас ---------- */
.app {
  min-height: 100vh;
}
.shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 14px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), var(--violet));
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: var(--surface-3);
  color: var(--text);
}
.nav .count {
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(106, 165, 255, 0.16);
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.run-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.run-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}
.run-dot.live::before {
  background: var(--violet);
  box-shadow: 0 0 0 0 rgba(155, 140, 255, 0.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  70% {
    box-shadow: 0 0 0 8px rgba(155, 140, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(155, 140, 255, 0);
  }
}
.main {
  min-width: 0;
  padding: 28px clamp(16px, 4vw, 44px) 64px;
}
.page {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1080px;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
}
.page-head h1 {
  font-size: 26px;
  line-height: 1.2;
}
.page-head .lead {
  margin-top: 4px;
  color: var(--muted);
  max-width: 62ch;
}
.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.demo-flag {
  align-self: flex-start;
  padding: 3px 10px;
  border: 1px solid rgba(242, 178, 92, 0.4);
  border-radius: 999px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover {
  background: var(--surface-3);
  text-decoration: none;
}
.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, #4f8df5, #8a78f7);
  color: #fff;
}
.btn.primary:hover {
  background: linear-gradient(135deg, #5c98fb, #9785fb);
}
.btn.small {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 8px;
}
.btn.ghost {
  background: transparent;
}
.btn.on {
  border-color: var(--blue);
  background: rgba(106, 165, 255, 0.14);
  color: var(--blue);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field > span,
.field > label {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.field .hint {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
}
input[type='text'],
input[type='password'],
input[type='number'],
input[type='time'],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
textarea {
  min-height: 108px;
  resize: vertical;
  line-height: 1.45;
}
select {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}
.check input {
  width: 17px;
  height: 17px;
  accent-color: var(--blue);
}
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.filters .field {
  flex: 1 1 170px;
  max-width: 280px;
}

/* ---------- карточки ---------- */
.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.card h2 {
  font-size: 17px;
}
.card h3 {
  font-size: 16px;
  line-height: 1.35;
}
.card-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  padding: 2px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.accent {
  border-color: rgba(106, 165, 255, 0.45);
  color: var(--blue);
}
.badge.violet {
  border-color: rgba(155, 140, 255, 0.5);
  color: var(--violet);
}
.badge.amber {
  border-color: rgba(242, 178, 92, 0.45);
  color: var(--amber);
}
.badge.red {
  border-color: rgba(255, 111, 134, 0.45);
  color: var(--red);
}
.note {
  padding: 12px 14px;
  border: 1px solid rgba(155, 140, 255, 0.35);
  border-radius: 12px;
  background: rgba(155, 140, 255, 0.08);
  font-size: 14px;
}
.note.warn {
  border-color: rgba(242, 178, 92, 0.4);
  background: rgba(242, 178, 92, 0.08);
  color: #f6cf97;
}
.note.error {
  border-color: rgba(255, 111, 134, 0.4);
  background: rgba(255, 111, 134, 0.08);
  color: #ffb1bd;
}
.empty {
  padding: 34px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
.loading {
  padding: 40px 0;
  color: var(--muted);
}

/* ---------- обзор ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
a.tile:hover {
  border-color: var(--border-strong);
  text-decoration: none;
}
.tile .tile-label {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.tile .tile-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}
.tile .tile-sub {
  color: var(--muted);
  font-size: 13px;
}
.todo {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.todo li {
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.todo li::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--amber);
  transform: translateY(-1px);
}
.stages {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  gap: 8px 14px;
  align-items: baseline;
}
.stages .stage-name {
  font-weight: 600;
}
.pill {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.done {
  background: rgba(106, 165, 255, 0.16);
  color: var(--blue);
}
.pill.running {
  background: rgba(155, 140, 255, 0.18);
  color: var(--violet);
}
.pill.failed {
  background: rgba(255, 111, 134, 0.16);
  color: var(--red);
}
.pill.partial,
.pill.skipped {
  background: rgba(242, 178, 92, 0.14);
  color: var(--amber);
}
details > summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 600;
  font-size: 14px;
  list-style: none;
}
details > summary::-webkit-details-marker {
  display: none;
}
details > summary::before {
  content: '+ ';
}
details[open] > summary::before {
  content: '− ';
}
.log {
  margin: 10px 0 0;
  padding: 12px 14px;
  max-height: 320px;
  overflow: auto;
  border-radius: 10px;
  background: var(--bg);
  color: #b9c0cf;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- сценарии и хуки ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.orig {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.45;
  unicode-bidi: plaintext;
}
.orig-line {
  unicode-bidi: plaintext;
}
.block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}
.block .label {
  color: var(--violet);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 3px 12px;
  font-size: 14px;
}
.kv dt {
  color: var(--muted);
}
.kv dd {
  margin: 0;
  unicode-bidi: plaintext;
}
.scenes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}
.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}
.steps .t {
  display: inline-block;
  min-width: 46px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12.5px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.actions .spacer {
  flex: 1;
}
.script.status-rejected,
.script.status-done {
  opacity: 0.72;
}
.card.hidden-ad {
  border-color: rgba(155, 140, 255, 0.4);
}
.score {
  font-weight: 700;
  color: var(--blue);
}

/* ---------- формы ---------- */
.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.vertical-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.vertical-box.enabled {
  border-color: rgba(106, 165, 255, 0.45);
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
}
.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
code {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-3);
  font-family: var(--mono);
  font-size: 12.5px;
}

/* ---------- вход ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login .card {
  width: min(380px, 100%);
  gap: 16px;
  padding: 26px;
}

/* ---------- уведомление ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font-weight: 500;
  z-index: 20;
}
.toast.error {
  border-color: rgba(255, 111, 134, 0.5);
  color: #ffb1bd;
}

/* ---------- узкие экраны ---------- */
@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav {
    order: 3;
    flex: 1 0 100%;
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
  }
  .nav a {
    white-space: nowrap;
  }
  .side-foot {
    margin: 0 0 0 auto;
    flex-direction: row;
    align-items: center;
  }
  .main {
    padding-top: 18px;
  }
  .stages {
    grid-template-columns: max-content minmax(0, 1fr);
  }
  .stages .stage-sum {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
