/* ==========================================================================
   SIH Premium Design System
   Shared design tokens + utility classes for all workflow pages.
   Usage: <link rel="stylesheet" href="/sih-premium.css"> in <head>.
   Non-invasive: adds classes on top of existing page <style> blocks.
   ========================================================================== */

:root {
  /* Brand */
  --sih-purple-50:  #F5F3FF;
  --sih-purple-100: #EDE9FE;
  --sih-purple-200: #DDD6FE;
  --sih-purple-300: #C4B5FD;
  --sih-purple-500: #8B5CF6;
  --sih-purple-600: #7C3AED;
  --sih-purple-700: #6D28D9;
  --sih-purple-900: #4C1D95;

  --sih-green-50:   #ECFDF5;
  --sih-green-500:  #10B981;
  --sih-green-700:  #047857;

  --sih-amber-50:   #FFFBEB;
  --sih-amber-500:  #F59E0B;
  --sih-amber-700:  #B45309;

  --sih-red-50:     #FEF2F2;
  --sih-red-500:    #EF4444;
  --sih-red-700:    #B91C1C;

  --sih-slate-50:   #F8FAFC;
  --sih-slate-100:  #F1F5F9;
  --sih-slate-200:  #E2E8F0;
  --sih-slate-300:  #CBD5E1;
  --sih-slate-400:  #94A3B8;
  --sih-slate-500:  #64748B;
  --sih-slate-600:  #475569;
  --sih-slate-700:  #334155;
  --sih-slate-800:  #1E293B;
  --sih-slate-900:  #0F172A;

  /* Radii */
  --sih-r-sm: 6px;
  --sih-r-md: 10px;
  --sih-r-lg: 14px;
  --sih-r-xl: 20px;
  --sih-r-2xl: 28px;
  --sih-r-full: 999px;

  /* Shadows — multi-layer for depth */
  --sih-shadow-xs:  0 1px 2px rgba(15, 23, 42, 0.04);
  --sih-shadow-sm:  0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --sih-shadow-md:  0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
  --sih-shadow-lg:  0 12px 32px -8px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.06);
  --sih-shadow-xl:  0 24px 48px -12px rgba(15, 23, 42, 0.18), 0 8px 16px -4px rgba(15, 23, 42, 0.08);
  --sih-shadow-brand-md: 0 8px 24px -6px rgba(124, 58, 237, 0.22), 0 2px 6px -1px rgba(124, 58, 237, 0.14);
  --sih-shadow-brand-lg: 0 20px 44px -12px rgba(124, 58, 237, 0.35), 0 6px 14px -2px rgba(124, 58, 237, 0.18);

  /* Gradients */
  --sih-gradient-brand: linear-gradient(135deg, #7C3AED 0%, #A855F7 55%, #C084FC 100%);
  --sih-gradient-brand-soft: linear-gradient(135deg, #EDE9FE 0%, #F5F3FF 100%);
  --sih-gradient-border: linear-gradient(135deg, #7C3AED, #A855F7, #C084FC);
  --sih-gradient-success: linear-gradient(135deg, #10B981 0%, #34D399 100%);
  --sih-gradient-warning: linear-gradient(135deg, #F59E0B 0%, #FBBF24 100%);
  --sih-gradient-danger:  linear-gradient(135deg, #EF4444 0%, #F87171 100%);

  /* Transitions */
  --sih-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sih-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sih-dur-fast: 140ms;
  --sih-dur-med:  220ms;
  --sih-dur-slow: 420ms;
}

/* ============================== HERO BAND ============================== */
.sih-hero {
  position: relative;
  border-radius: var(--sih-r-2xl);
  padding: 36px 40px 32px;
  margin: 20px 0 28px;
  color: #fff;
  background: var(--sih-gradient-brand);
  box-shadow: var(--sih-shadow-brand-md);
  overflow: hidden;
  isolation: isolate;
}
.sih-hero::before,
.sih-hero::after {
  content: ''; position: absolute; border-radius: 50%; z-index: 0;
  pointer-events: none;
}
.sih-hero::before {
  top: -100px; right: -80px; width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 70%);
}
.sih-hero::after {
  bottom: -140px; left: -60px; width: 280px; height: 280px;
  background: radial-gradient(circle, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0) 70%);
}
.sih-hero > * { position: relative; z-index: 1; }
.sih-hero-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: 1.8px;
  text-transform: uppercase; opacity: 0.92; margin-bottom: 10px;
  display: inline-flex; align-items: center; gap: 8px;
}
.sih-hero-eyebrow::before {
  content: ''; width: 18px; height: 2px; background: rgba(255,255,255,0.7); border-radius: 2px;
}
.sih-hero h1, .sih-hero .sih-hero-title {
  font-size: 30px; font-weight: 800; line-height: 1.15;
  letter-spacing: -0.5px; margin: 0 0 10px; color: #fff;
}
.sih-hero-sub {
  font-size: 15px; line-height: 1.55; opacity: 0.95; max-width: 640px; color: #fff;
}
.sih-hero-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }

@media (max-width: 700px) {
  .sih-hero { padding: 26px 22px; border-radius: var(--sih-r-xl); }
  .sih-hero h1, .sih-hero .sih-hero-title { font-size: 24px; }
}

/* ============================== CARD ============================== */
.sih-card {
  background: #fff;
  border: 1px solid var(--sih-slate-200);
  border-radius: var(--sih-r-lg);
  box-shadow: var(--sih-shadow-sm);
  transition: transform var(--sih-dur-med) var(--sih-ease-out),
              box-shadow var(--sih-dur-med) var(--sih-ease-out),
              border-color var(--sih-dur-med) var(--sih-ease-out);
}
.sih-card-hover { cursor: pointer; }
.sih-card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--sih-shadow-lg);
  border-color: var(--sih-purple-300);
}
.sih-card-brand {
  border-color: transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    var(--sih-gradient-border) border-box;
  border: 1px solid transparent;
}
.sih-card-pad { padding: 20px 22px; }
.sih-card-pad-lg { padding: 26px 28px; }

