/* ── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3a;
  --primary:  #5865f2;
  --primary-h:#4752c4;
  --success:  #3ba55c;
  --danger:   #ed4245;
  --warning:  #faa61a;
  --text:     #e3e5e8;
  --muted:    #72767d;
  --radius:   10px;
  --font:     'Segoe UI', system-ui, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .5px;
  color: #fff;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  letter-spacing: .3px;
}
.badge-waiting  { background: #2a2a2a; color: var(--muted); }
.badge-ready    { background: #1e3a2a; color: var(--success); }
.badge-error    { background: #3a1e1e; color: var(--danger); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: #fff; border-bottom-color: var(--primary); }

.tab-icon { font-size: 16px; }

/* ── Main Layout ─────────────────────────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.card-header h2 { margin-bottom: 0; }

h2 {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
input[type="text"]:focus { border-color: var(--primary); }

/* ── Drop Zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-top: 6px;
}
.drop-zone:hover,
.drop-zone.dragover { border-color: var(--primary); background: rgba(88,101,242,.07); }

.drop-zone.large { padding: 50px 20px; }

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  color: var(--muted);
  font-size: 14px;
}
.drop-icon { font-size: 32px; }

/* ── Image Previews ──────────────────────────────────────────────────────── */
.preview-wrap {
  margin: 12px 0;
}
.preview-wrap img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--border);
}

.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}
.thumb-row img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.thumb-row .thumb-more {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  justify-content: center;
  margin-top: 8px;
  padding: 12px;
  font-size: 15px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }

.btn-sm {
  background: var(--border);
  color: var(--text);
  padding: 6px 14px;
  font-size: 13px;
}
.btn-sm:hover:not(:disabled) { background: #3a3d4a; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 4px 10px;
  font-size: 12px;
}
.btn-danger:hover { background: rgba(237,66,69,.1); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.msg.ok      { background: #1e3a2a; color: var(--success); }
.msg.err     { background: #3a1e1e; color: var(--danger); }

/* ── Subjects List ───────────────────────────────────────────────────────── */
.subjects-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.subject-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.subject-name {
  font-weight: 600;
  color: #fff;
}

/* ── Progress Bar ────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--border);
  border-radius: 20px;
  height: 10px;
  overflow: hidden;
  margin: 10px 0 18px;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 20px;
  transition: width .3s ease;
}

#progress-text {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 4px;
}

.progress-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.progress-tag {
  background: #1e2a3a;
  color: #7cb9e8;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
}
.progress-tag.sconosciuti { background: #2a1e2a; color: #c97bc0; }

/* ── Jobs List ───────────────────────────────────────────────────────────── */
.job-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 12px;
}

.job-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.job-id {
  font-family: monospace;
  font-size: 13px;
  color: var(--muted);
  background: var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}

.job-status {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.status-queued     { background: #2a2a2a; color: var(--muted); }
.status-processing { background: #2a2010; color: var(--warning); }
.status-completed  { background: #1e3a2a; color: var(--success); }
.status-error      { background: #3a1e1e; color: var(--danger); }

.job-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.job-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.stat-pill {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: #1a2030;
  color: #7cb9e8;
}
.stat-pill.unknown { background: #2a1e2a; color: #c97bc0; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.empty-msg { color: var(--muted); font-size: 14px; }
code { font-family: monospace; background: var(--border); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ── Output: folder grid ─────────────────────────────────────────────────── */
.folder-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 180px;
}

.folder-icon { font-size: 20px; }

.folder-name {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
  flex: 1;
}

.folder-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.folder-item .btn-danger {
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Output: ZIP toolbar ─────────────────────────────────────────────────── */
.zip-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--border);
  border-radius: 8px;
  margin: 18px 0 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.zip-select-all-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.zip-select-all-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--primary);
}

.zip-bulk-actions {
  display: flex;
  gap: 8px;
}

/* ── Output: ZIP rows ────────────────────────────────────────────────────── */
.zip-row {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}

.zip-checkbox {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary);
}
.zip-row:has(.zip-checkbox:checked) {
  border-color: var(--primary);
  background: rgba(88,101,242,.08);
}

.zip-icon { font-size: 18px; }

.zip-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.zip-size {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.btn-download {
  background: #1e3a2a;
  color: var(--success);
  border: 1px solid var(--success);
  text-decoration: none;
  white-space: nowrap;
}
.btn-download:hover { background: #2a4a38; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spin {
  display: inline-block;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
