:root {
  --bg: #14161b;
  --bg-raised: #1b1e25;
  --bg-input: #23272f;
  --line: #2c313a;
  --text: #e6e8ec;
  --text-dim: #9aa2b1;
  --accent: #d9a441;
  --accent-dim: #8a6a29;
  --danger: #d4574a;
  --ok: #5ba36b;
  --radius: 10px;
}

* { box-sizing: border-box; }

/*
 * L'attributo hidden vale display:none, ma arriva dal foglio dello user-agent e perde contro
 * qualunque regola di classe che imposti display. Senza questa riga un elemento con display
 * dichiarato (es. .gate, che e' grid) resta visibile anche dopo aver impostato hidden da JS.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}

.gate-box {
  max-width: 460px;
  padding: 32px;
  text-align: center;
}

.gate-box h1 { margin: 0 0 12px; font-size: 22px; }
.gate-hint { color: var(--text-dim); font-size: 13px; margin-top: 20px; }
code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
}

.ns-picker { display: flex; gap: 8px; align-items: center; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user { color: var(--text-dim); font-size: 13px; }

.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--accent); border-color: var(--accent-dim); }
.pill.off { color: var(--danger); border-color: var(--danger); }

select, input[type="text"], input[type="search"], input[type="number"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

select:focus, input:focus, textarea:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

.btn {
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { border-color: var(--accent-dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #201a0c; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
}

.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.is-active { display: block; }

.panel-head { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.panel-head input { flex: 1; min-width: 200px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.card-thumb {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 8px;
  background: var(--bg-input);
  display: grid;
  place-items: center;
  image-rendering: pixelated;
  overflow: hidden;
  font-size: 11px;
  color: var(--text-dim);
}

.card-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }

.card-main { min-width: 0; flex: 1; }
.card-title { font-weight: 600; margin: 0 0 2px; overflow-wrap: anywhere; }
.card-sub { color: var(--text-dim); font-size: 12px; overflow-wrap: anywhere; }
.card-tags { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-dim);
}

.tag-type { background: var(--accent-dim); color: #f3e5c6; }

.thumb-missing {
  color: var(--danger);
  font-size: 22px;
  font-weight: 700;
}

.upload-opt { margin-top: 14px; font-size: 13px; color: var(--text-dim); }
.upload-opt code { font-size: 12px; }

.card-actions { display: flex; flex-direction: column; gap: 6px; }
.card-actions .btn { padding: 4px 10px; font-size: 12px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }

.cat-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.cat-card h3 { margin: 0 0 4px; font-size: 16px; }
.cat-items { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto; }
.cat-foot { margin-top: 12px; display: flex; gap: 8px; }

.dropzones { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  display: grid;
  gap: 6px;
  transition: border-color .15s, background .15s;
}

.dropzone span { color: var(--text-dim); font-size: 13px; }
.dropzone.is-over { border-color: var(--accent); background: rgba(217, 164, 65, .07); }

.report {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}

.report { max-height: 340px; overflow-y: auto; }
.report .row { padding: 3px 0; }
.report .row.bad { color: var(--danger); }
.report .row.good { color: var(--ok); }
.report .row.warn { color: var(--accent); }

.report-head {
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px !important;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  background: var(--bg-raised);
}

.mode-switch {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.batch-config {
  background: var(--bg-raised);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.dropzone-batch { padding: 40px 16px; border-color: var(--accent-dim); }
.batch-opt { margin: 4px 0 12px; font-size: 13px; }

.slot-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.slot-row:last-child { border-bottom: none; }

.slot-preview {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  background: var(--bg-input);
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.slot-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.slot-missing { color: var(--danger); font-size: 24px; font-weight: 600; }
.slot-main { flex: 1; min-width: 0; }
.slot-name { font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-family: ui-monospace, monospace; }
.slot-main select { width: 100%; }
.slot-warn { color: var(--accent); font-size: 12px; margin-top: 5px; }

.section-title { margin: 26px 0 12px; font-size: 15px; color: var(--text-dim); font-weight: 600; }

.tex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }

.tex-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}

.tex-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  background: var(--bg-input);
  border-radius: 6px;
}

.tex-card .name {
  font-size: 11px;
  color: var(--text-dim);
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.model-list { display: grid; gap: 8px; }

.model-row {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-row .name { flex: 1; overflow-wrap: anywhere; }

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

.status-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.status-card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.status-card .value { font-size: 20px; margin-top: 6px; overflow-wrap: anywhere; }
.status-card .value.small { font-size: 13px; }
.status-actions { margin-top: 20px; display: flex; gap: 10px; flex-wrap: wrap; }
.hint { color: var(--text-dim); font-size: 13px; margin-top: 12px; }
.empty { color: var(--text-dim); text-align: center; padding: 40px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}

.modal-box {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(720px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
}

.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 20px; overflow-y: auto; }

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
}

.modal-foot .error { flex: 1; color: var(--danger); font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { min-height: 84px; resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }
.field .desc { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.picker-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
}

.picker-row { display: flex; align-items: center; gap: 10px; padding: 5px 6px; border-radius: 6px; }
.picker-row:hover { background: var(--bg-input); }
.picker-row input { width: auto; }
.picker-row img { width: 24px; height: 24px; image-rendering: pixelated; object-fit: contain; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 60; }

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 11px 16px;
  max-width: 380px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.toast.bad { border-left-color: var(--danger); }
.toast.good { border-left-color: var(--ok); }

@media (max-width: 620px) {
  .topbar { gap: 12px; }
  .topbar-right { width: 100%; }
  .field-row { grid-template-columns: 1fr; }
}
