/**
 * base.css
 *
 * Reset, tipografia di base, layout scheletro, animazioni globali.
 * Texture dot-grid sul body — colore adattivo via --dot-color (per tema).
 *
 * @module    CSS.Base
 * @author    Lab67
 * @version   2.1.0
 * @since     2026-11-16
 * @requires  variables.css
 *
 * Changelog:
 *   2.1.0  2026-11-27  Regola globale [hidden]: l'attributo vince su qualsiasi display di componente
 *   2.0.0  2026-11-16  Aggiunta texture dot-grid; spinner usa --spinner-track
 *   1.0.0  2026-11-16  Prima versione
 */

/* ------------------------------------------------------------------ */
/* Reset                                                                */
/* ------------------------------------------------------------------ */

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

/* L'attributo hidden deve sempre nascondere. Senza questa regola ogni componente con un proprio
   display (es. .badge { display: inline-flex }) resta visibile anche con hidden: era il caso
   del badge "In attesa di connessione", sempre mostrato. */
[hidden] {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(circle, var(--dot-color) 1px, transparent 1px),
    var(--bg-gradient);
  background-size: 32px 32px, 100% 100%;
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Accessibilità: focus outline visibile su tutti gli elementi interattivi */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: 1.2;
  font-weight: 700;
}

/* ------------------------------------------------------------------ */
/* Animazioni                                                           */
/* ------------------------------------------------------------------ */

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 12px var(--accent-glow); }
  50%       { box-shadow: 0 0 28px var(--accent-glow-strong); }
}

.animate-in {
  animation: fadeInUp var(--transition-base) both;
}

/* Stagger: nth-child delay via classi utility */
.animate-delay-1 { animation-delay: 60ms; }
.animate-delay-2 { animation-delay: 120ms; }
.animate-delay-3 { animation-delay: 180ms; }
.animate-delay-4 { animation-delay: 240ms; }
.animate-delay-5 { animation-delay: 300ms; }
.animate-delay-6 { animation-delay: 360ms; }

/* ------------------------------------------------------------------ */
/* Layout scheletro SPA                                                 */
/* ------------------------------------------------------------------ */

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

/* Tutte le viste sono nascoste per default; app.js mostra quella attiva */
[id^="view-"] {
  display: none;
  flex: 1;
  padding: var(--space-md);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

[id^="view-"].active {
  display: flex;
  flex-direction: column;
  animation: fadeInUp var(--transition-base) both;
}

/* Header comune alle viste autenticate */
.view-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) 0 var(--space-lg);
}

.view-header h1 {
  font-size: var(--text-2xl);
  color: var(--text-primary);
  flex: 1;
}

.view-header .user-badge {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: var(--space-xs) var(--space-md);
}

/* ------------------------------------------------------------------ */
/* Toast                                                                */
/* ------------------------------------------------------------------ */

#toast-container {
  position: fixed;
  bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  z-index: 9999;
  pointer-events: none;
  width: min(calc(100vw - 100px), 380px);
}

.toast {
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  font-size: var(--text-sm);
  font-weight: 500;
  animation: fadeInUp 300ms both;
  pointer-events: auto;
  text-align: center;
}

.toast--success {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.4);
  color: var(--color-success);
}

.toast--error {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--color-error);
}

.toast--info {
  background: var(--glass-bg);
  color: var(--text-primary);
}

/* ------------------------------------------------------------------ */
/* Spinner                                                              */
/* ------------------------------------------------------------------ */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--spinner-track);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ------------------------------------------------------------------ */
/* Overlay modale                                                       */
/* ------------------------------------------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-md);
  animation: fadeIn var(--transition-fast) both;
}

.overlay.hidden { display: none; }

.modal {
  width: min(100%, 480px);
  animation: fadeInUp var(--transition-base) both;
}

/* ------------------------------------------------------------------ */
/* Accessibilità                                                        */
/* ------------------------------------------------------------------ */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ */
/* Badge                                                                */
/* ------------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-xl);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge--pending  { background: rgba(255,255,255,0.1); color: var(--text-secondary); }
.badge--offline  { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge--you      { background: var(--glass-bg); color: var(--accent-primary); border: 1px solid var(--glass-border-focus); }
