/* ============================================================
   SISTEMIPOS CRM - Design System v2.0
   Mobile-First | Premium UI | Full CRM
   ============================================================ */

/* Google Fonts & Material Symbols are preconnected and loaded directly in index.php to avoid CSS import waterfall */

/* ---- VARIABILI ---- */
:root {
  --primary:        #2563eb;
  --primary-rgb:    37, 99, 235;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --secondary:      #64748b;
  --success:        #059669;
  --success-rgb:    5, 150, 105;
  --danger:         #dc2626;
  --danger-rgb:     220, 38, 38;
  --warning:        #d97706;
  --warning-rgb:    217, 119, 6;
  --info:           #0891b2;
  --info-rgb:       8, 145, 178;
  --purple:         #7c3aed;

  --sidebar-bg:     #0f172a;
  --sidebar-w:      260px;
  --sidebar-w-col:  70px;
  --sidebar-text:   #94a3b8;
  --sidebar-hover:  rgba(255,255,255,0.07);
  --topbar-h:       64px;

  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --border:         #e2e8f0;
  --text:           #0f172a;
  --text-muted:     #64748b;

  --radius-sm:      8px;
  --radius:         12px;
  --radius-lg:      16px;
  --radius-xl:      24px;

  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:         0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg:      0 10px 40px rgba(0,0,0,0.1);

  --transition:     0.2s cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 0.35s cubic-bezier(0.4,0,0.2,1);
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { 
  font-size: 16px; 
  scroll-behavior: smooth; 
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto; /* Abilita sempre scroll verticale naturale */
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }

/* ---- MATERIAL ICONS ---- */
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal; font-style: normal;
  font-size: 20px; line-height: 1; display: inline-block;
  white-space: nowrap; direction: ltr; vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  user-select: none; flex-shrink: 0;
}
.icon-fill { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }

/* ---- iOS TOUCH FIX (elimina delay 300ms tap) ---- */
button, a, .btn, .nav-item, .icon-btn, .filter-chip, .kpi-card, .search-result-item {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0.05);
}

/* ============================================================
   APP LAYOUT
   ============================================================ */

#app-root {
  display: flex;
  min-height: 100vh;
}

/* ---- SIDEBAR ---- */
#sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 1000;
  transition: transform var(--transition-slow), width var(--transition-slow);
  overflow: hidden;
  box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}

.sidebar-nav {
  flex: 1;
  padding: 10px 15px; /* Ridotto padding per evitare tagli testo */
  overflow-y: auto;
  scrollbar-width: thin;
}

/* ---- SIDEBAR COLLASSATA (desktop) ---- */
#sidebar.collapsed {
  width: var(--sidebar-w-col);
}
#sidebar.collapsed .brand-name,
#sidebar.collapsed .brand-sub,
#sidebar.collapsed .nav-item span:not(.material-symbols-outlined),
#sidebar.collapsed .nav-section,
#sidebar.collapsed .nav-divider,
#sidebar.collapsed .user-mini-info,
#sidebar.collapsed .user-mini .icon-btn,
#sidebar.collapsed .nav-item-badge {
  display: none;
}
#sidebar.collapsed .sidebar-brand { justify-content: center; padding: 18px 0; }
#sidebar.collapsed .sidebar-nav   { padding: 14px 8px; }
#sidebar.collapsed .nav-item      { justify-content: center; padding: 10px 0; gap: 0; }
#sidebar.collapsed .nav-cta       { margin: 0 2px 8px; }
#sidebar.collapsed .sidebar-footer { padding: 10px 0; }
#sidebar.collapsed .user-mini     { justify-content: center; padding: 10px 0; gap: 0; }

/* Tooltip on collapsed nav items */
#sidebar.collapsed .nav-item { position: relative; }
#sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(var(--sidebar-w-col) - 6px);
  top: 50%; transform: translateY(-50%);
  background: #1e293b;
  color: #e2e8f0;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 2000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
