:root {
  --bg: #f5f5f6;
  --card: #ffffff;
  --ink: #16171a;
  --muted: #6b6f76;
  --line: #e6e7ea;
  --accent: #111318;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --ok: #1e8e57;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  --maxw: 960px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; }
img { max-width: 100%; display: block; }

/* ── Шапка ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(245, 245, 246, .85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  font-weight: 700;
  letter-spacing: .3px;
  font-size: 17px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.topbar .brand .dot { color: var(--muted); font-weight: 400; }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px;
}

/* ── Кнопки ── */
.btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .05s ease, opacity .15s ease;
}
.btn:hover { opacity: .9; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 8px; }

/* ── Карточки ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

h1 { font-size: 22px; margin: 4px 0 2px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.section { margin-bottom: 22px; }

/* ── Форма загрузки ── */
.uploader { padding: 18px; }
.dropzone {
  border: 1.5px dashed #cfd2d7;
  border-radius: 12px;
  padding: 26px 16px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  background: #fafafb;
}
.dropzone:hover { border-color: #a9adb5; }
.dropzone.drag { border-color: var(--accent); background: #f0f1f3; color: var(--ink); }
.dropzone .big { font-size: 30px; margin-bottom: 6px; }
.dropzone .hint { font-size: 13px; margin-top: 4px; }

.previews {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.previews:empty { display: none; }
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eee;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .rm {
  position: absolute;
  top: 5px; right: 5px;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 15px;
  line-height: 24px;
  cursor: pointer;
  padding: 0;
}

.field { margin-top: 14px; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text],
.field input[type=password],
.field select {
  width: 100%;
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.field input[type=text]:focus,
.field select:focus { outline: 2px solid #d6d8dc; border-color: #c7cad0; }

.actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.msg { margin-top: 12px; font-size: 14px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ── Галерея ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.model-card {
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: transform .08s ease, box-shadow .15s ease;
}
.model-card:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgba(0,0,0,.09); }
.model-card .preview {
  aspect-ratio: 1 / 1;
  background: #ececee center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 30px;
}
.model-card .meta { padding: 10px 12px; }
.model-card .meta .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-card .meta .date { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Статусы ── */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  margin-top: 8px;
}
.badge.PENDING, .badge.IN_PROGRESS { background: #fff5e0; color: #a6741a; }
.badge.SUCCEEDED { background: #e5f5ec; color: var(--ok); }
.badge.FAILED { background: #fdecea; color: var(--danger); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

/* ── Спиннер ── */
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progressbar {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0 6px;
}
.progressbar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width .4s ease;
}

/* ── Карточка модели ── */
.viewer-wrap { padding: 16px; }
model-viewer {
  width: 100%;
  height: min(64vh, 520px);
  background: linear-gradient(180deg, #fafafb, #eeeef1);
  border-radius: 12px;
  --poster-color: transparent;
}
.status-box { padding: 30px 18px; text-align: center; }

.photos-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.photos-row a { border-radius: 10px; overflow: hidden; border: 1px solid var(--line); aspect-ratio: 1/1; }
.photos-row img { width: 100%; height: 100%; object-fit: cover; }

/* ── Экран входа ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 360px; padding: 26px; }
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login-card .field { text-align: center; margin-top: 20px; }

@media (max-width: 480px) {
  .previews { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  h1 { font-size: 20px; }
  .container { padding: 14px; }
}