/* ============================== SECTION ============================== */
.sih-section {
  background: #fff;
  border: 1px solid var(--sih-slate-200);
  border-radius: var(--sih-r-lg);
  padding: 24px 26px;
  box-shadow: var(--sih-shadow-xs);
  margin-bottom: 20px;
}
.sih-section-title {
  font-size: 12px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--sih-slate-500);
  margin: 0 0 14px 0;
  display: flex; align-items: center; gap: 10px;
}
.sih-section-title::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--sih-slate-200), transparent);
}

/* ============================== BUTTONS ============================== */
.sih-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 10px 18px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--sih-r-md);
  cursor: pointer; text-decoration: none;
  transition: all var(--sih-dur-fast) var(--sih-ease-out);
  white-space: nowrap; user-select: none;
  line-height: 1.2;
}
.sih-btn:focus-visible {
  outline: 2px solid var(--sih-purple-600);
  outline-offset: 2px;
}
.sih-btn:active { transform: translateY(1px); }

.sih-btn-primary {
  color: #fff;
  background: var(--sih-gradient-brand);
  box-shadow: var(--sih-shadow-brand-md);
}
.sih-btn-primary:hover {
  box-shadow: var(--sih-shadow-brand-lg);
  transform: translateY(-1px);
}

.sih-btn-secondary {
  color: var(--sih-purple-700);
  background: var(--sih-purple-50);
  border-color: var(--sih-purple-200);
}
.sih-btn-secondary:hover {
  background: var(--sih-purple-100);
  border-color: var(--sih-purple-300);
}

.sih-btn-ghost {
  color: var(--sih-slate-700);
  background: #fff;
  border-color: var(--sih-slate-200);
}
.sih-btn-ghost:hover {
  background: var(--sih-slate-50);
  border-color: var(--sih-slate-300);
  color: var(--sih-slate-900);
}

.sih-btn-danger {
  color: #fff;
  background: var(--sih-gradient-danger);
}
.sih-btn-danger:hover { filter: brightness(1.05); }

.sih-btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--sih-r-sm); }
.sih-btn-lg { padding: 14px 26px; font-size: 14px; }
.sih-btn-block { width: 100%; }
.sih-btn[disabled], .sih-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ============================== BADGES / CHIPS ============================== */
.sih-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--sih-r-full);
  line-height: 1.4;
}
.sih-badge-purple { background: var(--sih-purple-100); color: var(--sih-purple-700); }
.sih-badge-green  { background: var(--sih-green-50);   color: var(--sih-green-700); }
.sih-badge-amber  { background: var(--sih-amber-50);   color: var(--sih-amber-700); }
.sih-badge-red    { background: var(--sih-red-50);     color: var(--sih-red-700); }
.sih-badge-slate  { background: var(--sih-slate-100);  color: var(--sih-slate-700); }
.sih-badge-dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.8;
}