#sidebar.collapsed .nav-item:hover::after { opacity: 1; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  min-height: var(--topbar-h);
  overflow: hidden;
  white-space: nowrap;
  text-decoration: none;
}
.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(37,99,235,0.4);
}
.brand-icon .material-symbols-outlined { font-size: 20px; color: #fff; }
.brand-name {
  font-size: 1rem; font-weight: 800;
  color: #f1f5f9;
  letter-spacing: -0.02em;
  transition: opacity var(--transition);
}
.brand-sub {
  font-size: 0.62rem; color: var(--sidebar-text);
  display: block; margin-top: 1px;
  letter-spacing: 0.06em; text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.nav-section {
  padding: 16px 10px 6px;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(148,163,184,0.5);
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  overflow: hidden;
  position: relative;
  z-index: 10;
  pointer-events: auto !important;
  -webkit-user-select: none;
  user-select: none;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}
.nav-item.active {
  background: rgba(37,99,235,0.2);
  color: #60a5fa;
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
}
.nav-item .material-symbols-outlined { font-size: 20px; flex-shrink: 0; }
.nav-item-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 10px 10px;
}

/* Nuovo Intervento Button */
.nav-cta {
  background: linear-gradient(135deg, var(--primary), #7c3aed) !important;
  color: #fff !important;
  margin: 0 2px 8px;
  font-weight: 700 !important;
  box-shadow: 0 4px 15px rgba(37,99,235,0.3);
}
.nav-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37,99,235,0.4);
  color: #fff !important;
  background: linear-gradient(135deg, #1d4ed8, #6d28d9) !important;
}
.nav-cta .material-symbols-outlined { color: #fff; }

.nav-cta-blue {
  background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
  color: #fff !important;
  margin: 0 2px 8px;
  font-weight: 700 !important;
  box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}
.nav-cta-blue:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
  color: #fff !important;
  background: linear-gradient(135deg, #0284c7, #1d4ed8) !important;
}
.nav-cta-blue .material-symbols-outlined { color: #fff; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.user-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  white-space: nowrap;
}
.user-mini-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.user-mini-info { flex: 1; overflow: hidden; }
.user-mini-name { font-size: 0.8rem; color: #e2e8f0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.user-mini-role { font-size: 0.65rem; color: var(--sidebar-text); }

/* Sidebar Overlay for Mobile */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.15); /* Molto leggero - come Android */
  z-index: 999;
  /* NOTA: backdrop-filter rimosso - causa offuscamento sidebar su iOS Safari */
}

/* ---- MAIN WRAPPER ---- */
#main-wrapper {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w)); /* Forza larghezza corretta */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  flex: 1;
  transition: margin-left var(--transition-slow);
  background: var(--bg);
}
#main-wrapper.sidebar-collapsed {
  margin-left: var(--sidebar-w-col);
  width: calc(100% - var(--sidebar-w-col));
}

/* ---- TOPBAR ---- */
#topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  padding: 0 24px; /* Default */
}

@media (max-width: 768px) {
  #topbar { padding: 0 16px; } 
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.page-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.icon-btn {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm); transition: var(--transition);
  position: relative;
}
.icon-btn:hover { background: var(--bg); color: var(--primary); transform: scale(1.05); }
.icon-btn .material-symbols-outlined { font-size: 20px; }
.notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  border: 2px solid var(--surface);
}
.notif-badge {
  position: absolute; top: -2px; right: -2px;
  background: var(--danger); color: #fff;
  font-size: 0.65rem; font-weight: 800;
  min-width: 18px; height: 18px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.notif-badge.badge-empty {
  background: var(--secondary);
  opacity: 0.7;
}
.notif-badge.badge-orange {
  background: #ea6c0a;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.notif-badge.badge-red {
  background: var(--danger);
  color: #fff;
}
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px 6px 6px;
  border-radius: 40px;
  background: var(--bg);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 250px;
}
.topbar-user:hover { box-shadow: var(--shadow-sm); background: var(--surface-2); }
.topbar-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.topbar-info { display: flex; flex-direction: column; line-height: 1.2; overflow: hidden; }
.topbar-username { font-size: 0.85rem; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.topbar-role { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; }

/* ---- APP CONTENT ---- */
#app-content {
  flex: 1;
  padding: 24px;
  width: 100%;
  max-width: 100%; /* Rimosso limite 1600px per visione a tutto schermo */
  margin: 0;
}

.wizard-grid-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 1100px) {
  .wizard-grid-layout { grid-template-columns: 1.5fr 1fr; gap: 16px; }
}

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

/* Forza singola colonna su mobile anche contro inline style del wizard */
@media (max-width: 768px) {
  .wizard-grid-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    width: 100% !important;
  }
}

/* ---- WIZARD STEPS BAR ---- */
.wizard-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}
.step {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: default;
  flex-shrink: 0;
}
.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.step-txt {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: color var(--transition);
  white-space: nowrap;
}
.step.active .step-num {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}
.step.active .step-txt {
  color: var(--primary);
}
.step.done .step-num {
  background: var(--success);
  color: #fff;
}
.step.done .step-txt {
  color: var(--success);
}
.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 12px;
  min-width: 30px;
  border-radius: 2px;
  transition: background var(--transition);
}

@media (max-width: 768px) {
  .wizard-steps {
    padding: 10px 12px;
    margin-bottom: 16px;
    gap: 0;
    border-radius: 0 !important;
    border-left: none;
    border-right: none;
  }
  .step { gap: 6px; }
  .step-num { width: 26px; height: 26px; font-size: 0.78rem; }
  .step-txt { font-size: 0.7rem; }
  .step-line { min-width: 16px; margin: 0 6px; }
}

