:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e3e3ea;
  --text: #1c1c24;
  --muted: #6b6b7b;
  --accent: #5b5bd6;
  --accent-hover: #4b4bc4;
  --accent-soft: #ececfd;
  --danger: #d6455b;
  --warn: #b7791f;
  --ok: #2f9e6b;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 16px rgba(20, 20, 40, .05);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111116;
    --surface: #1a1a21;
    --surface-2: #23232c;
    --border: #2e2e39;
    --text: #ececf1;
    --muted: #9a9aab;
    --accent: #7b7bf0;
    --accent-hover: #8e8ef5;
    --accent-soft: #26264a;
    --danger: #f06a7e;
    --warn: #e0a940;
    --ok: #4cc28d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h2 { font-size: 18px; margin: 0; font-weight: 650; }
h3 { font-size: 15px; margin: 0; font-weight: 650; }
button, input, select, textarea { font: inherit; color: inherit; }
img, video { display: block; max-width: 100%; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 550; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 11px 22px; font-size: 15px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }

input, select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 11px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; font-size: 13px; line-height: 1.45; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 550; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.error.soft { color: var(--muted); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }

/* сегментный переключатель */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0; background: none; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-size: 13px;
  font-weight: 550; color: var(--muted);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; padding: 7px 10px; }
.seg button small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card .hint { margin: 0; }

