:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #252833;
  --border: #2d3142;
  --text: #e4e6eb;
  --text-dim: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #22c55e, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  cursor: pointer;
}
nav { display: flex; gap: 0.5rem; }
.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}
.nav-btn:hover, .nav-btn.active {
  color: var(--text);
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

/* Main */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}
.view { display: none; }
.view.active { display: block; }

/* Buttons */
.btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text-dim); }
.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }

/* Upload */
.upload-container { max-width: 900px; margin: 0 auto; }
.section-title { font-size: 1.5rem; margin-bottom: 0.25rem; }
.section-subtitle { color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.05);
}
.drop-zone-content svg { color: var(--text-dim); margin-bottom: 1rem; }
.drop-zone-content p { color: var(--text-dim); margin-bottom: 0.5rem; }
.drop-zone-content .subtle { font-size: 0.8rem; opacity: 0.7; }

/* Preview grid */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.preview-thumb {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-thumb .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 24px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-thumb .thumb-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 4px;
  background: rgba(0,0,0,0.7);
  font-size: 0.65rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Model selector */
.model-selector {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.model-selector h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.model-checkboxes { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.model-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}
.model-checkbox:hover { border-color: var(--primary); }
.model-checkbox input[type="checkbox"] { accent-color: var(--primary); }
.model-checkbox .badge-primary {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-hover);
  border-radius: 999px;
}

/* Upload actions */
.upload-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* Batch Results */
.batch-header {
  margin-bottom: 1rem;
}
.batch-progress {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}
#progress-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Image thumbs strip */
.image-thumbs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
}
.image-thumb {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}
.image-thumb:hover { border-color: var(--text-dim); }
.image-thumb.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3); }
.image-thumb.done { border-color: var(--success); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-thumb .thumb-label {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* Current image */
.current-image-container {
  text-align: center;
  margin-bottom: 1.5rem;
}
.current-image-container img {
  max-width: 100%;
  max-height: 250px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.current-image-container h3 {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Prompt sections */
.prompt-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.prompt-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.prompt-section-header:hover { background: rgba(255,255,255,0.02); }
.prompt-section-header h3 { font-size: 0.95rem; font-weight: 600; }
.prompt-toggle {
  font-size: 0.75rem;
  color: var(--text-dim);
  transition: transform 0.2s;
}
.prompt-section-body {
  display: none;
  padding: 0.75rem;
}
.prompt-section-body.open { display: block; }

/* Models grid inside prompt section */
.models-grid {
  display: grid;
  gap: 0.75rem;
}
.model-result-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.model-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
}
.model-result-name {
  font-size: 0.85rem;
  font-weight: 600;
}
.model-result-status {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-dim);
}
.model-result-status.running {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-hover);
}
.model-result-status.done {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}
.model-result-status.error {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}
.model-result-content {
  padding: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.6;
  max-height: 400px;
  overflow-y: auto;
  word-break: break-word;
}
.model-result-content strong { color: #a5b4fc; }
.model-result-content .error-text { color: var(--danger); }

.cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  background: var(--primary);
  animation: blink 1s infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* History */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}
.history-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.history-card img { width: 100%; height: 160px; object-fit: cover; }
.history-card-info { padding: 0.75rem; }
.history-card-info .date { font-size: 0.8rem; color: var(--text-dim); }
.history-card-info .name { font-size: 0.9rem; margin-top: 0.25rem; }
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Prompts */
.prompt-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.prompt-form input, .prompt-form textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  resize: vertical;
}
.prompt-form input:focus, .prompt-form textarea:focus { border-color: var(--primary); }

.prompt-list { display: flex; flex-direction: column; gap: 0.75rem; }
.prompt-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.prompt-card.active { border-color: var(--success); }
.prompt-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.prompt-card-header h4 { font-size: 0.95rem; }
.prompt-card-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}
.prompt-card-text {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: vertical;
}
.prompt-card-text:focus { border-color: var(--primary); }
.prompt-card-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

/* Telegram */
.tg-header {
  margin-bottom: 1rem;
}
.tg-header h2 { margin-bottom: 1rem; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
}
.stat-num { font-size: 1.5rem; font-weight: 700; color: var(--primary-hover); }
.stat-label { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }

.tg-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.tg-filter.active { background: var(--primary); color: white; border-color: var(--primary); }

.tg-log-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.tg-log-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
}
.tg-log-card.completed { border-left: 3px solid var(--success); }
.tg-log-card.error { border-left: 3px solid var(--danger); }
.tg-log-card.processing { border-left: 3px solid var(--warning); }

.tg-log-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.tg-log-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.tg-log-chat { font-weight: 600; }
.tg-log-user { color: var(--primary-hover); }
.tg-log-date { color: var(--text-dim); font-size: 0.8rem; }

.tg-log-badges {
  display: flex;
  gap: 0.35rem;
}
.tg-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
}
.tg-badge.photo { background: rgba(99, 102, 241, 0.2); color: var(--primary-hover); }
.tg-badge.status-completed { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.tg-badge.status-error { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.tg-badge.status-processing { background: rgba(245, 158, 11, 0.2); color: var(--warning); }

.tg-log-msg {
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}
.tg-log-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-bottom: 0.5rem;
}
.tg-log-response {
  margin-top: 0.5rem;
}
.tg-log-response summary {
  font-size: 0.8rem;
  color: var(--primary-hover);
  cursor: pointer;
  padding: 0.25rem 0;
}
.tg-log-response-body {
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 0.5rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-top: 0.35rem;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.tg-log-models {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

/* Responsive */
@media (max-width: 768px) {
  .header-inner { padding: 0.5rem 1rem; }
  .logo { font-size: 1.1rem; }
  nav { gap: 0.25rem; }
  .nav-btn { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
  main { padding: 1rem; }
  .models-grid { grid-template-columns: 1fr !important; }
  .history-list { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .image-thumb { width: 60px; height: 60px; }
}

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

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  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); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
}
