/* ==========================================================================
   SICIDEL - GESTIONALE AZIENDALE CSS (v2.3)
   Ottimizzato ad alte prestazioni, zero lag di scrolling, stampa A4/PDF perfetta
   ========================================================================== */

:root {
  --primary: #0a2540;
  --primary-light: #133a63;
  --primary-dark: #06192c;
  --secondary: #0284c7;
  --secondary-hover: #0369a1;
  --accent-gold: #f59e0b;
  --accent-gold-hover: #d97706;
  --accent-emerald: #10b981;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  --bg-dark: #0b1320;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  --border-focus: #0284c7;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(10, 37, 64, 0.08);
  --shadow-lg: 0 12px 32px rgba(10, 37, 64, 0.12);
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --transition: all 0.15s ease;
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ==========================================================================
   1. LOGIN VIEW (SCHERMATA DI ACCESSO BLINDATA)
   ========================================================================== */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 10% 20%, #0f2744 0%, #081424 90%);
  position: relative;
  overflow: hidden;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  position: relative;
  z-index: 10;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo {
  height: 60px;
  margin-bottom: 1.25rem;
  object-fit: contain;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f1f5f9;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
  border: 1px solid #e2e8f0;
}

.login-badge svg {
  color: var(--accent-gold);
}

.login-header h1 {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.form-group {
  margin-bottom: 1.15rem;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 0.35rem;
}

.input-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon-wrap svg.input-icon {
  position: absolute;
  left: 1rem;
  color: #94a3b8;
  pointer-events: none;
}

.form-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  background: #f8fafc;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.input-icon-wrap .form-input {
  padding-left: 2.75rem;
}

.form-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.toggle-pwd {
  position: absolute;
  right: 0.85rem;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.35rem;
  display: flex;
  align-items: center;
}

.toggle-pwd:hover {
  color: var(--primary);
}

.login-error {
  display: none;
  align-items: center;
  gap: 0.6rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
}

.login-error.active {
  display: flex;
}

.btn-login {
  width: 100%;
  padding: 0.9rem 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, #173d66 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(10, 37, 64, 0.25);
}

.btn-login:hover {
  background: linear-gradient(135deg, #0e3053 0%, #1e4b7c 100%);
}

/* PWA Install Buttons */
.pwa-install-box {
  margin-top: 1rem;
}

.btn-pwa-install {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #f0fdf4;
  color: #15803d;
  border: 1.5px solid #86efac;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.btn-pwa-install:hover {
  background: #dcfce7;
  border-color: #4ade80;
}

.btn-header-pwa {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f0fdf4;
  color: #166534;
  border: 1.5px solid #86efac;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.btn-header-pwa:hover {
  background: #dcfce7;
}

.login-footer-info {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid #f1f5f9;
  text-align: center;
  font-size: 0.78rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

/* ==========================================================================
   2. GESTIONALE APP LAYOUT & SIDEBAR NAVIGATION (MODERNO ERP)
   ========================================================================== */
.app-view {
  display: none;
  min-height: 100vh;
  flex-direction: row;
  background: #f8fafc;
}

.app-view.active {
  display: flex;
}

/* Backdrop per Drawer Mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 19, 32, 0.65);
  backdrop-filter: blur(3px);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   SIDEBAR LATERALE SINISTRA
   ========================================================================== */
/* ==========================================================================
   SIDEBAR LATERALE SINISTRA (DARK OBSIDIAN GLASS)
   ========================================================================== */
.app-sidebar {
  width: 280px;
  min-width: 280px;
  background: linear-gradient(180deg, #090e1a 0%, #0c1322 50%, #080c16 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 100;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-header {
  padding: 1.35rem 1.25rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(0, 0, 0, 0.15);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.sidebar-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.sidebar-brand-name {
  font-size: 1.15rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand-sub {
  font-size: 0.65rem;
  font-weight: 800;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.sidebar-close-mobile {
  display: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  cursor: pointer;
  padding: 0.45rem;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.sidebar-close-mobile:hover {
  color: #ffffff;
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Navigazione Scrollabile */
.sidebar-scrollable {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-scrollable::-webkit-scrollbar {
  width: 4px;
}

.sidebar-scrollable::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.sidebar-section-title {
  font-size: 0.68rem;
  font-weight: 800;
  color: #64748b;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.85rem 0.75rem 0.45rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Pulsanti Voci di Menu Verticale */
.sidebar-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: #94a3b8;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: left;
  user-select: none;
  position: relative;
}

.sidebar-nav-btn .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #94a3b8;
  transition: color 0.2s ease;
  flex-shrink: 0;
}

.sidebar-nav-btn .nav-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.86rem;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.sidebar-nav-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
  transform: translateX(2px);
}

.sidebar-nav-btn:hover .nav-icon {
  color: #38bdf8;
}

.sidebar-nav-btn.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  font-weight: 700;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.38);
}

.sidebar-nav-btn.active .nav-icon {
  color: #ffffff;
}

/* Badge Contatori Voci Sidebar - Stile Raffinato & Allineamento Perfetto */
.nav-counter-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 7px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1;
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  box-sizing: border-box;
}

.sidebar-nav-btn:hover .nav-counter-badge {
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.18);
}

.sidebar-nav-btn.active .nav-counter-badge {
  background: rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 2px 6px rgba(0, 0, 0, 0.15) !important;
  font-weight: 800;
}

/* Link Rapido */
.sidebar-link-btn {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.sidebar-link-btn:hover {
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
  transform: translateX(2px);
}

.sidebar-link-btn .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex-shrink: 0;
  color: #38bdf8;
}

/* Footer Sidebar (Profilo, App, Logout) */
.sidebar-footer {
  padding: 1.15rem 1rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-pwa-btn {
  width: 100%;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-pwa-btn:hover {
  background: rgba(16, 185, 129, 0.22);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.5);
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-user-card .user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb 0%, #0a2540 100%);
  border: 2px solid #38bdf8;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  position: relative;
}

.sidebar-user-card .user-avatar .user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 25%;
  display: block;
  border-radius: 50%;
}

.sidebar-user-card .user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  line-height: 1.25;
}

.sidebar-user-card .user-email {
  font-weight: 700;
  color: #f8fafc;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-card .user-role {
  font-size: 0.68rem;
  color: #94a3b8;
  font-weight: 500;
}

.sidebar-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #f87171;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0.6rem;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-logout-btn:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  border-color: #ef4444;
}

.sidebar-version-tag {
  text-align: center;
  font-size: 0.68rem;
  color: #475569;
  letter-spacing: 0.02em;
  margin-top: 0.15rem;
}

/* ==========================================================================
   MOBILE BOTTOM NAVIGATION (APP BAR)
   ========================================================================== */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 950;
  background: rgba(9, 14, 26, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.45rem 0.35rem max(0.45rem, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.mob-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.35rem 0.2rem;
  border-radius: 8px;
  transition: all 0.18s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mob-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
}

.mob-label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.mob-nav-btn .mob-badge {
  position: absolute;
  top: -3px;
  right: -8px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: #2563eb;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #090e1a;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.mob-nav-btn.active {
  color: #38bdf8;
}

.mob-nav-btn.active .mob-label {
  font-weight: 800;
}

.mob-nav-btn.active .mob-icon-wrap svg {
  stroke: #38bdf8;
  filter: drop-shadow(0 0 6px rgba(56, 189, 248, 0.5));
}

/* ==========================================================================
   CONTENITORE PRINCIPALE & TOPBAR
   ========================================================================== */
.app-main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

.app-topbar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 2.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.03);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-menu-toggle {
  display: none;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--primary);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.topbar-menu-toggle:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.92rem;
}

.breadcrumb-root {
  color: var(--text-muted);
  font-weight: 600;
}

.breadcrumb-sep {
  color: #cbd5e1;
  font-size: 0.8rem;
}

.breadcrumb-current {
  color: #0f172a;
  font-weight: 800;
  background: #f1f5f9;
  padding: 0.2rem 0.65rem;
  border-radius: 6px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.topbar-status-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #047857;
}

.status-pulse-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3);
  animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.topbar-date-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Area di Lavoro Principale */
