@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent-cyan: #38bdf8;
  --accent-pink: #ec4899;
  
  --bg-color: #0b0f19;
  --card-bg: rgba(22, 30, 49, 0.65);
  --card-border: rgba(255, 255, 255, 0.1);
  --card-glow: rgba(99, 102, 241, 0.08);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --input-bg: rgba(15, 23, 42, 0.7);
  --danger: #f43f5e;
  --danger-hover: #e11d48;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Sfondo immersivo con luce ambientale (Mesh Gradient) */
html, body {
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(circle at 15% 10%, rgba(99, 102, 241, 0.18) 0%, transparent 45%),
    radial-gradient(circle at 85% 60%, rgba(56, 189, 248, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 50% 90%, rgba(236, 72, 153, 0.08) 0%, transparent 40%);
  background-attachment: fixed;
}

body {
  color: var(--text-main);
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(100px + env(safe-area-inset-bottom)) 16px;
  max-width: 440px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Titolo d'impatto con gradiente e bagliore */
h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 22px;
  text-align: center;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  drop-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Base Card Glassmorphic Premium */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  padding: 22px;
  border-radius: 24px;
  box-shadow: 
    0 12px 32px -8px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 0 rgba(255, 255, 255, 0.12);
  margin-bottom: 18px;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.25s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, var(--card-glow) 0%, transparent 70%);
  pointer-events: none;
}

/* Form Styling */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #a5b4fc;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input {
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 1rem;
  width: 100%;
  outline: none;
  transition: all 0.2s ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Gestione colore icona calendario */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.7;
}

/* ==========================================
   Input con Stepper & Pulsanti Modelli
   ========================================== */

