:root {
    --bg: #020617;
    --surface: #0F172A;
    --surface-2: #17213A;
    --border: #253249;
    --text: #F1F5F9;
    --muted: #94A3B8;
    --blue: #2563EB;
    --blue-light: #3B82F6;
    --teal: #14B8A6;
    --danger: #E5536B;
    --radius: 16px;
    --amber: #F0A93B;
    --amber-bg: #3A2E12;
    --rose: #3B82F6; /* Ripetizione usa il blu, coerente col riferimento */
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --modal-overlay: rgba(2, 6, 23, .65);
  }
  html[data-theme="light"] {
    --bg: #F3F5FA;
    --surface: #FFFFFF;
    --surface-2: #F1F4FA;
    --border: #E1E6F0;
    --text: #0F172A;
    --muted: #64748B;
    --amber-bg: #FDF0D8;
    --modal-overlay: rgba(15, 23, 42, .45);
  }
  html[data-theme="light"] body { background: var(--bg); }
  html[data-theme="light"] .splash-logo { box-shadow: 0 8px 30px rgba(59,130,246,.25); }
  html[data-theme="light"] input, html[data-theme="light"] select, html[data-theme="light"] textarea { background: var(--surface-2); color: var(--text); }
  html[data-theme="light"] .tab-btn.active { color: #0B1220; background: #0F172A0D; }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
  }

  .hidden { display: none !important; }
  h1, h2, h3 { margin-top: 0; font-weight: 800; color: var(--text); }
  p { color: var(--muted); }

  input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    margin: 6px 0 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: var(--surface-2);
    color: var(--text);
  }
  input::placeholder, textarea::placeholder { color: #56637D; }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue-light); }
  label { font-size: 13px; font-weight: 600; color: var(--muted); }

  button { font-family: inherit; cursor: pointer; }
  .btn-primary {
    width: 100%; padding: 12px; background: linear-gradient(120deg, var(--blue), var(--teal));
    color: #fff; border: none; border-radius: 10px;
    font-weight: 700; font-size: 15px;
    box-shadow: 0 8px 20px rgba(37, 99, 235, .25);
    transition: transform .15s ease, box-shadow .15s ease;
  }
  .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(37, 99, 235, .32); }
  .btn-secondary {
    width: 100%; padding: 11px; background: var(--surface-2); color: var(--text);
    border: 1.5px solid var(--border); border-radius: 10px; font-weight: 700; margin-top: 8px;
  }
  .btn-secondary:hover { border-color: var(--blue-light); }
  .btn-google {
    width: 100%; padding: 11px; background: var(--surface-2); color: var(--text);
    border: 1.5px solid var(--border); border-radius: 10px; font-weight: 600; margin-top: 8px;
  }
  .btn-small {
    padding: 7px 12px; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-weight: 600; margin-right: 6px;
  }
  .btn-small:hover { border-color: var(--blue-light); }
  .btn-small:disabled { cursor: default; opacity: .6; }
  .btn-voted { background: var(--amber-bg); color: var(--amber); border-color: var(--amber); }
  .btn-danger { background: #35131C; color: var(--danger); border-color: #572230; }
  .btn-danger:hover { border-color: var(--danger); }
  .btn-back {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 10px; margin-bottom: 14px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 0;
  }
  .btn-back svg { width: 17px; height: 17px; }
  .btn-back:hover { border-color: var(--blue-light); color: var(--text); }

  /* ===================== AUTH — schermo diviso ===================== */
  #page-auth { display: none; min-height: 100vh; max-width: none; padding: 0; margin: 0; }
  #page-auth.active { display: flex; }
  #page-auth.active .auth-hero { display: none; }
  #page-auth.active .auth-form-side { flex: 1 1 100%; }

  .auth-hero {
    position: relative; overflow: hidden; padding: 48px;
    background-image: url('og-image.png');
    background-size: cover; background-position: center;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; gap: 30px;
  }
  .auth-hero::before {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(29,78,216,.88) 0%, rgba(37,99,235,.88) 45%, rgba(14,165,160,.88) 100%),
                radial-gradient(circle at 20% 20%, rgba(255,255,255,.12), transparent 45%),
                radial-gradient(circle at 80% 70%, rgba(255,255,255,.10), transparent 40%);
  }
  .auth-hero-top { position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 800; font-size: 18px; color: #fff; }
  .auth-hero-logo { width: 34px; height: 34px; border-radius: 9px; background: rgba(255,255,255,.18); display: flex; align-items: center; justify-content: center; font-size: 17px; }
  .auth-hero-mid { position: relative; color: #fff; max-width: 520px; display: flex; flex-direction: column; align-items: center; margin: 0 auto; }
  .hero-eyebrow {
    display: inline-block; color: #fff; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.28);
    border-radius: 20px; padding: 5px 14px; font-size: 12px; font-weight: 700; margin-bottom: 16px;
    text-transform: uppercase; letter-spacing: .03em;
  }
  .auth-hero-mid h1 { color: #fff; font-size: 38px; line-height: 1.15; margin-bottom: 14px; }
  .auth-hero-mid p { color: rgba(255,255,255,.85); font-size: 15px; }
  .auth-hero-bottom { position: relative; width: 100%; display: flex; justify-content: center; align-items: center; }

  /* Nascosto su schermo stretto: deve stare DOPO le regole base di .auth-hero
     qui sopra, altrimenti con la stessa specificità vince l'ultima dichiarata
     nel file (è esattamente il bug che ha causato lo schiacciamento visto
     su mobile) */
  @media (max-width: 860px) { .auth-hero { display: none; } }

  /* Mini anteprima decorativa del sito, dentro il pannello hero */
  .hero-mock { background: rgba(15, 23, 42, .55); border: 1px solid rgba(255,255,255,.18); border-radius: 20px;
    padding: 26px; backdrop-filter: blur(6px); max-width: 560px; width: 100%; margin: 0 auto; }
  .hero-mock-row { display: flex; gap: 8px; margin-bottom: 10px; }
  .hero-mock-chip { flex: 1; background: rgba(255,255,255,.1); border-radius: 10px; padding: 10px; }
  .hero-mock-chip .n { color: #fff; font-weight: 800; font-size: 15px; }
  .hero-mock-chip .l { color: rgba(255,255,255,.7); font-size: 10px; }
  .hero-mock-card { background: rgba(255,255,255,.08); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
  .hero-mock-card .t { color: #fff; font-weight: 700; font-size: 12.5px; margin-bottom: 6px; }
  .hero-mock-bar { height: 5px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; }
  .hero-mock-bar span { display: block; height: 100%; background: #fff; border-radius: 4px; }

  .hero-mock-label { color: rgba(255,255,255,.8); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 18px; text-align: center; }
  .hero-mock-quadrants { display: flex; gap: 16px; justify-content: center; }
  .hero-mock-quad { flex: 1; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.18); border-radius: 20px; padding: 40px 14px; text-align: center; }
  .hero-mock-quad .ic-box { width: 78px; height: 78px; border-radius: 18px; background: rgba(255,255,255,.16); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
  .hero-mock-quad .ic-box svg { width: 38px; height: 38px; color: #fff; }
  .hero-mock-quad .lb { color: #fff; font-size: 16px; font-weight: 700; }

  /* Card di benvenuto compatta, solo su mobile: stesso sfondo sfumato del
     pannello desktop, badge+titolo+sottotitolo, sopra al carosello */
  .mobile-hero-header { display: none; }
  @media (max-width: 860px) {
    .mobile-hero-header {
      display: block; margin: 0 auto 20px; max-width: 420px;
      background: linear-gradient(135deg, #1D4ED8 0%, #2563EB 45%, #0EA5A0 100%);
      border-radius: 18px; padding: 26px 22px; position: relative; overflow: hidden;
    }
    .mobile-hero-header::before {
      content: ''; position: absolute; inset: 0;
      background: radial-gradient(circle at 15% 20%, rgba(255,255,255,.14), transparent 45%);
    }
    .mobile-hero-header .hero-eyebrow { position: relative; margin-bottom: 12px; }
    .mobile-hero-header h1 { position: relative; color: #fff; font-size: 25px; line-height: 1.2; margin: 0 0 10px; }
    .mobile-hero-header p { position: relative; color: rgba(255,255,255,.9); font-size: 13.5px; margin: 0; }
  }

  /* Anteprima a carosello, visibile solo su mobile (dove il pannello hero è nascosto).
     Riusa le stesse .hub-card-icon (blu/teal/amber) dell'app vera, per coerenza visiva. */
  .mobile-hero-preview { display: none; }
  @media (max-width: 860px) {
    .mobile-hero-preview { display: block; margin: 0 auto 22px; max-width: 420px; }
  }
  .mobile-hero-preview .hero-mock-label { color: var(--muted); text-align: center; }
  .mobile-hero-carousel {
    display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; padding: 2px 2px 6px; scrollbar-width: thin;
  }
  .mobile-hero-card {
    flex: 0 0 132px; scroll-snap-align: start; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px 10px; text-align: center;
  }
  .mobile-hero-card .hub-card-icon { margin: 0 auto 10px; }
  .mobile-hero-card .lb { font-size: 12.5px; font-weight: 700; color: var(--text); }

  .auth-form-side {
    display: flex; align-items: center; justify-content: center; padding: 40px 24px; min-height: 100vh;
    background: var(--bg);
  }
  @media (min-width: 861px) {
    .auth-form-side {
      background:
        radial-gradient(circle at 15% 20%, rgba(59,130,246,.10), transparent 40%),
        radial-gradient(circle at 85% 80%, rgba(20,184,166,.08), transparent 40%),
        var(--bg);
    }
  }
  .auth-card { width: 100%; max-width: 380px; }
  @media (min-width: 861px) {
    .auth-card { max-width: 560px; }
    .welcome-title { font-size: 44px; }
    .welcome-sub { font-size: 16.5px; margin-bottom: 34px; }
    .welcome-brand-name { font-size: 19px; }
    .welcome-logo { width: 36px; height: 36px; border-radius: 11px; font-size: 18px; }
    .carousel-arrow { width: 42px; height: 42px; font-size: 22px; }
    #auth-welcome .btn-primary, #auth-welcome .btn-secondary { padding: 15px; font-size: 15.5px; }
    .auth-card h1 { font-size: 32px; }
    .auth-card .subtitle { font-size: 15.5px; }
    .auth-card input, .auth-card select { padding: 13px 14px; font-size: 15px; }
    .auth-card .btn-primary, .auth-card .btn-google, .auth-card .btn-secondary { padding: 14px; font-size: 15px; }
  }
  .auth-card h1 { font-size: 26px; margin-bottom: 4px; }
  .auth-card .subtitle { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
  .auth-card p { font-size: 13px; color: var(--muted); }
  .auth-card a { color: var(--blue-light); text-decoration: none; font-weight: 700; }
  .auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 18px 0; }
  .auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

  /* ===================== SCHERMATA DI BENVENUTO (carosello) ===================== */
  .welcome-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 30px; }
  .welcome-logo {
    width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--blue), var(--teal));
    display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff;
  }
  .welcome-brand-name { font-weight: 800; font-size: 16.5px; color: var(--text); }
  .welcome-uni-pill {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
    font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; margin-left: 2px;
  }
  .welcome-title { font-size: 32px; line-height: 1.15; margin: 0 0 12px; font-weight: 800; }
  .welcome-sub { font-size: 14.5px; color: var(--muted); margin: 0 0 26px; line-height: 1.5; }

  .welcome-carousel { display: flex; align-items: center; gap: 10px; }
  .welcome-slide {
    flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border);
    border-radius: 18px; padding: 22px; min-height: 170px;
    display: flex; flex-direction: column; justify-content: center;
    animation: pageIn .3s ease both;
  }
  .welcome-slide-icon {
    width: 44px; height: 44px; border-radius: 13px; margin-bottom: 14px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  }
  .welcome-slide-icon svg { width: 22px; height: 22px; color: #fff; }
  .welcome-slide-title { font-weight: 800; font-size: 17px; margin: 0 0 7px; }
  .welcome-slide-desc { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; }
  @media (min-width: 861px) {
    .welcome-slide { padding: 32px; min-height: 190px; }
    .welcome-slide-icon { width: 54px; height: 54px; border-radius: 15px; margin-bottom: 18px; }
    .welcome-slide-icon svg { width: 27px; height: 27px; }
    .welcome-slide-title { font-size: 20px; margin-bottom: 9px; }
    .welcome-slide-desc { font-size: 14.5px; }
  }

  /* ===================== TOUR GUIDATO OSPITI (schermo intero) ===================== */
  #page-guest-tour.active {
    position: fixed; inset: 0; z-index: 250; background: var(--bg);
    display: flex; padding: calc(20px + env(safe-area-inset-top, 0px)) 24px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    animation: none !important; max-width: none !important; margin: 0 !important;
  }
  .guest-tour-shell { display: flex; flex-direction: column; width: 100%; max-width: 420px; margin: 0 auto; min-height: 0; height: 100%; }
  @media (min-width: 861px) { .guest-tour-shell { max-width: 780px; } }
  @media (min-width: 1180px) { .guest-tour-shell { max-width: 960px; } }
  .guest-tour-top { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
  .guest-tour-salta { background: none; border: none; color: var(--muted); font-weight: 700; font-size: 14px; padding: 8px; }
  .guest-tour-salta:hover { color: var(--text); }
  #tour-bottone-avanti { flex-shrink: 0; }
  .carousel-arrow {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; background: var(--surface-2);
    border: 1px solid var(--border); color: var(--muted); font-size: 18px; line-height: 1;
    display: flex; align-items: center; justify-content: center; padding: 0;
  }
  .carousel-arrow:hover { color: var(--text); border-color: var(--blue-light); }

  /* Contenitore esterno: le frecce sono ancorate qui in posizione assoluta,
     fisse a metà altezza dello schermo (comoda per il pollice), indipendenti
     dall'altezza della card che cambia in base al testo di ogni slide. */
  .tour-carousel-outer { position: relative; flex: 1; min-height: 0; margin: auto 0; display: flex; }
  .tour-arrow-fixed {
    position: absolute; top: 50%; transform: translateY(-50%); z-index: 5;
  }
  .tour-arrow-fixed:first-child { left: -4px; }
  .tour-arrow-fixed:last-child { right: -4px; }

  /* Layout a due colonne: mockup telefono a sinistra, badge+titolo+checklist
     a destra, verticalmente centrati. Su schermi stretti le due colonne si
     impilano (telefono sopra, testo sotto). Stessa struttura per ogni slide,
     cambia solo il contenuto. */
  .tour-carousel { display: flex; align-items: stretch; gap: 10px; flex: 1; min-height: 0; padding: 0 38px; }
  .tour-slide {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center;
    gap: 22px; overflow: hidden auto; animation: pageIn .3s ease both;
    padding: 6px 4px;
  }
  /* Cornice telefono finta: bordo scuro spesso, angoli molto arrotondati,
     tacca (notch) in alto, screenshot reale incastonato dentro. */
  .tour-slide-shot-wrap {
    flex: 0 0 auto; width: min(220px, 62vw); aspect-ratio: 9 / 19.2;
    background: #04080f; border: 7px solid #04080f; border-radius: 34px;
    box-shadow: 0 0 0 1.5px var(--border), 0 14px 34px rgba(0,0,0,.4);
    position: relative; overflow: hidden; padding: 0;
  }
  .tour-slide-shot-wrap::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 46%; height: 20px; background: #04080f; border-radius: 0 0 14px 14px; z-index: 2;
  }
  .tour-slide-shot-wrap img {
    width: 100%; height: 100%; max-width: none; max-height: none;
    display: block; object-fit: cover; object-position: top center;
    border-radius: 27px; border: none; box-shadow: none;
  }
  .tour-slide-text {
    flex: 1 1 auto; min-height: 0; width: 100%; max-width: 360px;
    display: flex; flex-direction: column; align-items: center; text-align: center;
  }
  .tour-slide-title { font-weight: 800; font-size: 19px; margin-bottom: 10px; }
  .tour-slide-desc { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin: 0; }
  .tour-slide-desc ul { margin: 0; padding-left: 0; list-style: none; text-align: left; display: inline-block; }
  .tour-slide-desc li { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 8px; }
  .tour-slide-desc li:last-child { margin-bottom: 0; }
  @media (min-width: 861px) {
    .tour-slide { flex-direction: row; align-items: center; justify-content: center; gap: 60px; padding: 10px; }
    .tour-slide-shot-wrap { width: min(250px, 22vw); }
    .tour-slide-text { align-items: flex-start; text-align: left; max-width: 460px; }
    .tour-slide-desc ul { text-align: left; }
    .tour-slide-title { font-size: 26px; }
    .tour-slide-desc { font-size: 15px; }
  }
  @media (min-width: 1180px) {
    .tour-slide { gap: 90px; }
    .tour-slide-shot-wrap { width: 260px; }
    .tour-slide-text { max-width: 520px; }
    .tour-slide-title { font-size: 30px; }
    .tour-slide-desc { font-size: 16px; }
  }

  .tour-slide-shot-wrap.hidden { display: none; }
  .tour-slide.no-shot .tour-slide-text { flex: 1 1 auto; }
  .tour-slide-badge {
    display: inline-block; margin-bottom: 10px;
    padding: 4px 12px; border-radius: 999px; font-size: 11px; font-weight: 800;
    letter-spacing: .04em; text-transform: uppercase; color: #04120e;
    background: linear-gradient(135deg, var(--blue), var(--teal));
  }
  .tour-check { flex: 0 0 auto; margin-top: 2px; color: var(--teal); }
  .tour-slide-counter { text-align: center; color: var(--muted); font-size: 12.5px; font-weight: 600; margin: 10px 0 2px; }
  .carousel-dots { display: flex; justify-content: center; gap: 6px; margin: 16px 0 26px; }
  .carousel-dots span { width: 6px; height: 6px; border-radius: 4px; background: var(--border); transition: width .2s ease, background .2s ease; }
  .carousel-dots span.active { width: 20px; background: var(--text); }

  /* ===================== SHELL (sidebar + contenuto) ===================== */
  #app-shell { display: flex; flex-direction: column; min-height: 100vh; }
  #app-shell.hidden { display: none; }
  .app-shell-body { display: flex; flex: 1; min-height: 0; }

  /* Barra fissa in alto, solo su mobile: logo, avatar, tasto esci
     (su mobile "Esci" non sta più nella barra in basso, che ha solo 3 icone) */
  .mobile-topbar { display: none; }
  @media (max-width: 780px) {
    .mobile-topbar {
      display: flex; align-items: center; justify-content: space-between;
      position: sticky; top: 0; z-index: 140; background: var(--surface); border-bottom: 1px solid var(--border);
      padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    }
    .mobile-topbar-brand {
      font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px;
      background: none; border: none; color: inherit; cursor: pointer; font-family: inherit; padding: 0;
    }
    .mobile-topbar-brand .ico {
      width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--blue), var(--teal));
      display: flex; align-items: center; justify-content: center; font-size: 13px;
    }
    .mobile-topbar-right { display: flex; align-items: center; gap: 10px; position: relative; }
    .topbar-popup {
      position: absolute; top: calc(100% + 10px); right: 0; z-index: 200; min-width: 190px;
      background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
      box-shadow: 0 14px 34px rgba(0,0,0,.45);
    }
    .mobile-topbar .avatar {
      width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--teal));
      color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
    }
    .mobile-topbar-logout { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 14px; color: var(--muted); }
  }

  #sidebar {
    width: 240px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  }
  .sidebar-logo {
    display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; padding: 6px 8px 22px;
    text-decoration: none; color: inherit; cursor: pointer; background: none; border: none; width: 100%; text-align: left; font-family: inherit;
  }
  .sidebar-logo .ico { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--blue), var(--teal)); display: flex; align-items: center; justify-content: center; font-size: 15px; }
  .sidebar-nav { display: flex; flex-direction: column; gap: 3px; }
  .sidebar-link {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
    color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
  }
  .sidebar-link { position: relative; }
  .nav-ico { width: 19px; height: 19px; flex-shrink: 0; }
  @media (max-width: 780px) { .nav-ico { width: 22px; height: 22px; } }
  .sidebar-link:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-link.active { background: var(--surface-2); color: var(--text); }
  .nav-badge {
    background: #EF4444; color: #fff; font-size: 10.5px; font-weight: 800;
    min-width: 17px; height: 17px; border-radius: 20px; display: inline-flex;
    align-items: center; justify-content: center; padding: 0 4px; margin-left: auto;
  }
  .sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 3px; }
  .sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 8px 4px; border-top: 1px solid var(--border); margin-top: 8px; }
  .sidebar-user .avatar {
    width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--teal));
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
  }
  #user-name-label { font-size: 13px; font-weight: 700; color: var(--text); }

  #main-content { flex: 1; min-width: 0; }
  .page { display: none; padding: 30px 32px; max-width: 1100px; margin: 0 auto; }
  .page.active { display: block; }
  @media (max-width: 780px) {
    #sidebar {
      position: fixed; bottom: 0; left: 0; right: 0; top: auto; width: 100%; height: auto;
      flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
      border-right: none; border-top: 1px solid var(--border); z-index: 150;
    }
    .sidebar-logo, .sidebar-bottom { display: none; }
    .sidebar-nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 0; }
    .sidebar-link { position: relative; flex-direction: column; gap: 2px; font-size: 10.5px; padding: 7px 4px; text-align: center; border-radius: 10px; }
    .sidebar-link .nav-badge { position: absolute; top: 2px; right: 20%; margin-left: 0; }
    .sidebar-link.active { color: var(--blue-light); }
    .sidebar-link.active::before {
      content: ''; position: absolute; top: -1px; left: 50%; transform: translateX(-50%);
      width: 4px; height: 4px; border-radius: 50%; background: var(--blue-light);
    }
    .page { padding: 20px 16px calc(72px + env(safe-area-inset-bottom, 0px)); }
  }

  /* ===================== DASHBOARD ===================== */
  .dash-header { margin-bottom: 22px; }
  .dash-date { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
  .dash-greeting { font-size: 26px; }
  .dash-sub { margin-top: 2px; }

  .stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
  @media (max-width: 780px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
  .stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
  .stat-card.blue { background: linear-gradient(155deg, #12213F, var(--surface) 75%); border-color: #1F3665; }
  .stat-card.amber { background: linear-gradient(155deg, #302311, var(--surface) 75%); border-color: #4A3311; }
  .stat-card.teal-card { background: linear-gradient(155deg, #0F2B2A, var(--surface) 75%); border-color: #114A44; }
  .stat-card-top.teal-text { color: var(--teal); }
  .stat-card-top { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--blue-light); margin-bottom: 10px; }
  .stat-card.amber .stat-card-top { color: var(--amber); }
  .stat-icon { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; margin-bottom: 12px; }
  .stat-icon.blue { background: #14264D; }
  .stat-icon.amber { background: var(--amber-bg); }
  .stat-icon.teal { background: #0F2B35; }
  .stat-value { font-size: 26px; font-weight: 800; }
  .stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
  .stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

  .btn-outline-add {
    width: 100%; padding: 13px; margin-top: 4px; background: none; color: var(--muted);
    border: 1.5px dashed var(--border); border-radius: 12px; font-weight: 700; font-size: 14px;
  }
  .btn-outline-add:hover { border-color: var(--blue-light); color: var(--blue-light); }

  /* ===================== IMPOSTAZIONI (stile lista righe) ===================== */
  .profile-header-card {
    background: linear-gradient(155deg, #1B2340, var(--surface) 70%); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; margin-bottom: 22px; cursor: pointer;
  }
  .profile-header-top { display: flex; align-items: center; gap: 14px; }
  .profile-header-name { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 6px; }
  .profile-header-corso { font-size: 13px; color: var(--muted); margin-top: 2px; }
  .profile-header-tags { display: flex; gap: 8px; margin-top: 14px; }
  .pill-tag { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 20px; }

  .settings-section-label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 22px 2px 8px; }
  .settings-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
  .settings-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
  .settings-row:last-child { border-bottom: none; }
  .settings-row:hover { background: var(--surface-2); }
  .settings-row-icon {
    width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; background: #1E2A45; color: #93C5FD;
    display: flex; align-items: center; justify-content: center;
  }
  .settings-row-icon svg { width: 16px; height: 16px; }
  .settings-row-icon.blue { background: #14264D; color: #93C5FD; }
  .settings-row-icon.teal { background: #0F2B35; color: #5EEAD4; }
  .settings-row-icon.amber { background: var(--amber-bg); color: #FCD34D; }
  .settings-row-icon.violet { background: #241A45; color: #C4B5FD; }
  .settings-row-label { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
  .settings-row-value { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
  .settings-row-chevron { color: var(--muted); font-size: 16px; }

  .btn-esci-pill {
    width: 100%; margin-top: 22px; margin-bottom: 20px; padding: 14px; background: #35131C; color: var(--danger);
    border: 1px solid #572230; border-radius: 16px; font-weight: 700; font-size: 14.5px;
  }
  .btn-esci-pill:hover { border-color: var(--danger); }
  @media (max-width: 780px) {
    .btn-esci-pill { margin-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
  }

  .faq-item { margin-bottom: 16px; }
  .faq-item:last-child { margin-bottom: 0; }
  .faq-q { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
  .faq-a { font-size: 13px; color: var(--muted); line-height: 1.5; }

  .istruzioni-installa { margin: 0; padding-left: 20px; color: var(--text); font-size: 14px; line-height: 1.7; }
  .istruzioni-installa li { margin-bottom: 4px; }
  .istruzioni-installa b { color: var(--blue-light); }

  .campo-password-wrap { position: relative; }
  .campo-password-wrap input { padding-right: 42px; }
  .btn-occhio-password {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: none; border: none; width: 32px; height: 32px; padding: 0;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
    opacity: .6; margin: 0;
  }
  .btn-occhio-password:hover { opacity: 1; }
  .btn-occhio-password.attivo { opacity: 1; }

  .toolbar-search-row { display: flex; gap: 10px; margin-bottom: 12px; }
  .toolbar-search-row input[type="text"] { margin: 0; flex: 1; max-width: 320px; }
  .toolbar-search-row .btn-primary { width: auto; padding: 11px 18px; white-space: nowrap; }
  @media (max-width: 600px) {
    .toolbar-search-row { flex-direction: column; }
    .toolbar-search-row input[type="text"] { max-width: none; }
    .toolbar-search-row .btn-primary { width: 100%; }
  }
  .filter-pills-scroll {
    display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 18px;
    -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  }
  .filter-pill {
    flex: 0 0 auto; padding: 8px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface);
    color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap;
  }
  .filter-pill.active { background: var(--blue); border-color: var(--blue); color: #fff; }

  .materie-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  @media (max-width: 780px) { .materie-grid { grid-template-columns: 1fr; } }

  .card-materia {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; cursor: pointer; transition: border-color .15s ease, transform .15s ease;
  }
  .card-materia:hover { border-color: var(--blue-light); transform: translateY(-2px); }
  .card-materia-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; gap: 8px; }
  .card-materia-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .pill-hot { background: var(--amber-bg); color: var(--amber); font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
  .pill-countdown { display: flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; color: var(--amber); white-space: nowrap; }
  .card-materia-top h3 { font-size: 16px; margin: 10px 0 0; }
  .card-materia .prof { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
  .card-materia-progress-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
  .card-materia-progress-row b { color: var(--text); }
  .card-materia-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 12px; color: var(--muted); }

  /* Levetta "visibile ai Buddy" per singola materia */
  .buddy-toggle-row {
    display: flex; align-items: center; gap: 9px; margin-top: 12px; padding-top: 12px;
    border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
  }
  .bb-switch { position: relative; display: inline-block; width: 34px; height: 19px; flex-shrink: 0; }
  .bb-switch input { opacity: 0; width: 0; height: 0; }
  .bb-switch .slider {
    position: absolute; inset: 0; background: #EF4444; border-radius: 20px; cursor: pointer; transition: background .15s ease;
  }
  .bb-switch .slider::before {
    content: ''; position: absolute; height: 15px; width: 15px; left: 2px; bottom: 2px;
    background: #fff; border-radius: 50%; transition: transform .15s ease;
  }
  .bb-switch input:checked + .slider { background: #22C55E; }
  .bb-switch input:checked + .slider::before { transform: translateX(15px); }

  .pill { padding: 4px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; border: 1px solid transparent; white-space: nowrap; }
  .pill[data-stato="Da preparare"] { background: #212C40; color: var(--muted); border-color: var(--border); }
  .pill[data-stato="In preparazione"] { background: var(--amber-bg); color: var(--amber); }
  .pill[data-stato="Ripetizione"] { background: #13223F; color: #6FA8F5; }
  .pill[data-stato="Fase finale"] { background: #0F2B35; color: var(--teal); }

  .progress-bar { background: var(--surface-2); border-radius: 20px; height: 7px; overflow: hidden; }
  .progress-fill { height: 100%; border-radius: 20px; background: var(--blue-light); }
  .progress-fill[data-stato="Da preparare"] { background: var(--muted); }
  .progress-fill[data-stato="In preparazione"] { background: var(--amber); }
  .progress-fill[data-stato="Ripetizione"] { background: #6FA8F5; }
  .progress-fill[data-stato="Fase finale"] { background: var(--teal); }

  .empty { color: var(--muted); text-align: center; padding: 32px; grid-column: 1 / -1; }

  /* ===================== STANZA MATERIA ===================== */
  .materia-header-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; margin: 16px 0 22px; }
  .materia-header-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
  .materia-header-meta { font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
  .materia-header-card h2 { font-size: 24px; margin: 2px 0 10px; }
  .materia-quick-actions { display: flex; gap: 8px; }
  .btn-icon-mini {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    background: #14264D; border: none; color: var(--blue-light);
    display: flex; align-items: center; justify-content: center;
  }
  .btn-icon-mini svg { width: 16px; height: 16px; }
  .btn-icon-mini:hover { background: #1B3564; }
  .btn-icon-mini.whatsapp { background: var(--surface-2); }
  .btn-icon-mini.whatsapp:hover { background: var(--border); }
  .btn-icon-mini.danger { background: var(--surface-2); color: var(--danger); }
  .btn-icon-mini.danger:hover { background: #35131C; }
  .materia-header-info { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
  .materia-header-pct { text-align: right; }
  .materia-header-pct .n { font-size: 28px; font-weight: 800; }
  .materia-header-pct .l { font-size: 11.5px; color: var(--muted); }
  .materia-ring {
    width: 60px; height: 60px; border-radius: 50%; flex-shrink: 0;
    background: conic-gradient(var(--blue-light) calc(var(--pct) * 1%), var(--surface-2) 0);
    display: flex; align-items: center; justify-content: center;
    transition: background .4s ease;
  }
  .materia-ring-inner {
    width: 47px; height: 47px; border-radius: 50%; background: var(--surface);
    display: flex; align-items: center; justify-content: center;
  }
  .materia-ring .n { font-size: 13.5px; font-weight: 800; }

  .materia-tabs { margin-bottom: 20px; }
  .materia-tabs-scroll {
    display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .materia-tabs-scroll::-webkit-scrollbar { display: none; }
  .materia-tabs-scroll .tab-btn { flex: 1 1 0; }
  .tab-btn {
    background: none; border: none; padding: 10px 8px; color: var(--muted); font-weight: 700; font-size: 13.5px;
    border-radius: 10px; white-space: nowrap; transition: background .15s ease, color .15s ease;
  }
  .tab-btn:hover { color: var(--text); }
  .tab-btn.active { color: #0B1220; background: #F1F5F9; }
  .tab-btn.active .tab-count { background: var(--blue); color: #fff; }
  .tab-ico { display: inline-flex; vertical-align: -3px; margin-right: 5px; }
  .tab-ico svg { width: 15px; height: 15px; }

  .search-input-wrap { position: relative; }
  .search-input-ico {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--muted); display: flex; pointer-events: none;
  }
  .search-input-ico svg { width: 15px; height: 15px; }
  .search-input-wrap input { padding-left: 38px; }

  /* Hub d'ingresso alla materia: tre card compatte con statistiche reali */
  .materia-hub { display: none !important; }

  .mini-avatar {
    border-radius: 50%; color: #fff; font-weight: 700; display: flex; align-items: center;
    justify-content: center; flex-shrink: 0;
  }
  .card-action-link {
    background: none; border: none; color: var(--muted); font-size: 12.5px; font-weight: 600;
    cursor: pointer; padding: 4px 6px; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  }
  .card-action-link:hover { color: var(--text); }
  .card-action-link.danger { color: var(--danger); }
  .card-action-link.danger:hover { color: #FF8199; }

  /* Menù a tendina "Contatta" nelle card Buddy */
  .contact-dropdown { position: relative; }
  .contact-dropdown-menu {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 200;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 6px; box-shadow: 0 14px 34px rgba(0,0,0,.45);
  }
  .contact-dropdown-menu.apri-in-alto { top: auto; bottom: calc(100% + 6px); }
  .contact-option {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
    background: none; border: none; border-radius: 8px; color: var(--text); font-size: 13.5px; font-weight: 600;
    cursor: pointer; text-align: left;
  }
  .contact-option:hover:not(:disabled) { background: var(--surface-2); }
  .contact-option:disabled { color: var(--muted); opacity: .4; cursor: not-allowed; }
  .contact-option .opt-icon { flex-shrink: 0; display: flex; }
  .contact-option .opt-sub { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: auto; }
  .tab-count {
    display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
    padding: 0 6px; border-radius: 20px; background: var(--surface-2); color: var(--muted);
    font-size: 11px; font-weight: 700; margin-left: 6px;
  }
  .hub-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; cursor: pointer; transition: border-color .15s ease, transform .15s ease;
  }
  .hub-card:hover { border-color: var(--blue-light); transform: translateY(-2px); }
  .hub-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
  .hub-card-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
  .hub-card-icon svg { width: 22px; height: 22px; }
  .hub-card-icon.blue { background: #14264D; color: #93C5FD; }
  .hub-card-icon.teal { background: #0F2B35; color: #5EEAD4; }
  .hub-card-icon.amber { background: var(--amber-bg); color: #FCD34D; }
  .hub-chevron { color: var(--muted); font-size: 20px; }
  .hub-card-title { font-weight: 800; font-size: 16.5px; margin-bottom: 4px; }
  .hub-card-stats { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); min-height: 16px; }
  .hub-card-preview { font-size: 12.5px; color: var(--muted); font-style: italic; min-height: 16px; }
  .hub-avatars-row { display: flex; align-items: center; }
  .hub-avatar {
    width: 26px; height: 26px; border-radius: 50%; background: var(--blue); color: #fff;
    font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface); margin-left: -8px;
  }
  .hub-avatar:first-child { margin-left: 0; }

  .panel-add, .panel-compagni, .panel-faq { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
  .quick-edit-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; }
  .quick-edit-row select, .quick-edit-row input { width: auto; margin: 0; padding: 8px 10px; }

  #lista-compagni { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; padding-bottom: 180px; }
  @media (max-width: 640px) { #lista-compagni { grid-template-columns: 1fr; } }
  .card-compagno, .card-faq {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 12px; padding: 16px; overflow-wrap: break-word; word-break: break-word;
  }
  .card-faq { margin-bottom: 10px; }
  .contatti a { margin-right: 14px; color: var(--blue-light); font-size: 13px; font-weight: 700; text-decoration: none; }
  .privacy-note { font-size: 12px; color: var(--muted); font-style: italic; }
  .note { color: var(--muted); font-size: 13px; margin: 8px 0 0; overflow-wrap: break-word; word-break: break-word; }

  /* ===================== VOTO (su/giù) ===================== */
  .vote-widget { display: flex; flex-direction: column; align-items: center; margin-right: 14px; flex-shrink: 0; width: 30px; }
  .forum-tempo-row { margin-bottom: 8px; }
  .forum-vote-row-h { display: flex; align-items: center; gap: 6px; }
  .forum-vote-row-h .vote-btn { width: auto; padding: 2px 6px; }
  .forum-vote-row-h .vote-score { font-size: 13.5px; }
  .vote-btn { background: none; border: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 3px 0; width: 100%; border-radius: 6px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
  .vote-btn:hover { background: var(--surface); color: var(--text); }
  .vote-btn.up.active { color: #22C55E; }
  .vote-btn.down.active { color: #EF4444; }
  .vote-score { display: block; font-weight: 800; font-size: 13.5px; text-align: center; padding: 1px 0; }

  /* ===================== BUDDY / CONVERSAZIONI ===================== */
  .card-conversazione { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; }
  .card-conversazione:hover { border-color: var(--blue-light); }
  .card-conversazione-top { display: flex; justify-content: space-between; align-items: center; }

  /* ===================== MODALI (aggiungi materia / chat) ===================== */
  .modal {
    position: fixed; inset: 0; background: var(--modal-overlay);
    display: flex; align-items: center; justify-content: center; z-index: 250;
  }
  .modal-content {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; width: 90%; max-width: 420px;
    max-height: 85vh; overflow-y: auto; display: flex; flex-direction: column; position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,.5); padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  }
  .modal-close { position: absolute; top: 14px; right: 16px; background: none; border: none; font-size: 18px; color: var(--muted); }

  /* ===================== CHAT: BLOCCO SIGILLATO A 3 LIVELLI =====================
     #page-chat è un contenitore fisso a schermo intero, sempre sopra a tutto
     il resto (topbar, barra di navigazione, qualunque altra pagina). Dentro,
     .chat-shell è una colonna flex con esattamente 3 figli:
       1. header  → flex-shrink:0, sempre in cima, non si muove mai
       2. messaggi → flex:1 + overflow-y:auto, è l'UNICA parte che scorre
       3. input   → flex-shrink:0, sempre in fondo
     Niente logiche che nascondono/mostrano la barra di navigazione in base
     alla tastiera: il contenitore è già sopra a tutto, quindi non serve. */
  #page-chat.active {
    position: fixed; inset: 0; z-index: 300; background: var(--bg);
    display: flex; /* .page normalmente usa block: qui serve flex per centrare .chat-shell */
    padding: 0 !important; margin: 0 !important; max-width: none !important;
    animation: none !important; /* la pagina chat gestisce la propria "transform" via JS
      per seguire la tastiera: l'animazione generica di apertura pagina la terrebbe
      occupata (anche a fine animazione, per via di "fill-mode: both") e la
      correzione sotto non riuscirebbe mai a muovere davvero il blocco. */
  }
  /* Mentre la chat è aperta, blocchiamo lo scroll di TUTTA la pagina: senza
     questo, quando il telefono porta in vista il campo di testo per aprire
     la tastiera, sposta anche la pagina sotto — e la chat "salta" invece di
     restare ferma con l'input ancorato sopra la tastiera. */
  body.chat-attiva { position: fixed; inset: 0; width: 100%; overflow: hidden; }
  .chat-shell {
    flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%;
    height: 100vh; height: 100dvh; /* dvh evita i salti dovuti alla tastiera su Safari/Chrome mobile */
  }

  .chat-shell-header {
    flex-shrink: 0; display: flex; align-items: center; gap: 12px;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
    border-bottom: 1px solid var(--border); background: var(--surface);
  }
  .chat-shell-header h2 { margin: 0; font-size: 17px; }

  .chat-shell-messaggi {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 14px 16px; display: flex; flex-direction: column; gap: 6px;
  }
  .chat-shell-messaggi .msg { min-width: 0; }

  .chat-shell-input {
    flex-shrink: 0; display: flex; gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border); background: var(--surface);
  }
  .chat-shell-input input { flex: 1; margin: 0; }
  .chat-shell-input button { width: auto; padding: 0 20px; margin: 0; flex-shrink: 0; }

  .msg { background: var(--surface-2); padding: 9px 13px; border-radius: 12px; margin-bottom: 8px; max-width: 80%; font-size: 14px; overflow-wrap: break-word; word-break: break-word; }
  .msg.mine { background: var(--blue); color: #fff; margin-left: auto; }

  /* ===================== TOAST ===================== */
  .toast {
    position: fixed; bottom: -80px; left: 50%; transform: translateX(-50%);
    background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 12px 22px; border-radius: 10px;
    font-size: 14px; font-weight: 600; transition: bottom .3s ease; z-index: 400;
  }
  .toast.show { bottom: 24px; }
  .toast.error { background: #35131C; border-color: #572230; color: #FCA5B5; }

  /* ===================== RIFINITURE MOBILE ===================== */
  @media (max-width: 780px) {
    /* iOS ingrandisce automaticamente la pagina quando un campo ha font-size sotto i 16px */
    input, select, textarea { font-size: 16px; }
    .btn-small { padding: 9px 14px; font-size: 13.5px; }
    .vote-btn { padding: 7px 0; font-size: 17px; }
  }
  @media (max-width: 600px) {
    .quick-edit-row { flex-direction: column; align-items: stretch; }
    .quick-edit-row select, .quick-edit-row input {
      width: 100%; height: 46px; padding: 0 14px; box-sizing: border-box; margin: 0;
    }
    .quick-edit-row button {
      width: 100%; height: 46px; padding: 0 14px; box-sizing: border-box;
      display: flex; align-items: center; justify-content: center; line-height: 1;
    }
  }

  /* ===================== SPLASH SCREEN ===================== */
  #splash-screen {
    position: fixed; inset: 0; z-index: 9999; background: linear-gradient(160deg, #0B1220, #101B33);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
    transition: opacity .35s ease, visibility .35s ease;
  }
  #splash-screen.hide { opacity: 0; visibility: hidden; pointer-events: none; }
  .splash-logo {
    width: 78px; height: 78px; border-radius: 22px; background: linear-gradient(135deg, var(--blue), var(--teal));
    display: flex; align-items: center; justify-content: center; font-size: 34px;
    animation: splashPop .55s cubic-bezier(.34,1.56,.64,1);
    box-shadow: 0 8px 30px rgba(59,130,246,.35);
  }
  .splash-title { color: #fff; font-weight: 800; font-size: 19px; letter-spacing: .2px; animation: splashFadeIn .5s ease .1s both; }
  .splash-dots { display: flex; gap: 6px; animation: splashFadeIn .5s ease .2s both; }
  .splash-dots span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--blue-light); opacity: .35;
    animation: splashBlink 1.1s ease-in-out infinite;
  }
  .splash-dots span:nth-child(2) { animation-delay: .15s; }
  .splash-dots span:nth-child(3) { animation-delay: .3s; }
  @keyframes splashPop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  @keyframes splashFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
  @keyframes splashBlink { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

  /* ===================== TRANSIZIONI TRA PAGINE ===================== */
  .page.active {
    animation: pageIn .28s cubic-bezier(.25,.8,.4,1) both;
  }
  @keyframes pageIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @media (prefers-reduced-motion: reduce) {
    .page.active { animation: none; }
  }

  /* ===================== FEEDBACK TATTILE SUI TAP ===================== */
  .btn-primary, .btn-secondary, .btn-danger, .btn-small, .vote-btn,
  .card-materia, .card-conversazione, .card-compagno, .sidebar-link,
  .contact-option, .stat-card, .btn-back {
    transition: transform .12s ease, opacity .12s ease;
  }
  .btn-primary:active, .btn-secondary:active, .btn-danger:active, .btn-small:active, .vote-btn:active,
  .card-materia:active, .card-conversazione:active, .card-compagno:active, .sidebar-link:active,
  .contact-option:active {
    transform: scale(.96); opacity: .85;
  }

  /* ===================== SKELETON LOADING ===================== */
  .skeleton-riga, .skeleton-card { position: relative; overflow: hidden; background: var(--surface-2); border-radius: 8px; }
  .skeleton-riga::after, .skeleton-card::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
    animation: skeletonShine 1.3s ease-in-out infinite;
  }
  @keyframes skeletonShine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
  .skeleton-card { height: 130px; border: 1px solid var(--border); }
  .skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
  .skeleton-riga { height: 58px; margin-bottom: 10px; border: 1px solid var(--border); }

  /* ===================== PULL-TO-REFRESH ===================== */
  #ptr-indicator {
    position: fixed; top: 0; left: 50%; transform: translate(-50%, -46px);
    width: 34px; height: 34px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center; font-size: 15px; z-index: 140;
    transition: transform .15s ease, opacity .15s ease; opacity: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
  }
  #ptr-indicator.spin span { display: inline-block; animation: ptrSpin .6s linear infinite; }
  @keyframes ptrSpin { to { transform: rotate(360deg); } }