/* REMIX — закрытый мобильный PWA. System light/dark темы, без внешних шрифтов. */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: rgba(0, 0, 0, 0.04);
  --text: #1c1c1e;
  --text-2: #6e6e73;
  --separator: rgba(0, 0, 0, 0.08);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.14);
  --ok: #34c759;
  --warn: #ff9f0a;
  --danger: #ff3b30;
  --dock-bg: rgba(255, 255, 255, 0.74);
  --dock-border: rgba(0, 0, 0, 0.12);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: rgba(255, 255, 255, 0.08);
    --text: #ffffff;
    --text-2: #98989f;
    --separator: rgba(255, 255, 255, 0.12);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.22);
    --dock-bg: rgba(28, 28, 30, 0.72);
    --dock-border: rgba(255, 255, 255, 0.16);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

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

html, body { margin: 0; padding: 0; height: 100%; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

/* Верхняя шапка: НЕ sticky, с учётом safe-area сверху. */
#topbar {
  flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.capacity { text-align: right; min-width: 120px; }
.capacity-line { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.capacity-track {
  margin-top: 4px;
  height: 4px;
  width: 120px;
  margin-left: auto;
  border-radius: 2px;
  background: var(--surface-2);
  overflow: hidden;
}
.capacity-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--ok);
  transition: width 0.3s ease, background-color 0.3s ease;
}
.capacity-fill.low { background: var(--danger); }
.capacity.low .capacity-line { color: var(--danger); }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.topbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: none;
  background: var(--surface-2);
  color: var(--text-1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: background-color 0.15s ease, transform 0.1s ease;
}
.topbar-btn svg { width: 18px; height: 18px; }
.topbar-btn:active { transform: scale(0.92); }
.topbar-btn.active { background: var(--accent); color: #fff; }
.topbar-btn:disabled { opacity: 0.5; }
.topbar-btn.spinning svg { animation: remix-spin 0.6s linear infinite; }
@keyframes remix-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Контент прокручивается под доком: у main свой скролл и нижний отступ. */
#content {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 8px 20px calc(96px + env(safe-area-inset-bottom, 0px));
}

.tab { display: none; }
.tab.active { display: block; animation: fade-in 0.15s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---- Загрузить ---- */
.upload-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 40px 0 28px;
}

.add-big {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  border: 1.5px dashed var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.add-big svg { width: 64px; height: 64px; }
.add-big:active { transform: scale(0.96); }
.add-big:disabled { opacity: 0.4; pointer-events: none; }

.btn {
  min-height: 48px;
  border: none;
  border-radius: 14px;
  padding: 0 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.small { min-height: 44px; padding: 0 16px; font-size: 14px; }
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.hint { margin: 0; font-size: 13px; color: var(--text-2); text-align: center; }

.upload-status {
  background: var(--surface);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.status-note { font-size: 13px; color: var(--accent); font-weight: 600; margin-bottom: 10px; }
.overall-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.percent { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.progress-track, .queue-progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-fill, .queue-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.25s ease;
}
.progress-fill.error { background: var(--danger); }

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.queue-title, .section-title { margin: 0; font-size: 17px; font-weight: 700; }

.queue-list, .library-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.queue-item, .lib-item {
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.queue-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.queue-name { font-size: 15px; font-weight: 600; word-break: break-word; }
.queue-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.queue-item-foot { margin-top: 8px; }
.queue-progress-track { height: 5px; }
.queue-progress-fill { height: 100%; width: 0%; border-radius: 3px; background: var(--accent); transition: width 0.2s ease; }

.badge {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.badge.done { background: var(--ok); color: #fff; }
.badge.duplicate { background: var(--surface-2); color: var(--text-2); }
.badge.error { background: var(--danger); color: #fff; }
.badge.uploading { background: var(--accent-soft); color: var(--accent); }
.badge.stale { background: var(--warn); color: #fff; }
.badge.queued { background: var(--surface-2); color: var(--text-2); }

.queue-error { font-size: 13px; color: var(--danger); margin-top: 6px; word-break: break-word; }
.queue-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.queue-actions .btn { min-height: 44px; font-size: 14px; padding: 0 16px; }

/* ---- Библиотека ---- */
.lib-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.lib-item { display: flex; align-items: center; gap: 12px; }
.lib-icon {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lib-icon svg { width: 22px; height: 22px; }
.lib-body { flex: 1 1 auto; min-width: 0; }
.lib-name { font-size: 15px; font-weight: 600; word-break: break-word; }
.lib-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.empty { color: var(--text-2); font-size: 14px; text-align: center; padding: 40px 0; }

/* ---- Сборки (внутренний QA-инструмент) ---- */
.builds-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.builds-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.build-item {
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.build-name { font-size: 15px; font-weight: 600; word-break: break-word; }
.build-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; word-break: break-word; }
.build-item video {
  width: 100%;
  margin-top: 8px;
  border-radius: 10px;
  background: #000;
  aspect-ratio: 9 / 16;
  max-height: 420px;
  object-fit: cover;
}
.build-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Настройки: блок уведомлений с тумблером (тёмная тема) ---- */
.settings-block { display: flex; flex-direction: column; gap: 20px; padding-top: 8px; }
.settings-group { display: flex; flex-direction: column; gap: 12px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.setting-text { flex: 1 1 auto; min-width: 0; }
.setting-name { font-size: 15px; font-weight: 600; }
.setting-hint { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.setting-note { margin: 0; font-size: 13px; color: var(--text-2); }

.toggle {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 52px;
  height: 32px;
  cursor: pointer;
}
.toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--separator);
  transition: background-color 0.2s ease;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-track { background: var(--ok); border-color: transparent; }
.toggle input:checked + .toggle-track + .toggle-thumb { transform: translateX(20px); }
.toggle input:disabled ~ .toggle-track { opacity: 0.6; }
.toggle input:disabled ~ .toggle-thumb { opacity: 0.6; }

/* ---- «Скоро» честно, без имитации ---- */
.soon { text-align: center; padding: 80px 20px; color: var(--text-2); }
.soon-title { font-size: 20px; font-weight: 700; color: var(--text); }
.soon-text { margin-top: 8px; font-size: 15px; }

/* Кнопка «Выйти» во вкладке Настройки */
.logout-link { margin-top: 18px; }

/* ---- Insta-style нижний док (прямой потомок body) ---- */
#dock {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 4px;
  width: min(94vw, 520px);
  padding: 6px;
  border-radius: 24px;
  background: var(--dock-bg);
  border: 1px solid var(--dock-border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}
#dock.disabled { pointer-events: none; opacity: 0.65; }

.dock-item { position: relative; flex: 1 1 0; min-width: 44px; min-height: 48px; border: none; background: transparent; color: var(--text-2); border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; padding: 4px 6px; font: inherit; transition: background-color 0.15s ease, color 0.15s ease; }
.dock-item:active { opacity: 0.7; }
.dock-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 18px;
}
.dock-icon { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; }
.dock-icon svg { width: 24px; height: 24px; }
.dock-label { font-size: 10px; font-weight: 600; line-height: 1; white-space: nowrap; }

/* Маленький круглый бейдж с числом непросмотренных сборок на табе «Сборки». */
.dock-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--dock-bg);
}
.build-item .dot-badge {
  flex: 0 0 auto;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

@media (max-width: 639px) {
  .dock-label { display: none; }
  .dock-item { min-height: 44px; }
  #dock { width: min(92vw, 420px); }
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  max-width: 86vw;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

@media (min-width: 640px) {
  #content { max-width: 640px; margin: 0 auto; width: 100%; }
  #topbar { max-width: 640px; margin: 0 auto; width: 100%; }
}