.app-main {
  flex: 1;
  padding: 2rem 2.25rem;
  max-width: 1540px;
  width: 100%;
  margin: 0 auto;
}

/* Media Queries Responsive Layout */
@media (max-width: 1024px) {
  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 1000;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.7);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close-mobile {
    display: flex;
  }

  .topbar-menu-toggle {
    display: flex;
  }

  .app-topbar {
    padding: 0.75rem 1.25rem;
  }

  .app-main {
    padding: 1.5rem 1.25rem 5.5rem;
  }

  .mobile-bottom-nav {
    display: flex;
  }
}

@media (max-width: 768px) {
  .app-topbar {
    padding: 0.65rem 1rem;
  }
  .breadcrumb-root, .breadcrumb-sep {
    display: none;
  }
  .topbar-date-badge {
    display: none;
  }
  .app-main {
    padding: 1rem 0.85rem 5.5rem;
  }
  .welcome-banner {
    padding: 1.25rem 1rem;
    flex-direction: column;
    align-items: flex-start;
  }
  .welcome-quick-actions {
    width: 100%;
    flex-direction: column;
  }
  .welcome-quick-actions .btn-action {
    width: 100%;
    justify-content: center;
  }
}

.module-view {
  display: none;
}

.module-view.active {
  display: block;
}

/* Welcome & Action Banner */
.welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, #17385c 100%);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 1.75rem 2rem;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
  box-shadow: var(--shadow-md);
}

.welcome-text h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.welcome-text p {
  color: #cbd5e1;
  font-size: 0.9rem;
}

.welcome-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-action-primary {
  background: var(--accent-gold);
  color: #0b1320;
}

.btn-action-primary:hover {
  background: var(--accent-gold-hover);
}

