:root {
  --bg: #09090b;
  --card: #131316;
  --card-border: #23232a;
  --surface: #0c0c0f;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --border: #27272a;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Header */
.header {
  text-align: center;
  padding: 24px 0 32px;
}
.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* Card grid */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 860px) {
  .cards { grid-template-columns: 1fr; }
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--card-border);
}
.card-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
}
.badge {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--primary);
  background: rgba(124, 58, 237, 0.12);
  padding: 3px 10px;
  border-radius: 20px;
}
.card-body {
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}
.req { color: var(--error); }
.opt { color: var(--text-dim); font-weight: 400; }

.field-row {
  display: flex;
  gap: 12px;
}
.flex-1 { flex: 1; }
.w-80 { width: 100px; }

textarea, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}
textarea:focus, select:focus {
  border-color: var(--primary);
}
select {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(124, 58, 237, 0.05);
}
.drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
.drop-inner svg { opacity: 0.5; }
.drop-inner em {
  color: var(--primary);
  font-style: normal;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.drop-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Preview */
.preview-wrap { margin-top: -8px; }
.preview-item {
  position: relative;
  display: inline-block;
}
.preview-item img {
  max-height: 120px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.btn-x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--error);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Preview list (multiple) */
.preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -8px;
}
.preview-list:empty { display: none; }
.preview-list .preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Progress */
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

/* Results */
.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.results:empty { display: none; }

.result-slot {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  background: var(--surface);
}
.result-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.2s;
}
.result-slot img:hover { opacity: 0.85; }

.slot-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.slot-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 4px;
  color: var(--error);
  font-size: 0.7rem;
  padding: 8px;
  text-align: center;
}

.slot-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px;
  display: flex;
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.2s;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
}
.result-slot:hover .slot-actions { opacity: 1; }
.slot-actions button {
  padding: 4px 10px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.7rem;
  cursor: pointer;
}
.slot-actions button:hover { background: rgba(255,255,255,0.25); }

/* Source label for batch results */
.result-group-label {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 6px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.result-group-label:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
}
.lightbox-img {
  position: relative;
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.lightbox-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 1;
}
.btn-dl {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
}
.btn-dl:hover { background: var(--primary-hover); }
.btn-close-lb {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-close-lb:hover { background: rgba(255,255,255,0.2); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: #fff;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }

/* Settings panel */
.btn-settings {
  margin-top: 10px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}
.btn-settings:hover {
  border-color: var(--primary);
  color: var(--text);
}
.settings-panel {
  margin-bottom: 20px;
}
.settings-panel[hidden] { display: none; }
.settings-inner {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px 22px;
  max-width: 600px;
  margin: 0 auto;
}
.key-row {
  display: flex;
  gap: 8px;
}
.input-key {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s;
}
.input-key:focus { border-color: var(--primary); }
.btn-eye {
  width: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-eye:hover { border-color: var(--primary); color: var(--text); }
.btn-save {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-save:hover { background: var(--primary-hover); }
.key-status {
  font-size: 0.75rem;
  margin-top: 4px;
  min-height: 1.2em;
}
.key-status.ok { color: var(--success); }
.key-status.err { color: var(--error); }
.key-status.warn { color: var(--warning); }

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