.sih-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  background: #fff; border: 1px solid var(--sih-slate-200);
  border-radius: var(--sih-r-full); cursor: pointer;
  transition: all var(--sih-dur-fast) var(--sih-ease-out);
  color: var(--sih-slate-700);
}
.sih-chip:hover { border-color: var(--sih-purple-300); color: var(--sih-purple-700); }
.sih-chip.is-active {
  background: var(--sih-purple-600); color: #fff; border-color: var(--sih-purple-600);
}

/* ============================== STAT CARDS ============================== */
.sih-stat {
  position: relative;
  background: #fff;
  border: 1px solid var(--sih-slate-200);
  border-radius: var(--sih-r-lg);
  padding: 16px 18px;
  box-shadow: var(--sih-shadow-xs);
  overflow: hidden;
}
.sih-stat::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--sih-gradient-brand);
}
.sih-stat-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--sih-slate-500); margin: 0 0 6px;
}
.sih-stat-value {
  font-size: 24px; font-weight: 800; color: var(--sih-slate-900);
  line-height: 1.1; letter-spacing: -0.5px;
}
.sih-stat-delta {
  font-size: 11px; font-weight: 600; margin-top: 4px;
  display: inline-flex; align-items: center; gap: 4px;
}
.sih-stat-delta.pos { color: var(--sih-green-700); }
.sih-stat-delta.neg { color: var(--sih-red-700); }
.sih-stat-success::before { background: var(--sih-gradient-success); }
.sih-stat-warning::before { background: var(--sih-gradient-warning); }
.sih-stat-danger::before  { background: var(--sih-gradient-danger); }

/* ============================== INPUTS ============================== */
.sih-input, .sih-select, .sih-textarea {
  width: 100%;
  font-family: inherit; font-size: 14px;
  padding: 11px 14px;
  background: #fff;
  border: 1px solid var(--sih-slate-200);
  border-radius: var(--sih-r-md);
  color: var(--sih-slate-900);
  transition: border-color var(--sih-dur-fast) var(--sih-ease-out),
              box-shadow var(--sih-dur-fast) var(--sih-ease-out);
}
.sih-input:focus, .sih-select:focus, .sih-textarea:focus {
  outline: none;
  border-color: var(--sih-purple-500);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}
.sih-input::placeholder, .sih-textarea::placeholder { color: var(--sih-slate-400); }

.sih-field { display: flex; flex-direction: column; gap: 6px; }
.sih-field-label {
  font-size: 12px; font-weight: 600;
  color: var(--sih-slate-700);
}

/* ============================== EMPTY STATE ============================== */
.sih-empty {
  text-align: center; padding: 48px 32px;
  background: var(--sih-slate-50);
  border: 1px dashed var(--sih-slate-300);
  border-radius: var(--sih-r-lg);
  color: var(--sih-slate-600);
}
.sih-empty-icon {
  width: 56px; height: 56px;
  border-radius: var(--sih-r-full);
  background: #fff;
  box-shadow: var(--sih-shadow-sm);
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--sih-purple-600);
}
.sih-empty h3 {
  font-size: 16px; font-weight: 700; color: var(--sih-slate-800);
  margin: 0 0 6px;
}
.sih-empty p { font-size: 13px; line-height: 1.55; max-width: 420px; margin: 0 auto; }

/* ============================== SKELETON LOADER ============================== */
.sih-skeleton {
  display: block;
  background: linear-gradient(90deg, var(--sih-slate-100) 0%, var(--sih-slate-200) 50%, var(--sih-slate-100) 100%);
  background-size: 200% 100%;
  animation: sih-shimmer 1.4s infinite linear;
  border-radius: var(--sih-r-sm);
  height: 12px;
}
.sih-skeleton-lg { height: 24px; }
.sih-skeleton-circle { border-radius: 50%; width: 40px; height: 40px; }
.sih-skeleton-line + .sih-skeleton-line { margin-top: 8px; }