.btn-action-outline {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-action-outline:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   3. KPI STATS CARDS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-blue {
  background: #eff6ff;
  color: var(--secondary);
}

.stat-icon-green {
  background: #ecfdf5;
  color: var(--accent-emerald);
}

.stat-icon-yellow {
  background: #fffbeb;
  color: var(--accent-gold);
}

.stat-icon-purple {
  background: #f5f3ff;
  color: var(--accent-purple);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.highlight-green {
  color: #059669;
}

.highlight-yellow {
  color: #d97706;
}

.highlight-purple {
  color: #7c3aed;
}

/* ==========================================================================
   4. QUOTES & ESTIMATES PANELS, SEARCH & FILTER TABS
   ========================================================================== */
.quotes-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.quotes-panel-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  background: #ffffff;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 280px;
  max-width: 420px;
  display: flex;
  align-items: center;
}

.search-wrap svg {
  position: absolute;
  left: 0.85rem;
  color: #94a3b8;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.4rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: inherit;
  background: #f8fafc;
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.filter-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tab-btn {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.tab-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.tab-btn-new.active {
  background: #059669;
  border-color: #059669;
}

.tab-btn-work.active {
  background: #d97706;
  border-color: #d97706;
}

.tab-btn-done.active {
  background: var(--secondary);
  border-color: var(--secondary);
}

/* ==========================================================================
   5. TABLE VIEW FOR QUOTES & ESTIMATES
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.quotes-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.quotes-table th {
  background: #f8fafc;
  color: #475569;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.quotes-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.quotes-table tr:hover td {
  background-color: #f8fafc;
}

.quotes-table tr.row-new td {
  background-color: #f0fdf4;
}

/* Cell Elements */
.req-id-tag {
  font-family: monospace;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--primary);
}

.req-date {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.req-source-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #475569;
  margin-top: 0.25rem;
}

.client-name {
  font-weight: 800;
  color: var(--primary);
  font-size: 0.94rem;
}

.client-city {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.15rem;
}

.service-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--primary);
}

.service-scope-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.scale-badge {
  display: inline-block;
  font-size: 0.74rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  color: #334155;
  margin-top: 0.25rem;
}

.contact-links-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.quick-contact-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  transition: var(--transition);
}

.quick-contact-link:hover {
  color: var(--secondary);
}

.quick-contact-link.link-wa {
  color: #15803d;
  font-weight: 700;
}

/* Status Selectors */
.status-select {
  padding: 0.35rem 0.65rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1.5px solid transparent;
  cursor: pointer;
  outline: none;
}

.status-select.status-nuovo {
  background: #dcfce7;
  color: #15803d;
  border-color: #86efac;
}

.status-select.status-in_lavorazione,
.status-select.status-in_attesa {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}

.status-select.status-preventivo_inviato {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.status-select.status-approvato {
  background: #dcfce7;
  color: #166534;
  border-color: #86efac;
}

.status-select.status-rifiutato {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

.status-select.status-concluso {
  background: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}

/* Table Action Buttons */
.table-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border-color);
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-icon-primary {
  color: var(--secondary);
  background: #eff6ff;
}

.btn-icon-primary:hover {
  background: var(--secondary);
  color: #ffffff;
}

.btn-icon-danger:hover {
  background: var(--accent-red);
  color: #ffffff;
  border-color: var(--accent-red);
}

.btn-icon-wa {
  color: #166534;
  background: #f0fdf4;
}

.btn-icon-wa:hover {
  background: #22c55e;
  color: #ffffff;
}

.quotes-empty-state {
  padding: 3.5rem 2rem;
  text-align: center;
}

.quotes-empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.quotes-empty-state h4 {
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.quotes-empty-state p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ==========================================================================
   6. MODAL OVERLAY & MODAL DIALOGS (ZERO-LAG HARDWARE ACCELERATED)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 19, 32, 0.88);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateZ(0);
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 620px;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  margin: auto;
  position: relative;
  contain: layout;
  transform: translateZ(0);
  will-change: transform;
}

.modal-card form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.modal-card-large {
  max-width: 980px;
  max-height: 92vh;
}

.modal-card-print {
  max-width: 940px;
  max-height: 94vh;
}

.modal-header {
  padding: 1.15rem 1.75rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.modal-badge {
  font-family: monospace;
  font-size: 0.78rem;
  font-weight: 800;
  background: #eff6ff;
  color: var(--secondary);
  border: 1px solid #bfdbfe;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: #94a3b8;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  transition: color 0.15s ease;
}

.modal-close:hover {
  color: var(--accent-red);
}

.modal-body {
  padding: 1.5rem 1.75rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.modal-footer {
  padding: 1rem 1.75rem;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.btn-modal {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-modal-secondary {
  background: #e2e8f0;
  color: #334155;
}

.btn-modal-secondary:hover {
  background: #cbd5e1;
}

.btn-modal-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-modal-primary:hover {
  background: #173d66;
}

.btn-modal-whatsapp {
  background: #25d366;
  color: #ffffff;
}

.btn-modal-whatsapp:hover {
  background: #20ba5a;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

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

.stat-card.highlight-blue {
  border-top-color: #0284c7;
}

.stat-card.highlight-blue .stat-value {
  color: #0284c7;
}

.nav-counter-purple {
  background: #7c3aed !important;
  color: #ffffff !important;
}

.nav-counter-emerald {
  background: #059669 !important;
  color: #ffffff !important;
}

/* ==========================================================================
   7. EDITOR PREVENTIVO PROFESSIONALE
   ========================================================================== */
.editor-section-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}

.editor-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.editor-section-title {
  font-size: 0.84rem;
  text-transform: uppercase;
  color: #475569;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin-bottom: 0.85rem;
}

.preset-buttons-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.btn-preset {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: var(--primary);
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.btn-preset:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Editor Items Table */
.editor-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
}

.editor-items-table th {
  background: #f8fafc;
  color: #64748b;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border-color);
}

.editor-items-table td {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border-color);
  vertical-align: middle;
}

.item-desc-input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  font-family: inherit;
  font-size: 0.86rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: #f8fafc;
}

.item-desc-input:focus {
  outline: none;
  background: #fff;
  border-color: var(--secondary);
}

.item-um-select,
.item-qty-input,
.item-price-input {
  width: 100%;
  padding: 0.45rem 0.45rem;
  font-family: inherit;
  font-size: 0.86rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: #f8fafc;
}

.item-row-total {
  font-weight: 800;
  color: var(--primary);
  text-align: right;
  padding-right: 0.5rem;
  font-size: 0.88rem;
  display: block;
}

.btn-remove-row {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}

.btn-remove-row:hover {
  transform: scale(1.2);
}

.btn-add-item-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f0fdf4;
  color: #15803d;
  border: 1.5px dashed #86efac;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: var(--transition);
}

.btn-add-item-row:hover {
  background: #dcfce7;
  border-color: #22c55e;
}

/* Totals Grid */
.editor-totals-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1rem;
}

