/* Tema scuro neutro, font di sistema, layout a schede verticali. */
:root {
  --bg: #14161a;
  --bg-card: #1c1f25;
  --bg-elev: #23272f;
  --bg-input: #101216;
  --border: #2c313a;
  --border-strong: #3a404b;
  --text: #e6e8ec;
  --text-dim: #a2a8b3;
  --text-faint: #6f7681;
  --accent: #4f8cff;
  --accent-hover: #6a9dff;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- header ---------- */
.site-header {
  padding: 40px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.site-header h1 {
  font-size: 24px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.subtitle {
  color: var(--text-dim);
  margin: 10px 0 0;
  max-width: 780px;
}

/* ---------- badge motore ---------- */
.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  white-space: nowrap;
}
.badge-loading { color: var(--warn); border-color: var(--warn); }
.badge-ready { color: var(--ok); border-color: var(--ok); }
.badge-error { color: var(--err); border-color: var(--err); }

/* ---------- schede ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 28px;
}
.step-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  flex: none;
}
.step-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
}
.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text);
}

/* ---------- campi ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field .label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.field .help {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.45;
}
.align-end { justify-content: flex-end; }

input[type="text"],
input[type="number"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input[type="file"] {
  color: var(--text-dim);
  font-size: 13px;
}
textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  min-height: 420px;
  resize: vertical;
  line-height: 1.5;
}
#annotation-text { min-height: 160px; }
#manifest-text { min-height: 140px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.row .grow { flex: 1 1 240px; }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 16px;
}
.overrides {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 16px 0;
  margin-bottom: 16px;
}

/* ---------- pulsanti ---------- */
button, .button-like {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
button:hover, .button-like:hover {
  background: #2b3038;
  border-color: #4a515d;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}

/* ---------- progress ---------- */
.progress { margin: 12px 0; }
.progress-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
}
#analyze-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}
.progress-text {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ---------- tabelle ---------- */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
}
.table-wrap.compact { max-height: 320px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  background: var(--bg-elev);
  color: var(--text-dim);
  font-weight: 500;
  position: sticky;
  top: 0;
}
tr:last-child td { border-bottom: none; }

/* ---------- riquadri ---------- */
.summary {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-dim);
  margin: 12px 0;
  white-space: pre-wrap;
}
.errors {
  background: rgba(248, 81, 73, 0.08);
  border: 1px solid var(--err);
  border-radius: 8px;
  padding: 12px 14px;
  color: #ffb4ae;
  font-size: 13px;
  margin: 12px 0;
  white-space: pre-wrap;
}
.notice {
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid var(--warn);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 13px;
}
.notice p { margin: 0 0 10px; }

.mono-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow: auto;
  max-height: 320px;
  white-space: pre;
  margin: 12px 0;
}
.svg-box {
  background: #fff;
  border-radius: 8px;
  padding: 8px;
  margin: 12px 0;
  overflow: auto;
}
.svg-box svg { max-width: 100%; height: auto; display: block; }

.markdown-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  max-height: 480px;
  overflow: auto;
  font-size: 14px;
}
.markdown-box h1, .markdown-box h2, .markdown-box h3 { margin-top: 1em; }
.markdown-box table { font-size: 12px; }
.markdown-box code {
  background: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

/* ---------- collapsible ---------- */
.collapsible {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 12px 0;
  overflow: hidden;
}
.collapsible > summary {
  cursor: pointer;
  padding: 10px 14px;
  background: var(--bg-elev);
  font-size: 13px;
  color: var(--text-dim);
  list-style: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before { content: "▸ "; }
.collapsible[open] > summary::before { content: "▾ "; }
.collapsible > .collapsible-body {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: pre-wrap;
}

/* ---------- varianti ---------- */
.variants {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.variant {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.variant h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.variant .meta { font-size: 12px; color: var(--text-dim); }
.variant .badge-ok { color: var(--ok); }
.variant .badge-err { color: var(--err); }
.variant .variant-svg {
  background: #fff;
  border-radius: 6px;
  padding: 4px;
  overflow: auto;
}
.variant .variant-svg svg { max-width: 100%; height: auto; display: block; }
.variant .variant-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.variant .variant-actions button { font-size: 12px; padding: 6px 10px; }
.variant ul.validation { margin: 0; padding-left: 18px; font-size: 12px; color: #ffb4ae; }

/* ---------- registro ---------- */
.log-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #0d0f12;
  border-top: 1px solid var(--border);
  z-index: 50;
}
.log-toggle {
  width: 100%;
  border: none;
  border-radius: 0;
  background: #0d0f12;
  color: var(--text-dim);
  text-align: left;
  padding: 8px 24px;
  font-size: 12px;
}
.log-toggle:hover { background: #14171b; }
#log-content {
  margin: 0;
  padding: 0 24px 12px;
  max-height: 220px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
  display: none;
}
.log-panel.open #log-content { display: block; }
body { padding-bottom: 44px; }

/* ---------- overlay ---------- */
.busy {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.busy-box {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 24px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modale ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 24px;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 4px 8px;
}
.modal-body { padding: 20px; overflow: auto; }
#modal-body.markdown-box { max-height: none; border: none; background: transparent; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 24px 0 40px;
  color: var(--text-faint);
  font-size: 13px;
}
.site-footer p { margin: 6px 0; }
.site-footer a { color: var(--accent); }

.tempo-map { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.tempo-row { display: flex; gap: 12px; align-items: flex-start; }
.tempo-row .field { margin-bottom: 0; }

.hidden { display: none !important; }
.sep { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

@media (max-width: 640px) {
  .card { padding: 20px; }
  .wrap { padding: 0 16px; }
  .site-header h1 { font-size: 20px; }
}
