/* ============================================================================
   STILE PERSONALIZZATO - Backend amministrativo
   ============================================================================
   Integra Tailwind (caricato da CDN) con stili specifici per:
     - accessibilita' WCAG 2.1 AA
     - focus visibile e contrastato
     - messaggi flash colorati
   ============================================================================ */

html,
body {
  margin: 0;
}

/* --- Skip link: navigazione tastiera per saltare al contenuto principale --- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  background: #1e40af;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  text-decoration: none;
  font-weight: 600;
  border-radius: 0 0 0.5rem 0;
}

.skip-link:focus {
  left: 0;
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}

.app-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  font-weight: 600;
  line-height: 1;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.app-btn-primary {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.app-btn-primary:hover {
  background: #1e40af;
  border-color: #1e40af;
}

.app-btn-invert {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.app-btn-invert:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.30);
}

.app-btn-secondary {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.app-btn-secondary:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.app-btn-danger {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.app-btn-danger:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.app-page-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(29, 78, 216, 0.10), transparent 60%),
    linear-gradient(180deg, rgba(248, 250, 252, 0.95), rgba(255, 255, 255, 0.95));
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

@media (min-width: 640px) {
  .app-page-header {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
  }
}

.app-page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.app-page-subtitle {
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.4;
}

.app-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 1rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.app-card-pad {
  padding: 1rem;
}

.app-table-card {
  overflow: hidden;
}

.app-card-muted {
  background: rgba(248, 250, 252, 0.9);
}

.app-ai-bg {
  position: relative;
  isolation: isolate;
}

.app-ai-bg header,
.app-ai-bg main,
.app-ai-bg footer {
  position: relative;
  z-index: 3;
}

.app-ai-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1100px 600px at 10% 0%, rgba(59, 130, 246, 0.18), transparent 55%),
    radial-gradient(900px 520px at 95% 10%, rgba(14, 165, 233, 0.14), transparent 55%),
    radial-gradient(900px 520px at 50% 100%, rgba(139, 92, 246, 0.10), transparent 55%),
    radial-gradient(rgba(2, 132, 199, 0.14) 1px, transparent 1px);
  background-size: auto, auto, auto, 26px 26px;
  opacity: 0.65;
}

.app-ai-bg::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(15, 23, 42, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 23, 42, 0.03) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px;
  mask-image: radial-gradient(900px 600px at 50% 20%, rgba(0, 0, 0, 1), transparent 65%);
  -webkit-mask-image: radial-gradient(900px 600px at 50% 20%, rgba(0, 0, 0, 1), transparent 65%);
  opacity: 0.55;
}

.app-ai-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44vh;
  z-index: 1;
  pointer-events: none;
  opacity: 0.92;
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
  -webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
}

.app-ai-bottom::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(900px 520px at 15% 100%, rgba(59, 130, 246, 0.30), transparent 55%),
    radial-gradient(700px 420px at 70% 100%, rgba(14, 165, 233, 0.22), transparent 55%),
    radial-gradient(650px 380px at 95% 95%, rgba(139, 92, 246, 0.16), transparent 60%),
    radial-gradient(rgba(148, 163, 184, 0.32) 1px, transparent 1px);
  background-size: auto, auto, auto, 24px 24px;
  background-position: 0 0, 0 0, 0 0, 0 0;
  animation: app-ai-drift 10s linear infinite;
  filter: saturate(1.15);
}

.app-ai-bottom::after {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    conic-gradient(from 180deg at 50% 100%,
      rgba(59, 130, 246, 0.00),
      rgba(59, 130, 246, 0.18),
      rgba(14, 165, 233, 0.18),
      rgba(139, 92, 246, 0.12),
      rgba(59, 130, 246, 0.00)
    ),
    linear-gradient(90deg, rgba(255, 255, 255, 0.00), rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.00));
  mix-blend-mode: screen;
  opacity: 0.6;
  transform: translate3d(0, 0, 0);
  animation: app-ai-sweep 6.5s ease-in-out infinite;
}

@keyframes app-ai-drift {
  0% { background-position: 0 0, 0 0, 0 0, 0 0; }
  50% { background-position: 0 0, 0 0, 0 0, 120px 60px; }
  100% { background-position: 0 0, 0 0, 0 0, 240px 120px; }
}

@keyframes app-ai-sweep {
  0% { transform: translate3d(-8%, 6%, 0) rotate(-8deg); filter: blur(6px); }
  50% { transform: translate3d(6%, -2%, 0) rotate(6deg); filter: blur(10px); }
  100% { transform: translate3d(-8%, 6%, 0) rotate(-8deg); filter: blur(6px); }
}

@media (prefers-reduced-motion: reduce) {
  .app-ai-bottom::before,
  .app-ai-bottom::after {
    animation: none !important;
  }
}

.app-tabs {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.7) transparent;
}

.app-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.88);
  font-weight: 600;
  font-size: 0.875rem;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-tab:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.app-tab.is-active {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.26);
  color: #ffffff;
}

/* --- Focus visibile su tutti gli elementi interattivi --- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
  border-radius: 0.25rem;
}

/* --- Messaggi flash: colori con contrasto AA --- */
.flash {
  padding: 0.875rem 1.25rem;
  border-radius: 0.5rem;
  border-left-width: 4px;
  border-left-style: solid;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.flash-successo {
  background-color: #d1fae5;
  border-left-color: #047857;
  color: #064e3b;
}

.flash-errore {
  background-color: #fee2e2;
  border-left-color: #b91c1c;
  color: #7f1d1d;
}

.flash-info {
  background-color: #dbeafe;
  border-left-color: #1d4ed8;
  color: #1e3a8a;
}

.flash-avviso {
  background-color: #fef3c7;
  border-left-color: #b45309;
  color: #78350f;
}

/* --- Campi obbligatori: indicati visivamente E semanticamente --- */
.campo-obbligatorio::after {
  content: " *";
  color: #b91c1c;
  font-weight: 700;
}

/* --- Errori sotto i campi --- */
.errore-campo {
  color: #b91c1c;
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* --- Input con errore --- */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: #b91c1c;
  background-color: #fef2f2;
}

/* --- Tabelle leggibili --- */
table.tabella-dati {
  width: 100%;
  border-collapse: collapse;
}

table.tabella-dati th,
table.tabella-dati td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

table.tabella-dati th {
  background-color: #f3f4f6;
  font-weight: 600;
  color: #111827;
}

table.tabella-dati tbody tr:hover {
  background-color: #f9fafb;
}

/* --- Caption per screen reader (visivamente nascosta) --- */
.solo-screen-reader {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Card sulla dashboard --- */
.card-stat {
  background: #ffffff;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e7eb;
}

.card-stat .numero {
  font-size: 2.25rem;
  font-weight: 700;
  color: #1e40af;
  line-height: 1.2;
}

.card-stat .etichetta {
  font-size: 0.875rem;
  color: #4b5563;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.5rem;
}

/* --- Riduzione movimento per chi preferisce meno animazioni --- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