.input-with-stepper {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 4px 6px 4px 14px;
  transition: all 0.25s ease;
  width: 100%;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.input-with-stepper input {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 10px 4px 10px 0 !important;
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  font-weight: 600;
}

.input-with-stepper:focus-within {
  border-color: #818cf8;
  box-shadow: 0 0 16px var(--primary-glow), inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

.input-with-stepper input[type="number"]::-webkit-inner-spin-button,
.input-with-stepper input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper-buttons {
  position: static;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.step-btn {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.03) 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-size: 1.1rem;
  transition: all 0.2s ease;
  touch-action: manipulation;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.step-btn:active:not(:disabled) {
  transform: scale(0.92);
  background: var(--primary);
}

.step-btn:hover:not(:disabled) {
  background: rgba(129, 140, 248, 0.3);
  border-color: #818cf8;
}

.step-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

/* Pulsante Salva Principale con Gradiente & Glow */
button[type="submit"] {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 16px;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
  box-shadow: 0 8px 20px -4px rgba(99, 102, 241, 0.5);
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  touch-action: manipulation;
  letter-spacing: 0.02em;
}

button[type="submit"]:active {
  transform: scale(0.97);
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

/* ==========================================
   Switch Obiettivo (Soft-Skeuomorphic)
   ========================================== */

.goal-toggle-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.goal-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.goal-switch {
  position: relative;
  display: inline-block;
  width: 72px;
  height: 36px;
  cursor: pointer;
}

.goal-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

/* Binario dello switch con effetto incassato (Inset) */
.goal-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.8) 0%, rgba(30, 41, 59, 0.8) 100%);
  border-radius: 36px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 
    inset 0 3px 6px rgba(0, 0, 0, 0.6),
    inset 0 -1px 2px rgba(255, 255, 255, 0.1),
    0 1px 2px rgba(0, 0, 0, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

/* Icone integrate nello sfondo dello switch (entrambe azzurro elettrico) */
.goal-icon {
  z-index: 1;
  color: #00d2ff !important;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.goal-icon svg {
  stroke: #00d2ff !important;
}

.icon-lose {
  opacity: 1;
}

.icon-gain {
  opacity: 0.35;
}

.goal-switch input:checked + .goal-slider .icon-lose {
  opacity: 0.35;
}

.goal-switch input:checked + .goal-slider .icon-gain {
  opacity: 1;
}

/* Pomello 3D (Knob) */
.goal-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(180deg, #e2e8f0 0%, #94a3b8 100%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 
    0 4px 8px rgba(0, 0, 0, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.3),
    inset 0 1px 1px rgba(255, 255, 255, 0.8);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
}

/* Movimento Pomello al toggle */
.goal-switch input:checked + .goal-slider .goal-knob {
  transform: translateX(36px);
  background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
}

/* Stili Sezione Statistiche */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-box {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--card-border);
  padding: 14px 12px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-value.up {
  color: #34d399;
  text-shadow: 0 0 10px rgba(52, 211, 153, 0.3);
}

.stat-value.down {
  color: #fb7185;
  text-shadow: 0 0 10px rgba(251, 113, 133, 0.3);
}

.stat-value.neutral {
  color: #94a3b8;
}

/* Header del Grafico */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.chart-header .date-display h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
  margin: 0;
  text-transform: capitalize;
}

/* Canvas & Contenitore Grafico */
.chart-container {
  position: relative;
  width: 100%;
  height: 240px;
}

/* ==========================================
   Storico (Design Moderno & Interactive)
   ========================================== */

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Pulsante Attivazione Calendario */
.calendar-trigger-btn {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  touch-action: manipulation;
  user-select: none;
}

.calendar-trigger-btn:active {
  transform: scale(0.92);
  background: var(--primary);
}

.date-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.date-display h2 {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
  text-align: center;
  margin: 0;
  letter-spacing: -0.01em;
}

/* Pulsanti Frecce Glassmorphic per lo storico */
.history-header .nav-btn {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  touch-action: manipulation;
  user-select: none;
}

.history-header .nav-btn:active:not(:disabled) {
  transform: scale(0.92);
  background: var(--primary);
}

.history-header .nav-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  box-shadow: none;
}

/* Badge Tasto "Oggi" */
.today-btn {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 20px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: all 0.2s ease;
  touch-action: manipulation;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.today-btn:active {
  transform: scale(0.92);
  background: var(--primary);
  color: #ffffff;
}

.today-btn.hidden {
  display: none;
}

/* Lista Misurazioni con Carte animate */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Card del singolo elemento */
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  transition: all 0.2s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.history-item:active {
  background: rgba(15, 23, 42, 0.8);
}

.history-item-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Badge Orario con gradiente di sfondo */
.time-badge {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 10px;
  letter-spacing: 0.02em;
}

/* Valore del peso */
.weight-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.weight-unit {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Pulsante Elimina */
.delete-btn {
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.3);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.delete-btn:active {
  transform: scale(0.92);
  background: var(--danger);
  color: #ffffff;
}

/* Stato Vuoto */
.empty-history {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 32px 12px;
  background: rgba(15, 23, 42, 0.3);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 16px;
}

/* ==========================================
   Modale & Calendario Moderno
   ========================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: rgba(22, 30, 49, 0.95);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 22px;
  width: 90%;
  max-width: 360px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-main);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: capitalize;
}

.close-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.close-btn:active {
  transform: scale(0.92);
  background: var(--danger);
  color: #ffffff;
}

.calendar-grid-header, 
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  text-align: center;
}

.calendar-grid-header {
  font-size: 0.7rem;
  color: #a5b4fc;
  margin-bottom: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.cal-day:active:not(.empty) {
  transform: scale(0.92);
  background: var(--primary);
}

.cal-day.empty {
  background: transparent;
  border: none;
  cursor: default;
}

.cal-day.selected {
  border: 2px solid #818cf8;
  background: rgba(99, 102, 241, 0.35);
  color: #ffffff;
  box-shadow: 0 0 12px var(--primary-glow);
}

.cal-day.disabled {
  opacity: 0.2;
  cursor: not-allowed;
  pointer-events: none;
  background: transparent;
  border-color: transparent;
}

/* Pallino Neon per giornate registrate */
.has-data-dot {
  width: 5px;
  height: 5px;
  background-color: #34d399;
  border-radius: 50%;
  position: absolute;
  bottom: 4px;
  box-shadow: 0 0 8px #34d399;
}

.disabled-btn {
  opacity: 0.3 !important;
  cursor: not-allowed !important;
  pointer-events: none;
}

#dateInput::-webkit-calendar-picker-indicator {
  display: none;
  -webkit-appearance: none;
}

/* ==========================================
   FLOATING PILL NAVIGATION BAR (Vetro Acrilico - 4 Icone)
   ========================================== */

.nav-container {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 16px;
  z-index: 1000;
  pointer-events: none;
}

.floating-nav {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  height: 64px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Indicatore ridimensionato a 1/4 della larghezza disponibile */
.nav-indicator {
  position: absolute;
  top: 6px;
  left: 6px;
  width: calc((100% - 12px) / 4);
  height: calc(100% - 12px);
  background: rgba(255, 255, 255, 0.16);
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.35, 1);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

/* Spostamento dinamico per 4 elementi (da index 0 a 3) */
.floating-nav[data-active-index="0"] .nav-indicator {
  transform: translateX(0%);
}

.floating-nav[data-active-index="1"] .nav-indicator {
  transform: translateX(100%);
}

.floating-nav[data-active-index="2"] .nav-indicator {
  transform: translateX(200%);
}

.floating-nav[data-active-index="3"] .nav-indicator {
  transform: translateX(300%);
}

.floating-nav .nav-btn {
  position: relative;
  z-index: 2;
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: color 0.3s ease, transform 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  box-shadow: none;
}

.floating-nav .nav-btn .icon-fill {
  fill: currentColor;
}

.floating-nav .nav-btn.active {
  color: #ffffff;
}

.floating-nav .nav-btn:active {
  transform: scale(0.9);
}

/* ==========================================
   OPTIMIZATIONS PER MOBILE / DEVICE TATTILI
   ========================================== */
@media (max-width: 600px) {
  .calendar-trigger-btn {
    width: 42px;
    height: 42px;
    font-size: 1.1rem;
    flex-shrink: 0;
  }

  .step-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .cal-day {
    font-size: 0.9rem;
    min-height: 40px;
  }
}

@media (max-width: 380px) {
  .calendar-trigger-btn {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }

  .date-display h2,
  .chart-header .date-display h2 {
    font-size: 0.95rem;
  }
}