*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text2: #888;
  --text3: #555;
  --accent: #ffffff;
  --accent-dim: rgba(255,255,255,0.08);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --radius: 8px;
  --sidebar-w: 220px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.5; }

a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Login ── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.login-box {
  width: 360px; padding: 40px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; text-align: center;
}
.login-logo {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 28px; font-size: 18px; font-weight: 600;
}
.login-box h2 { font-size: 20px; font-weight: 600; margin-bottom: 24px; color: var(--text); }
.login-box input[type=password] {
  width: 100%; padding: 10px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px;
  outline: none; margin-bottom: 12px;
  transition: border-color 0.15s;
}
.login-box input:focus { border-color: #555; }
.error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; }

/* ── Buttons ── */
.btn-primary {
  width: 100%; padding: 10px 20px;
  background: #fff; color: #000;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); border-color: #444; }
.btn.btn-run {
  background: #fff; color: #000; border-color: #fff; font-weight: 600;
  padding: 10px 24px; font-size: 14px;
}
.btn.btn-run:hover { opacity: 0.85; }
.btn.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.btn-danger { border-color: var(--red); color: var(--red); }
.btn.btn-danger:hover { background: rgba(239,68,68,0.1); }

/* ── App Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 20px; font-size: 16px; font-weight: 700;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 6px; color: var(--text2);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover, .nav-item.active { background: var(--accent-dim); color: var(--text); }
.sidebar-section-label {
  font-size: 10px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 16px 10px 6px;
}
.nav-model { font-size: 12px; gap: 8px; }
.nav-model-icon { font-size: 14px; width: 16px; text-align: center; flex-shrink: 0; }
.sidebar-bottom { padding-top: 16px; border-top: 1px solid var(--border); }
.nav-item.logout:hover { background: rgba(239,68,68,0.1); color: var(--red); }

/* ── Sidebar recent predictions ── */
#sidebar-recent {
  overflow-y: auto;
  max-height: 230px;
  scrollbar-width: thin;
}
.sidebar-recent-loading, .sidebar-recent-empty {
  font-size: 11px; color: var(--text3); padding: 4px 10px;
}
.sidebar-recent-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; cursor: pointer; border-radius: 6px;
  font-size: 12px; transition: background 0.15s;
  min-width: 0;
}
.sidebar-recent-item:hover { background: var(--accent-dim); }
.sri-status { flex-shrink: 0; font-size: 11px; line-height: 1; }
.sri-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--text);
}
.sri-cost {
  flex-shrink: 0; font-size: 11px; color: var(--green);
  font-weight: 600; font-variant-numeric: tabular-nums;
}

/* ── Main ── */
.main-content { flex: 1; overflow-y: auto; padding: 32px; }
.page { display: none; }
.page.active { display: block; }

