/* Fira Code (данные/mono) + Fira Sans (UI) — рекомендация ui-ux-pro-max для
   dashboard/data-tool продуктов ("dashboard, data, analytics, code, technical,
   precise"). font-display:swap — Google Fonts CSS2 отдаёт его по умолчанию,
   не блокирует рендер текста (см. ux-guidelines: font-loading). */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e232b;
  --surface-3: #262c35;
  --ink: #e8e6df;
  --muted: #8b9099;
  --faint: #5c6470;
  --line: #272d37;
  --line-soft: #202631;
  --accent: #e0a13c;
  --accent-dim: #b6802f;
  --accent-glow: rgba(224, 161, 60, 0.35);
  --ok: #4fb6a8;
  --err: #e05c5c;
  --warn: #e0b040;
  --mono: "Fira Code", Consolas, "SF Mono", "Cascadia Code", ui-monospace, monospace;
  --sans: "Fira Sans", "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
  --r: 8px;
  --r-sm: 5px;
  /* Единый ритм анимаций (ui-ux-pro-max: 150-300мс микро, expo.out на вход) —
     один источник правды для CSS-transition И для Motion (web/_motion.js). */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 220ms;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  font-size: 14px;
}

/* Табличные/статусные цифры не должны "прыгать" при живых обновлениях
   (Очередь/Консоль поллятся каждые 4с) — tabular-nums держит ширину цифр
   константной. */
.mono, table.data td, .stat-value, .count {
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── App shell + sidebar ─────────────────────────────────────────────── */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #14171c;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
  box-shadow: 0 0 18px var(--accent-glow);
}

.brand-name { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

nav { flex: 1; padding: 14px 12px; overflow-y: auto; }

.nav-group { margin-bottom: 18px; }

.nav-section {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0 10px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.nav-item:hover { background: var(--surface-2); color: var(--ink); }

.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.nav-item.active {
  background: var(--surface-3);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent), 0 0 14px -6px var(--accent-glow);
}

.nav-icon {
  width: 20px;
  text-align: center;
  font-family: var(--mono);
  color: var(--faint);
  font-size: 13px;
}
.nav-item.active .nav-icon { color: var(--accent); }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--line-soft); }

.worker-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); animation: dot-pulse 2s ease-in-out infinite; }
.dot.off { background: var(--faint); }

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Skeleton — заполнитель на время загрузки >300мс (ux-guidelines: не морозить
   UI без фидбека). Ширина/высота задаются inline-стилем в месте использования. */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ── Main area ───────────────────────────────────────────────────────── */

.main { flex: 1; min-width: 0; }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 34px 80px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 26px;
  gap: 20px;
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

section { margin-bottom: 32px; }

h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 14px;
}

/* ── Form ────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 20px;
}

form.brief-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
form.brief-form .full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

input, textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  padding: 9px 11px;
  font-family: var(--sans);
  font-size: 14px;
}

input:focus, textarea:focus, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #14171c;
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: filter var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
button:hover { filter: brightness(1.07); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; filter: none; transform: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 600;
}
button.secondary:hover { background: var(--surface-2); filter: none; }

button.reject { background: var(--err); color: #fff; }
button.approve { background: var(--ok); color: #0e2420; }

.status-line {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
  white-space: pre-wrap;
}
.status-line.error { color: var(--err); }

.engines-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13.5px;
}
.checkbox-label input { width: auto; }
.gambling-field { grid-column: 1 / -1; }
.gambling-field .hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

.reviewer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.reviewer-bar label { margin: 0; white-space: nowrap; }
.reviewer-bar input { max-width: 240px; }

/* ── Brief list ──────────────────────────────────────────────────────── */

.brief-list { list-style: none; margin: 0; padding: 0; }

.brief-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.12s, background 0.12s;
}
.brief-list li:hover { border-color: var(--accent-dim); background: var(--surface-2); }