/* ============================================================
   COMPONENTI UI
   ============================================================ */

/* ---- VIEW HEADER ---- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.view-title h2 {
  font-size: 1.5rem; font-weight: 800;
  color: var(--text); margin: 0;
  letter-spacing: -0.02em;
}
.view-title p {
  margin: 4px 0 0;
  font-size: 0.8rem; color: var(--text-muted);
}
.view-actions {
  display: flex; gap: 10px; flex-wrap: wrap; flex-shrink: 0;
}

/* ---- BREADCRUMB ---- */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.75rem; color: var(--text-muted);
}
.breadcrumb-sep { color: var(--border); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.875rem;
  cursor: pointer; transition: var(--transition);
  border: none; font-family: 'Inter', sans-serif;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn .material-symbols-outlined { font-size: 18px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 26px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* ---- CARDS / PANELS ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-body { padding: 20px; }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 0.9rem;
}
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* Legacy .panel support */
.panel { background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); overflow: hidden; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.panel-header { padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 0.9rem; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-body { padding: 20px; }

/* ---- KPI GRID ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  padding: 20px;
  border-radius: var(--radius-lg);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  user-select: none;
}
.kpi-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0,0,0,0.25);
  filter: brightness(1.1);
}
.kpi-card:active {
  transform: translateY(-2px) scale(0.98);
}
.kpi-card.active {
  box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--primary);
  z-index: 2;
}
.kpi-card::after {
  content: '';
  position: absolute; top: -15px; right: -15px;
  width: 70px; height: 70px;
  background: rgba(255,255,255,0.12);
  border-radius: 50%;
}
.kpi-card::before {
  content: '';
  position: absolute; bottom: -20px; right: -5px;
  width: 50px; height: 50px;
  background: rgba(255,255,255,0.07);
  border-radius: 50%;
}
.kpi-icon {
  background: rgba(255,255,255,0.2);
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; z-index: 1;
}
.kpi-icon .material-symbols-outlined { font-size: 24px; }
.kpi-info { flex: 1; z-index: 1; }
.kpi-number { font-size: 2rem; font-weight: 800; line-height: 1; }
.kpi-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; opacity: 0.85; margin-top: 3px; letter-spacing: 0.05em; }
.kpi-link { font-size: 0.72rem; opacity: 0.75; display: inline-flex; align-items: center; gap: 2px; margin-top: 6px; cursor: pointer; }
.kpi-link:hover { opacity: 1; }
.kpi-card.loading { background: #e2e8f0; box-shadow: none; min-height: 90px; }

/* ---- DATA TABLE ---- */
.table-container {
  overflow-x: auto;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table thead { background: var(--surface-2); }
.data-table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .actions { display: flex; gap: 6px; align-items: center; }

/* ---- RESPONSIVE TABLE TO CARDS ---- */
@media (max-width: 500px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { 
    margin-bottom: 16px; 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .data-table td { 
    text-align: right; 
    padding: 12px 16px; 
    position: relative; 
    border-bottom: 1px solid var(--surface-2); 
    min-height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    margin-top: 2px;
  }
  .data-table td > * {
    text-align: right;
    word-break: break-word;
  }
  .data-table td:last-child { border-bottom: none; background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
  .data-table .actions { justify-content: flex-end; width: 100%; }
}

/* Allineamento a sinistra opzionale per tabelle specifiche */
@media (max-width: 500px) {
  .table-mobile-left td { justify-content: flex-start; text-align: left; }
  .table-mobile-left td > * { text-align: left; }
  .table-mobile-left .actions { justify-content: flex-start; }
}

/* ---- BADGES / STATUS ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700;
  white-space: nowrap;
}
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-teal   { background: #ccfbf1; color: #0f766e; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-black  { background: #000000; color: #ffffff; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 12px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
label {
  display: block;
  font-size: 0.8rem; font-weight: 600;
  color: var(--text); margin-bottom: 4px;
}
label .req { color: var(--danger); margin-left: 2px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select, textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 12px;
  padding-right: 36px;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
input::placeholder, textarea::placeholder { color: #cbd5e1; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 5px; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 5px; }

/* ---- SIGNATURE PAD ---- */
.signature-wrap {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  overflow: hidden;
  position: relative;
}
.signature-wrap canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
}
.signature-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; color: var(--text-muted);
  pointer-events: none;
  gap: 6px;
}

/* ---- MODALS ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.6);
  z-index: 5000;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeModal 0.2s ease;
}
@keyframes fadeModal { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-lg);
  animation: slideModal 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-xl { max-width: 1000px; }
.modal-xxl { max-width: 1300px; }
.modal-xxxl { max-width: 1500px; }
@keyframes slideModal { from { transform: translateY(20px) scale(0.97); } to { transform: translateY(0) scale(1); } }
.modal-header {
  padding: 20px 24px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-body { 
  padding: 24px; 
  overflow-y: auto; 
  flex: 1;
  scrollbar-width: thin;
}
.modal-footer { 
  padding: 16px 24px; 
  border-top: 1px solid var(--border); 
  display: flex; 
  gap: 10px; 
  justify-content: flex-end; 
  background: var(--surface-2); 
  border-radius: 0 0 var(--radius-xl) var(--radius-xl); 
  flex-shrink: 0;
}

/* ---- TOAST ---- */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 14px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 600; font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 280px; max-width: 380px;
  pointer-events: auto;
}
@keyframes toastIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { background: linear-gradient(135deg, var(--success), #047857); }
.toast-danger   { background: linear-gradient(135deg, var(--danger), #b91c1c); }
.toast-warning  { background: linear-gradient(135deg, var(--warning), #b45309); }
.toast-info     { background: linear-gradient(135deg, var(--info), #0e7490); }

/* ---- SMART NOTIFICATIONS (PWA) ---- */
.smart-notif-card {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  color: #fff;
  padding: 0;
  width: 320px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  overflow: hidden;
  margin-bottom: 12px;
}
.smart-notif-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.smart-notif-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}
.smart-notif-brand img {
  width: 20px;
  height: 20px;
  border-radius: 4px;
}
.smart-notif-header button {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}
.smart-notif-body {
  padding: 14px;
}
.smart-notif-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: #fff;
}
.smart-notif-text {
  font-size: 0.8rem;
  color: #94a3b8;
  line-height: 1.4;
}

.fade-in { animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
.fade-out { animation: toastIn 0.3s ease reverse forwards; }

/* ---- LOADER ---- */
#loader {
  position: fixed; inset: 0;
  background: rgba(241,245,249,0.8);
  backdrop-filter: blur(4px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 4000; /* Sotto le modali (5000) */
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { font-size: 0.875rem; color: var(--text-muted); font-weight: 500; }

/* ---- LOGIN PAGE ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-visual {
  display: none !important;
}

.login-form-side {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 50px 48px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-form-title { font-size: 1.5rem; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.login-form-sub { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 36px; }
.login-logo-mobile { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 30px; }
.login-logo-mobile .brand-icon { width: 64px; height: 64px; border-radius: 18px; }
.login-logo-mobile .brand-icon .material-symbols-outlined { font-size: 34px; }
.login-logo-mobile .brand-name { font-size: 1.4rem; font-weight: 800; color: var(--text); }

.login-error {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 18px;
  display: flex; align-items: center; gap: 8px;
  width: 100%;
}
.login-divider { display: none; }

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .material-symbols-outlined { font-size: 48px; opacity: 0.3; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 0.875rem; }

/* ---- FILTERS ROW ---- */
.filters-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.filter-chip {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: var(--transition);
}
.filter-chip.active, .filter-chip:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---- SEARCH BOX ---- */
.search-box {
  position: relative;
  flex: 1;
  min-width: 180px;
}
.search-box input {
  padding-left: 38px !important;
}
.search-box .material-symbols-outlined {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--text-muted);
}

/* ---- RESPONSIVE / MOBILE ---- */
@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  /* Sidebar Drawer Mobile */
  #sidebar {
    transform: translateX(-100%);
    -webkit-transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    z-index: 999999 !important; /* Estremamente alto */
    will-change: transform;
    pointer-events: auto !important;
    visibility: visible !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  
  #sidebar-nav {
    height: auto !important;
    overflow: visible !important;
  }

  .nav-item {
    padding: 12px 16px !important;
  }
  
  #sidebar.mobile-open {
    transform: translateX(0) !important;
    -webkit-transform: translateX(0) !important;
  }

  #sidebar-overlay {
    z-index: 999998 !important;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  #sidebar-overlay.active {
    display: block !important;
    pointer-events: auto !important;
    opacity: 1;
  }

  #main-wrapper { margin-left: 0 !important; }
  #topbar { padding: 0 16px; } 
  #app-content { padding: 12px 8px; width: 100%; box-sizing: border-box; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi-card { padding: 16px; gap: 12px; }
  .kpi-number { font-size: 1.6rem; }

  .view-header { margin-bottom: 16px; }
  .view-title h2 { font-size: 1.2rem; }

  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  .login-visual { display: none; }
  .login-form-side { width: 100%; padding: 30px 24px; }
  .login-logo-mobile { display: flex; }

  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 10px 10px; }

  /* Hide less important columns and info on mobile */
  .data-table .hide-mobile { display: none; }
  .topbar-info { display: none !important; }
  .topbar-user { padding: 4px; border-radius: 50%; }
  .breadcrumb { display: none !important; }
  .page-subtitle { display: none; }

  #toast-container {
    right: 16px;
    left: 16px;
    top: env(safe-area-inset-top, 20px);
    bottom: auto !important;
    z-index: 99999999;
  }
  .toast { min-width: auto; max-width: calc(100vw - 32px); }

  /* Admin tabs vertical */
  .admin-tabs { flex-direction: column; gap: 8px; border-bottom: none; background: transparent; padding: 0; }
  .admin-tab-btn { width: 100%; text-align: left; border-bottom: 1px solid var(--border) !important; border-radius: var(--radius-sm) !important; padding: 12px 16px; background: var(--surface); }
  .admin-tab-btn.active { background: var(--primary-light); color: var(--primary); border-left: 4px solid var(--primary) !important; }

  /* Forms optimization */
  .form-group { margin-bottom: 20px; }
  label { font-size: 0.9rem; margin-bottom: 8px; }
  input, select, textarea { padding: 14px; font-size: 1rem; border-radius: var(--radius); }

  /* View actions stacking */
  .view-actions { width: 100%; display: grid; grid-template-columns: 1fr; gap: 10px; }
  .view-actions .btn { width: 100%; justify-content: center; padding: 14px; }

  /* KPI adjustment (Rimosso per evitare conflitti) */
  
  /* Modals full screen */
  .modal { height: 100%; max-height: 100vh; border-radius: 0; display: flex; flex-direction: column; max-width: 100% !important; margin: 0; }
  .modal-body { flex: 1; overflow-y: auto; padding: 16px; }
  .modal-header, .modal-footer { position: sticky; z-index: 10; background: #fff; }
  .modal-header { top: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .modal-footer { bottom: 0; border-top: 1px solid var(--border); padding: 12px 16px; }
  
  .card-body { padding: 16px; }
  .card-header { padding: 12px 16px; }
  .card-footer { padding: 12px 16px; }
}

@media (max-width: 480px) {
  :root { --topbar-h: 70px; }
  .page-title { font-size: 1.1rem; }
  .breadcrumb { display: none; } /* Simplify topbar */

  /* kpi-grid gestito da blocco principale */
  .kpi-card { padding: 18px; }
  
  /* Bottom navigation simulation for quick actions if needed */
  .mobile-quick-actions {
    position: fixed; bottom: 20px; right: 20px;
    z-index: 900;
  }
  .btn-fab {
    width: 60px; height: 60px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 25px rgba(37,99,235,0.4);
  }
}

/* ---- ANIMATIONS ---- */
.fade-in {
  animation: fadeIn 0.35s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.slide-in {
  animation: slideIn 0.3s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- UTILITY ---- */
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.fw-medium { font-weight: 500; }
.small { font-size: 0.8rem; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.overflow-x-auto { overflow-x: auto; }

/* KPI Mobile Accordion */
.kpi-mobile-content {
  animation: slideDown 0.3s ease-out;
  overflow: hidden;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); max-height: 0; }
  to { opacity: 1; transform: translateY(0); max-height: 2000px; }
}
@media (max-width: 768px) {
  .kpi-mobile-content {
    grid-column: 1 / -1;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .kpi-grid { 
    display: flex !important; 
    flex-direction: column !important; 
    gap: 16px !important; 
    width: 100% !important;
  }
  .kpi-card { padding: 16px; gap: 12px; }
  .kpi-number { font-size: 1.6rem; }

  .view-header { margin-bottom: 16px; }
  .view-title h2 { font-size: 1.2rem; }

  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  .login-visual { display: none; }
  .login-form-side { width: 100%; padding: 30px 24px; }
  .login-logo-mobile { display: flex; }

  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 10px 10px; }

  /* Hide less important columns and info on mobile */
  .data-table .hide-mobile { display: none; }
  .topbar-info { display: none !important; }
  .topbar-user { padding: 4px; border-radius: 50%; }
  .breadcrumb { display: none !important; }
  .page-subtitle { display: none; }

  .toast { min-width: auto; max-width: calc(100vw - 32px); }

  /* Admin tabs vertical */
  .admin-tabs { flex-direction: column; gap: 8px; border-bottom: none; background: transparent; padding: 0; }
  .admin-tab-btn { width: 100%; text-align: left; border-bottom: 1px solid var(--border) !important; border-radius: var(--radius-sm) !important; padding: 12px 16px; background: var(--surface); }
  .admin-tab-btn.active { background: var(--primary-light); color: var(--primary); border-left: 4px solid var(--primary) !important; }

  /* Forms optimization */
  .form-group { margin-bottom: 20px; }
  label { font-size: 0.9rem; margin-bottom: 8px; }
  input, select, textarea { padding: 14px; font-size: 1rem; border-radius: var(--radius); }

  /* View actions stacking */
  .view-actions { width: 100%; display: grid; grid-template-columns: 1fr; gap: 10px; }
  .view-actions .btn { width: 100%; justify-content: center; padding: 14px; }

  /* KPI adjustment */
  .kpi-grid { grid-template-columns: 1fr; gap: 12px; }
  
  /* Modals full screen */
  .modal { height: 100%; max-height: 100vh; border-radius: 0; display: flex; flex-direction: column; max-width: 100% !important; margin: 0; }
  .modal-body { flex: 1; overflow-y: auto; padding: 16px; }
  .modal-header, .modal-footer { position: sticky; z-index: 10; background: #fff; }
  .modal-header { top: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; }
  .modal-footer { bottom: 0; border-top: 1px solid var(--border); padding: 12px 16px; }
  
  .card-body { padding: 16px; }
  .card-header { padding: 12px 16px; }
  .card-footer { padding: 12px 16px; }
}

@media (max-width: 480px) {
  :root { --topbar-h: 70px; }
  .page-title { font-size: 1.1rem; }
  .breadcrumb { display: none; } /* Simplify topbar */

  .kpi-grid { grid-template-columns: 1fr; } /* Stack KPIs on very small screens */
  .kpi-card { padding: 18px; }
  
  /* Bottom navigation simulation for quick actions if needed */
  .mobile-quick-actions {
    position: fixed; bottom: 20px; right: 20px;
    z-index: 900;
  }
  .btn-fab {
    width: 60px; height: 60px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 25px rgba(37,99,235,0.4);
  }
}

/* ---- ANIMATIONS ---- */
.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

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

.slide-in {
  animation: slideIn 0.3s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- UTILITY ---- */
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.fw-medium { font-weight: 500; }
.small { font-size: 0.8rem; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-3 { margin-bottom: 12px; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.w-100 { width: 100%; }
.overflow-x-auto { overflow-x: auto; }

/* KPI Mobile Accordion */
.kpi-mobile-content {
  animation: slideDown 0.3s ease-out;
  overflow: hidden;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); max-height: 0; }
  to { opacity: 1; transform: translateY(0); max-height: 2000px; }
}
@media (max-width: 768px) {
  .kpi-mobile-content {
    grid-column: 1 / -1;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: 15px;
  }
  .hide-on-mobile {
    display: none !important;
  }
}

.call-notification {
    bottom: 24px;
    right: 24px;
    width: 340px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 50px rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    z-index: 10000;
    padding: 20px;
    animation: callSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@keyframes callSlideIn {
    from { transform: translateX(100%) scale(0.9); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

.call-notification .close-btn {
    position: absolute; top: 10px; right: 10px;
    cursor: pointer; opacity: 0.5;
}

.call-notification .close-btn:hover { opacity: 1; }

.call-notification h4 { 
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; 
    margin: 0; display: flex; align-items: center; gap: 6px;
}

.call-notification .client-name { font-size: 1.1rem; font-weight: 800; color: var(--text); }
.call-notification .phone-num { font-size: 1.2rem; color: var(--primary); font-weight: 700; font-family: monospace; }

/* Animazione Chiamata in Arrivo */
.pulse-call {
    animation: pulse-red 2s infinite;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.pulse {
    animation: pulse-red 2s infinite;
    border-radius: 50%;
}

.call-popup {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 350px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 9999;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.call-popup-header {
    background: var(--primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.call-popup-body {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.call-popup-footer {
    padding: 12px 20px;
    background: var(--surface-2);
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

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

/* ---- SEARCH RESULTS ENHANCEMENT ---- */
.search-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
    background: var(--surface);
}
.search-result-item:hover {
    background: var(--primary-light);
}
.search-result-item.blocked {
    background: #fff5f5;
    border-left: 4px solid var(--danger);
}
.search-result-item.blocked strong {
    color: var(--danger);
}

/* ?? Cascata Documentale Preview */
.doc-preview-item { transition: transform 0.2s; }
.doc-preview-item:hover { transform: translateY(-5px); }
.doc-preview-item img { box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); transition: box-shadow 0.2s; }
.doc-preview-item:hover img { box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); }

/* Forza visibilità filtri dashboard */
.card-header .filters-row { display: flex !important; }


/* ============================================================
   TOGGLE SWITCH (iOS Style)
   ============================================================ */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 24px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
input:checked + .slider {
  background-color: var(--primary);
}
input:focus + .slider {
  box-shadow: 0 0 1px var(--primary);
}
input:checked + .slider:before {
  transform: translateX(22px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}
/* ============================================================
   MOBILE OPTIMIZATION & AUTOSIZE (v301)
   ============================================================ */

/* Stabilizzazione Viewport Mobile (Consolidata) */
html, body { 
    width: 100%; 
    height: auto !important; /* Forza altezza naturale per permettere lo scroll */
    min-height: 100vh;
    overflow-x: hidden !important; 
    overflow-y: visible !important; /* Permetti lo scroll verticale naturale su tutto il documento */
    position: relative; 
    margin: 0; 
    padding: 0; 
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    /* Reset Strutturale Layout Mobile */
    #app-root {
        display: block !important;
        width: 100% !important;
        min-height: 100vh !important;
        overflow-x: hidden !important;
    }
    
    #main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0 !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        min-height: 100vh;
        display: flex !important; 
        flex-direction: column !important;
    }

    #topbar {
        padding: 0 10px !important;
        height: 60px !important;
    }
    .page-title { font-size: 1.1rem !important; }
    .breadcrumb { display: none !important; } /* Nascondi breadcrumb per spazio */
    
    #app-content {
        padding: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Ottimizzazione Stepper Wizard su Mobile */
    .wizard-steps {
        padding: 10px 12px !important;
        margin-bottom: 16px !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }
    .step { gap: 6px !important; }
    .step-num { width: 24px !important; height: 24px !important; font-size: 0.75rem !important; }
    .step-txt { font-size: 0.68rem !important; }
    .step-line { min-width: 12px !important; margin: 0 4px !important; }

    /* Fix per la Login su schermi stretti */
    .login-form-side {
        padding: 40px 20px !important;
        max-width: 95% !important;
        margin: 20px auto !important;
    }
    .login-visual { display: none !important; }

    /* Griglie e Card */
    .form-row, .form-row-3, .wizard-grid-layout, .kpi-grid, .dashboard-grid, .grid-2, .grid-3, .area-cliente-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        width: 100% !important;
    }
    .card {
        margin: 0 0 15px 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        border-radius: 0 !important; /* Su mobile meglio senza bordi arrotondati per guadagnare spazio */
        box-sizing: border-box !important;
    }
    .card-body { padding: 15px !important; }

    /* Input e Bottoni */
    /* Escludi .icon-btn e .mobile-only (bottoni speciali) dalla larghezza 100% */
    .btn:not(.icon-btn):not(.mobile-only) { width: 100% !important; justify-content: center !important; }
    .view-actions { flex-direction: column !important; width: 100% !important; }
    input, select, textarea { font-size: 16px !important; width: 100% !important; }

    /* Tabelle Responsive */
    .table-container {
        margin: 0 !important;
        width: 100% !important;
        border-radius: 8px !important;
    }

    /* Nascondi elementi ingombranti */
    #btn-push-notif, .breadcrumb { display: none !important; }
}

/* Fix per schermi ultra-piccoli (iPhone SE, etc) */
@media (max-width: 380px) {
    .page-title { font-size: 0.9rem !important; }
    /* Topbar Mobile: Massima Pulizia */
    .topbar-right .icon-btn#btn-push-notif,
    .topbar-right .icon-btn#btn-notif-alerts,
    .topbar-right .topbar-user { 
        display: none !important; 
    }
    .topbar-right { gap: 5px !important; }
    
    /* Ingrandimento pulsanti Foto per Touch */
    .foto-placeholder .btn-sm {
        padding: 12px 8px !important;
        font-size: 11px !important;
        height: auto !important;
    }
    .foto-slot {
        min-height: 180px !important;
    }

    /* Sidebar Mobile Scroll Fix gestito da blocco 768px */
}

/* Visibilità Esclusiva Mobile (nascosto su Desktop) */
.mobile-only {
    display: none !important;
}
@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex !important;
    }
}
    .foto-placeholder .btn {
        font-size: 11px !important;
        padding: 10px 5px !important;
        min-height: 40px;
    }
    .foto-placeholder .material-symbols-outlined {
        font-size: 38px !important;
    }
    .foto-slot {
        min-height: 180px !important;
    }
}

/* ---- UTILITIES DASHBOARD (v396) ---- */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    max-height: 2.8em;
}
.text-truncate-single {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
    text-align: left;
}
.col-tecnico {
    white-space: nowrap !important;
    min-width: 120px;
}
.col-problema {
    max-width: 280px;
    min-width: 200px;
}
@media (max-width: 768px) {
    .col-problema { min-width: 0 !important; max-width: none !important; }
    .text-truncate-single { text-align: right; }
    .col-tecnico { min-width: 0 !important; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

.scale-in {
  animation: scaleIn 0.3s ease forwards;
}

/* Delay per grid items */
.fade-in:nth-child(2) { animation-delay: 0.1s; }
.fade-in:nth-child(3) { animation-delay: 0.15s; }
.fade-in:nth-child(4) { animation-delay: 0.2s; }
.fade-in:nth-child(5) { animation-delay: 0.25s; }

/* MODAL MEDIA (FOTO/VIDEO) */
.photo-source-mini { padding: 15px 0; display: flex; flex-direction: column; gap: 20px; align-items: center; width: 100%; }
.photo-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; }
.photo-opt { 
    display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important; gap: 10px;
    padding: 20px 10px; border-radius: 20px; cursor: pointer; transition: all 0.25s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08); border: 2px solid transparent;
}
.photo-opt:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(0,0,0,0.12); }
.btn-camera { background: var(--primary); color: white; border: none; }
.btn-gallery { background: white; color: var(--primary); border: 2px solid var(--primary); }
.photo-opt span.material-symbols-outlined { font-size: 36px !important; }
.photo-opt span:not(.material-symbols-outlined) { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-cancel-mini { 
    all: unset; display: inline-block;
    color: var(--text-muted); font-weight: 700; 
    font-size: 0.85rem; padding: 12px 24px; cursor: pointer; 
    text-transform: uppercase; transition: color 0.2s;
    text-align: center; width: auto;
}
.btn-cancel-mini:hover { color: var(--danger); }
.modal-foto-compact { 
    max-width: 340px !important; 
    border-radius: 28px !important; 
    margin: auto !important; 
    height: auto !important;
    min-height: 0 !important;
    padding: 10px !important;
}

/* ============================================================
   CLIENTS & PDV MOBILE OPTIMIZATION
   ============================================================ */


/* Griglia PDV standard */
.pdv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* Pulsanti e azioni card PDV standard */
.pdv-actions-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.pdv-card-buttons {
  display: flex;
  gap: 8px;
}

/* Media Query per smartphone e tablet piccoli */
@media (max-width: 500px) {
  /* Forza flex-wrap per le azioni principali solo su mobile per evitare overflow */
  .data-table .actions {
    flex-wrap: wrap !important;
  }

  /* Layout a blocco per evitare lo schiacciamento laterale dei testi e la deformazione delle colonne */
  .table-mobile-left td {
    display: block !important;
    text-align: left !important;
    padding: 10px 16px !important;
    min-height: auto !important;
    border-bottom: 1px solid var(--surface-2) !important;
  }
  
  .table-mobile-left td::before {
    display: block !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    font-size: 0.65rem !important;
    color: var(--text-muted) !important;
    text-align: left !important;
    margin-bottom: 4px !important;
  }
  
  .table-mobile-left td > * {
    text-align: left !important;
  }
  
  /* Cella speciale per le azioni del cliente a fondo card */
  .data-table td[data-label="Azioni"] {
    display: block !important;
    text-align: center !important;
    background: var(--surface-2) !important;
    border-top: 1px solid var(--border) !important;
    border-radius: 0 0 var(--radius) var(--radius) !important;
    padding: 10px 16px !important;
  }
  
  .data-table td[data-label="Azioni"]::before {
    display: none !important; /* Nasconde l'etichetta AZIONI */
  }
  
  .data-table td[data-label="Azioni"] .actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: space-evenly !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
  }
  
  .data-table td[data-label="Azioni"] .actions .btn {
    display: inline-flex !important;
    width: auto !important;
    height: auto !important;
    padding: 8px !important;
    margin: 0 !important;
  }

  /* Di default su mobile nascondiamo la riga dei PDV se non è esplicitamente contrassegnata come aperta */
  .data-table tr.pdv-expand-row {
    display: none !important;
  }
  
  /* Impedisce che la riga espandibile dei PDV subisca la trasformazione card di default delle tabelle */
  .data-table tr.pdv-expand-row.open {
    display: block !important;
    margin-top: -16px !important; /* Si fonde con la riga/card del cliente soprastante */
    margin-bottom: 16px !important;
    border: 1px solid var(--border) !important;
    border-top: none !important;
    border-radius: 0 0 var(--radius) var(--radius) !important;
    box-shadow: none !important;
    background: rgba(37, 99, 235, 0.02) !important;
    padding: 0 !important;
    overflow: hidden;
  }
  
  .data-table tr.pdv-expand-row td {
    display: block !important;
    width: 100% !important;
    text-align: left !important;
    padding: 0 !important;
    border-bottom: none !important;
    min-height: auto !important;
  }
  
  /* Rimuove l'etichetta prima della riga espandibile */
  .data-table tr.pdv-expand-row td::before {
    display: none !important;
  }
  
  /* Adatta il contenitore espandibile a piccoli schermi */
  .pdv-list-expanded {
    padding: 12px 10px !important;
    border-left-width: 3px !important;
  }
  
  /* Griglia PDV a colonna singola su mobile */
  .pdv-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  
  /* Dispone i pulsanti di azione in orizzontale per un tocco agevole */
  .pdv-actions-group {
    flex-direction: row !important;
    gap: 8px !important;
  }
  
  /* Impila i pulsanti principali verticalmente a larghezza intera */
  .pdv-card-buttons {
    flex-direction: column !important;
    gap: 6px !important;
  }
  
  .pdv-card-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
    padding: 10px !important;
    font-size: 0.8rem !important;
    height: 38px !important; /* Touch friendly height */
  }
}
