/* Variabili di default (tema scuro) — sovrascritte a runtime da app.js con
   i colori letti da GET /api/branding (config/branding.yaml, vedi README §11).
   Restano qui solo come fallback prima che il branding sia stato applicato. */
:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --accent: #60a5fa;
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2229;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa3b2;
  --danger: #ef4444;
  --warn: #f59e0b;
  --success: #22c55e;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow-x: hidden;
  transition: background-color 0.15s ease, color 0.15s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5em; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h2, h3 { letter-spacing: -0.01em; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55em 0.85em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

button {
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: transparent;
  color: white;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
button:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
button.secondary { background: var(--panel-2); color: var(--text); border-color: var(--border); box-shadow: none; }
button.danger { background: linear-gradient(135deg, var(--danger), #b91c1c); }
button.icon-btn {
  background: var(--panel-2); box-shadow: none; border: 1px solid var(--border);
  color: var(--text-dim); width: 30px; height: 30px; border-radius: 50%;
  padding: 0; font-size: 0.95em; display: inline-flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
button.icon-btn:hover { color: var(--text); border-color: var(--primary); transform: none; filter: none; }
button.icon-btn.icon-danger:hover { color: var(--danger); border-color: var(--danger); }
button.icon-btn + button.icon-btn { margin-left: 0.35em; }

/* ---------- Login ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 45%),
    radial-gradient(circle at 85% 85%, color-mix(in srgb, var(--text-dim) 12%, transparent), transparent 45%),
    var(--bg);
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.2em 2.2em 1.8em;
  width: 340px;
  box-shadow: var(--shadow);
}
.login-box .brand-logo { display: flex; justify-content: center; margin-bottom: 1em; }
.login-box .brand-logo img { max-height: 44px; max-width: 220px; object-fit: contain; }
.login-box h1 { margin: 0 0 0.2em; font-size: 1.3em; text-align: center; }
.login-box p.subtitle { color: var(--text-dim); margin: 0 0 1.4em; font-size: 0.85em; text-align: center; }
.login-box input { width: 100%; margin-bottom: 0.7em; }
.login-box button { width: 100%; margin-top: 0.4em; padding: 0.7em; }
.field-error { color: var(--danger); font-size: 0.85em; min-height: 1.2em; text-align: center; }
.field-success { color: var(--success); font-size: 0.85em; text-align: center; margin-bottom: 0.6em; }
.login-links { display: flex; justify-content: space-between; margin-top: 1em; font-size: 0.82em; }
.login-links a { color: var(--text-dim); }
.login-links a:hover { color: var(--primary); }
.software-footer { margin: 1.1em 0 0; text-align: center; font-size: 0.72em; color: var(--text-dim); }
.software-footer a { color: inherit; }
.software-footer a:hover { color: var(--primary); text-decoration: underline; }
.sidebar-footer { margin: 0.6em 0 0.2em; padding-top: 0.6em; border-top: 1px solid var(--border); }

/* ---------- Contenuto generico dentro un modal-dialog (§9.5) ---------- */
.modal-dialog input, .modal-dialog textarea { width: 100%; margin-bottom: 0.7em; }
.modal-dialog textarea { resize: vertical; font-family: inherit; }
.modal-actions { display: flex; gap: 0.6em; justify-content: flex-end; margin-top: 1em; }
.pw-requirements { list-style: none; margin: -0.3em 0 0.7em; padding: 0; font-size: 0.82em; }
.pw-requirements li {
  display: flex; align-items: center; gap: 0.55em;
  padding: 0.15em 0; color: var(--text-dim);
  transition: color 0.15s ease;
}
.pw-requirements li .pw-check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid var(--border); font-size: 0.72em; line-height: 1; color: transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.pw-requirements li.met { color: var(--success); }
.pw-requirements li.met .pw-check {
  background: var(--success); border-color: var(--success); color: #fff;
}
.pw-requirements li.met .pw-check::after { content: "\2713"; }

/* ---------- App shell ---------- */
#app-view { display: none; min-height: 100vh; }

#sidebar {
  width: 232px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 90%, black 10%));
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.08);
  padding: 1.2em 0.7em;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}
#sidebar .brand {
  display: flex; align-items: center; gap: 0.6em;
  font-weight: 700; font-size: 1.05em; padding: 0.2em 0.5em 1em; line-height: 1.2;
  border-bottom: 1px solid var(--border); margin: 0 0.1em 0.8em;
}
#sidebar .brand img { max-height: 28px; max-width: 140px; object-fit: contain; }
#sidebar .brand small { display: block; color: var(--text-dim); font-weight: 400; font-size: 0.68em; }
#sidebar .brand .brand-spacer { flex: 1; }
/* Hamburger e overlay esistono solo per il layout mobile/tablet sotto gli
   800px (vedi il media query più sotto): a desktop il pannello nav resta
   incorporato nella sidebar come sempre, senza posizionamento fisso. */