.totals-calculation-card {
  background: #f8fafc;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  margin-bottom: 0.5rem;
  color: #475569;
}

.grand-total-row {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 2px solid var(--primary);
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
}

.grand-total-row span:last-child {
  color: #0284c7;
  font-size: 1.35rem;
}

/* ==========================================================================
   8. OFFICIAL PRINTABLE A4 SHEET (PREVENTIVO STAMPABILE & PDF)
   ========================================================================== */
.printable-document-wrapper {
  background: #334155;
  padding: 2rem 1.5rem;
  display: block;
  overflow-y: auto;
}

.official-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 820px;
  min-height: 1050px;
  margin: 0 auto;
  padding: 2.5rem 2.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  color: #0f172a;
  font-size: 0.9rem;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 1.75rem;
}

.sheet-logo {
  height: 56px;
  object-fit: contain;
  margin-bottom: 0.4rem;
}

.sheet-coop-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
}

.sheet-coop-details {
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.35;
}

.sheet-doc-meta {
  text-align: right;
}

.sheet-doc-title {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.sheet-doc-number {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--secondary);
}

.sheet-doc-date {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 0.2rem;
}

/* Client & Job Box */
.sheet-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.sheet-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 1rem 1.15rem;
}

.sheet-box-title {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.25rem;
}

.sheet-client-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.2rem;
}

.sheet-client-detail {
  font-size: 0.82rem;
  color: #334155;
  line-height: 1.35;
}

/* Sheet Items Table */
.sheet-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  table-layout: auto;
}

.sheet-items-table th {
  background: var(--primary);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.65rem 0.85rem;
  text-align: left;
}

.sheet-items-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.84rem;
  color: #1e293b;
  word-break: break-word;
}

.sheet-items-table tr:nth-child(even) td {
  background: #f8fafc;
}

/* Sheet Totals */
.sheet-totals-container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.75rem;
}

.sheet-totals-table {
  width: 320px;
  border-collapse: collapse;
}

.sheet-totals-table td {
  padding: 0.35rem 0.6rem;
  font-size: 0.86rem;
}

.sheet-totals-table tr.total-highlight td {
  background: #f1f5f9;
  border-top: 2px solid var(--primary);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  padding: 0.6rem 0.6rem;
}

.sheet-totals-table tr.total-highlight td:last-child {
  color: #0369a1;
  font-size: 1.2rem;
  text-align: right;
}

/* Terms & Signatures */
.sheet-terms-box {
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  padding: 0.85rem 1rem;
  font-size: 0.78rem;
  color: #475569;
  line-height: 1.4;
  margin-bottom: 2rem;
}

.sheet-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin-top: auto;
  padding-top: 1.5rem;
}

.sheet-sig-box {
  border-top: 1px dashed #94a3b8;
  padding-top: 0.5rem;
  text-align: center;
  font-size: 0.78rem;
  color: #64748b;
}

/* Detail Sections */
.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section-title {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 0.5rem;
  letter-spacing: 0.04em;
}

.detail-card-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
}

.detail-grid-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.88rem;
}

.detail-grid-item:last-child {
  border-bottom: none;
}

.detail-label {
  color: #64748b;
  font-weight: 600;
}

.detail-value {
  color: var(--text-main);
  font-weight: 700;
  text-align: right;
}

