/* Zavodik dashboard — dark "factory control panel" theme, single amber accent.
 * Mobile-first, system font stack, no external assets.
 * Spacing scale: 4 / 8 / 12 / 16 / 20 / 24 / 32 px. */

:root {
  --bg: #14110c;
  --bg-soft: #1a1610;
  --panel: #1d1913;
  --panel-2: #251f17;
  --border: #2e281e;
  --border-strong: #40382a;
  --text: #ede8dd;
  --muted: #a2988a;
  --accent: #f0a416;
  --accent-bright: #ffbc3d;
  --accent-dim: rgba(240, 164, 22, 0.14);
  --danger: #f07362;
  --danger-dim: rgba(240, 115, 98, 0.13);
  --success: #57c78f;
  --success-dim: rgba(87, 199, 143, 0.13);
  --info: #9fb6d9;
  --info-dim: rgba(143, 183, 232, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* ============================== Base ============================== */

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 340px at 50% -120px, rgba(240, 164, 22, 0.07), transparent 70%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent-bright); }

.hidden { display: none !important; }
.no-scroll { overflow: hidden; }
.muted { color: var(--muted); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.noscript {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* ============================== Spinner ============================== */

@keyframes rot { to { transform: rotate(360deg); } }

.spin {
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(240, 164, 22, 0.25);
  border-top-color: var(--accent);
  animation: rot 0.8s linear infinite;
}
.spin-sm { width: 14px; height: 14px; }
.spin-xs { width: 10px; height: 10px; border-width: 1.5px; }

/* ============================== Buttons ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}
.btn:hover { background: #2b2419; border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1c1204;
}
.btn-primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); }
.btn-primary .spin { border-color: rgba(28, 18, 4, 0.3); border-top-color: #1c1204; }

.btn-danger {
  background: transparent;
  border-color: rgba(240, 115, 98, 0.4);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-dim); border-color: var(--danger); }

.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 0.85rem; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--panel-2); color: var(--text); }
.btn-icon:active { transform: translateY(1px); }

/* ============================== Top bar ============================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  height: 56px;
  background: rgba(20, 17, 12, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}
.brand svg { color: var(--accent); }

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.topnav a {
  position: relative;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.topnav a:hover { color: var(--text); background: var(--panel-2); }
.topnav a.active { color: var(--text); }
.topnav a.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 2px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

/* ============================== Layout ============================== */

.view {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: 48px;
}

.page-title { font-size: 1.4rem; margin-bottom: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-title {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.loading-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  text-align: center;
}

/* ============================== Login ============================== */

.screen-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  padding: 32px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo { color: var(--accent); margin-bottom: 4px; }
.login-title { font-size: 1.6rem; letter-spacing: 0.01em; }
.login-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

.form-error {
  color: var(--danger);
  font-size: 0.88rem;
}

/* ============================== Form controls ============================== */

.field { display: block; margin-bottom: 14px; }

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}
.field-label em {
  font-style: normal;
  font-weight: 500;
  text-transform: none;
  opacity: 0.75;
}

textarea, select, input[type="password"], input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 44px; }
textarea::placeholder, input::placeholder { color: #6f6758; }

textarea:focus, select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
  min-height: 44px;
  cursor: pointer;
}

/* Segmented control (scene count) */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.seg-btn {
  flex: 1;
  min-height: 38px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--text); background: var(--panel-2); }
.seg-btn.active { background: var(--accent); color: #1c1204; }
.seg-btn:active { transform: translateY(1px); }

.estimate-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--accent-dim);
  border: 1px solid rgba(240, 164, 22, 0.25);
  border-radius: var(--radius-sm);
}
.estimate-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent-bright);
  font-variant-numeric: tabular-nums;
}