#sidebar-toggle { display: none; }
#sidebar-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#sidebar-backdrop { display: none; }

.nav-link {
  display: flex; align-items: center; gap: 0.8em;
  padding: 0.65em 0.9em;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  text-decoration: none;
  margin-bottom: 0.25em;
  cursor: pointer;
  font-size: 0.93em;
  font-weight: 600;
  position: relative;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.nav-link .nav-icon { flex-shrink: 0; width: 18px; height: 18px; display: flex; opacity: 0.8; }
.nav-link .nav-icon svg { width: 100%; height: 100%; }
.nav-link:hover { background: var(--panel-2); color: var(--text); transform: translateX(1px); }
.nav-link:hover .nav-icon { opacity: 1; }
.nav-link.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: var(--shadow-sm);
}
.nav-link.active .nav-icon { opacity: 1; }
.nav-link.active::before {
  content: ""; position: absolute; left: -0.7em; top: 20%; bottom: 20%;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}

/* Scorciatoia verso l'editor di sequenza aperto (§10.1): indentata e più
   piccola per leggersi come "derivata" dalla voce Sequenze sopra di lei,
   non come una sezione di primo livello a sé stante. */
.nav-link.nav-sub {
  padding-left: 2.3em;
  font-size: 0.85em;
  margin-top: -0.1em;
}
.nav-link.nav-sub .nav-icon { width: 15px; height: 15px; }

