:root {
  color-scheme: dark;
  --bg: #070b15;
  --surface: #101728;
  --surface-2: #151e33;
  --surface-3: #1b2740;
  --text: #f4f7ff;
  --muted: #9ca9c1;
  --line: #2a3650;
  --accent: #73e6b1;
  --accent-strong: #2fcf8a;
  --warning: #f6c85f;
  --danger: #ff7272;
  --info: #79b8ff;
  --red: #b9364c;
  --black: #171d2b;
  --green: #167c58;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(47, 207, 138, 0.12), transparent 32rem),
    radial-gradient(circle at top left, rgba(121, 184, 255, 0.10), transparent 26rem),
    var(--bg);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }
button { touch-action: manipulation; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  background: rgba(7, 11, 21, 0.88);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.15rem; font-size: clamp(1.45rem, 4vw, 2.15rem); }
h2 { margin-bottom: 0.35rem; }
h3 { margin-bottom: 0.4rem; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.92rem; }
.eyebrow { margin: 0 0 0.25rem; color: var(--accent); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.label { display: block; margin: 0 0 0.35rem; color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }

.header-actions, .button-row, .play-tools, .action-topline, .history-heading, .log-heading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.page-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.2rem auto 3rem;
}

.action-panel, .panel, .metric-card {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, rgba(21, 30, 51, 0.98), rgba(12, 18, 32, 0.98));
  box-shadow: var(--shadow);
}

.action-panel {
  padding: clamp(1rem, 3vw, 1.6rem);
  border-radius: 1.35rem;
  overflow: hidden;
}

.action-main {
  display: grid;
  grid-template-columns: minmax(105px, 150px) 1fr;
  gap: 1.25rem;
  align-items: center;
  margin-top: 0.9rem;
}

