/* ============================================================
   PSM — Percorsi Sonoro Musicali
   main.css — Foglio stili principale
   ============================================================ */

/* ------------------------------------------------------------
   1. IMPORT FONT
   ------------------------------------------------------------ */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&family=Inter:wght@300;400;500&display=swap');


/* ------------------------------------------------------------
   2. VARIABILI DI DESIGN (Design Tokens)
   ------------------------------------------------------------ */
:root {

  /* Palette colori */
  --color-bg:               #0f0f0f;   /* sfondo pagina — quasi nero */
  --color-surface:          #1a1a1a;   /* superfici: header, card, pannelli */
  --color-surface-raised:   #222222;   /* superfici elevate: hover, input */
  --color-border:           #2e2e2e;   /* bordi sottili */
  --color-border-light:     #3a3a3a;   /* bordi in evidenza */

  /* Testo */
  --color-text-primary:     #e8e8e8;   /* testo principale */
  --color-text-secondary:   #8a8a8a;   /* testo secondario, label, placeholder */
  --color-text-muted:       #555555;   /* testo disabilitato, decorativo */

  /* Accento */
  --color-accent:           #c9a84c;   /* oro caldo — elemento firma */
  --color-accent-dim:       #a8873a;   /* oro scuro per hover */
  --color-accent-glow:      rgba(201, 168, 76, 0.12); /* alone sottile */

  /* Stati semantici */
  --color-success:          #4a9e6a;
  --color-warning:          #c9a84c;   /* riusa l'oro */
  --color-error:            #c95a4a;
  --color-info:             #5a8ac9;

  /* Tipografia */
  --font-display:  'Cormorant Garamond', Georgia, serif;
  --font-body:     'Inter', system-ui, sans-serif;

  /* Scala tipografica */
  --text-xs:    0.75rem;    /*  12px */
  --text-sm:    0.875rem;   /*  14px */
  --text-base:  1rem;       /*  16px */
  --text-lg:    1.125rem;   /*  18px */
  --text-xl:    1.25rem;    /*  20px */
  --text-2xl:   1.5rem;     /*  24px */
  --text-3xl:   1.875rem;   /*  30px */
  --text-4xl:   2.25rem;    /*  36px */
  --text-5xl:   3rem;       /*  48px */

  /* Pesi tipografici */
  --weight-light:   300;
  --weight-regular: 400;
  --weight-medium:  500;
  --weight-semibold: 600;

  /* Spaziature */
  --space-1:   0.25rem;   /*  4px */
  --space-2:   0.5rem;    /*  8px */
  --space-3:   0.75rem;   /* 12px */
  --space-4:   1rem;      /* 16px */
  --space-5:   1.25rem;   /* 20px */
  --space-6:   1.5rem;    /* 24px */
  --space-8:   2rem;      /* 32px */
  --space-10:  2.5rem;    /* 40px */
  --space-12:  3rem;      /* 48px */
  --space-16:  4rem;      /* 64px */

  /* Layout */
  --header-height:        64px;
  --footer-height:        56px;
  --content-max-width:    860px;
  --content-padding-x:    var(--space-6);

  /* Bordi */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   20px;
  --radius-full: 9999px;

  /* Transizioni */
  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   400ms ease;

  /* Ombre */
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.6);

  /* Linea firma — rigo musicale */
  --score-line-color:  var(--color-accent);
  --score-line-height: 1px;

  /* Timing messaggi temporanei — letto anche da JS via
     getComputedStyle (vedi timeoutMessaggioMs() in base.html) */
  --timeout-message: 4s;
}


/* ------------------------------------------------------------
   3. RESET E BASE
   ------------------------------------------------------------ */
*, *::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: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, video, audio {
  max-width: 100%;
  display: block;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent-dim);
}

ul, ol {
  list-style: none;
}

button {
  cursor: pointer;
  font-family: var(--font-body);
  border: none;
  background: none;
}

input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text-primary);
  background-color: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-glow);
}

input::placeholder, textarea::placeholder {
  color: var(--color-text-muted);
}


/* ------------------------------------------------------------
   4. LAYOUT STRUTTURALE
   ------------------------------------------------------------ */

/* Header */
.psm-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background-color: var(--color-surface);
  border-bottom: var(--score-line-height) solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--content-padding-x);
  z-index: 100;
}

/* Linea firma oro sotto l'header */
.psm-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--content-padding-x);
  right: var(--content-padding-x);
  height: var(--score-line-height);
  background: linear-gradient(
    to right,
    transparent,
    var(--score-line-color) 20%,
    var(--score-line-color) 80%,
    transparent
  );
  animation: score-line-reveal 1.2s ease forwards;
}