/* ---------- шапка и вкладки ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; min-width: 0; }
.brand .sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none; position: relative;
}
.logo::before { content: ""; position: absolute; left: 6px; top: 9px; width: 11px; height: 10px; border-radius: 2px; background: #fff; }
.logo::after { content: ""; position: absolute; left: 18px; top: 10px; border: 4px solid transparent; border-left: 0; border-right: 6px solid #fff; height: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; max-width: 1180px; margin: 0 auto; }
.tabs {
  display: flex; gap: 4px; max-width: 1180px; margin: 0 auto; padding: 0 24px; overflow-x: auto;
  border-bottom: 1px solid var(--border); scrollbar-width: none;
}
.tab {
  border: 0; background: none; cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.num {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: 12px;
  background: var(--surface-2); color: var(--muted); font-weight: 650; flex: none;
}
.tab.active .num, .step h3 .num { background: var(--accent); color: #fff; }
.count { font-size: 12px; color: var(--muted); font-weight: 500; }
main { max-width: 1180px; margin: 0 auto; padding: 20px 24px 60px; }
.page { display: flex; flex-direction: column; gap: 18px; }
.section-title { margin-top: 10px; }
.empty { color: var(--muted); margin: 0; font-size: 14px; }
.empty.small { font-size: 13px; }

/* ---------- загрузка ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px 16px; background: var(--surface);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { color: var(--accent); flex: none; }
.drop .hint { max-width: 560px; }
.upload-progress { display: flex; align-items: center; gap: 10px; width: min(420px, 100%); margin-top: 6px; }
.bar { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .2s; }
.bar.indeterminate i { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
.upload-progress .label { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- сетка карточек ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.grid.photos { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { overflow: hidden; display: flex; flex-direction: column; cursor: default; }
.thumb { position: relative; aspect-ratio: 16 / 10; background: #000; overflow: hidden; }
.photos .thumb { aspect-ratio: 3 / 4; background: var(--surface-2); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.photos .thumb img { object-fit: cover; }
.thumb.clickable { cursor: pointer; }
.badge {
  position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .7); color: #fff; font-size: 12px;
  padding: 1px 7px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
.badge.left { left: 6px; right: auto; }
.badge.top { top: 6px; bottom: auto; }
.badge.warn { background: var(--warn); }
.warn-note { margin: 0; font-size: 13px; color: var(--warn); }
.tile-body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tile-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { font-size: 12px; color: var(--muted); }
.tile-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ---------- редактор видео ---------- */
.editor { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.editor-head h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.player-wrap { background: #000; border-radius: 10px; overflow: hidden; display: flex; justify-content: center; }
.player-wrap video { max-height: 56vh; width: 100%; }

.timeline {
  position: relative; height: 64px; border-radius: 10px; background: var(--surface-2); overflow: hidden;
  touch-action: none; user-select: none; cursor: pointer;
}
.timeline .strip { position: absolute; inset: 0; background-size: 100% 100%; background-repeat: no-repeat; opacity: .95; }
.shade { position: absolute; top: 0; bottom: 0; background: rgba(10, 10, 20, .62); pointer-events: none; }
.shade.left { left: 0; }
.shade.right { right: 0; }
.sel {
  position: absolute; top: 0; bottom: 0; border: 3px solid var(--accent); border-radius: 8px; cursor: grab;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .5) inset;
}
.sel.bad { border-color: var(--danger); }
.sel.warn { border-color: var(--warn); }
.sel:active { cursor: grabbing; }
.handle {
  position: absolute; top: -3px; bottom: -3px; width: 16px; background: var(--accent); cursor: ew-resize;
  display: grid; place-items: center;
}
.sel.bad .handle { background: var(--danger); }
.sel.warn .handle { background: var(--warn); }
.handle::after { content: ""; width: 2px; height: 22px; border-radius: 1px; background: rgba(255, 255, 255, .85); }
.h-start { left: -3px; border-radius: 7px 0 0 7px; }
.h-end { right: -3px; border-radius: 0 7px 7px 0; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 3px rgba(0, 0, 0, .6); pointer-events: none; }
.trim-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.times { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.times b { color: var(--text); font-variant-numeric: tabular-nums; }
.len.ok { color: var(--ok); }
.len.warn { color: var(--warn); }
.len.bad { color: var(--danger); }
#trim-hint { margin: -4px 0 0; min-height: 1.4em; }

/* ---------- замена ---------- */
.swap-form { padding: 18px; display: flex; flex-direction: column; gap: 20px; }
.step { display: flex; flex-direction: column; gap: 10px; }
.step h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pick-row { display: flex; gap: 10px; overflow-x: auto; padding: 3px 3px 6px; scrollbar-width: thin; }
.pick {
  flex: none; position: relative; border: 2px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer;
  background: #000; padding: 0; transition: border-color .15s, transform .1s;
}
.pick:hover { border-color: var(--accent-hover); }
.pick.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pick.clip { width: 168px; aspect-ratio: 16 / 10; }
.pick.photo { width: 92px; aspect-ratio: 3 / 4; background: var(--surface-2); }
.pick img { width: 100%; height: 100%; object-fit: cover; }
.pick .order {
  position: absolute; top: 5px; left: 5px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}
.pick.off { opacity: .4; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; align-items: start; }
.methods button { text-align: center; line-height: 1.3; padding: 8px 10px; }
.frame-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; background: #000; }
.frame-pair figure { margin: 0; position: relative; }
.frame-pair img { width: 100%; max-height: 62vh; object-fit: contain; display: block; cursor: zoom-in; }
.frame-pair figcaption { position: absolute; left: 6px; top: 6px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; padding: 1px 7px; border-radius: 6px; }
.animate-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; border: 1px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); }
.animate-box .hint { flex-basis: 100%; }
.job-src { width: 42px; height: 54px; object-fit: cover; border-radius: 6px; border: 2px solid var(--accent); }
.prompt-box { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.prompt-box summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.prompt-box[open] summary { margin-bottom: 10px; }
.prompt-box textarea { margin-bottom: 8px; }

.jobs { display: flex; flex-direction: column; gap: 14px; }
.job { padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; }
.job-media { background: #000; border-radius: 10px; overflow: hidden; position: relative; min-height: 120px; display: flex; align-items: center; justify-content: center; }
.job-media video, .job-media img { width: 100%; max-height: 62vh; object-fit: contain; }
.job-media .placeholder { color: #bbb; font-size: 14px; padding: 30px; text-align: center; }
.job-side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.job-side .bar { flex: none; }
.job-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 650; padding: 2px 9px; border-radius: 20px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.chip.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.chip.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip.run { background: var(--accent-soft); color: var(--accent); }
.spinner { width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-faces { display: flex; gap: 6px; }
.job-faces img { width: 42px; height: 54px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.job-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.job-error { color: var(--danger); font-size: 13px; background: color-mix(in srgb, var(--danger) 8%, transparent); padding: 8px 10px; border-radius: 8px; word-break: break-word; }
.job-prompt { font-size: 12px; color: var(--muted); max-height: 4.5em; overflow: hidden; }
.compare { position: absolute; top: 8px; left: 8px; }
.compare .seg { background: rgba(0, 0, 0, .55); }
.compare .seg button { color: #ddd; }
.compare .seg button.on { background: #fff; color: #111; }

/* ---------- окно обрезки ---------- */
.modal { position: fixed; inset: 0; background: rgba(8, 8, 16, .6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px; width: min(760px, 100%);
  max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.crop-area { height: min(60vh, 520px); background: #111; border-radius: 10px; overflow: hidden; }
.crop-area img { max-width: 100%; display: block; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(460px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- телефон ---------- */
@media (max-width: 760px) {
  .top { padding: 12px 16px; }
  .brand .sub { display: none; }
  .tabs { padding: 0 8px; }
  .tab { padding: 10px 9px; font-size: 14px; }
  .tab .long { display: none; }
  main { padding: 16px 16px 48px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .grid.photos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor, .swap-form { padding: 12px; }
  .job { grid-template-columns: 1fr; }
  .timeline { height: 58px; }
  .handle { width: 22px; }
  .btn.big { width: 100%; }
  .row.end, .row.between { justify-content: stretch; }
}