@keyframes sih-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================== LOADING SPINNER ============================== */
.sih-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--sih-purple-200);
  border-top-color: var(--sih-purple-600);
  border-radius: 50%;
  animation: sih-spin 0.7s linear infinite;
}
.sih-spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes sih-spin { to { transform: rotate(360deg); } }

/* ============================== ANIMATIONS ============================== */
.sih-fade-in       { animation: sih-fade-in var(--sih-dur-slow) var(--sih-ease-out) both; }
.sih-fade-in-up    { animation: sih-fade-in-up var(--sih-dur-slow) var(--sih-ease-out) both; }
.sih-scale-in      { animation: sih-scale-in var(--sih-dur-med) var(--sih-ease-spring) both; }
.sih-stagger > *   { animation: sih-fade-in-up var(--sih-dur-slow) var(--sih-ease-out) both; }
.sih-stagger > *:nth-child(1) { animation-delay: 0ms; }
.sih-stagger > *:nth-child(2) { animation-delay: 60ms; }
.sih-stagger > *:nth-child(3) { animation-delay: 120ms; }
.sih-stagger > *:nth-child(4) { animation-delay: 180ms; }
.sih-stagger > *:nth-child(5) { animation-delay: 240ms; }
.sih-stagger > *:nth-child(6) { animation-delay: 300ms; }

@keyframes sih-fade-in    { from { opacity: 0; } to { opacity: 1; } }
@keyframes sih-fade-in-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sih-scale-in   { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .sih-fade-in, .sih-fade-in-up, .sih-scale-in, .sih-stagger > *,
  .sih-skeleton, .sih-spinner { animation: none !important; }
  .sih-card-hover:hover, .sih-btn:hover { transform: none !important; }
}

/* ============================== UTILITIES ============================== */
.sih-text-muted   { color: var(--sih-slate-500); }
.sih-text-subtle  { color: var(--sih-slate-600); }
.sih-text-brand   { color: var(--sih-purple-700); }
.sih-text-xs      { font-size: 11px; }
.sih-text-sm      { font-size: 12px; }
.sih-text-lg      { font-size: 16px; }
.sih-text-xl      { font-size: 20px; }
.sih-mono         { font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.sih-divider      { height: 1px; background: var(--sih-slate-200); border: none; margin: 18px 0; }
.sih-divider-soft { background: linear-gradient(90deg, transparent, var(--sih-slate-200), transparent); }

/* Print: hide decorative elements */
@media print {
  .sih-hero::before, .sih-hero::after { display: none !important; }
  .sih-skeleton, .sih-spinner { display: none !important; }
  .sih-card-hover:hover { transform: none !important; }
  .no-print { display: none !important; }
}

/* ==========================================================================
   Global mobile safety net — prevents horizontal overflow on small viewports.
   Intentionally does NOT set overflow-x:hidden on body/html (would mask bugs).
   Instead: box-sizing everywhere, fluid media, break long strings.
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

/* Fluid media — raster images, video, iframes, and block-level SVG charts.
   Icon-sized SVGs (explicit width/height attr in HTML) are untouched because
   they render at their attribute size by default; this only caps accidentally
   oversized block SVGs. */
img, video, iframe { max-width: 100%; height: auto; }
svg { max-width: 100%; }

/* Scrollable table wrapper — opt-in via <div class="table-scroll"> around a
   wide <table>. Preserved here so pages don't need to redefine it. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Explicit word-break helpers for fields that hold user URLs, emails, handles.
   Add class="sih-break" on the element to opt in. */
.sih-break { overflow-wrap: anywhere; word-break: break-word; }

/* Unified top bar — at very narrow viewports (<=400px) truncate the agent
   label aggressively and tighten padding, so the header never forces a
   horizontal scroll. Pages that define their own .sih-topbar rules keep
   working; these act as a final safety net. */
@media (max-width: 400px) {
  .sih-topbar { padding: 12px 12px !important; gap: 6px !important; }
  .sih-topbar h1 { font-size: 15px !important; }
  .sih-topbar .agent-box { font-size: 11.5px !important; gap: 4px !important; }
  .sih-topbar .agent-box #agentLabel { max-width: 80px !important; }
  .sih-topbar .home-btn,
  .sih-topbar .logout-btn { padding: 4px 8px !important; font-size: 11.5px !important; }
}

/* =====================================================================
   Mobile: no horizontal scroll / swipe. Applies globally to tutte le
   pagine che includono sih-premium.css (tutti gli step + admin + dashboard).

   Safari iOS in particolare lascia "trascinare" la pagina a destra/sinistra
   se UN QUALSIASI elemento eccede la larghezza del viewport (per esempio
   una bottom-bar fissa con white-space:nowrap). Qui blocchiamo entrambi:
   - overflow-x hidden su html+body cattura gli overflow
   - max-width 100vw impedisce che layout con width:100% + padding diventino
     piu larghi del viewport
   - overscroll-behavior-x none toglie il bounce orizzontale iOS
   - touch-action pan-y limita il gesture al pan verticale (NON affetta
     scrolling verticale ne pinch-zoom; non ci sono slider orizzontali nel
     prodotto quindi e sicuro).
   ===================================================================== */
@media (max-width: 900px) {
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
    overscroll-behavior-x: none;
  }
  body {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }
  /* Safety net: nessun elemento fissato puo' sforare il viewport a destra.
     Applica solo a posizionamento fisso perche' sono i piu' comuni colpevoli
     (bottom bar, FAB stampa, topbar) — non tocca il layout normale. */
  [class*="bottom-bar"],
  [class*="nav-bar"],
  .sih-topbar,
  .print-fab {
    max-width: 100vw;
  }
}