/* ==========================================================================
   9. MEDIA PRINT (STAMPA PERFETTA SU FOGLIO A4 / SALVATAGGIO PDF)
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
  }

  /* Nascondi l'interfaccia e tutte le modali non di stampa */
  .login-view,
  .app-header,
  .app-main,
  #viewQuotesModule,
  #viewEstimatesModule,
  #detailModal,
  #newManualModal,
  #estimateEditorModal,
  #pwaHelpModal,
  .no-print,
  .modal-close,
  .modal-footer {
    display: none !important;
  }

  /* Rendi visibile e non vincolata la modale di stampa */
  .modal-overlay#estimatePrintModal {
    display: block !important;
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    z-index: 1 !important;
  }

  .modal-card.modal-card-print {
    display: block !important;
    position: static !important;
    max-width: 100% !important;
    max-height: none !important;
    box-shadow: none !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .modal-header {
    display: none !important;
  }

  .modal-body.printable-document-wrapper {
    display: block !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  .official-sheet {
    display: flex !important;
    flex-direction: column !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
    background: #ffffff !important;
    color: #0f172a !important;
    font-size: 10pt !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sheet-header {
    border-bottom: 2.5px solid #0a2540 !important;
    padding-bottom: 12px !important;
    margin-bottom: 15px !important;
  }

  .sheet-logo {
    height: 52px !important;
  }

  .sheet-info-grid {
    margin-bottom: 15px !important;
    gap: 15px !important;
  }

  .sheet-box {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sheet-items-table {
    margin-bottom: 15px !important;
  }

  .sheet-items-table th {
    background-color: #0a2540 !important;
    color: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sheet-items-table tr:nth-child(even) td {
    background-color: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sheet-totals-table tr.total-highlight td {
    background-color: #f1f5f9 !important;
    border-top: 2px solid #0a2540 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .sheet-terms-box {
    background: #f8fafc !important;
    border-left: 3px solid #0a2540 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ==========================================================================
   10. RESPONSIVE MOBILE & TABLET ENHANCEMENTS
   ========================================================================== */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .form-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .editor-totals-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }
  .stat-card {
    padding: 0.9rem 1rem;
    gap: 0.75rem;
    border-radius: 12px;
  }
  .stat-icon-wrap {
    width: 40px;
    height: 40px;
  }
  .stat-number {
    font-size: 1.35rem;
  }
  .stat-label {
    font-size: 0.7rem;
  }

  .quotes-panel-header {
    padding: 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .search-wrap {
    min-width: 100%;
    max-width: 100%;
  }
  .filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.35rem;
    -webkit-overflow-scrolling: touch;
  }
  .tab-btn {
    white-space: nowrap;
    padding: 0.4rem 0.75rem;
    font-size: 0.78rem;
    flex-shrink: 0;
  }

  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 0 0 12px 12px;
  }
  .quotes-table th, .quotes-table td {
    padding: 0.75rem 0.9rem;
    font-size: 0.82rem;
  }

  .modal-card {
    width: calc(100% - 1.25rem);
    max-height: 90vh;
    border-radius: 16px;
    margin: 0.625rem;
  }
  .modal-body {
    padding: 1.15rem;
  }
  .modal-footer {
    padding: 0.85rem 1.15rem;
    flex-direction: column-reverse;
    gap: 0.5rem;
  }
  .modal-footer .btn-modal {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
  }

  .form-input, .form-select, select.form-input {
    font-size: 16px !important; /* Previene lo zoom automatico su iOS Safari */
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }
  .form-grid-4 {
    grid-template-columns: 1fr;
  }
  .official-sheet {
    padding: 1rem;
  }
  .sheet-info-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .sheet-signatures {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .stat-card {
    padding: 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}

/* ==========================================================================
   8. MODULO NOVITÀ & PROMOZIONI SITO WEB
   ========================================================================== */
.badge-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-cat-promo {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.badge-cat-bonus {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.badge-cat-news {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.badge-cat-notice {
  background: #f5f3ff;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}

.badge-pill-gold {
  display: inline-block;
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fcd34d;
  font-weight: 800;
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.3rem;
}

.badge-top-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  margin-top: 0.25rem;
}

/* Switch Toggle On/Off */
.status-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  vertical-align: middle;
}

.status-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.status-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: 0.2s;
  border-radius: 24px;
}

.status-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.status-switch input:checked + .status-slider {
  background-color: #10b981;
}

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

.status-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.status-active-text {
  color: #059669;
}

.status-inactive-text {
  color: #64748b;
}

.news-table-title {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.92rem;
  line-height: 1.35;
  margin-bottom: 0.25rem;
}

.news-table-desc {
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.45;
  max-width: 480px;
}

.news-table-validity {
  font-size: 0.74rem;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   MODULO 5: FIRMA RAPIDA FATTURE & DOCUMENTI PDF
   ========================================================================== */
.nav-counter-blue {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

/* Status Bar Firma Salvata */
.sig-status-bar {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.sig-status-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.sig-preview-thumb-box {
  width: 140px;
  height: 54px;
  background: #f8fafc;
  border: 1.5px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  overflow: hidden;
}

.sig-status-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sig-status-tag-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sig-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.sig-badge-active {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.sig-badge-missing {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.sig-signer-name {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.92rem;
}

.sig-status-note {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-sig-modify {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #f8fafc;
  color: var(--primary);
  border: 1px solid #cbd5e1;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-sig-modify:hover {
  background: #eff6ff;
  color: var(--secondary);
  border-color: #93c5fd;
}

/* Area Studio di Firma / Workspace */
.invoice-workspace-panel {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* Dropzone Upload */
.invoice-dropzone {
  padding: 3.5rem 2rem;
  text-align: center;
  background: #fbfdff;
  border: 2px dashed #bfdbfe;
  margin: 1.5rem;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  cursor: pointer;
}

.invoice-dropzone:hover,
.invoice-dropzone.dragover {
  border-color: var(--secondary);
  background: #f0f9ff;
  transform: translateY(-1px);
}

.dropzone-inner {
  max-width: 580px;
  margin: 0 auto;
}

.dropzone-icon-circle {
  width: 72px;
  height: 72px;
  background: #e0f2fe;
  color: var(--secondary);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.dropzone-inner h3 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.dropzone-inner p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.btn-dropzone-select {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--secondary);
  color: #ffffff;
  border: none;
  padding: 0.85rem 1.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.96rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
  transition: var(--transition);
}

.btn-dropzone-select:hover {
  background: var(--secondary-hover);
  transform: translateY(-1px);
}

.dropzone-formats {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: #64748b;
}

.signing-steps-guide {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 2.25rem;
  padding-top: 1.5rem;
  border-top: 1px dashed #e2e8f0;
}

.step-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  text-align: left;
}

.step-num {
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: #ffffff;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-desc {
  font-size: 0.78rem;
  color: #334155;
  line-height: 1.3;
}

.step-arrow {
  color: #94a3b8;
  font-size: 1rem;
  font-weight: bold;
}

/* Studio di Firma Attivo (Workspace) */
.invoice-studio-view {
  display: flex;
  flex-direction: column;
  background: #f1f5f9;
}

.invoice-studio-toolbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 60px;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.doc-badge-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
}

.doc-icon-pill {
  background: #fee2e2;
  color: #dc2626;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.doc-texts {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.doc-texts strong {
  font-size: 0.82rem;
  color: var(--primary);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-texts span {
  font-size: 0.7rem;
  color: #64748b;
}

.page-nav-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.2rem;
}

.btn-tool-nav {
  background: transparent;
  border: none;
  color: var(--primary);
  width: 28px;
  height: 28px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-tool-nav:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-tool-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-counter-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0 0.5rem;
  min-width: 65px;
  text-align: center;
}

.btn-tool-nav-text {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-tool-nav-text:hover {
  background: #dbeafe;
}

.btn-tool-quick {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  color: #15803d;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-tool-quick:hover {
  background: #dcfce7;
  border-color: #4ade80;
}

.tool-separator {
  width: 1px;
  height: 24px;
  background: #e2e8f0;
}

.scale-control-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.range-slider {
  width: 80px;
  height: 6px;
  accent-color: var(--secondary);
  cursor: pointer;
}

#sigScaleVal {
  min-width: 38px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
}

.toolbar-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
}

.toolbar-checkbox-label input {
  accent-color: var(--secondary);
}

.btn-studio-apply {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: #ffffff;
  border: none;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.25);
  transition: var(--transition);
}

.btn-studio-apply:hover {
  background: linear-gradient(135deg, #047857 0%, #065f46 100%);
  transform: translateY(-1px);
}

.btn-studio-close {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 1.5rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-studio-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Hint Bar */
.studio-hint-bar {
  background: #eff6ff;
  border-bottom: 1px solid #dbeafe;
  color: #1e40af;
  padding: 0.5rem 1.5rem;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Canvas Viewport */
.studio-canvas-viewport {
  padding: 2rem 1.5rem;
  overflow: auto;
  max-height: 75vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #cbd5e1;
}

.studio-page-wrapper {
  position: relative;
  display: inline-block;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  border-radius: 4px;
  cursor: crosshair;
  user-select: none;
  overflow: visible;
}

#studioPdfCanvas {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Signature Overlay Box */
/* Signature Overlay Box */
.studio-signature-overlay {
  position: absolute;
  z-index: 40;
  background: rgba(239, 246, 255, 0.9);
  border: 2px dashed #0284c7;
  border-radius: 6px;
  box-shadow: 0 4px 18px rgba(2, 132, 199, 0.28);
  cursor: move;
  user-select: none;
  touch-action: none;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  backdrop-filter: blur(2px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.studio-signature-overlay:hover,
.studio-signature-overlay.dragging {
  border-color: #0369a1;
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.4);
}

.sig-drag-header {
  background: #0284c7;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sig-drag-title {
  letter-spacing: 0.02em;
}

.btn-sig-box-remove {
  background: none;
  border: none;
  color: #ffffff;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.85;
}

.btn-sig-box-remove:hover {
  opacity: 1;
  color: #fecaca;
}

.sig-box-content {
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  pointer-events: none;
  overflow: hidden;
}

.sig-box-content img {
  max-width: 100%;
  max-height: 100%;
  flex: 1;
  min-height: 0;
  display: block;
  object-fit: contain;
}

.sig-overlay-meta {
  text-align: center;
  line-height: 1.2;
  margin-top: 2px;
  flex-shrink: 0;
}

.sig-text-line {
  font-size: 0.65rem;
  font-weight: 700;
  color: #0f2744;
  white-space: nowrap;
}

.sig-date-line {
  font-size: 0.62rem;
  color: #475569;
  white-space: nowrap;
}

/* 8 Resize Handles (4 Lati + 4 Angoli) */
.sig-handle {
  position: absolute;
  background: #0284c7;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  z-index: 45;
  transition: background 0.15s ease, box-shadow 0.15s ease;
  touch-action: none;
}

/* 4 Angoli */
.sig-handle-nw { top: -6px; left: -6px; width: 13px; height: 13px; border-radius: 50%; cursor: nwse-resize; }
.sig-handle-ne { top: -6px; right: -6px; width: 13px; height: 13px; border-radius: 50%; cursor: nesw-resize; }
.sig-handle-sw { bottom: -6px; left: -6px; width: 13px; height: 13px; border-radius: 50%; cursor: nesw-resize; }
.sig-handle-se { bottom: -6px; right: -6px; width: 13px; height: 13px; border-radius: 50%; cursor: nwse-resize; }

/* 4 Lati */
.sig-handle-n { top: -5px; left: 50%; transform: translateX(-50%); width: 26px; height: 9px; border-radius: 4px; cursor: ns-resize; }
.sig-handle-s { bottom: -5px; left: 50%; transform: translateX(-50%); width: 26px; height: 9px; border-radius: 4px; cursor: ns-resize; }
.sig-handle-w { left: -5px; top: 50%; transform: translateY(-50%); width: 9px; height: 26px; border-radius: 4px; cursor: ew-resize; }
.sig-handle-e { right: -5px; top: 50%; transform: translateY(-50%); width: 9px; height: 26px; border-radius: 4px; cursor: ew-resize; }

.sig-handle:hover,
.sig-handle.active {
  background: #0369a1;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.7);
}

/* Stili Modale Configurazione Firma */
.sig-tabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 1.25rem;
}

.sig-tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: -2px;
}

.sig-tab-btn.active {
  color: var(--secondary);
  border-bottom-color: var(--secondary);
}

.sig-tab-content {
  display: none;
}

.sig-tab-content.active {
  display: block;
}

.sig-draw-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  margin-bottom: 0.75rem;
}

.sig-colors,
.sig-pen-sizes {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.color-dot.active {
  box-shadow: 0 0 0 2px var(--secondary);
  transform: scale(1.15);
}

.btn-pen-size {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}

.btn-pen-size.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-sig-clear {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
}

.btn-sig-clear:hover {
  background: #fecaca;
}

.sig-canvas-wrap {
  position: relative;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  background: #ffffff;
  overflow: hidden;
  touch-action: none;
}

#sigDrawCanvas {
  display: block;
  width: 100%;
  height: 180px;
  cursor: crosshair;
  background: #ffffff;
}

.sig-canvas-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.88rem;
  color: #94a3b8;
  pointer-events: none;
}

.sig-upload-box {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 2rem;
  text-align: center;
}

.sig-image-preview-box {
  background: #ffffff;
  background-image: linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
                    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
                    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
                    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: inline-block;
}

.sig-font-selection {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.font-choice-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #ffffff;
  border: 1.5px solid #e2e8f0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.font-choice-label.active {
  border-color: var(--secondary);
  background: #f0f9ff;
}

.sig-text-canvas-wrap {
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 0.5rem;
}

#sigTextCanvas {
  display: block;
  width: 100%;
  height: 120px;
}

/* ==========================================================================
   10. MODULO DICHIARAZIONE DI CONFORMITA' (Di.Co. DM 37/08 - Allegato I)
   ========================================================================== */

.dico-form-section {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.dico-section-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
}

.dico-section-title .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #0284c7;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
}

.dico-radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dico-choice-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  padding: 0.5rem 0.85rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
  transition: all 0.15s ease;
}

.dico-choice-pill:hover {
  border-color: #0284c7;
  background: #f0f9ff;
}

.dico-choice-pill input[type="radio"]:checked + span {
  color: #0369a1;
}

.dico-choice-pill:has(input[type="radio"]:checked) {
  background: #e0f2fe;
  border-color: #0284c7;
}

.dico-checks-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.dico-check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
}

.dico-annex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 0.65rem;
}

.dico-annex-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  font-size: 0.83rem;
  font-weight: 500;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dico-annex-card:hover {
  background: #f0f9ff;
  border-color: #bae6fd;
}

.chip-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-text-action {
  background: none;
  border: none;
  color: #0284c7;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 6px;
}

.btn-text-action:hover {
  text-decoration: underline;
}

/* ==========================================================================
   FOGLIO DI STAMPA UFFICIALE MINISTERIALE Di.Co. (ALLEGATO I DM 37/08)
   ========================================================================== */

.dico-official-sheet {
  background: #ffffff;
  color: #000000;
  width: 100%;
  max-width: 820px;
  min-height: 1120px;
  padding: 28px 36px;
  margin: 0 auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 11.5px;
  line-height: 1.45;
}

.dico-sheet-top-right {
  text-align: right;
  margin-bottom: 8px;
}

.dico-sheet-top-right .dico-allegato-title {
  font-size: 13px;
  font-weight: 800;
}

.dico-sheet-top-right .dico-allegato-sub {
  font-size: 10px;
  font-style: italic;
}

.dico-sheet-main-title-box {
  border: 1.5px solid #000000;
  text-align: center;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.dico-sheet-main-title-box h1 {
  font-size: 14.5px;
  font-weight: 800;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.dico-text-block {
  text-align: justify;
  margin-bottom: 7px;
  font-size: 11px;
}

.dico-fill {
  font-weight: 800;
  color: #000000;
  border-bottom: 1px dotted #000000;
  padding: 0 4px;
  display: inline;
}

.dico-inline-box {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.2px solid #000000;
  vertical-align: middle;
  text-align: center;
  line-height: 12px;
  font-size: 11px;
  font-weight: 800;
  margin: 0 2px 2px 4px;
}

.dico-inline-box.checked::after {
  content: 'X';
  font-family: sans-serif;
  font-weight: 900;
  font-size: 11px;
}

.dico-note-gas-electric {
  font-size: 9.5px;
  font-style: italic;
  margin: 6px 0;
  line-height: 1.35;
}

.dico-center-heading {
  text-align: center;
  font-weight: 800;
  font-size: 13px;
  margin: 10px 0 6px 0;
  letter-spacing: 0.5px;
}

.dico-list-legal {
  list-style: none;
  padding-left: 0;
  margin: 5px 0 10px 0;
}

.dico-list-legal li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 4px;
  font-size: 10.5px;
  line-height: 1.35;
}

.dico-list-legal li .dico-inline-box {
  position: absolute;
  left: 0;
  top: 1px;
}

.dico-annexes-section {
  margin: 8px 0;
}

.dico-annexes-title {
  font-weight: 800;
  font-size: 11px;
  text-decoration: underline;
  margin-bottom: 4px;
}

.dico-declina-box {
  text-align: center;
  margin: 14px 0 8px 0;
}

.dico-declina-title {
  font-weight: 800;
  font-size: 12px;
  margin-bottom: 3px;
}

.dico-declina-text {
  font-size: 9.5px;
  line-height: 1.35;
  text-align: justify;
}

.dico-signatures-table {
  width: 100%;
  margin-top: 18px;
  border-collapse: collapse;
}

.dico-signatures-table td {
  vertical-align: top;
}

.dico-sig-col {
  width: 42%;
  text-align: center;
}

.dico-sig-role {
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 2px;
}

.dico-sig-sub {
  font-size: 9px;
  font-style: italic;
  color: #222;
  margin-bottom: 8px;
}

.dico-sig-space {
  height: 48px;
  border-bottom: 1px dotted #000000;
  margin-bottom: 4px;
  position: relative;
}

.dico-sig-name-print {
  font-size: 10px;
  font-weight: 700;
}

.dico-footer-avvertenze {
  margin-top: 18px;
  padding-top: 6px;
  border-top: 1px solid #000000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
}

/* ==========================================================================
   REGOLE DI STAMPA A4 UFFICIALE (@media print)
   ========================================================================== */

@media print {
  body * {
    visibility: hidden;
  }

  .app-sidebar,
  .app-topbar,
  .mobile-bottom-nav,
  .welcome-banner,
  .stats-grid,
  .quotes-panel,
  .modal-overlay:not(#modalDicoPrint),
  .modal-header,
  .modal-footer {
    display: none !important;
  }

  #modalDicoPrint,
  #modalDicoPrint * {
    visibility: visible;
  }

  #modalDicoPrint {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    height: auto !important;
    background: #ffffff !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    overflow: visible !important;
  }

  #modalDicoPrint .modal-card {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    box-shadow: none !important;
    border: none !important;
  }

  #modalDicoPrint .modal-header {
    display: none !important;
  }

  #modalDicoPrint .modal-body {
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    overflow: visible !important;
  }

  .dico-official-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 10mm 12mm !important;
    page-break-after: avoid;
    break-after: avoid;
    page-break-inside: avoid;
  }

  @page {
    size: A4 portrait;
    margin: 8mm 6mm;
  }
}

/* ==========================================================================
   STATO SITO & MODIFICA PASSWORD (LUXURY ERP UI COMPONENTS)
   ========================================================================== */

/* Modern iOS Luxury Switches */
.status-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}