.form-hint {
  margin-bottom: 14px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ============================== Home layout ============================== */

.home { display: grid; gap: 20px; }

.orders-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.orders-head .panel-title { margin-bottom: 0; }

#orders-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ============================== Order cards ============================== */

.order-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.order-card:hover { border-color: var(--border-strong); background: #221d15; }
.order-card:active { transform: translateY(1px); }

.order-thumb {
  flex: none;
  width: 54px;
  height: 96px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.order-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-ph { color: #4d4638; display: inline-flex; }

.order-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.order-topic {
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.order-error {
  font-size: 0.82rem;
  color: var(--danger);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.order-meta {
  display: flex;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.order-chev {
  flex: none;
  color: #55503f;
  font-size: 1.6rem;
  line-height: 1;
  padding-right: 2px;
}
.order-card:hover .order-chev { color: var(--accent); }

/* ============================== Status badges ============================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  width: fit-content;
}
.badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge .spin-xs {
  border-color: currentColor;
  border-top-color: transparent;
  opacity: 0.9;
}

.badge-wait { color: var(--info); background: var(--info-dim); }
.badge-work { color: var(--accent-bright); background: var(--accent-dim); }
.badge-ok   { color: var(--success); background: var(--success-dim); }
.badge-pub  { color: var(--success); background: var(--success-dim); border-color: rgba(87, 199, 143, 0.45); }
.badge-err  { color: var(--danger); background: var(--danger-dim); }
.badge-off  { color: var(--muted); background: rgba(162, 152, 138, 0.12); }

/* ============================== Empty states ============================== */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center;
}
.empty-icon { color: #4d4638; margin-bottom: 4px; }
.empty .muted { font-size: 0.9rem; max-width: 340px; }
.empty-sm { padding: 24px 16px; border: none; }

/* ============================== Order detail ============================== */

.detail {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  padding: 4px 0;
}
.back-link:hover { color: var(--accent-bright); }

.detail-head { display: flex; flex-direction: column; gap: 8px; }

.detail-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.detail-title { font-size: 1.3rem; }
.detail-topic { font-size: 0.92rem; }

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.error-banner {
  padding: 12px 14px;
  background: var(--danger-dim);
  border: 1px solid rgba(240, 115, 98, 0.4);
  border-radius: var(--radius-sm);
  color: #ffb3a8;
  font-size: 0.92rem;
  line-height: 1.45;
}
.error-banner strong { color: var(--danger); }

/* Stage timeline */
.tl-panel { padding: 16px 8px 12px; }

.tl {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.tl::-webkit-scrollbar { display: none; }

.tl-step {
  position: relative;
  flex: 1;
  min-width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.tl-step::before {
  content: "";
  position: absolute;
  top: 14px;
  left: calc(-50% + 15px);
  width: calc(100% - 30px);
  height: 2px;
  background: var(--border-strong);
}
.tl-step:first-child::before { display: none; }
.tl-step.done::before,
.tl-step.current::before,
.tl-step.fail::before { background: var(--accent); }

.tl-dot {
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 2px solid var(--border-strong);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}
.tl-step.done .tl-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: #1c1204;
}
.tl-step.current .tl-dot {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}
.tl-step.fail .tl-dot {
  background: var(--danger);
  border-color: var(--danger);
  color: #1c0906;
}
.tl-step.off .tl-dot { opacity: 0.5; }

.tl-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.tl-step.done .tl-label,
.tl-step.current .tl-label { color: var(--text); }
.tl-step.fail .tl-label { color: var(--danger); }

/* Final video player */
.player { display: flex; justify-content: center; }
.player video {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 9 / 16;
  max-height: 72vh;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 16px;
  display: block;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.actions .btn { flex: 1 1 auto; }

/* Caption */
.caption-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.caption-head .panel-title { margin-bottom: 0; }

.caption-text {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 0.95rem;
  line-height: 1.55;
  color: #d8d2c4;
  user-select: text;
}

/* Scene grid */
.scenes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
}

.scene-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  overflow: hidden;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s;
}
.scene-card:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.scene-card:disabled { cursor: default; }

.scene-media {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #0e0c08;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.scene-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.scene-ph { color: #4d4638; display: inline-flex; }

.play-badge {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(20, 17, 12, 0.72);
  border: 1px solid rgba(240, 164, 22, 0.6);
  color: var(--accent-bright);
  padding-left: 2px;
  transition: transform 0.15s, background 0.15s;
}
.scene-card:hover .play-badge {
  transform: scale(1.1);
  background: rgba(20, 17, 12, 0.9);
}

.scene-fail {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--danger);
  color: #1c0906;
  font-size: 0.8rem;
  font-weight: 800;
}

.scene-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--panel);
}
.scene-foot .muted { font-weight: 500; white-space: nowrap; }

/* ============================== Settings ============================== */

.settings {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ig-status { margin-bottom: 16px; min-height: 28px; display: flex; flex-direction: column; gap: 6px; }
.ig-status > .spin { align-self: flex-start; }
.ig-status:has(> .spin) { flex-direction: row; align-items: center; gap: 10px; }

.ig-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.ig-username { font-size: 1rem; }
.ig-quota { font-size: 0.85rem; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.pill-ok { color: var(--success); background: var(--success-dim); }
.pill-warn { color: var(--accent-bright); background: var(--accent-dim); }
.pill-danger { color: var(--danger); background: var(--danger-dim); border-color: rgba(240, 115, 98, 0.4); }

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.steps li {
  position: relative;
  padding-left: 40px;
  counter-increment: step;
  font-size: 0.92rem;
  line-height: 1.5;
  min-height: 28px;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(240, 164, 22, 0.4);
  color: var(--accent-bright);
  font-size: 0.8rem;
  font-weight: 800;
}
.steps-note { margin-top: 14px; font-size: 0.85rem; }

/* ============================== Toasts ============================== */

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

#toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  background: #262017;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  line-height: 1.4;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.25s, transform 0.25s;
}
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
.toast-out { opacity: 0; transform: translateY(6px); }

/* ============================== Lightbox ============================== */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(8, 6, 3, 0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox-body {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}
.lightbox-body video,
.lightbox-body img {
  max-width: min(94vw, 480px);
  max-height: 88vh;
  border-radius: 14px;
  background: #000;
  display: block;
}

.lightbox-close {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(38, 32, 23, 0.8);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lightbox-close:hover { background: var(--panel-2); color: var(--accent-bright); }

/* ============================== Desktop ============================== */

@media (min-width: 920px) {
  .view { padding: 24px 20px 64px; }

  .home {
    grid-template-columns: 360px 1fr;
    align-items: start;
    gap: 24px;
  }
  .form-panel {
    position: sticky;
    top: 76px;
  }

  .panel { padding: 20px; }

  .scenes-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  .order-thumb { width: 60px; height: 106px; }

  .detail-title { font-size: 1.5rem; }

  .actions .btn { flex: 0 1 auto; }
}