@keyframes score-line-reveal {
  from { opacity: 0; transform: scaleX(0.3); }
  to   { opacity: 1; transform: scaleX(1); }
}

/* Logo area */
.psm-header__logo {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  text-decoration: none;
}

.psm-header__logo img {
  height: 36px;
  width: auto;
}

.psm-header__app-name {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-light);
  color: var(--color-text-secondary);
  letter-spacing: 0.04em;
  white-space: nowrap;

  /* Separatore verticale sottile prima del testo */
  border-left: 1px solid var(--color-border-light);
  padding-left: var(--space-4);
}

/* Azioni header (destra) */
.psm-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.psm-header__user {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* Main content */
.psm-main {
  flex: 1;
  margin-top: var(--header-height);
  margin-bottom: var(--footer-height);
  padding: var(--space-8) var(--content-padding-x);
}

.psm-main--centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
  padding: var(--space-6) var(--content-padding-x);
}

.psm-main__inner {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* Sfondo di pagina — immagine a tutta pagina con velo scuro per la
   leggibilità dei testi. Per le pagine che mostrano l'immagine di sfondo
   aggiungere <div class="psm-page-bg"> in cima al contenuto */
.psm-page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: url("../img/welcome.jpeg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.psm-page-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(10, 10, 10, 0.55) 0%,
    rgba(10, 10, 10, 0.70) 60%,
    rgba(10, 10, 10, 0.85) 100%
  );
}

/* Footer */
.psm-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-height);
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--content-padding-x);
  z-index: 100;
  gap: var(--space-4);
}
 
.psm-footer__copy {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
 
.psm-footer__progress {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
}
 
.psm-footer__datetime {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;  /* cifre allineate, no sbalzi */
}
 
/* Responsive footer */
@media (max-width: 480px) {
  .psm-footer {
    grid-template-columns: 1fr 1fr;
  }
 
  .psm-footer__progress {
    display: none;  /* su mobile piccolo sparisce il progressivo */
  }
 
  .psm-footer__datetime {
    text-align: right;
  }
}


/* ------------------------------------------------------------
   5. COMPONENTI — BOTTONI
   ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: 0.03em;
  transition:
    background-color var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

/* Bottone primario — oro */
.btn-primary {
  background-color: var(--color-accent);
  color: #0f0f0f;
  border: 1px solid var(--color-accent);
}

.btn-primary:hover {
  background-color: var(--color-accent-dim);
  border-color: var(--color-accent-dim);
  color: #0f0f0f;
}

/* Bottone secondario — outline */
.btn-secondary {
  background-color: transparent;
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-light);
}

.btn-secondary:hover {
  background-color: var(--color-surface-raised);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Bottone ghost — solo testo */
.btn-ghost {
  background-color: transparent;
  color: var(--color-text-secondary);
  border: 1px solid transparent;
  padding: var(--space-2) var(--space-4);
}

.btn-ghost:hover {
  color: var(--color-text-primary);
  background-color: var(--color-surface-raised);
}

/* Bottone logout */
.btn-logout {
  background-color: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

.btn-logout:hover {
  color: var(--color-error);
  border-color: var(--color-error);
}

/* Dimensioni */
.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-base);
}

.btn-full {
  width: 100%;
}

/* Stato disabilitato */
.btn:disabled,
.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}


/* ------------------------------------------------------------
   6. COMPONENTI — CARD
   ------------------------------------------------------------ */

.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: border-color var(--transition-base);
}

.card--hoverable:hover {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent-glow);
}

.card--accent {
  border-color: var(--color-accent);
}

/* Card stretta e centrata — pagine di accesso (login, errore, logout) */
.card--narrow {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

/* Card semitrasparente con sfocatura — per le card che stanno sopra lo
   sfondo di pagina (.psm-page-bg) */
.card--glass {
  background-color: rgba(26, 26, 26, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card__title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-light);
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.card__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}

.card__body {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  line-height: 1.7;
}

.card__footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}


/* ------------------------------------------------------------
   7. COMPONENTI — BADGE / STATO
   ------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge--active {
  background-color: rgba(74, 158, 106, 0.15);
  color: var(--color-success);
}

.badge--completed {
  background-color: rgba(201, 168, 76, 0.15);
  color: var(--color-accent);
}

.badge--pending {
  background-color: rgba(138, 138, 138, 0.15);
  color: var(--color-text-secondary);
}

.badge--error {
  background-color: rgba(201, 90, 74, 0.15);
  color: var(--color-error);
}


/* ------------------------------------------------------------
   8. COMPONENTI — PROGRESS BAR
   ------------------------------------------------------------ */

