/* ChaosCraft panel — MOBILE FIRST.
   Базовые правила описывают телефон (360–430 px), расширения — в @media (min-width).
   Правило проекта: любая страница обязана быть пригодной на телефоне без
   горизонтального скролла и без «уменьшить-чтобы-прочитать». */

:root {
  --bg: #0b0d10;
  --panel: #12161b;
  --panel-2: #171d24;
  --line: #232b35;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4cc2ff;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono, .id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }

/* ---------- шапка ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); }
.brand span { color: var(--accent); }
.brand em { font-style: normal; font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.top nav {
  order: 3;
  width: 100%;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.top nav::-webkit-scrollbar { display: none; }
.top nav a {
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  white-space: nowrap;
  font-size: 14px;
}
.top nav a.active { color: var(--text); background: var(--panel-2); }
.env {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.on { background: var(--ok); }
.dot.warn { background: var(--warn); }
.user { color: var(--text); font-size: 12px; overflow-wrap: anywhere; }

/* ---------- контент ---------- */
main { padding: 14px; max-width: 1240px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.panel h1 { font-size: 20px; line-height: 1.25; margin: 0 0 8px; }
.panel h2 {
  font-size: 13px; margin: 0 0 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.panel h3 { font-size: 15px; margin: 18px 0 8px; }
.crumb { margin-bottom: 8px; font-size: 13px; }

/* ---------- формы ---------- */
.row { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

input[type=text], input[type=email], input[type=password], select, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  width: 100%;
  min-height: 44px;
}
textarea { resize: vertical; font-size: 15px; }
textarea.en { color: #b7c9d9; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #04121b;
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  min-height: 44px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
form.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
form.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.top form { margin: 0; display: inline-flex; }

/* ---------- таблицы → карточки на телефоне ---------- */
table { width: 100%; border-collapse: collapse; }
thead { display: none; }
tbody, tr, td { display: block; width: 100%; }
tbody tr {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 10px 12px;
  margin-bottom: 10px;
}
td {
  border: 0;
  padding: 5px 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}
td::before {
  content: attr(data-label);
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: left;
}
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* сцены: карточка с полями на всю ширину */
table.scenes tbody tr { padding: 12px; }
table.scenes td { display: block; text-align: left; padding: 4px 0; }
table.scenes td::before { display: none; }
table.scenes td.c-id { font-weight: 700; color: var(--accent); }
table.scenes td.c-id::after { content: " сцена"; color: var(--muted); font-weight: 400; font-size: 12px; }
table.scenes td.c-status, table.scenes td.c-audio { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
table.scenes td.c-status::before { display: block; content: "статус"; }
table.scenes td.c-audio::before { display: block; content: "звук"; }
table.scenes .cell-actions { display: flex; gap: 8px; margin-top: 6px; }
table.scenes .cell-actions form { flex: 1 1 0; display: flex; }
table.scenes .cell-actions button { width: 100%; }

/* ---------- элементы ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.st-draft { color: #a5b3c2; }
.st-script_ready { color: var(--accent); border-color: var(--accent); }
.st-audio_ready { color: #7ee787; border-color: var(--ok); }
.st-video_ready { color: #d2a8ff; border-color: #8957e5; }
.st-compiled { color: #ffd166; border-color: var(--warn); }
.st-published, .st-partial { color: #7ee787; border-color: var(--ok); }
.st-failed { color: var(--err); border-color: var(--err); }
.st-audio_ok, .st-video_ok, .st-ok { color: #7ee787; border-color: var(--ok); }
.st-pending, .st-new, .st-backlog, .st-queued { color: var(--muted); }

.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; }

.progress { margin: 14px 0; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, #2ea043, #4cc2ff); }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.actions form { display: flex; flex-direction: column; gap: 8px; }
.hint {
  margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--warn);
  background: rgba(210, 153, 34, .08); color: #e3c07b; font-size: 13px; border-radius: 6px;
}
.err { color: var(--err); font-size: 12px; margin-top: 6px; }
.empty { color: var(--muted); padding: 12px 0; }
.alert {
  margin-top: 14px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #f8514955; background: #f8514914; color: #ffb4ae; font-size: 14px;
}

.log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.log li { padding: 8px 0; border-bottom: 1px dashed var(--line); display: block; }
.log li .when { display: block; color: var(--muted); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; }
.log li.lvl-error { color: #ffb4ae; }
.log li.lvl-warn { color: #e3c07b; }

/* логин */
.login { max-width: 420px; margin: 16px auto; }

/* ---------- страница стиля ---------- */
.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.swatches li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 1px solid #ffffff22; flex: 0 0 auto; }
.asset-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.asset { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
.asset img { display: block; width: 100%; height: auto; }
.asset .cap { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.asset .cap b { color: var(--text); display: block; font-size: 13px; margin-bottom: 2px; }
.checker-bg {
  background-image: linear-gradient(45deg, #2a2f38 25%, transparent 25%), linear-gradient(-45deg, #2a2f38 25%, transparent 25%),
                    linear-gradient(45deg, transparent 75%, #2a2f38 75%), linear-gradient(-45deg, transparent 75%, #2a2f38 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.steps-list { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps-list li {
  counter-increment: step; position: relative; padding: 10px 0 10px 40px;
  border-bottom: 1px dashed var(--line); font-size: 14px;
}
.steps-list li::before {
  content: counter(step); position: absolute; left: 0; top: 10px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--accent);
  font-size: 12px; font-weight: 700;
}
.steps-list b { display: block; }
.kv { display: grid; grid-template-columns: 1fr; gap: 6px 12px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0 0 6px; overflow-wrap: anywhere; }

/* ---------- темы: рабочее место ---------- */
.adder { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; margin: 12px 0; }
.adder summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.adder[open] summary { margin-bottom: 10px; }
.small { font-size: 12px; }
.cell-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cell-actions form { display: flex; }
.ok-mark { color: #7ee787; font-size: 12px; }

.ws { display: block; }
.editor textarea { min-height: 44vh; font-size: 16px; line-height: 1.6; }
.editor-bar { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.warn-box {
  margin-top: 14px; border: 1px solid #d2992255; background: rgba(210, 153, 34, .08);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; color: #e3c07b;
}
.warn-box ul { margin: 8px 0 0; padding-left: 18px; }
.warn-box li { margin-bottom: 5px; }
.ok-box {
  margin-top: 14px; border: 1px solid #2ea04366; background: rgba(46, 160, 67, .08);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; color: #7ee787;
}

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 12px; }
.presets form { display: flex; }
.chat { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; font-size: 13px; }
.chat li {
  padding: 8px 10px; border-radius: 10px; margin-bottom: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat li.user { border-color: #4cc2ff55; background: #4cc2ff12; }
.chat .who { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.chat-form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.check input { width: 18px; height: 18px; }

.runs { list-style: none; margin: 0; padding: 0; }
.runs li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--panel-2); }
.run-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.run-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; margin-top: 6px; }

/* ---------- подвал ---------- */
.foot {
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  padding: 14px 14px 26px; font-size: 12px;
}
.providers { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.ok { color: #7ee787; border-color: #2ea04366; }
.chip.no { color: #8b98a5; border-style: dashed; }

/* ================= планшет / десктоп ================= */
@media (min-width: 700px) {
  body { font-size: 15px; }
  .top { flex-wrap: nowrap; padding: 14px 24px; gap: 24px; }
  .top nav { order: 0; width: auto; overflow: visible; gap: 16px; }
  .top nav a { padding: 0; }
  main { padding: 24px; }
  .panel { padding: 20px; margin-bottom: 20px; }
  .panel h1 { font-size: 22px; }
  .row { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .row input[type=text] { flex: 1 1 260px; }
  button, .button { width: auto; }
  .actions { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .actions form { flex-direction: row; align-items: center; }
  .actions form select { width: auto; }

  table { display: table; }
  thead { display: table-header-group; }
  tbody { display: table-row-group; }
  tr { display: table-row; background: none; border: 0; padding: 0; margin: 0; }
  td { display: table-cell; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
  td::before { display: none; }
  th {
    display: table-cell; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line);
    font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
  }
  tbody tr:hover { background: var(--panel-2); }
  td.num { text-align: right; }

  table.scenes td { display: table-cell; padding: 10px 12px; text-align: left; }
  table.scenes td.c-id::after { content: ""; }
  table.scenes .cell-actions { margin-top: 0; flex-wrap: wrap; }
  table.scenes .cell-actions form { flex: 0 0 auto; }

  .swatches { grid-template-columns: repeat(4, 1fr); }
  .asset-grid { grid-template-columns: repeat(2, 1fr); }
  .kv { grid-template-columns: 220px 1fr; }
  .kv dd { margin-bottom: 0; }
  .foot { flex-direction: row; justify-content: space-between; align-items: center; padding: 16px 24px 28px; }
  .log li { display: flex; gap: 10px; flex-wrap: wrap; padding: 6px 0; }
  .log li .when { display: inline; }
}

@media (min-width: 1100px) {
  .asset-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ================= десктоп (>=900): читаемая ширина, а не «растянутый телефон» ======= */
@media (min-width: 900px) {
  .top { padding: 14px max(24px, calc((100% - 1160px) / 2)); }
  main { max-width: 1160px; padding: 28px 24px 10px; }

  .panel { padding: 22px 24px; }
  .panel h1 { font-size: 24px; }
  /* заголовки секций на большом экране — полноценные, а не 13-пиксельные ярлыки */
  .panel h2 {
    font-size: 15px; text-transform: none; letter-spacing: .01em; color: var(--text);
    padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
  }
  .panel h3 { font-size: 15px; color: var(--accent); margin: 22px 0 10px; }
  /* длина строки под чтение: без «простыней» на 1100 px */
  .panel > p, .panel li, .steps-list li { max-width: 92ch; }

  .kv { grid-template-columns: 240px minmax(0, 1fr); font-size: 14px; row-gap: 10px; }
  .kv dd { margin: 0; }
  .swatches { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .asset-grid { gap: 16px; }
  .asset img { max-height: 300px; object-fit: cover; }
  .asset .cap { font-size: 12px; }

  table { font-size: 14px; }
  th { padding: 10px 14px; }
  td { padding: 12px 14px; }

  /* сцены: фиксированные колонки, чтобы текст не «прыгал» */
  /* снять мобильные ярлыки «статус»/«звук» и flex-раскладку ячеек */
  table.scenes td.c-status, table.scenes td.c-audio { display: table-cell; text-align: left; }
  table.scenes td.c-status::before, table.scenes td.c-audio::before { display: none; content: none; }
  table.scenes td.c-id { width: 86px; }
  table.scenes td.c-status { width: 124px; }
  table.scenes td.c-audio { width: 136px; }
  table.scenes td.c-actions { width: 236px; }
  table.scenes textarea { min-height: 92px; max-height: 240px; }

  /* рабочее место темы: редактор + чат в две колонки */
  .ws { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 20px; align-items: start; }
  .ws > .panel { margin-bottom: 0; }
  .ws-side { position: sticky; top: 78px; }
  .editor textarea { min-height: 420px; }
  .editor-bar { flex-direction: row; align-items: center; }
  .chat { max-height: 320px; }
  .cell-actions { flex-wrap: nowrap; }

  /* узкие служебные колонки: «Сцены», «Звук», «Видео» больше не растягиваются */
  table.jobs, table.topics { table-layout: fixed; }
  table.jobs th:nth-child(1), table.jobs td:nth-child(1) { width: 104px; }
  table.jobs th:nth-child(3), table.jobs td:nth-child(3) { width: 136px; }
  table.jobs th:nth-child(4), table.jobs td:nth-child(4) { width: 84px; }
  table.jobs th:nth-child(5), table.jobs td:nth-child(5) { width: 84px; }
  table.jobs th:nth-child(6), table.jobs td:nth-child(6) { width: 84px; }
  table.jobs th:nth-child(7), table.jobs td:nth-child(7) { width: 132px; }
  table.jobs th:nth-child(8), table.jobs td:nth-child(8) { width: 172px; }
  table.topics th:nth-child(1), table.topics td:nth-child(1) { width: 56px; }
  table.topics th:nth-child(4), table.topics td:nth-child(4) { width: 136px; }
  table.topics th:nth-child(5), table.topics td:nth-child(5) { width: 176px; }
  table.topics th:nth-child(6), table.topics td:nth-child(6) { width: 208px; }

  form.stack { max-width: 620px; }
  .row { gap: 12px; }
  .row input[type=text] { flex: 1 1 320px; }
  .log li { border-bottom-style: solid; }
  .login { margin: 64px auto; max-width: 460px; }
  .foot { padding: 18px max(24px, calc((100% - 1160px) / 2)) 30px; }
}

/* плеер готового ролика (mobile-first) */
.player-wrap { margin: 16px 0 8px; background: #000; border-radius: 14px; overflow: hidden; }
.player { display: block; width: 100%; max-height: 70vh; background: #000; }