/* ── Page Header ── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.page-header p { color: var(--text2); }

/* ── Search ── */
.search-bar {
  display: flex; gap: 10px; margin-bottom: 28px;
}
.search-bar input {
  flex: 1; padding: 10px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
.search-bar input:focus { border-color: #555; }

/* ── Model Grid ── */
.model-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.model-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  display: flex; flex-direction: column; gap: 10px;
}
.model-card:hover { border-color: #444; transform: translateY(-1px); }
.model-card-header { display: flex; align-items: center; gap: 10px; }
.model-cover {
  width: 44px; height: 44px; border-radius: 6px;
  background: var(--bg3); flex-shrink: 0; object-fit: cover;
}
.model-cover-placeholder {
  width: 44px; height: 44px; border-radius: 6px;
  background: linear-gradient(135deg, var(--bg3), #222);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.model-card-meta { min-width: 0; }
.model-name {
  font-weight: 600; font-size: 13px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-owner { font-size: 12px; color: var(--text2); }
.model-desc {
  font-size: 13px; color: var(--text2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.model-stats { display: flex; gap: 12px; }
.model-stat { font-size: 11px; color: var(--text3); }
.model-stat span { color: var(--text2); }

/* ── Model Page ── */
.model-page-header {
  display: flex; align-items: flex-start; gap: 20px;
  margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border);
}
.model-page-cover {
  width: 72px; height: 72px; border-radius: 10px;
  background: var(--bg3); object-fit: cover; flex-shrink: 0;
}
.model-page-cover-placeholder {
  width: 72px; height: 72px; border-radius: 10px;
  background: linear-gradient(135deg, #1a1a2e, #222);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; flex-shrink: 0;
}
.model-page-info h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.model-page-info .owner { color: var(--text2); font-size: 14px; margin-bottom: 8px; }
.model-page-info .desc { color: var(--text2); font-size: 14px; max-width: 600px; }

/* ── Pricing badge ── */
.pricing-row {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px; margin-top: 10px;
}
.pricing-icon { color: var(--text2); flex-shrink: 0; width: 14px; height: 14px; }
.pricing-label { font-size: 12px; color: var(--text3); }
.pricing-hw {
  font-size: 11px; color: var(--text3);
  padding: 2px 7px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 20px;
}
.price-tiers-wrap { display: flex; flex-wrap: wrap; gap: 4px; }
.price-tier-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2);
  font-size: 12px;
}
.ptc-label { color: var(--text2); }
.ptc-price { color: var(--green); font-weight: 600; }

.model-run-layout {
  display: grid; grid-template-columns: 380px 1fr; gap: 28px; align-items: start;
}
@media (max-width: 900px) { .model-run-layout { grid-template-columns: 1fr; } }

/* ── Form ── */
.run-form-panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.form-section-title { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-group .field-desc { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.form-group textarea, .form-group input[type=text], .form-group input[type=number], .form-group select {
  width: 100%; padding: 8px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px;
  outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: #555; }
.form-group select option { background: var(--bg3); }

.range-group { display: flex; align-items: center; gap: 10px; }
.range-group input[type=range] { flex: 1; accent-color: #fff; }
.range-group .range-val {
  min-width: 52px; padding: 5px 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; text-align: center;
  color: var(--text);
}

.toggle-group { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 11px; cursor: pointer; transition: 0.2s;
}
.toggle-slider:before {
  content: ''; position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text2); bottom: 3px; left: 3px; transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: #fff; border-color: #fff; }
.toggle input:checked + .toggle-slider:before { background: #000; transform: translateX(18px); }

.form-actions { margin-top: 20px; display: flex; gap: 10px; align-items: center; }
.form-version { font-size: 11px; color: var(--text3); margin-top: 12px; }

/* ── Output Panel ── */
.output-panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; min-height: 300px;
}
.output-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 260px; color: var(--text3); gap: 10px;
}
.output-empty svg { width: 40px; height: 40px; opacity: 0.3; }

.status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.status-badge.starting, .status-badge.processing { background: rgba(245,158,11,0.15); color: var(--yellow); }
.status-badge.succeeded { background: rgba(34,197,94,0.15); color: var(--green); }
.status-badge.failed, .status-badge.canceled { background: rgba(239,68,68,0.15); color: var(--red); }

.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--yellow); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.output-status-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.output-time { font-size: 12px; color: var(--text2); }

.output-images { display: flex; flex-direction: column; gap: 12px; }
.output-image-wrap { position: relative; border-radius: 8px; overflow: hidden; background: var(--bg3); }
.output-image-wrap img { display: block; width: 100%; border-radius: 8px; }
.output-image-actions {
  position: absolute; bottom: 10px; right: 10px; display: flex; gap: 8px; opacity: 0;
  transition: opacity 0.15s;
}
.output-image-wrap:hover .output-image-actions { opacity: 1; }
.img-btn {
  padding: 6px 12px; background: rgba(0,0,0,0.7); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px; color: #fff; font-size: 12px; cursor: pointer; text-decoration: none;
}
.img-btn:hover { background: rgba(0,0,0,0.9); }

.output-text {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; font-family: 'Menlo', 'Consolas', monospace; font-size: 13px;
  color: var(--text); white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto;
}
.output-error {
  background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2);
  border-radius: 8px; padding: 16px; color: var(--red); font-size: 13px;
}

/* ── History ── */
.history-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.history-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: border-color 0.15s;
}
.history-card:hover { border-color: #444; }
.history-card-img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  background: var(--bg3);
}
.history-card-img-placeholder {
  width: 100%; aspect-ratio: 1;
  background: var(--bg3); display: flex; align-items: center; justify-content: center;
  color: var(--text3); font-size: 13px;
}
.history-card-info { padding: 12px; }
.history-card-model { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card-time { font-size: 11px; color: var(--text3); }
.history-card-status { display: inline-block; margin-top: 6px; }

.history-list-item {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; cursor: pointer; transition: border-color 0.15s;
  display: flex; gap: 16px; align-items: flex-start;
}
.history-list-item:hover { border-color: #444; }
.history-list-thumb {
  width: 80px; height: 80px; border-radius: 6px; object-fit: cover;
  background: var(--bg3); flex-shrink: 0;
}
.history-list-thumb-placeholder {
  width: 80px; height: 80px; border-radius: 6px;
  background: var(--bg3); display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.history-list-info { flex: 1; min-width: 0; }
.history-list-model { font-weight: 600; margin-bottom: 4px; }
.history-list-prompt { font-size: 13px; color: var(--text2); margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-list-meta { display: flex; gap: 12px; align-items: center; }
.history-list-actions { display: flex; gap: 8px; align-items: center; }

/* ── Archive (History) Cards ── */
.ha-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px;
  overflow: hidden; transition: border-color 0.15s;
}
.ha-card:hover { border-color: #444; }

.ha-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg3); flex-wrap: wrap; gap: 8px;
}
.ha-header-left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ha-header-right { display: flex; gap: 8px; align-items: center; }
.ha-model { font-weight: 600; font-size: 14px; }
.ha-time  { font-size: 12px; color: var(--text3); }
.ha-cost  { font-size: 12px; color: var(--green); font-weight: 600; background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2); padding: 1px 7px; border-radius: 20px; }

.ha-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
}
@media (max-width: 720px) { .ha-body { grid-template-columns: 1fr; } }

.ha-col-input  {
  padding: 16px; border-right: 1px solid var(--border);
  display: flex; gap: 12px; align-items: flex-start;
}
.ha-input-sidebar {
  flex-shrink: 0; display: flex; flex-direction: column; gap: 6px;
}
.ha-input-sidebar .ha-input-media { display: block; }
.ha-input-sidebar .ha-input-thumb {
  width: 120px; height: 120px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border); display: block;
}
.ha-input-content { flex: 1; min-width: 0; }
.ha-col-output { padding: 16px; }
@media (max-width: 720px) {
  .ha-col-input { border-right: none; border-bottom: 1px solid var(--border); flex-direction: column; }
  .ha-input-sidebar .ha-input-thumb { width: 80px; height: 80px; }
}

.ha-section-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 10px;
}
.ha-prompt {
  font-size: 14px; color: var(--text); background: var(--bg3);
  border-left: 3px solid var(--accent); padding: 8px 12px;
  border-radius: 0 4px 4px 0; margin-bottom: 10px;
  word-break: break-word; white-space: pre-wrap;
}
.ha-param {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12px; margin-bottom: 6px; flex-wrap: wrap;
}
.ha-param-key {
  color: var(--text3); flex-shrink: 0; min-width: 80px;
  font-family: monospace; font-size: 11px; margin-top: 2px;
}
.ha-param-val {
  color: var(--text2); word-break: break-word;
}
.ha-input-media {
  position: relative; display: inline-block;
}
.ha-input-thumb {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--border); display: block;
}
.ha-input-media-row { display: flex; gap: 6px; flex-wrap: wrap; }
.ha-dl-btn {
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(0,0,0,.65); color: #fff;
  border-radius: 4px; font-size: 11px; padding: 1px 5px;
  text-decoration: none; display: block;
  opacity: 0; transition: opacity 0.15s;
}
.ha-input-media:hover .ha-dl-btn { opacity: 1; }

.ha-out-grid {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.ha-out-item {
  display: flex; flex-direction: column; gap: 6px;
  flex: 1; min-width: 140px;
}
.ha-out-thumb {
  width: 100%; border-radius: 8px;
  border: 1px solid var(--border); object-fit: cover;
  cursor: pointer; transition: opacity 0.15s;
  max-height: 400px;
}
.ha-out-thumb:hover { opacity: .85; }
.ha-dl-full-btn {
  display: flex; align-items: center; gap: 5px; justify-content: center;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px;
  font-size: 12px; color: var(--text2); text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.ha-dl-full-btn:hover { border-color: #555; color: var(--text); }

.ha-text-out {
  font-size: 13px; color: var(--text2); background: var(--bg3);
  border-radius: 6px; padding: 12px; white-space: pre-wrap;
  word-break: break-word; max-height: 300px; overflow-y: auto;
  border: 1px solid var(--border);
}
.ha-error {
  font-size: 12px; color: #f87171; background: rgba(248,113,113,.08);
  border: 1px solid rgba(248,113,113,.2); border-radius: 6px; padding: 10px;
  word-break: break-word;
}
.ha-empty { font-size: 13px; color: var(--text3); }

/* ── Collections ── */
.collections-row { display: flex; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; }
.collection-chip {
  padding: 6px 14px; border-radius: 20px;
  background: var(--bg2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text2); cursor: pointer; transition: all 0.12s;
}
.collection-chip:hover, .collection-chip.active { background: var(--accent-dim); border-color: #555; color: var(--text); }

/* ── Pagination ── */
.pagination { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 28px; }

/* ── Loader ── */
.page-loader {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; color: var(--text3);
}
.loader-spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--text2); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
  padding: 12px 18px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  font-size: 13px; color: var(--text); box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Image Upload ── */
.img-upload-zone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.img-upload-zone:hover { border-color: #555; background: var(--accent-dim); }
.img-upload-zone.drag-over { border-color: var(--accent); background: var(--accent-dim); border-style: solid; }
.img-upload-zone span { font-size: 12px; color: var(--text2); }
.img-upload-zone-sm { padding: 10px; margin-top: 8px; }
.img-upload-zone-sm svg { display: inline; }

.img-upload-preview { width: 100%; border-radius: 6px; max-height: 280px; object-fit: contain; }

.multi-img-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.multi-img-item {
  position: relative; width: 72px; height: 72px;
}
.multi-img-item img {
  width: 72px; height: 72px; border-radius: 6px; object-fit: cover;
  border: 1px solid var(--border);
}
.multi-img-item button {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); color: #fff; border: none;
  font-size: 10px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

/* ── Batch processing ── */
.batch-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px; padding: 5px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; font-size: 12px; color: var(--text2);
  cursor: pointer; transition: all 0.12s;
}
.batch-add-btn:hover { border-color: #555; color: var(--text); }

.batch-list {
  display: flex; flex-direction: column; gap: 6px; margin-top: 8px;
}
.batch-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px;
}
.batch-thumb {
  width: 36px; height: 36px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0;
}
.batch-item-name {
  flex: 1; font-size: 12px; color: var(--text2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.batch-item-status { font-size: 13px; flex-shrink: 0; min-width: 20px; text-align: center; }
.batch-remove-btn {
  background: none; border: none; color: var(--text3);
  cursor: pointer; font-size: 12px; padding: 2px 4px; flex-shrink: 0;
}
.batch-remove-btn:hover { color: var(--red); }

/* Результаты пакета */
.batch-results-grid {
  display: flex; flex-direction: column; gap: 10px;
}
.batch-result-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px;
}
.batch-result-thumb-wrap {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px;
}
.batch-result-src {
  width: 80px; height: 80px; object-fit: cover;
  border-radius: 6px; flex-shrink: 0;
  border: 1px solid var(--border);
}
.batch-result-arrow { color: var(--text3); font-size: 18px; flex-shrink: 0; }
.batch-result-out {
  flex: 1; min-width: 80px; min-height: 80px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.batch-result-img {
  width: 100%; max-height: 200px; object-fit: contain;
  border-radius: 6px; border: 1px solid var(--border);
}
.batch-result-dl {
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(0,0,0,.7); color: #fff;
  border-radius: 4px; padding: 2px 8px; font-size: 12px;
  text-decoration: none;
}
.batch-result-name {
  font-size: 11px; color: var(--text3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.batch-spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--yellow); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Back link ── */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text2); font-size: 13px; margin-bottom: 20px; cursor: pointer; }
.back-link:hover { color: var(--text); }
.back-link svg { width: 14px; height: 14px; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: var(--text2); }

/* ── Section label ── */
.section-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 14px; }

/* ── Official badge ── */
.badge-official { display: inline-block; margin-left: 8px; padding: 2px 8px; background: rgba(59,130,246,0.15); color: var(--blue); border-radius: 20px; font-size: 11px; font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════════
   MOBILE  (≤ 768px)
══════════════════════════════════════════════════════════════════════════════ */

/* Mobile top header — скрыт на десктопе */
.mobile-header {
  display: none;
  align-items: center; justify-content: space-between;
  height: 56px; padding: 0 16px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  flex-shrink: 0;
}
.mobile-logo { font-size: 16px; font-weight: 700; }
.burger-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 8px;
  background: none; border: none; color: var(--text); cursor: pointer;
}
.burger-btn:hover { background: var(--accent-dim); }

/* Overlay backdrop */
.mobile-overlay {
  display: none; position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(2px);
}
.mobile-overlay.visible { display: block; }

@media (max-width: 768px) {
  /* Показываем мобильную шапку */
  .mobile-header { display: flex; }

  /* App — вертикальная колонка, отступ сверху под шапку */
  .app {
    flex-direction: column;
    padding-top: 56px;
  }

  /* Сайдбар — скрытый drawer слева */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
    padding-top: 16px;
    /* safe area для iOS */
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.6);
  }

  /* Основной контент — полная ширина, меньше padding */
  .main-content {
    padding: 16px;
    height: calc(100vh - 56px);
    /* safe area снизу для iOS */
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  /* Заголовок страницы */
  .page-header h1 { font-size: 20px; }
  .page-header { margin-bottom: 20px; }

  /* Login */
  .login-box {
    width: calc(100vw - 32px);
    max-width: 360px;
    padding: 28px 20px;
  }

  /* Форма — 16px чтобы iOS не зумил */
  .form-group textarea,
  .form-group input[type=text],
  .form-group input[type=number],
  .form-group input[type=url],
  .form-group select,
  .login-box input[type=password],
  .search-bar input,
  .form-input {
    font-size: 16px;
  }
  .range-group .range-val { font-size: 16px; }

  /* Поиск моделей */
  .search-bar { flex-wrap: wrap; }

  /* Сетка моделей — одна колонка на маленьких экранах */
  .model-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  /* Страница модели — шапка стекируется */
  .model-page-header {
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 16px;
  }
  .model-page-cover,
  .model-page-cover-placeholder {
    width: 56px; height: 56px;
  }
  .model-page-info h1 { font-size: 18px; }

  /* Run layout — одна колонка уже при 900px, ок */

  /* Кнопки — крупнее touch target */
  .btn { padding: 10px 16px; min-height: 44px; }
  .btn.btn-run { padding: 12px 24px; }

  /* Кнопки в шапке архива */
  .ha-header { padding: 10px 12px; }
  .ha-header-right { width: 100%; justify-content: flex-end; }

  /* Toast — полная ширина снизу */
  .toast-container {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 16px;
    left: 16px;
  }
  .toast { text-align: center; }

  /* Output image actions — всегда видны на тач-устройствах */
  .output-image-actions { opacity: 1; }

  /* Скачивание в архиве — всегда видна кнопка */
  .ha-dl-btn { opacity: 1; }

  /* Быстрый доступ — chips под поиском на главной */
  .quick-access-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
}

@media (max-width: 480px) {
  /* Совсем маленькие экраны */
  .model-grid { grid-template-columns: 1fr; }
  .ha-out-item { max-width: 100%; }
  .ha-out-thumb { max-width: 100%; }
  .collections-row { gap: 6px; }
  .collection-chip { font-size: 12px; padding: 5px 10px; }
  .main-content { padding: 12px; }
}