#sidebar .user-box {
  margin-top: auto;
  padding: 0.9em 0.5em 0.2em;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.7em;
}
.user-avatar {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8em; letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
}
.user-info { min-width: 0; display: flex; flex-direction: column; gap: 0.25em; }
.user-info b {
  color: var(--text); font-size: 0.88em; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge.role-admin { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.badge.role-test_engineer { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.role-operator { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.role-viewer { background: color-mix(in srgb, var(--text-dim) 18%, transparent); color: var(--text-dim); }
.badge.role-superuser { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }

#sidebar .cert-logo {
  display: block; max-height: 40px; max-width: 80%; object-fit: contain;
  margin: 0.8em auto 0.4em; opacity: 0.85;
}

#content {
  flex: 1;
  padding: 1.6em 2em;
  overflow-y: auto;
}

/* ---------- Componenti generici ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2em;
  margin-bottom: 1.2em;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 1.2em; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: 0.9em; }
th, td { text-align: left; padding: 0.55em 0.6em; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.02em; }
tr:hover td { background: var(--panel-2); }

.badge {
  display: inline-flex; align-items: center; gap: 0.3em;
  padding: 0.18em 0.65em;
  border-radius: 999px;
  font-size: 0.76em;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.badge.pass, .badge.approved, .badge.online {
  background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.fail, .badge.error {
  background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.warn, .badge.in_review, .badge.busy, .badge.skipped {
  background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.draft, .badge.offline {
  background: color-mix(in srgb, var(--text-dim) 18%, transparent); color: var(--text-dim); }
.badge.running { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }

.text-dim { color: var(--text-dim); font-size: 0.85em; }

/* ---------- Configurazione branding (§10.1, §11), solo Superuser ---------- */
.color-grid { display: grid; gap: 0.5em; }
.color-grid-row {
  display: grid; grid-template-columns: 1fr 60px 60px; align-items: center; gap: 0.8em;
}
.color-grid-header { font-size: 0.78em; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.02em; text-align: center; }
.color-grid-header span:first-child { text-align: left; }
.color-grid-row input[type="color"] {
  width: 100%; height: 34px; padding: 2px; cursor: pointer;
}
.bc-image-field { display: flex; flex-direction: column; gap: 0.5em; }
.bc-image-preview {
  height: 64px; display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px dashed var(--border); border-radius: var(--radius-sm);
  overflow: hidden;
}
.bc-image-preview img { max-height: 56px; max-width: 100%; object-fit: contain; }

/* ---------- Hero banner (dashboard) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 2.2em 2em;
  margin-bottom: 1.4em;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, black 45%));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.hero::after {
  content: ""; position: absolute; top: 50%; right: -70px;
  width: 440px; height: 440px; transform: translateY(-50%);
  border-radius: 50%; pointer-events: none;
  border: 1px solid rgba(255,255,255,0.18);
  box-shadow: 0 0 0 44px rgba(255,255,255,0.045) inset, 0 0 0 130px rgba(255,255,255,0.03) inset;
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg, transparent 0%, rgba(255,255,255,0.16) 48%, transparent 62%);
  transform: translateX(-130%);
  animation: hero-sheen 7s ease-in-out infinite;
}
@keyframes hero-sheen {
  0%, 55% { transform: translateX(-130%); }
  100% { transform: translateX(130%); }
}
@media (prefers-reduced-motion: reduce) { .hero::before { animation: none; } }
.hero-content { position: relative; z-index: 1; max-width: 640px; }
.hero-eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.72em; opacity: 0.85; margin: 0 0 0.35em; font-weight: 700; }
.hero-title { font-size: 1.9em; margin: 0 0 0.3em; font-weight: 800; }
.hero-sub { margin: 0 0 1.1em; opacity: 0.92; }
.hero-live-pill {
  display: inline-flex; align-items: center; gap: 0.55em;
  background: rgba(255,255,255,0.16); backdrop-filter: blur(4px);
  padding: 0.42em 0.95em; border-radius: 999px; font-size: 0.82em; font-weight: 600;
}
.hero-live-pill .dot { width: 0.6em; height: 0.6em; border-radius: 50%; background: #9aa3b2; flex: 0 0 auto; }
.hero-live-pill .dot.ok { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,0.35); }
.hero-live-pill .dot.warn { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245,158,11,0.35); }
.hero-live-pill .dot.down { background: #ef4444; box-shadow: 0 0 0 4px rgba(239,68,68,0.35); }
@media (max-width: 560px) {
  .hero { padding: 1.6em 1.3em; border-radius: 16px; }
  .hero-title { font-size: 1.4em; }
}

/* ---------- Stat cards (dashboard) ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1em; margin-bottom: 1.4em; }
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stat-grid { grid-template-columns: minmax(0, 1fr); } }
.stat-card {
  display: flex; gap: 0.9em; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.1em 1.2em; box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--border);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-left-color 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,0.16); }
.stat-card.ok { border-left-color: var(--success); }
.stat-card.warn { border-left-color: var(--warn); }
.stat-card.down { border-left-color: var(--danger); }
.stat-icon {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary);
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-body { min-width: 0; }
.stat-label { margin: 0; font-size: 0.75em; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.stat-value { margin: 0.15em 0 0; font-size: 1.5em; font-weight: 800; color: var(--text); line-height: 1.15; }
.stat-sub {
  margin: 0.2em 0 0; font-size: 0.78em; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Telemetria grezza (debug) ---------- */
.health-raw-details { margin-top: 0; margin-bottom: 1.4em; }
.health-raw-details summary { cursor: pointer; color: var(--text-dim); font-size: 0.82em; }
.health-raw-details pre {
  margin-top: 0.6em; max-height: 260px; overflow: auto;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.8em; font-size: 0.78em; font-family: "Consolas", "SF Mono", Menlo, monospace;
}

.toolbar { display: flex; gap: 0.5em; align-items: center; margin-bottom: 1.2em; flex-wrap: wrap; }
.toolbar input, .toolbar select { flex: 0 0 auto; }

textarea.code {
  width: 100%;
  min-height: 420px;
  font-family: "Consolas", "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  white-space: pre;
  tab-size: 2;
}

/* ---------- Esecuzione live ---------- */

/* Riquadri Step/Log sempre impilati verticalmente (Step sopra, Log sotto),
   a ogni larghezza di schermo — desktop, tablet, mobile (§10.1). */
.exec-layout { display: flex; flex-direction: column; gap: 1.2em; }

/* Esito PASS/FAIL grande e centrato in cima alla pagina (§10.1): visibile
   anche da lontano dall'operatore, colore riservato solo all'esito
   (principio "color reserved for status/deviation" delle linee guida
   High-Performance HMI / ISA-101, vedi README §10.1). */
.result-banner {
  text-align: center; padding: 0.7em 1em; margin-bottom: 1em;
  border-radius: var(--radius); font-weight: 800; letter-spacing: 0.03em;
  font-size: 2.4em; line-height: 1.15;
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
}
.result-banner.running { color: var(--primary); border-color: var(--primary); }
.result-banner.aborting {
  background: color-mix(in srgb, var(--warn) 14%, var(--panel));
  color: var(--warn); border-color: var(--warn);
}
.result-banner.pass {
  background: color-mix(in srgb, var(--success) 14%, var(--panel));
  color: var(--success); border-color: var(--success);
}
.result-banner.fail {
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  color: var(--danger); border-color: var(--danger);
}
@media (max-width: 560px) { .result-banner { font-size: 1.6em; padding: 0.55em; } }

/* Info di identificazione del run (test/PN/SN/orari), leggibili anche a
   distanza, sotto la scritta PASS/FAIL (§10.1). */
.run-info-bar {
  display: flex; flex-wrap: wrap; gap: 1.6em; justify-content: center;
  padding: 0.7em 1em; margin-bottom: 1.2em;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.run-info-item { display: flex; flex-direction: column; gap: 0.15em; text-align: center; min-width: 110px; }
.run-info-label { font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.run-info-value { font-size: 1.15em; font-weight: 700; font-family: monospace; }

.step-row {
  display: block; padding: 0.7em 0.6em;
  border-bottom: 1px solid var(--border); border-left: 3px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.step-row .step-main { display: flex; align-items: center; gap: 0.9em; }
.step-row:last-child { border-bottom: none; }
.step-row .step-icon { flex-shrink: 0; width: 22px; text-align: center; }
.step-row .step-text { flex: 1; min-width: 0; }
.step-row .name { display: block; }
.step-row .short-desc { display: block; color: var(--text-dim); font-size: 0.82em; margin-top: 0.1em; }
.step-row .value { font-family: monospace; font-weight: 600; white-space: nowrap; }
.step-row.pending { opacity: 0.55; }

/* Dettaglio "da report" sotto ogni step (§10.1): limiti/valore/esito in
   chiaro per gli step a limite singolo, maschera+traccia per gli step
   multi-punto. Vuoto per gli step senza limiti (bool, string, ecc). */
.step-detail:empty { display: none; }
.step-detail { margin: 0.6em 0 0.2em calc(22px + 0.9em); }
.limit-stats { display: flex; flex-wrap: wrap; gap: 1.4em; }
.limit-stat { display: flex; flex-direction: column; gap: 0.15em; }
.limit-label { font-size: 0.72em; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); }
.limit-value { font-family: monospace; font-weight: 700; font-size: 1.05em; }

.mask-chart {
  width: 100%; max-width: 640px; height: 140px; display: block;
  background: color-mix(in srgb, var(--bg) 92%, black 8%);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.chart-mask-line { fill: none; stroke: var(--warn); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: 0.85; }
.chart-trace { fill: none; stroke-width: 2; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 1.1em; margin-top: 0.4em; font-size: 0.78em; color: var(--text-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 0.4em; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend-swatch.mask { background: var(--warn); opacity: 0.85; }
.step-row.running { background: color-mix(in srgb, var(--primary) 8%, transparent); border-left-color: var(--primary); opacity: 1; }
.step-row.running .step-icon { color: var(--primary); }
.step-row.passed { border-left-color: var(--success); opacity: 1; }
.step-row.passed .value, .step-row.passed .step-icon { color: var(--success); }
.step-row.failed, .step-row.error { border-left-color: var(--danger); opacity: 1; }
.step-row.failed .value, .step-row.error .value, .step-row.failed .step-icon, .step-row.error .step-icon { color: var(--danger); }
.step-row.skipped, .step-row.aborted { border-left-color: var(--warn); opacity: 0.85; }
.step-row.skipped .step-icon, .step-row.aborted .step-icon { color: var(--warn); }
.step-row.done { border-left-color: var(--border); opacity: 1; }
.step-row.current-uut-marker { font-weight: 700; color: var(--primary); border-bottom: 1px solid var(--border); padding: 0.4em 0.6em; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-track {
  height: 8px; border-radius: 999px; background: var(--panel-2);
  overflow: hidden; border: 1px solid var(--border);
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease; border-radius: 999px;
}

.log-box {
  background: color-mix(in srgb, var(--bg) 92%, black 8%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8em;
  font-family: monospace;
  font-size: 0.8em;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ---------- Modal generico (popup che copre la pagina) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 1.2em;
}
.modal-dialog {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  padding: 1.4em; width: 100%; max-width: 560px; max-height: 90vh;
  overflow-y: auto;
}

/* ---------- User Message step (§7.15) ---------- */
.user-message-panel { border-top: 4px solid var(--primary); }
.user-message-panel h3 { margin-top: 0; }
.user-message-frame {
  width: 100%; min-height: 160px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: #fff;
  margin-bottom: 1em;
}
.user-message-buttons { display: flex; gap: 0.6em; flex-wrap: wrap; }
.user-message-buttons button { min-width: 90px; }

.notice { padding: 0.7em 0.9em; border-radius: var(--radius-sm); margin-bottom: 1.2em; font-size: 0.9em; }
.notice.ok { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.notice.error { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }

.hidden { display: none !important; }

/* ---------- Editor visuale delle sequenze (§10.1, §6.4c, §6.5) ---------- */
.step-builder-list { display: flex; flex-direction: column; gap: 0.4em; }
.step-builder-row {
  display: flex; align-items: center; gap: 0.6em 0.9em; flex-wrap: wrap;
  padding: 0.55em 0.8em;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.step-builder-type {
  flex-shrink: 0; font-size: 0.72em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent);
  padding: 0.25em 0.6em; border-radius: 999px; white-space: nowrap;
}
.step-builder-name { flex: 1; min-width: 160px; }
.step-builder-name .short-desc { display: block; color: var(--text-dim); font-size: 0.82em; margin-top: 0.1em; }
.step-builder-actions { display: flex; align-items: center; gap: 0.3em; flex-shrink: 0; margin-left: auto; }

.step-advanced { margin: 0.8em 0; }
.step-advanced summary { cursor: pointer; color: var(--text-dim); font-size: 0.85em; margin-bottom: 0.6em; }

/* ---------- Responsive: telefono/tablet ---------- */
@media (max-width: 800px) {
  #app-view { flex-direction: column; }
  #sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 0.5em;
    border-right: none;
    border-bottom: 1px solid var(--border);
    box-shadow: none;
    /* niente più stacking context qui sotto gli 800px (era position:relative
       + z-index:1, per far vedere l'ombra della sidebar sopra il contenuto a
       desktop): altrimenti #sidebar-panel qui sotto, pur essendo
       position:fixed con z-index alto, resterebbe "intrappolato" a competere
       solo con gli altri figli di #sidebar invece che con tutta la pagina,
       e il contenuto sotto (es. l'hero della Dashboard) lo attraverserebbe
       in trasparenza invece di restare coperto dal pannello. */
    position: static;
    z-index: auto;
  }
  #sidebar .brand { padding: 0 0.8em 0 0.2em; margin: 0; white-space: nowrap; border-bottom: none; flex: 1; }
  #sidebar .brand small { display: none; }
  #sidebar-toggle { display: inline-flex; order: -1; margin-right: 0.4em; }

  /* Sotto gli 800px la voce di menu non sta più nella barra in alto: il
     pulsante hamburger la apre come pannello sovrapposto alla pagina, con
     uno sfondo che la scurisce (stesso principio dei popup .modal-overlay),
     invece della fila orizzontale di pillole usata in precedenza. */
  #sidebar-panel {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 85vw;
    background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 90%, black 10%));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1001;
    padding: 1.2em 0.9em;
    display: flex; flex-direction: column;
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.35);
    overflow-y: auto;
  }
  #app-view.sidebar-open #sidebar-panel { transform: translateX(0); }
  #sidebar-panel .user-box { margin-top: auto; }

  #sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 1000;
  }
  #app-view.sidebar-open #sidebar-backdrop { display: block; }

  #content { padding: 1em; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}