.progress-bar {
  width: 100%;
  height: 3px;
  background-color: var(--color-border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background-color: var(--color-accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}


/* ------------------------------------------------------------
   9. COMPONENTI — MESSAGGI / ALERT
   ------------------------------------------------------------ */

.alert {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border-left: 3px solid;
  font-size: var(--text-sm);
  line-height: 1.6;
  background-color: var(--color-surface-raised);
  box-shadow: var(--shadow-md);
  color: var(--color-text-primary);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}

.alert--info {
  border-color: var(--color-info);
}

.alert--success {
  border-color: var(--color-success);
}

.alert--warning {
  border-color: var(--color-warning);
}

.alert--error {
  border-color: var(--color-error);
}

.alert--dismiss {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity var(--transition-base), transform var(--transition-base);
}

/* Variante "flottante" — sovrapposta e centrata sull'elemento che ha
   generato l'azione. Il contenitore di riferimento deve avere
   position: relative. Standard per messaggi temporanei contestuali. */
.alert--flottante {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 320px;
  z-index: 50;
  transition: opacity var(--transition-base), transform var(--transition-base);
}

.alert--flottante.alert--dismiss {
  opacity: 0;
  transform: translate(-50%, calc(-50% - 8px));
}

/* Flash message Flask — centrato a schermo (fixed), indipendente
   dal contenuto pagina. Usato in base.html per redirect flash. */
.psm-flash-messages {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 250;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 480px;
  width: 90%;
}

/* ------------------------------------------------------------
   10. TIPOGRAFIA — CLASSI UTILITY
   ------------------------------------------------------------ */

.text-display {
  font-family: var(--font-display);
  font-weight: var(--weight-light);
  line-height: 1.2;
}

.text-xs      { font-size: var(--text-xs); }
.text-sm      { font-size: var(--text-sm); }
.text-base    { font-size: var(--text-base); }
.text-lg      { font-size: var(--text-lg); }
.text-xl      { font-size: var(--text-xl); }
.text-2xl     { font-size: var(--text-2xl); }
.text-3xl     { font-size: var(--text-3xl); }
.text-4xl     { font-size: var(--text-4xl); }

.text-primary   { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted     { color: var(--color-text-muted); }
.text-accent    { color: var(--color-accent); }
.text-success   { color: var(--color-success); }
.text-error     { color: var(--color-error); }

.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }

.font-light   { font-weight: var(--weight-light); }
.font-regular { font-weight: var(--weight-regular); }
.font-medium  { font-weight: var(--weight-medium); }


/* ------------------------------------------------------------
   11. UTILITY — SPAZIATURE E LAYOUT
   ------------------------------------------------------------ */

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: var(--space-2); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }

.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mt-8  { margin-top: var(--space-8); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.mb-8  { margin-bottom: var(--space-8); }

.w-full   { width: 100%; }
.h-full   { height: 100%; }

.hidden   { display: none !important; }
.sr-only  {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


/* ------------------------------------------------------------
   12. DIVISORE / SEPARATORE
   ------------------------------------------------------------ */

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-6) 0;
}

.divider--accent {
  border-color: var(--color-accent);
  opacity: 0.4;
}


/* ------------------------------------------------------------
   13. MEDIA QUERIES — RESPONSIVE
   ------------------------------------------------------------ */

/* Tablet portrait e landscape */
@media (max-width: 768px) {
  :root {
    --header-height:      56px;
    --content-padding-x:  var(--space-4);
  }

  .psm-header__app-name {
    display: none;  /* su mobile mostra solo il logo */
  }

  .psm-header__user {
    max-width: 120px;
  }

  .psm-main {
    padding: var(--space-6) var(--content-padding-x);
  }

  .card {
    padding: var(--space-4);
  }
}

/* Smartphone portrait */
@media (max-width: 480px) {
  :root {
    --content-padding-x: var(--space-4);
    --footer-height:     52px;
  }

  .btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-sm);
  }

  .psm-header__user {
    display: none;  /* su schermi piccoli solo logout */
  }
}

/* Landscape su mobile (altezza ridotta) */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --header-height:  48px;
    --footer-height:  44px;
  }

  .psm-main {
    padding: var(--space-4) var(--content-padding-x);
  }
}


/* ------------------------------------------------------------
   14. ACCESSIBILITÀ
   ------------------------------------------------------------ */

/* Focus visibile per tastiera */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

/* Rispetta preferenza utente per ridurre il movimento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Previene FOUC (Flash Of Unstyled Content) durante il caricamento dei font esterni */
body.loaded {
  visibility: visible;
}
