/* ==========================================================================
   Open-ECG-Digitizer Studio — Style Design System
   Vanilla CSS con Estetica Clinica Moderna, Glassmorphism e Dark Mode
   ========================================================================== */

:root {
  /* Tavolozza Colori Primari (Dark Mode) */
  --bg-base: #0a0d14;
  --bg-surface-1: #111726;
  --bg-surface-2: #182032;
  --bg-surface-3: #222d46;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(6, 182, 212, 0.4);

  /* Accenti e Indicatori */
  --accent-primary: #06b6d4;     /* Ciano clinico */
  --accent-glow: rgba(6, 182, 212, 0.25);
  --accent-hover: #0891b2;
  --color-emerald: #10b981;
  --color-amber: #f59e0b;
  --color-rose: #f43f5e;
  --color-violet: #a855f7;

  /* Testi */
  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Punti Angolari Specifici */
  --point-tl: #10b981; /* Verde */
  --point-tr: #06b6d4; /* Ciano */
  --point-br: #a855f7; /* Viola */
  --point-bl: #f59e0b; /* Ambra */

  /* Carta ECG Tradizionale */
  --ecg-paper-pink: #fdf2f0;
  --ecg-grid-small: #f8b4ab;
  --ecg-grid-large: #e57373;
  --ecg-trace-dark: #1e1b4b;

  /* Carta ECG Dark Neon */
  --ecg-paper-dark: #090c15;
  --ecg-grid-dark-sm: rgba(6, 182, 212, 0.08);
  --ecg-grid-dark-lg: rgba(6, 182, 212, 0.22);
  --ecg-trace-neon: #38bdf8;

  /* Geometria e Raggi */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  /* Transizioni ed Effetti */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-subtle);
  --shadow-glow: 0 0 25px var(--accent-glow);
}

/* Light Theme Variables */
body.theme-light {
  --bg-base: #f8fafc;
  --bg-surface-1: #ffffff;
  --bg-surface-2: #f1f5f9;
  --bg-surface-3: #e2e8f0;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-active: rgba(6, 182, 212, 0.6);
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border-subtle);
}

/* ==========================================================================
   Base e Reset
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* Mesh di sfondo */
.bg-mesh {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: -1;
  background: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.07) 0%, transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(168, 85, 247, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(16, 185, 129, 0.04) 0%, transparent 50%);
}

/* ==========================================================================
   Header dell'Applicazione
   ========================================================================== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(17, 23, 38, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.85rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

body.theme-light .app-header {
  background: rgba(255, 255, 255, 0.85);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.4);
}

.brand-icon svg {
  width: 26px;
  height: 26px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-pro {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  background: linear-gradient(90deg, #06b6d4, #10b981);
  color: #032b30;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Stepper Bar */
.stepper-nav {
  display: flex;
  align-items: center;
  background: var(--bg-surface-2);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.step-btn {
  background: transparent;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
}

.step-btn:hover:not(.disabled) {
  color: var(--text-main);
  background: var(--bg-surface-3);
}

.step-btn.active {
  background: var(--accent-primary);
  color: #042429;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.step-btn.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.15);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.step-btn.active .step-num {
  background: rgba(0, 0, 0, 0.25);
  color: white;
}

.step-divider {
  width: 20px;
  height: 1px;
  background: var(--border-subtle);
  margin: 0 0.25rem;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.device-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-emerald);
  box-shadow: 0 0 8px var(--color-emerald);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.icon-btn {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-surface-3);
  border-color: var(--border-active);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ==========================================================================
   Contenitore Principale e Sezioni
   ========================================================================== */

.main-container {
  max-width: 1540px;
  margin: 0 auto;
  padding: 2rem;
}

.step-section {
  display: none;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.step-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.step-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.3rem;
}

.section-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
  max-width: 840px;
}