.target-number {
  display: grid;
  place-items: center;
  width: clamp(90px, 20vw, 130px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #334664, #111827 58%, #070b15 100%);
  border: 3px solid var(--accent);
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 0 0 7px rgba(115, 230, 177, 0.08);
}

.action-copy h2 { font-size: clamp(1.2rem, 3vw, 1.85rem); }
.action-copy p { color: var(--muted); margin-bottom: 0.75rem; }

.phase-badge, .trigger-badge, .status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.06em;
}
.phase-badge { background: rgba(121, 184, 255, 0.14); color: #b9dbff; border: 1px solid rgba(121, 184, 255, 0.35); }
.phase-badge.attack { background: rgba(115, 230, 177, 0.14); color: var(--accent); border-color: rgba(115, 230, 177, 0.38); }
.phase-badge.limit { background: rgba(255, 114, 114, 0.14); color: #ffadad; border-color: rgba(255, 114, 114, 0.38); }
.trigger-badge { background: rgba(246, 200, 95, 0.14); color: var(--warning); border: 1px solid rgba(246, 200, 95, 0.35); }
.status-pill { background: rgba(115, 230, 177, 0.10); color: var(--accent); }
.status-pill.offline { background: rgba(246, 200, 95, 0.10); color: var(--warning); }

.cinquina-wrap { margin-top: 0.7rem; }
.cinquina, .history-chips { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.number-chip {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  font-weight: 800;
}
.number-chip.leader { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(115, 230, 177, 0.09); }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0.9rem 0;
}
.metric-card {
  min-height: 112px;
  padding: 0.9rem;
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.metric-card.emphasis { border-color: rgba(115, 230, 177, 0.55); }
.metric-card.debt { border-color: rgba(246, 200, 95, 0.35); }
.metric-label { color: var(--muted); font-size: 0.76rem; font-weight: 700; }
.metric-card strong { margin: 0.2rem 0 0.2rem; font-size: clamp(1.2rem, 2.4vw, 1.65rem); }
.metric-card small { color: var(--muted); line-height: 1.25; }
.positive { color: var(--accent) !important; }
.negative { color: var(--danger) !important; }

.panel {
  margin-top: 0.9rem;
  border-radius: 1.15rem;
  overflow: hidden;
}
.panel-heading, .details-body { padding: 1rem; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.panel-heading h2 { margin: 0; }

summary {
  padding: 1rem;
  cursor: pointer;
  font-weight: 850;
  list-style: none;
  user-select: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: '＋'; float: right; color: var(--accent); }
details[open] > summary::after { content: '−'; }
details[open] > summary { border-bottom: 1px solid var(--line); }

.hint { color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

.number-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(42px, 1fr));
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}
.number-button {
  min-height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 0.75rem;
  color: white;
  font-weight: 900;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease;
}
.number-button:hover { filter: brightness(1.15); border-color: white; }
.number-button:active { transform: scale(0.95); }
.number-button.red { background: linear-gradient(145deg, #c54058, #812638); }
.number-button.black { background: linear-gradient(145deg, #30394c, #101621); }
.number-button.green { background: linear-gradient(145deg, #1d9a70, #0b533b); }

.history-block { padding: 0 1rem 1rem; }
.history-heading { justify-content: space-between; }
.history-heading h3 { margin: 0; }
.history-heading span { color: var(--muted); font-size: 0.8rem; }
.history-chips { margin-top: 0.75rem; }
.history-chips .number-chip { min-width: 31px; height: 31px; font-size: 0.84rem; }

.button {
  min-height: 40px;
  padding: 0.62rem 0.86rem;
  border-radius: 0.72rem;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
}
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button.primary { color: #04140d; background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.secondary { color: var(--text); background: var(--surface-3); border-color: var(--line); }
.button.ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button.danger { color: #ffdede; background: rgba(255, 114, 114, 0.13); border-color: rgba(255, 114, 114, 0.35); }
.button-row.compact .button { min-height: 34px; padding: 0.45rem 0.65rem; font-size: 0.85rem; }

.switch-label, .checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.switch-label input:checked + span { color: var(--warning); font-weight: 800; }

.import-layout { display: grid; grid-template-columns: 1.45fr 1fr; gap: 1rem; }
.import-form { min-width: 0; }
.form-row, .settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 0.8rem 0;
}
.settings-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.full-width { grid-column: 1 / -1; }

label { display: grid; gap: 0.38rem; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
input, textarea, select {
  width: 100%;
  color: var(--text);
  background: #090f1d;
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  padding: 0.72rem 0.78rem;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(115, 230, 177, 0.10); }
textarea { resize: vertical; line-height: 1.5; }


.diagnostic-summary {
  padding: 0.8rem;
  border-radius: 0.8rem;
  background: rgba(121, 184, 255, 0.08);
  border: 1px solid rgba(121, 184, 255, 0.20);
  color: #cfe7ff;
  margin-bottom: 0.8rem;
  line-height: 1.45;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 0.62rem; border-bottom: 1px solid var(--line); text-align: right; font-size: 0.85rem; }
th { color: var(--muted); font-size: 0.74rem; text-transform: uppercase; }
th:nth-child(2), td:nth-child(2), th:last-child, td:last-child { text-align: left; }
tr.top-five { background: rgba(115, 230, 177, 0.06); }
tr.leader-row { background: rgba(115, 230, 177, 0.13); }

.file-button { display: inline-flex; width: auto; }
.log-heading { justify-content: space-between; margin-top: 1rem; }
.log-heading h3 { margin: 0; }
.event-log { display: grid; gap: 0.55rem; margin-top: 0.7rem; max-height: 420px; overflow: auto; }
.log-entry { padding: 0.7rem; border-radius: 0.72rem; background: #0a1120; border: 1px solid var(--line); }
.log-entry strong { display: block; margin-bottom: 0.2rem; font-size: 0.8rem; color: var(--accent); }
.log-entry p { margin: 0; color: #dbe4f4; font-size: 0.86rem; line-height: 1.35; }
.log-entry time { display: block; color: var(--muted); font-size: 0.72rem; margin-top: 0.25rem; }
.empty { color: var(--muted); }

footer { width: min(1180px, calc(100% - 2rem)); margin: 0 auto 2rem; color: var(--muted); font-size: 0.8rem; text-align: center; }
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%);
  width: min(92vw, 540px);
  padding: 0.85rem 1rem;
  border-radius: 0.85rem;
  background: #edf9f3;
  color: #092015;
  box-shadow: var(--shadow);
  font-weight: 750;
  text-align: center;
}

@media (max-width: 980px) {
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .number-grid { grid-template-columns: repeat(8, minmax(42px, 1fr)); }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .app-header { align-items: flex-start; }
  .subtitle { display: none; }
  .page-shell { width: min(100% - 1rem, 1180px); margin-top: 0.6rem; }
  .action-main { grid-template-columns: 95px 1fr; gap: 0.9rem; }
  .target-number { width: 88px; font-size: 2.8rem; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.55rem; }
  .metric-card { min-height: 98px; padding: 0.72rem; }
  .number-grid { grid-template-columns: repeat(6, minmax(42px, 1fr)); gap: 0.42rem; }
  .number-button { min-height: 48px; }
  .import-layout, .form-row, .settings-grid { grid-template-columns: 1fr; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .play-tools { width: 100%; justify-content: space-between; }
}

@media (max-width: 390px) {
  .number-grid { grid-template-columns: repeat(5, minmax(42px, 1fr)); }
  .action-main { grid-template-columns: 1fr; }
  .target-number { width: 82px; }
}
.last-outcome {
  display: inline-block;
  margin: 0 0 0.65rem !important;
  padding: 0.45rem 0.65rem;
  border-radius: 0.65rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: #dbe4f4 !important;
  font-size: 0.84rem;
}
.toast.error { background: #ffe7e7; color: #4c1111; }

/* C5 Echo Multi v2 */
:root {
  --rapid: #ff9d55;
  --rapid-soft: rgba(255, 157, 85, 0.12);
  --violet: #a996ff;
}

.metric-card.emphasis-alt { border-color: rgba(169, 150, 255, 0.48); }
.action-panel.rapid-active {
  border-color: rgba(255, 157, 85, 0.72);
  box-shadow: 0 18px 55px rgba(255, 106, 45, 0.16);
}
.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #ffd5ba;
  background: rgba(255, 119, 58, 0.16);
  border: 1px solid rgba(255, 157, 85, 0.5);
}
.strategy-badge {
  color: #dfe6f5;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}
.target-block { display: grid; justify-items: center; gap: 0.45rem; }
.active-table-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}
.mother-five {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.45rem;
}
.mother-five::before {
  content: 'Cinquina madre:';
  color: var(--muted);
  font-size: 0.8rem;
  align-self: center;
  margin-right: 0.2rem;
}
.reentry-banner {
  margin-top: 0.7rem;
  padding: 0.65rem 0.75rem;
  border-radius: 0.75rem;
  color: #fff0c8;
  background: rgba(246, 200, 95, 0.09);
  border: 1px solid rgba(246, 200, 95, 0.28);
  font-size: 0.85rem;
}
.scanner-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 0.7rem;
  width: min(760px, 100%);
}
.compact-check { align-content: end; padding-bottom: 0.7rem; }
.rapid-warning {
  margin: 0 1rem 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: 0.8rem;
  color: #ffe0c9;
  background: var(--rapid-soft);
  border: 1px solid rgba(255, 157, 85, 0.4);
}
.table-tabs {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  padding: 0 1rem 0.8rem;
}
.table-tab {
  min-width: 105px;
  min-height: 43px;
  padding: 0.55rem 0.8rem;
  border-radius: 0.8rem;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0b1221;
  cursor: pointer;
  font-weight: 850;
}
.table-tab.selected {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(115, 230, 177, 0.08);
}
.table-tab.active-attack { color: var(--accent); }
.table-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  padding: 0 1rem 1rem;
}
.table-card {
  min-width: 0;
  padding: 0.85rem;
  border-radius: 0.9rem;
  border: 1px solid var(--line);
  background: rgba(7, 13, 24, 0.72);
}
.table-card.selected { border-color: rgba(115, 230, 177, 0.45); }
.table-card.active { background: rgba(115, 230, 177, 0.07); }
.table-card h3 { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.55rem; }
.table-card h3 span { color: var(--muted); font-size: 0.75rem; }
.table-status-line { display: flex; justify-content: space-between; gap: 0.5rem; margin: 0.32rem 0; font-size: 0.8rem; }
.table-status-line span:first-child { color: var(--muted); }
.table-status-value { font-weight: 850; text-align: right; }
.table-status-value.good { color: var(--accent); }
.table-status-value.rapid { color: var(--rapid); }
.strategy-description {
  padding: 0.8rem;
  border-radius: 0.8rem;
  background: rgba(169, 150, 255, 0.08);
  border: 1px solid rgba(169, 150, 255, 0.22);
  color: #ddd7ff;
  line-height: 1.45;
}
.progression-table-wrap { max-height: 520px; overflow: auto; }
.progression-table-wrap table { min-width: 780px; }
.progression-table-wrap tr.current-row { background: rgba(115, 230, 177, 0.14); }
.progression-table-wrap tr.reentry-row { background: rgba(246, 200, 95, 0.12); }

@media (max-width: 980px) {
  .table-cards { grid-template-columns: 1fr; }
  .scanner-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagnostic-columns { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .scanner-controls { grid-template-columns: 1fr; width: 100%; }
  .compact-check { padding-bottom: 0; }
  .table-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .table-tab { flex: 0 0 auto; }
}

/* C5 Echo Multi v2 */
.metrics-grid { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
.five-layout { grid-template-columns: minmax(320px, 0.95fr) 1.35fr; }
.five-target-block { display: grid; align-content: center; gap: 0.5rem; }
.active-five {
  display: grid;
  grid-template-columns: repeat(5, minmax(50px, 1fr));
  gap: 0.45rem;
  width: min(100%, 500px);
}
.active-five .number-chip {
  width: 100%;
  min-width: 0;
  height: 68px;
  border-radius: 0.9rem;
  font-size: 1.45rem;
}
.empty-five {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 68px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 0.9rem;
}
.number-button.active-target {
  box-shadow: 0 0 0 3px rgba(255, 211, 106, 0.88), 0 0 22px rgba(255, 211, 106, 0.26);
  border-color: #fff0b1;
  filter: brightness(1.18);
}
.panel-foot-hint { padding: 0 1rem 1rem; margin: 0; }

@media (max-width: 700px) {
  .five-layout { grid-template-columns: 1fr; }
  .active-five { width: 100%; }
  .active-five .number-chip { height: 58px; font-size: 1.2rem; }
}

@media (max-width: 390px) {
  .active-five { grid-template-columns: repeat(5, minmax(42px, 1fr)); gap: 0.3rem; }
  .active-five .number-chip { height: 52px; padding: 0; }
}
.number-chip.red { background: linear-gradient(145deg, #b9364c, #7c2435); border-color: rgba(255,255,255,0.2); }
.number-chip.black { background: linear-gradient(145deg, #30394c, #101621); border-color: rgba(255,255,255,0.16); }
.number-chip.green { background: linear-gradient(145deg, #1d9a70, #0b533b); border-color: rgba(255,255,255,0.2); }

@media (max-width: 980px) {
  .table-cards,   .scanner-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

@media (max-width: 700px) {
  .scanner-controls { grid-template-columns: 1fr; width: 100%; }
  .compact-check { padding-bottom: 0; }
  .table-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .table-tab { flex: 0 0 auto; }
}

.stable-note {
  margin: 0 0 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(84, 195, 255, 0.28);
  border-radius: 14px;
  background: rgba(14, 42, 65, 0.72);
  color: var(--muted, #b7c9d9);
  line-height: 1.5;
}

.stable-note strong {
  color: var(--text, #f5fbff);
}

.resume-section .diagnostic-summary {
  min-height: 3.2rem;
  display: flex;
  align-items: center;
}

@media (max-width: 700px) {
  .stable-note {
    font-size: 0.92rem;
  }
}

.history-heading > div { min-width: 0; }
.history-heading small {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.history-chips { max-height: 360px; }

/* Copertura adattiva v4 */
.coverage-decision {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  padding: 0.38rem 0.7rem;
  border: 1px solid rgba(255, 211, 106, 0.35);
  border-radius: 999px;
  background: rgba(65, 46, 12, 0.52);
  color: #ffe9a8;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.25;
}

.active-five .number-chip.selected-coverage {
  opacity: 1;
  transform: translateY(-2px);
  border-color: #fff0b1;
  box-shadow: 0 0 0 3px rgba(255, 211, 106, 0.72), 0 0 22px rgba(255, 211, 106, 0.24);
  filter: brightness(1.16);
}

.active-five .number-chip.excluded-coverage {
  opacity: 0.36;
  filter: saturate(0.42) brightness(0.72);
  box-shadow: none;
}

.active-five .number-chip.leader.selected-coverage {
  box-shadow: 0 0 0 3px rgba(115, 230, 177, 0.82), 0 0 24px rgba(115, 230, 177, 0.24);
  border-color: #baf9da;
}

.coverage-card strong {
  color: #ffe9a8;
}

/* C5 Echo Multi v5 — opzioni dinamiche e anticipate */
.trigger-badge.rapid {
  background: rgba(255, 126, 95, 0.16);
  color: #ffc0ae;
  border-color: rgba(255, 126, 95, 0.48);
}
.trigger-badge.dynamic {
  outline: 2px solid rgba(84, 195, 255, 0.42);
  outline-offset: 2px;
}
.table-status-value.risk { color: #ffc0ae; }
.rapid-line {
  padding-top: 0.38rem;
  margin-top: 0.42rem;
  border-top: 1px dashed rgba(255, 126, 95, 0.25);
}
.feature-switch {
  min-height: 74px;
  align-items: flex-start;
  padding: 0.75rem;
  border: 1px solid rgba(84, 195, 255, 0.24);
  border-radius: 0.8rem;
  background: rgba(14, 42, 65, 0.55);
}
.feature-switch > span {
  display: grid;
  gap: 0.22rem;
}
.feature-switch small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}
.risk-switch {
  border-color: rgba(255, 126, 95, 0.32);
  background: rgba(72, 27, 22, 0.42);
}
.warning-description {
  border-color: rgba(246, 200, 95, 0.28);
  background: rgba(72, 52, 15, 0.34);
  color: #ffe9a8;
}

/* Colore iniziale e colori dopo i cambi dinamici. */
.number-button.active-target.target-theme-0,
.active-five .number-chip.selected-coverage.target-theme-0 {
  box-shadow: 0 0 0 3px rgba(255, 211, 106, 0.88), 0 0 22px rgba(255, 211, 106, 0.28);
  border-color: #fff0b1;
}
.number-button.active-target.target-theme-1,
.active-five .number-chip.selected-coverage.target-theme-1 {
  box-shadow: 0 0 0 3px rgba(84, 195, 255, 0.9), 0 0 24px rgba(84, 195, 255, 0.3);
  border-color: #b9ecff;
}
.number-button.active-target.target-theme-2,
.active-five .number-chip.selected-coverage.target-theme-2 {
  box-shadow: 0 0 0 3px rgba(215, 132, 255, 0.9), 0 0 24px rgba(215, 132, 255, 0.3);
  border-color: #edc5ff;
}
.number-button.active-target.target-theme-3,
.active-five .number-chip.selected-coverage.target-theme-3 {
  box-shadow: 0 0 0 3px rgba(115, 230, 177, 0.9), 0 0 24px rgba(115, 230, 177, 0.3);
  border-color: #baf9da;
}

@media (max-width: 760px) {
  .feature-switch { grid-column: 1 / -1; }
}

/* v5.1.0: importazione senza supporto fotografico */
.import-layout-single { grid-template-columns: minmax(0, 1fr); }

/* v5.2.2 — calibrazione soft, contabilità non distruttiva e banner compatto */
.calibration-keyboard-message {
  margin: 0 1rem 0.8rem;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(84, 195, 255, 0.34);
  border-radius: 0.9rem;
  background: rgba(14, 42, 65, 0.74);
  color: #d9efff;
  font-weight: 850;
  line-height: 1.4;
  text-align: center;
}
.calibration-keyboard-message.extension {
  border-color: rgba(246, 200, 95, 0.48);
  background: rgba(72, 52, 15, 0.52);
  color: #ffe9a8;
}
.calibration-keyboard-message.passed,
.calibration-keyboard-message.ready,
.calibration-keyboard-message.legacy {
  border-color: rgba(115, 230, 177, 0.55);
  background: rgba(12, 76, 51, 0.55);
  color: #c8ffe4;
}
.calibration-keyboard-message.failed {
  border-color: rgba(255, 94, 94, 0.72);
  background: rgba(61, 7, 12, 0.82);
  color: #ffd2d2;
}
.phase-badge.calibration-running,
.phase-badge.calibration-extension {
  background: rgba(246, 200, 95, 0.16);
  color: #ffe9a8;
  border-color: rgba(246, 200, 95, 0.42);
}
.phase-badge.calibration-failed {
  background: rgba(255, 94, 94, 0.16);
  color: #ffd2d2;
  border-color: rgba(255, 94, 94, 0.48);
}
.number-grid.calibration-running .number-button,
.number-grid.calibration-extension .number-button {
  filter: saturate(0.45) brightness(0.72);
  border-color: rgba(246, 200, 95, 0.32);
  box-shadow: inset 0 0 0 1px rgba(246, 200, 95, 0.08);
}
.number-grid.calibration-passed .number-button {
  background: linear-gradient(145deg, #32b77f, #116542) !important;
  border-color: #baf9da;
  box-shadow: 0 0 0 2px rgba(115, 230, 177, 0.45), 0 0 14px rgba(115, 230, 177, 0.18);
  filter: brightness(1.08);
}
.number-grid.calibration-failed .number-button {
  background: linear-gradient(145deg, #351015, #0b0708) !important;
  border-color: rgba(255, 94, 94, 0.72);
  color: #ffb8b8;
  box-shadow: inset 0 0 0 1px rgba(255, 94, 94, 0.12);
  filter: saturate(0.5) brightness(0.72);
}
.number-grid.calibration-passed .number-button.active-target,
.number-grid.calibration-ready .number-button.active-target,
.number-grid.calibration-legacy .number-button.active-target {
  filter: brightness(1.22);
}
.table-tab.calibration-running,
.table-tab.calibration-extension,
.table-card.calibration-running,
.table-card.calibration-extension {
  border-color: rgba(246, 200, 95, 0.42);
}
.table-tab.calibration-failed,
.table-card.calibration-failed {
  border-color: rgba(255, 94, 94, 0.58);
  background: rgba(45, 10, 14, 0.58);
}


/* Dopo tre nuovi esiti dalla calibrazione, il messaggio lungo diventa discreto. */
.calibration-keyboard-message.compact {
  margin-bottom: 0.55rem;
  padding: 0.42rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  letter-spacing: 0.09em;
  line-height: 1.15;
  opacity: 0.82;
}


/* v5.2.3 — calibrazione ignorabile senza perdita di memoria */
.calibration-control-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: -0.2rem 1rem 0.9rem;
}
.calibration-control-row small {
  max-width: 42rem;
  color: var(--muted, #9eb3c7);
  line-height: 1.35;
}
.calibration-bypass-button {
  border-color: rgba(246, 200, 95, 0.52);
  background: rgba(72, 52, 15, 0.58);
  color: #ffe9a8;
  font-weight: 800;
}
.calibration-bypass-button:hover,
.calibration-bypass-button:focus-visible {
  border-color: rgba(255, 224, 139, 0.88);
  background: rgba(94, 68, 20, 0.78);
}
.calibration-keyboard-message.bypassed {
  border-color: rgba(143, 177, 255, 0.48);
  background: rgba(25, 46, 88, 0.58);
  color: #dbe6ff;
}
.number-grid.calibration-bypassed .number-button.active-target {
  filter: brightness(1.2);
}
@media (max-width: 680px) {
  .calibration-control-row {
    align-items: stretch;
    flex-direction: column;
    text-align: center;
  }
  .calibration-bypass-button { width: 100%; }
}

/* v5.4.0 — semaforo live del C5 e trigger indipendenti */
:root {
  --signal-high: #67f0a7;
  --signal-medium: #ffd45f;
  --signal-low: #ff765f;
  --trigger-markov: #4db7ff;
  --trigger-sector: #ff5fd2;
  --trigger-fusion: #a77bff;
}

.signal-assessment-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.045em;
  white-space: nowrap;
}
.signal-assessment-badge.signal-high,
.trigger-badge.signal-high {
  color: #bfffdc;
  background: rgba(56, 190, 120, 0.18);
  border-color: rgba(103, 240, 167, 0.58);
}
.signal-assessment-badge.signal-medium,
.trigger-badge.signal-medium {
  color: #fff0a9;
  background: rgba(203, 157, 27, 0.18);
  border-color: rgba(255, 212, 95, 0.58);
}
.signal-assessment-badge.signal-low,
.trigger-badge.signal-low {
  color: #ffd0c8;
  background: rgba(210, 67, 48, 0.2);
  border-color: rgba(255, 118, 95, 0.64);
}

.keyboard-status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 0.9fr);
  gap: 0.75rem;
  align-items: stretch;
  margin: 0 1rem 0.8rem;
}
.keyboard-status-row .calibration-keyboard-message {
  margin: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
}
.live-signal-monitor {
  display: grid;
  align-content: center;
  gap: 0.24rem;
  min-height: 58px;
  padding: 0.72rem 0.9rem;
  border-radius: 0.9rem;
  border: 1px solid var(--line);
  background: rgba(10, 18, 32, 0.86);
  line-height: 1.3;
}
.live-signal-monitor strong { font-size: 0.78rem; letter-spacing: 0.045em; }
.live-signal-monitor small { color: var(--muted); font-size: 0.74rem; }
.live-signal-monitor.signal-high {
  border-color: rgba(103, 240, 167, 0.58);
  background: rgba(12, 70, 43, 0.55);
  color: #c8ffe1;
}
.live-signal-monitor.signal-medium {
  border-color: rgba(255, 212, 95, 0.58);
  background: rgba(77, 57, 12, 0.58);
  color: #fff0a9;
}
.live-signal-monitor.signal-low {
  border-color: rgba(255, 118, 95, 0.62);
  background: rgba(76, 25, 20, 0.62);
  color: #ffd0c8;
}

/* Il colore dinamico resta come bordo interno; il semaforo è l'anello esterno. */
.target-theme-0 { --revision-color: rgba(255, 211, 106, 0.9); }
.target-theme-1 { --revision-color: rgba(84, 195, 255, 0.92); }
.target-theme-2 { --revision-color: rgba(215, 132, 255, 0.92); }
.target-theme-3 { --revision-color: rgba(115, 230, 177, 0.92); }
.number-button.active-target.signal-confidence-high,
.active-five .number-chip.selected-coverage.signal-confidence-high {
  outline: 3px solid var(--signal-high);
  outline-offset: 2px;
  border-color: #c6ffe0;
  box-shadow: 0 0 24px rgba(103, 240, 167, 0.56), inset 0 0 0 2px var(--revision-color, rgba(255,255,255,0.45));
  filter: brightness(1.2);
}
.number-button.active-target.signal-confidence-medium,
.active-five .number-chip.selected-coverage.signal-confidence-medium {
  outline: 3px solid var(--signal-medium);
  outline-offset: 2px;
  border-color: #fff0a9;
  box-shadow: 0 0 23px rgba(255, 212, 95, 0.5), inset 0 0 0 2px var(--revision-color, rgba(255,255,255,0.45));
  filter: brightness(1.18);
}
.number-button.active-target.signal-confidence-low,
.active-five .number-chip.selected-coverage.signal-confidence-low {
  outline: 3px solid var(--signal-low);
  outline-offset: 2px;
  border-color: #ffd0c8;
  box-shadow: 0 0 23px rgba(255, 86, 62, 0.52), inset 0 0 0 2px var(--revision-color, rgba(255,255,255,0.45));
  filter: brightness(1.18);
}

.number-button {
  position: relative;
  isolation: isolate;
}
.number-button-label { position: relative; z-index: 2; }
.number-signal-dots {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 7px;
  pointer-events: none;
}
.number-signal-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 7px currentColor;
}
.number-signal-dot.markov { color: var(--trigger-markov); background: var(--trigger-markov); }
.number-signal-dot.sector { color: var(--trigger-sector); background: var(--trigger-sector); }
.number-signal-dot.fusion { color: var(--trigger-fusion); background: var(--trigger-fusion); }
.number-button.experimental-target:not(.active-target) { filter: brightness(1.12); }
.number-button.experimental-markov-target:not(.active-target) {
  outline: 2px solid rgba(77, 183, 255, 0.82);
  outline-offset: 1px;
  box-shadow: 0 0 15px rgba(77, 183, 255, 0.28);
}
.number-button.experimental-sector-target:not(.active-target) {
  outline: 2px solid rgba(255, 95, 210, 0.82);
  outline-offset: 1px;
  box-shadow: 0 0 15px rgba(255, 95, 210, 0.28);
}
.number-button.experimental-fusion-target:not(.active-target) {
  outline: 2px solid rgba(167, 123, 255, 0.88);
  outline-offset: 1px;
  box-shadow: 0 0 17px rgba(167, 123, 255, 0.34);
}

.experimental-panel { border-color: rgba(133, 119, 255, 0.3); }
.experimental-toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}
.experimental-switch.markov-switch { border-color: rgba(77, 183, 255, 0.42); background: rgba(15, 54, 82, 0.48); }
.experimental-switch.sector-switch { border-color: rgba(255, 95, 210, 0.4); background: rgba(75, 17, 59, 0.42); }
.experimental-switch.fusion-switch { border-color: rgba(167, 123, 255, 0.42); background: rgba(49, 30, 91, 0.45); }
.accounting-source-box {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.85rem;
  padding: 0.9rem;
  border: 1px solid rgba(94, 220, 176, 0.34);
  border-radius: 0.9rem;
  background: rgba(8, 28, 31, 0.58);
}
.accounting-source-box > div:first-child {
  display: grid;
  gap: 0.25rem;
}
.accounting-source-box small { color: var(--muted); line-height: 1.4; }
.accounting-source-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}
.accounting-source-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: rgba(9, 17, 29, 0.86);
  color: #dce8f8;
  font-weight: 900;
  cursor: pointer;
}
.accounting-source-button:disabled { opacity: 0.38; cursor: not-allowed; }
.accounting-source-button.active {
  border-color: #66e7b2;
  box-shadow: 0 0 0 2px rgba(102, 231, 178, 0.18), 0 0 18px rgba(102, 231, 178, 0.22);
  color: #dffff2;
}
.accounting-source-button.pending { border-style: dashed; animation: accounting-pulse 1.2s ease-in-out infinite alternate; }
.accounting-source-button.markov.active { border-color: var(--trigger-markov); box-shadow: 0 0 0 2px rgba(77,183,255,.18), 0 0 18px rgba(77,183,255,.28); }
.accounting-source-button.sector.active { border-color: var(--trigger-sector); box-shadow: 0 0 0 2px rgba(255,95,210,.18), 0 0 18px rgba(255,95,210,.28); }
.accounting-source-button.fusion.active { border-color: var(--trigger-fusion); box-shadow: 0 0 0 2px rgba(167,123,255,.2), 0 0 18px rgba(167,123,255,.3); }
.accounting-source-status {
  margin: 0;
  padding: 0.62rem 0.72rem;
  border-radius: 0.7rem;
  background: rgba(255,255,255,0.055);
  color: #dff8ed;
  font-size: 0.8rem;
  font-weight: 850;
  line-height: 1.4;
}
@keyframes accounting-pulse { from { opacity: .62; } to { opacity: 1; } }
.experimental-note {
  margin: 0.85rem 0;
  padding: 0.78rem 0.9rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(246, 200, 95, 0.3);
  background: rgba(65, 47, 13, 0.35);
  color: #ffeab0;
  font-size: 0.82rem;
  line-height: 1.45;
}
.experimental-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}
.experimental-card {
  min-width: 0;
  padding: 0.8rem;
  border-radius: 0.9rem;
  border: 1px solid var(--line);
  background: rgba(8, 15, 27, 0.78);
}
.experimental-card.disabled { opacity: 0.58; }
.experimental-card.accounting-real { outline: 2px solid rgba(102, 231, 178, 0.55); outline-offset: 2px; }
.experimental-card.markov.enabled { border-color: rgba(77, 183, 255, 0.55); box-shadow: inset 0 0 20px rgba(77, 183, 255, 0.06); }
.experimental-card.sector.enabled { border-color: rgba(255, 95, 210, 0.5); box-shadow: inset 0 0 20px rgba(255, 95, 210, 0.06); }
.experimental-card.fusion.enabled { border-color: rgba(167, 123, 255, 0.55); box-shadow: inset 0 0 20px rgba(167, 123, 255, 0.07); }
.experimental-card-title {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.82rem;
}
.experimental-card-title span {
  padding: 0.2rem 0.42rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 900;
}
.experimental-card-status {
  min-height: 2.8em;
  margin: 0.55rem 0;
  color: #dce8f8;
  font-size: 0.78rem;
  line-height: 1.4;
}
.experimental-number-row { display: flex; flex-wrap: wrap; gap: 0.3rem; min-height: 34px; }
.number-chip.experimental-chip.markov { border-color: var(--trigger-markov); box-shadow: 0 0 11px rgba(77, 183, 255, 0.28); }
.number-chip.experimental-chip.sector { border-color: var(--trigger-sector); box-shadow: 0 0 11px rgba(255, 95, 210, 0.28); }
.number-chip.experimental-chip.fusion { border-color: var(--trigger-fusion); box-shadow: 0 0 11px rgba(167, 123, 255, 0.3); }
.experimental-card-metrics { display: block; margin-top: 0.55rem; color: var(--muted); line-height: 1.4; }
.accounting-card-button { width: 100%; margin-top: 0.65rem; font-size: 0.72rem; }
.accounting-card-button.markov { border-color: rgba(77, 183, 255, 0.48); }
.accounting-card-button.sector { border-color: rgba(255, 95, 210, 0.45); }
.accounting-card-button.fusion { border-color: rgba(167, 123, 255, 0.5); }

.trigger-badge.experimental-markov { border-color: var(--trigger-markov); color: #bdeaff; }
.trigger-badge.experimental-sector { border-color: var(--trigger-sector); color: #ffd0f3; }
.trigger-badge.experimental-fusion { border-color: var(--trigger-fusion); color: #e1d3ff; }

@media (max-width: 900px) {
  .experimental-toggle-grid, .experimental-cards { grid-template-columns: 1fr; }
  .accounting-source-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keyboard-status-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .signal-assessment-badge { white-space: normal; text-align: center; }
  .live-signal-monitor strong { font-size: 0.72rem; }
  .number-signal-dot { width: 6px; height: 6px; }
  .accounting-source-buttons { grid-template-columns: 1fr; }
}
.signal-legend {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin: -0.25rem 1rem 0.8rem;
  color: var(--muted);
  font-size: 0.72rem;
}
.signal-legend > span {
  padding: 0.22rem 0.48rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-weight: 850;
}
.signal-legend .high { color: var(--signal-high); }
.signal-legend .medium { color: var(--signal-medium); }
.signal-legend .low { color: var(--signal-low); }
.signal-legend small { flex: 1 1 280px; line-height: 1.35; }
.table-status-line.experimental-line {
  padding-top: 0.38rem;
  margin-top: 0.42rem;
  border-top: 1px dashed rgba(167, 123, 255, 0.26);
}
.table-status-line.experimental-line > span:first-child { color: #cdbbff; }