.brief-list .product { font-weight: 600; }
.brief-list .angle { color: var(--muted); font-size: 13px; }
.brief-list .count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

/* ── Variants grid ───────────────────────────────────────────────────── */

.variants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.variant-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.variant-card video {
  width: 100%;
  aspect-ratio: 9/16;
  background: #000;
  display: block;
}
.variant-card .placeholder {
  aspect-ratio: 9/16;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
  text-align: center;
  padding: 12px;
}
.variant-card .body { padding: 12px; }
.variant-card .hook { font-size: 13.5px; margin: 0 0 8px; }
.variant-card .actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.variant-card .actions button { padding: 6px 10px; font-size: 12px; }

/* ── Progress steps ──────────────────────────────────────────────────── */

.steps { display: flex; gap: 4px; margin-bottom: 8px; }
.step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-3);
}
.step.completed { background: var(--ok); }
.step.running { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.step.failed { background: var(--err); }
.step.skipped { background: var(--faint); }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ── Badges ──────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--line);
}
.badge.approved { color: var(--ok); border-color: var(--ok); }
.badge.rejected { color: var(--err); border-color: var(--err); }
.badge.pending { color: var(--muted); }
.badge.failed { color: var(--err); border-color: var(--err); background: rgba(224, 92, 92, 0.12); }
.badge.gambling { color: var(--accent); border-color: var(--accent); }
.badge.flagged {
  color: var(--warn);
  border-color: var(--warn);
  background: rgba(224, 176, 64, 0.1);
  cursor: help;
}

/* ── Tables (queue / console) ────────────────────────────────────────── */

.data-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 640px;
}
table.data th {
  text-align: left;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}
table.data td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--line);
}
.pill.local { color: #7fb8e0; border-color: #35566e; }
.pill.cloud { color: #c79fe0; border-color: #5a4470; }
.pill.pending { color: var(--muted); }
.pill.running { color: var(--accent); border-color: var(--accent-dim); }
.pill.completed { color: var(--ok); border-color: #2f5a52; }
.pill.failed { color: var(--err); border-color: #6e3535; }

/* ── Stat tiles ──────────────────────────────────────────────────────── */

.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 26px; }
.stat {
  flex: 1;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
}
.stat .stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  font-family: var(--mono);
}
.stat .stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }
.stat .stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.meter { height: 6px; border-radius: 3px; background: var(--surface-3); margin-top: 10px; overflow: hidden; }
.meter-fill { height: 100%; background: linear-gradient(90deg, var(--ok), var(--accent)); }
.meter-fill.hot { background: linear-gradient(90deg, var(--warn), var(--err)); }

/* ── Console ─────────────────────────────────────────────────────────── */

.console {
  background: #0b0d10;
  border: 1px solid var(--line);
  border-radius: var(--r);
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 14px 16px;
  max-height: 68vh;
  overflow-y: auto;
}
.log-line { display: flex; gap: 12px; padding: 3px 0; white-space: nowrap; }
.log-ts { color: var(--faint); flex-shrink: 0; }
.log-kind { flex-shrink: 0; width: 150px; }
.log-detail { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.k-ok { color: var(--ok); }
.k-warn { color: var(--warn); }
.k-err { color: var(--err); }
.k-info { color: #7fb8e0; }

.engine-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.engine-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.engine-card h3 { margin: 0 0 4px; font-size: 14px; }
.engine-card .current { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.engine-card .opts { font-size: 12px; color: var(--muted); margin-top: 8px; }

.hidden { display: none; }
.muted { color: var(--muted); }
.empty { color: var(--faint); text-align: center; padding: 40px; font-size: 13px; }

@media (max-width: 720px) {
  .sidebar { width: 60px; }
  .brand div, .brand-sub, .nav-item span:not(.nav-icon), .nav-section, .worker-pill { display: none; }
  .nav-item { justify-content: center; }
  .page { padding: 20px 16px 60px; }
  form.brief-form, .engines-row { grid-template-columns: 1fr; }
}