.step-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ==========================================================================
   Bottoni ed Elementi UI
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-fast);
  border: 1px solid transparent;
  user-select: none;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--accent-primary);
  color: #03252a;
  border-color: var(--accent-primary);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-camera {
  background: linear-gradient(135deg, #059669 0%, #06b6d4 100%);
  color: white;
  border-color: #10b981;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.btn-camera:hover:not(:disabled) {
  background: linear-gradient(135deg, #10b981 0%, #0891b2 100%);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.btn-outline {
  background: var(--bg-surface-2);
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: var(--bg-surface-3);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-main);
  background: var(--bg-surface-2);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.85rem 1.75rem;
  font-size: 1rem;
}

.btn-xl {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-full {
  width: 100%;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.glow-btn {
  position: relative;
  overflow: hidden;
}

.glow-btn::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    60deg,
    transparent 20%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 80%
  );
  transform: rotate(30deg);
  animation: shine 4s infinite linear;
}

@keyframes shine {
  0% { transform: translateX(-100%) rotate(30deg); }
  100% { transform: translateX(100%) rotate(30deg); }
}

/* Card Generica */
.card {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}

/* ==========================================================================
   STEP 1: Canvas Editor & 4 Mirini
   ========================================================================== */

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

.canvas-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  gap: 1rem;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.group-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Selettori dei 4 Punti */
.point-selectors {
  display: flex;
  gap: 0.35rem;
  background: var(--bg-surface-1);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.point-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.point-btn:hover {
  color: var(--text-main);
  background: var(--bg-surface-3);
}

.point-btn.active {
  background: var(--bg-surface-3);
  color: var(--text-main);
  border-color: var(--border-active);
}

.point-badge {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #051a1d;
  font-size: 0.7rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.point-badge.tl { background: var(--point-tl); }
.point-badge.tr { background: var(--point-tr); }
.point-badge.br { background: var(--point-br); }
.point-badge.bl { background: var(--point-bl); }

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-label input {
  accent-color: var(--accent-primary);
  width: 15px;
  height: 15px;
}

/* Contenitore Canvas */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 620px;
  background: #06080e;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

#editor-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Dropzone Iniziale */
.empty-dropzone {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 13, 20, 0.95);
  cursor: pointer;
  z-index: 10;
  transition: var(--transition-fast);
}

.empty-dropzone:hover {
  background: rgba(10, 13, 20, 0.85);
}

.dropzone-box {
  border: 2px dashed rgba(6, 182, 212, 0.4);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  max-width: 500px;
  background: rgba(24, 32, 50, 0.4);
  transition: var(--transition-fast);
}

.empty-dropzone:hover .dropzone-box {
  border-color: var(--accent-primary);
  transform: scale(1.01);
}

.dropzone-box svg {
  width: 60px;
  height: 60px;
  color: var(--accent-primary);
  margin-bottom: 1rem;
}

.dropzone-box h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.dropzone-box p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.dropzone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  justify-content: center;
  margin-top: 1.5rem;
}

/* Pulsanti Fluttuanti Rapidi sul Canvas */
.mobile-canvas-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  z-index: 25;
}