/* =====================================================================
   Mobile Baseline — audit responsive 2026-04-24.
   Regole globali per eliminare problemi mobile trasversali senza dover
   toccare i <style> inline di ogni pagina:

   1) Input font-size 16px — previene il zoom iOS automatico su tap.
      Apple Safari iOS zooma qualsiasi input con font-size < 16px: UX
      pessima perche' sposta il viewport. Alta specificita' (html body + attr
      selector) per vincere il cascade rispetto alle regole inline locali.

   2) Tap target min 44x44px su dispositivi touch — standard Apple HIG +
      WCAG 2.5.5 (AAA). Media query '(hover: none) and (pointer: coarse)'
      isola solo mouse-less touch: desktop con touchscreen ibrido NON viene
      toccato. min-height non altera il layout se il padding gia' basta.

   3) Container padding adaptive — le pagine usano 20-32px di padding
      orizzontale fisso. Su <=768px (tablet portrait) ridotto a 16px; su
      <=480px (phone) a 12px. Riprende spazio per il contenuto senza rompere
      il layout desktop.
   ===================================================================== */

/* 1) Input font-size 16px — anti-zoom iOS.
   Specificita' 0-0-4 (html + body + input + [type]) per battere regole
   inline come `input[type="email"] { font-size: 15px }` (specificita' 0-0-2)
   senza ricorrere a !important. */
html body input[type="text"],
html body input[type="email"],
html body input[type="password"],
html body input[type="search"],
html body input[type="tel"],
html body input[type="url"],
html body input[type="number"],
html body input[type="date"],
html body input[type="datetime-local"],
html body input[type="time"],
html body input:not([type]),
html body textarea,
html body select {
  font-size: 16px;
}

/* 2) Tap target 44x44px su touch device.
   Non usa !important: se una regola locale definisce min-height maggiore
   rispetta quella; se e' piu' bassa, la baseline nel media query vince
   perche' dichiarata dopo (sih-premium.css e' linkato prima degli inline). */
@media (hover: none) and (pointer: coarse) {
  html body button,
  html body .btn,
  html body a.btn,
  html body [role="button"],
  html body input[type="submit"],
  html body input[type="button"],
  html body input[type="reset"] {
    min-height: 44px;
  }
}

/* 3) Container padding adaptive.
   Usa 'html body' + classe per specificita' 0-1-2 che batte le regole
   locali 0-1-0 / 0-0-1 presenti nei <style> inline. */
@media (max-width: 768px) {
  html body .container,
  html body .sih-container,
  html body .app-container,
  html body .page-container {
    padding-left: 16px;
    padding-right: 16px;
  }
}

@media (max-width: 480px) {
  html body .container,
  html body .sih-container,
  html body .app-container,
  html body .page-container {
    padding-left: 12px;
    padding-right: 12px;
  }
}
