/* ============================================================
   recap-wa — stessa identità visiva di Palestra Tracker
   "ghisa & gesso": grafite/crema di base, rosso d'accento, Oswald
   per i titoli, JetBrains Mono per date/orari/numeri.
   ============================================================ */

:root {
  --bg: #F3F1EC;
  --surface: #FFFFFF;
  --surface-alt: #EAE7DF;
  --text: #1B1D1F;
  --text-secondary: #6B6F70;
  --border: #DEDBD2;
  --accent: #D93A2B;
  --accent-text: #FFFFFF;
  --accent-2: #C98A00;
  --danger: #C7362A;
  --radius: 16px;
  --font-display: "Oswald", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

[data-theme="dark"] {
  --bg: #14171A;
  --surface: #1E2226;
  --surface-alt: #262B30;
  --text: #F2F0EA;
  --text-secondary: #989D9D;
  --border: #33383D;
  --accent: #FF4A3D;
  --accent-text: #14171A;
  --accent-2: #FFC94D;
  --danger: #FF5C4D;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background 0.25s ease, color 0.25s ease;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  backdrop-filter: saturate(160%) blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  padding: 8px;
  color: var(--text);
  cursor: pointer;
  border-radius: 10px;
  text-decoration: none;
  display: inline-flex;
  transition: transform 0.05s ease, background 0.05s ease;
}
.icon-btn:active { transform: scale(0.88); background: var(--surface-alt); }

.container {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 18px 18px 100px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes dropIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes brandShine { to { background-position: 220% center; } }

/* ---------- Flash / errori ---------- */
.flash, .auth-flash, .errore-box {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  animation: dropIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.flash { background: var(--accent); color: var(--accent-text); }
.auth-flash, .errore-box {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

/* ---------- Login ---------- */
.login-box { text-align: center; margin-top: 12vh; animation: fadeUp 0.5s ease both; }
.login-box .emoji { font-size: 44px; margin-bottom: 4px; display: block; }
.login-box h1 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.subtitle { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.auth-hint, .auth-link { display: inline-block; margin-top: 18px; color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 600; }
.auth-hint:hover, .auth-link:hover { text-decoration: underline; }

/* ---------- Form elements ---------- */
input, select, textarea {
  font-size: 16px;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type="date"], input[type="datetime-local"], .stato-testo, .range-info {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 13px 18px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.08s ease, box-shadow 0.08s ease, border-color 0.08s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primario, .auth-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-primario:active, .auth-btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-full { width: 100%; }

/* ---------- Card (sezioni) ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.card h2 {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-size: 17px;
  margin: 0 0 6px;
}
.card .sotto { color: var(--text-secondary); font-size: 13px; margin: 0 0 16px; }

/* ---------- Dropzone upload ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 34px 18px;
  text-align: center;
  cursor: pointer;
  display: block;
  color: var(--text-secondary);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover, .dropzone.trascina { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.dropzone strong { color: var(--text); }
.dropzone input[type=file] { display: none; }

/* ---------- Toggle giorno/intervallo ---------- */
.righe-toggle { display: flex; gap: 10px; margin: 16px 0; }
.toggle-opzione {
  flex: 1;
  text-align: center;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: border-color 0.1s ease, color 0.1s ease, background 0.1s ease;
}
.toggle-opzione.attivo { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.campo-riga { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.campo-riga label { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-secondary); font-weight: 600; }

.range-info { font-size: 12px; color: var(--text-secondary); margin-top: -4px; margin-bottom: 12px; }

/* ---------- Barra di avanzamento (stesso stile dell'overlay video di Palestra) ---------- */
.barra-avanzamento {
  height: 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
  margin: 14px 0 8px;
  position: relative;
}
.barra-avanzamento-riempi {
  height: 100%;
  background: var(--accent);
  width: 0%;
  border-radius: 4px;
  transition: width 0.3s ease;
}
.barra-avanzamento-riempi.indeterminata {
  width: 40% !important;
  position: absolute;
  top: 0;
  animation: avanzamentoIndeterminato 1.1s ease-in-out infinite;
}
@keyframes avanzamentoIndeterminato { 0% { left: -40%; } 100% { left: 100%; } }
.stato-testo { font-size: 13px; color: var(--text-secondary); }

/* ---------- Riassunto ---------- */
.riassunto-box {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 14.5px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 10px;
}
.azioni { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- QR MFA ---------- */
.qr-box { background: #fff; padding: 12px; border-radius: 14px; display: inline-block; margin: 6px 0 14px; box-shadow: 0 12px 30px -10px rgba(0,0,0,0.35); }
.qr-img { display: block; width: 220px; height: 220px; }
.qr-manuale { font-size: 13px; color: var(--text-secondary); }
.qr-chiave { display: block; margin-top: 8px; word-break: break-all; background: var(--surface-alt); padding: 8px; border-radius: 9px; color: var(--accent); font-family: var(--font-mono); }

.nascosto { display: none !important; }

/* ============================================================================
   DESKTOP — atmosfera "spettacolare" (solo schermi larghi ≥ 900px), identica
   nello spirito a quella di Palestra Tracker: aurora sullo sfondo + faro del
   cursore + leggero tilt 3D sulle card.
   ============================================================================ */
@media (min-width: 900px) {
  html { background: var(--bg); }
  body {
    background: transparent;
    overflow-x: hidden;
    --au1: var(--accent);
    --au2: #4f7cff;
    --au3: var(--accent);
    --au4: #17d3c3;
    --au-glow: var(--accent);
  }
  body::before {
    content: "";
    position: fixed;
    inset: -25% -15% -15% -15%;
    z-index: -2;
    pointer-events: none;
    background:
      radial-gradient(38vw 38vw at 18% 20%, color-mix(in srgb, var(--au1) 40%, transparent), transparent 60%),
      radial-gradient(34vw 34vw at 84% 16%, color-mix(in srgb, var(--au2) 38%, transparent), transparent 60%),
      radial-gradient(42vw 42vw at 72% 90%, color-mix(in srgb, var(--au3) 30%, transparent), transparent 62%),
      radial-gradient(32vw 32vw at 22% 88%, color-mix(in srgb, var(--au4) 30%, transparent), transparent 60%);
    filter: blur(24px) saturate(125%);
    animation: auroraDrift 28s ease-in-out infinite alternate;
  }
  @keyframes auroraDrift {
    0%   { transform: translate3d(0, 0, 0) scale(1)    rotate(0deg); }
    50%  { transform: translate3d(2.5%, -2%, 0) scale(1.08) rotate(1.5deg); }
    100% { transform: translate3d(-2%, 2.5%, 0) scale(1.05) rotate(-1.5deg); }
  }
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
      radial-gradient(50vw 50vh at var(--mx, 50%) var(--my, 38%),
        color-mix(in srgb, var(--au-glow) 13%, transparent), transparent 55%),
      linear-gradient(color-mix(in srgb, var(--bg) 64%, transparent),
        color-mix(in srgb, var(--bg) 80%, transparent));
  }

  .topbar {
    background: color-mix(in srgb, var(--bg) 58%, transparent);
    -webkit-backdrop-filter: saturate(170%) blur(16px);
    backdrop-filter: saturate(170%) blur(16px);
    padding: 16px clamp(24px, 5vw, 60px);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  }
  .brand {
    font-size: 24px;
    letter-spacing: 1px;
    background: linear-gradient(90deg, var(--text) 20%, var(--accent) 50%, var(--text) 80%);
    background-size: 220% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: brandShine 7s linear infinite;
  }
  .icon-btn { transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease; }
  .icon-btn:hover { transform: translateY(-1px) scale(1.08); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

  .container { max-width: 760px; padding: 28px clamp(24px, 4vw, 48px) 96px; position: relative; z-index: 1; }

  .card {
    position: relative;
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
    backdrop-filter: blur(18px) saturate(150%);
    border: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
    box-shadow: 0 18px 42px -20px rgba(0, 0, 0, 0.35), inset 0 1px 0 color-mix(in srgb, #ffffff 18%, transparent);
    transform-style: preserve-3d;
    transform: perspective(1000px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
    transition: transform 0.18s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    will-change: transform;
  }
  .card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: radial-gradient(280px 280px at var(--gx, 50%) var(--gy, 50%),
      color-mix(in srgb, var(--accent) 20%, transparent), transparent 62%);
    opacity: 0;
    transition: opacity 0.3s ease;
    mix-blend-mode: screen;
    z-index: 0;
  }
  .card:hover {
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    box-shadow: 0 26px 60px -22px color-mix(in srgb, var(--accent) 40%, transparent), 0 10px 30px -14px rgba(0, 0, 0, 0.35);
  }
  .card:hover::before { opacity: 1; }
  .card > * { position: relative; z-index: 1; }

  .login-box { margin-top: 16vh; }
}