.status-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.status-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 30px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.status-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: #ffffff;
  transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
}

.status-switch input:checked + .status-slider {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
}

.status-switch input:checked + .status-slider:before {
  transform: translateX(24px);
}

.status-switch.switch-danger input:checked + .status-slider {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.35);
}

/* Luxury Setting Cards & Layout */
.settings-dual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 1.5rem;
  margin-top: 1.25rem;
}

@media (max-width: 900px) {
  .settings-dual-grid {
    grid-template-columns: 1fr;
  }
}

.setting-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.setting-card:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.07);
  border-color: #cbd5e1;
}

.setting-card-header {
  padding: 1.25rem 1.5rem;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.setting-card-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.setting-icon-bubble {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.setting-icon-bubble.danger {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.setting-icon-bubble.warning {
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.setting-icon-bubble.primary {
  background: rgba(37, 99, 235, 0.12);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.setting-card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.setting-card-desc {
  margin: 0.2rem 0 0 0;
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.35;
}

.setting-card-body {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.setting-status-pill {
  padding: 0.85rem 1.15rem;
  border-radius: 10px;
  margin-bottom: 1.35rem;
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  line-height: 1.4;
  transition: all 0.2s ease;
}

.setting-field {
  margin-bottom: 1.15rem;
}

.setting-field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.85rem;
  color: #334155;
  margin-bottom: 0.45rem;
}

.setting-field-helper {
  font-size: 0.74rem;
  font-weight: 500;
  color: #94a3b8;
}

.setting-field input,
.setting-field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.92rem;
  color: #0f172a;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.7rem 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.setting-field input:focus,
.setting-field textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.setting-note-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #3b82f6;
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.35rem;
  font-size: 0.82rem;
  color: #475569;
  line-height: 1.45;
}

.setting-card-footer {
  padding: 1.15rem 1.5rem;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: auto;
}

/* Modifica Password Modal Specific Styles */
#changePasswordModal .modal-card {
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  overflow: hidden;
}

#changePasswordModal .modal-header {
  background: linear-gradient(135deg, #091322 0%, #17283c 100%);
  color: #ffffff;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#changePasswordModal .modal-header h3 {
  color: #ffffff;
}

#changePasswordModal .modal-close {
  color: #94a3b8;
}

#changePasswordModal .modal-close:hover {
  color: #ffffff;
}

#changePasswordModal .form-input {
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.75rem 2.8rem 0.75rem 0.95rem;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
}

#changePasswordModal .form-input:focus {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}