.canvas-floating-btn {
  background: rgba(17, 23, 38, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: var(--transition-fast);
}

.canvas-floating-btn:hover {
  background: var(--bg-surface-3);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.canvas-floating-btn svg {
  width: 14px;
  height: 14px;
}

/* Lente d'Ingrandimento Fluttuante 2x */
.loupe-container {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  border: 3px solid var(--accent-primary);
  box-shadow: 0 12px 42px rgba(0, 0, 0, 0.9), 0 0 28px var(--accent-glow);
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
  background: #090d16;
  display: none;
  backdrop-filter: blur(8px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Modalità Top HUD per Smartphone */
.loupe-container.mobile-hud {
  border-radius: 14px !important;
  border-width: 2px !important;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.95), 0 0 24px rgba(6, 182, 212, 0.5) !important;
}

.loupe-container.mobile-hud #loupe-canvas {
  border-radius: 12px !important;
}

#loupe-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
}

.loupe-zoom-tag {
  position: absolute;
  top: 8px;
  right: 14px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.loupe-badge {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 15, 28, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f8fafc;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

.canvas-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1.25rem;
  background: var(--bg-surface-2);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.info-tip {
  color: var(--text-secondary);
}

.coord-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--accent-primary);
}

/* ==========================================================================
   Barra Laterale Strumenti (D-Pad & Anteprima)
   ========================================================================== */

.sidebar-tools {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.tool-card {
  text-align: center;
}

.tool-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* D-Pad a Croce */
.dpad-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.dpad-middle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.dpad-btn {
  width: 44px;
  height: 44px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  user-select: none;
}

.dpad-btn:hover {
  background: var(--accent-primary);
  color: #03252a;
  border-color: var(--accent-primary);
}

.dpad-btn:active {
  transform: scale(0.92);
}

.dpad-center {
  width: 44px;
  height: 44px;
  background: var(--bg-surface-3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--accent-primary);
  border: 2px solid var(--border-active);
}

.step-size-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.step-btn-val {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
}

.step-btn-val.active {
  background: var(--bg-surface-3);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* Anteprima Live Foglio Rettificato */
.preview-card {
  padding: 1rem;
}

.card-header-sm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.live-pill {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(16, 185, 129, 0.15);
  color: var(--color-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.rectified-preview-container {
  width: 100%;
  height: 180px;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#warp-preview-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-empty {
  position: absolute;
  padding: 1rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.preview-note {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 0.65rem;
}

/* ==========================================================================
   STEP 2: Configurazione e Parametri Pipeline
   ========================================================================== */

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.config-preview-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.final-warped-box {
  width: 100%;
  height: 480px;
  background: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

#step2-warped-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.warped-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.config-params-card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.col-half {
  flex: 1;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-control {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition-fast);
}

.form-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-control-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.form-help {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Toggle Switch Control */
.toggle-control {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  cursor: pointer;
  background: var(--bg-surface-2);
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.toggle-control input {
  position: absolute;
  opacity: 0;
}

.toggle-slider {
  width: 44px;
  height: 24px;
  background: var(--bg-surface-3);
  border-radius: var(--radius-full);
  position: relative;
  transition: var(--transition-fast);
  flex-shrink: 0;
  margin-top: 2px;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: var(--transition-fast);
}

.toggle-control input:checked + .toggle-slider {
  background: var(--accent-primary);
}

.toggle-control input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.toggle-label strong {
  font-size: 0.88rem;
}

.toggle-label small {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Spinner e Box Avanzamento */
.processing-status-box {
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.spinner-ring {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(6, 182, 212, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.processing-text strong {
  font-size: 0.95rem;
  color: var(--text-main);
  display: block;
}

.processing-text p {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   STEP 3: ECG Studio (12 Derivazioni) & Viewer
   ========================================================================== */

/* Barra Metriche */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-title {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-main);
}

.metric-value small {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.text-accent {
  color: var(--accent-primary);
}

/* Card Visualizzatore ECG */
.ecg-studio-card {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.studio-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-subtle);
  gap: 1rem;
  flex-wrap: wrap;
}

.view-mode-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--bg-surface-1);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.btn-tab {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-tab.active {
  background: var(--bg-surface-3);
  color: var(--accent-primary);
  border-color: var(--border-active);
}

/* Viewport Canvas ECG */
.ecg-canvas-viewport {
  position: relative;
  width: 100%;
  height: 680px;
  background: var(--bg-surface-1);
  overflow: hidden;
  cursor: crosshair;
}

#ecg-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Crosshair Tooltip */
.ecg-crosshair-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  color: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  font-size: 0.8rem;
  z-index: 60;
  min-width: 130px;
}

.tt-lead {
  font-weight: 800;
  color: var(--accent-primary);
  margin-bottom: 0.3rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 0.2rem;
  font-size: 0.85rem;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.76rem;
}

.ecg-canvas-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface-2);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.82rem;
}

.scale-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
}

.legend-box-small {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--ecg-grid-small);
  border: 1px solid var(--ecg-grid-large);
}

.legend-box-large {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: var(--ecg-grid-large);
}

.ecg-hover-coords {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent-primary);
}

/* Hub di Esportazione */
.export-hub {
  margin-top: 2rem;
}

.hub-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.export-cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.export-card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem;
  transition: var(--transition-fast);
}

.export-card:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
}

.export-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.csv-icon { background: rgba(16, 185, 129, 0.15); color: var(--color-emerald); }
.json-icon { background: rgba(6, 182, 212, 0.15); color: var(--accent-primary); }
.img-icon { background: rgba(168, 85, 247, 0.15); color: var(--color-violet); }
.plot-icon { background: rgba(245, 158, 11, 0.15); color: var(--color-amber); }

.export-details {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.export-details h4 {
  font-size: 0.95rem;
  font-weight: 700;
}

.export-details p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* ==========================================================================
   Notifiche Toast
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: rgba(17, 23, 38, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  color: white;
  font-size: 0.85rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 380px;
}

.toast.toast-success { border-color: var(--color-emerald); }
.toast.toast-error { border-color: var(--color-rose); }
.toast.toast-info { border-color: var(--accent-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Componenti Mobile Specifici
   ========================================================================== */

/* Mobile Thumb-Zone Bar (Fissa in basso su smartphone) */
.mobile-thumb-bar {
  display: none;
}

/* Banner Orizzontale per Step 3 */
.mobile-landscape-banner {
  display: none;
}

/* Barra orizzontale derivazioni rapide */
.mobile-lead-pills {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.5rem;
}

.pills-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.pills-scroll-wrapper {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.pills-scroll-wrapper::-webkit-scrollbar {
  display: none;
}

.lead-pill {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 40px;
  text-align: center;
  transition: var(--transition-fast);
}

.lead-pill:hover {
  background: var(--bg-surface-3);
  color: var(--text-main);
}

.lead-pill.active {
  background: var(--accent-primary);
  color: #032025;
  border-color: var(--accent-primary);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1200px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .config-grid {
    grid-template-columns: 1fr;
  }
  .export-cards-grid {
    grid-template-columns: 1fr 1fr;
  }
  .metrics-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 860px) {
  /* Mostra la barra ergonomica del pollice in basso */
  .mobile-thumb-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.7);
    padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom, 10px)) 1rem;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  /* Riserva spazio in fondo alla pagina per non coprire i controlli */
  #section-step-1 {
    padding-bottom: 5.5rem;
  }

  .thumb-point-strip {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .thumb-bar-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-right: 2px;
    display: none;
  }

  .thumb-point-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1.5px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-fast);
    padding: 0;
  }

  .thumb-point-btn.active {
    background: rgba(255, 255, 255, 0.16);
    border-color: var(--accent-primary);
    transform: scale(1.08);
    box-shadow: 0 0 12px var(--accent-glow);
  }

  .thumb-nudge-cluster {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .thumb-nudge-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bg-surface-3);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
  }

  .thumb-nudge-btn:active {
    background: var(--accent-primary);
    color: #032025;
  }

  .thumb-nudge-vgroup {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .thumb-nudge-vgroup .thumb-nudge-btn {
    height: 19px;
    width: 32px;
    font-size: 0.65rem;
    border-radius: 4px;
  }

  .thumb-confirm-btn {
    height: 40px;
    padding: 0 1rem;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    border-radius: var(--radius-md);
  }
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }

  .header-brand {
    justify-content: space-between;
  }

  .brand-title {
    font-size: 1.15rem;
  }

  .brand-sub {
    font-size: 0.75rem;
  }

  .stepper-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0.3rem 0.4rem;
  }

  .stepper-nav::-webkit-scrollbar {
    display: none;
  }

  .step-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .main-container {
    padding: 0.85rem;
  }

  .step-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .step-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .step-header-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .canvas-wrapper {
    height: 52vh;
    min-height: 360px;
    max-height: 520px;
  }

  .empty-dropzone .dropzone-box {
    padding: 1.75rem 1.25rem;
  }

  .dropzone-actions {
    flex-direction: column;
  }

  .dropzone-actions .btn {
    width: 100%;
  }

  .card-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .point-selectors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    width: 100%;
  }

  .mobile-lead-pills {
    display: flex;
  }

  .mobile-landscape-banner {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.9rem;
    background: rgba(6, 182, 212, 0.12);
    border: 1px solid rgba(6, 182, 212, 0.35);
    border-radius: var(--radius-md);
    color: #38bdf8;
    font-size: 0.8rem;
    margin-bottom: 1rem;
    line-height: 1.4;
  }

  .mobile-landscape-banner svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
  }

  .studio-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .view-mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .ecg-canvas-viewport {
    height: 380px;
  }

  .export-cards-grid {
    grid-template-columns: 1fr;
  }

  .metrics-bar {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .metric-card {
    padding: 0.85rem;
  }
}
