/* ==========================================================================
   BN PERSONAL TRAINING PWA — Minimalist Charcoal & Slate System
   Allineato alla palette ufficiale del sito web BN Personal Training (Granarolo)
   ========================================================================== */

@property --value {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

:root {
  color-scheme: light dark;

  /* Brand Palette - Clean Slate, Charcoal & Modern Monochrome (Dal sito web BN) */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --bg-subtle: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.92);

  /* Primary & Accent - Sophisticated Charcoal / Titanium Gray */
  --primary: #181b20;
  --primary-hover: #000000;
  --primary-light: #f1f3f5;
  --primary-border: #e2e5e9;

  --accent: #181b20;
  --accent-hover: #000000;
  --accent-slate: #3b424e;
  --accent-soft: rgba(24, 27, 32, 0.08);
  --accent-border: rgba(24, 27, 32, 0.22);

  /* Typography */
  --text-primary: #0f1115;
  --text-secondary: #3b424e;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --border-subtle: #e5e7eb;
  --border-strong: #cbd5e1;

  /* Semantic Status Colors */
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.12);
  --emerald-border: rgba(16, 185, 129, 0.32);
  --emerald-text: #047857;

  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.13);
  --amber-border: rgba(245, 158, 11, 0.38);
  --amber-text: #b45309;

  --rose: #e11d48;
  --rose-soft: rgba(225, 29, 72, 0.1);
  --rose-border: rgba(225, 29, 72, 0.3);
  --rose-text: #be123c;

  --slate-badge-bg: #f1f3f5;
  --slate-badge-text: #181b20;
  --slate-badge-border: #d1d5db;

  --whatsapp: #25d366;
  --whatsapp-hover: #1da851;

  /* Elevation & Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-md: 0 4px 8px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 12px 20px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --shadow-xl: 0 24px 35px -5px rgb(0 0 0 / 0.14), 0 10px 15px -6px rgb(0 0 0 / 0.06);

  /* Layout & Spacing */
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --nav-height: 72px;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --bg-app: #0f1115;
  --bg-surface: #181b20;
  --bg-surface-elevated: #20242b;
  --bg-surface-hover: #262b33;
  --bg-subtle: #12151a;
  --bg-glass: rgba(24, 27, 32, 0.92);

  --primary: #ffffff;
  --primary-hover: #e2e8f0;
  --primary-light: #262b33;
  --primary-border: #3b424e;

  --accent: #ffffff;
  --accent-hover: #e2e8f0;
  --accent-slate: #94a3b8;
  --accent-soft: rgba(255, 255, 255, 0.1);
  --accent-border: rgba(255, 255, 255, 0.24);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-inverse: #0f1115;

  --border-subtle: #262b33;
  --border-strong: #3b424e;

  --emerald-text: #34d399;
  --amber-text: #fbbf24;
  --rose-text: #fb7185;

  --slate-badge-bg: #262b33;
  --slate-badge-text: #f8fafc;
  --slate-badge-border: #3b424e;

  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  letter-spacing: normal;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea, label, summary, [role="button"] {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ==========================================================================
   APP SHELL LAYOUT (Mobile-First + Samsung Galaxy Z Fold Cover & Main Screen)
   ========================================================================== */

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
}

/* Z Fold Unfolded Landscape (820px+) & Desktop: Left Sidebar Rail */
@media (min-width: 820px) {
  .app-layout {
    flex-direction: row;
  }
}

.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 0.35rem env(safe-area-inset-bottom, 0px);
  z-index: 40;
}

/* Z Fold Unfolded Portrait (580px - 819px): Ergonomic Floating Pill Dock */
@media (min-width: 580px) and (max-width: 819px) {
  .app-nav {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(94vw, 540px);
    bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
    height: 68px;
    padding: 0 0.65rem;
    border-radius: 20px;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-lg);
  }
}

.nav-brand {
  display: none;
}

.brand-badge-bn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background-color: #181b20;
  color: #ffffff;
  font-weight: 900;
  font-size: 1rem;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(24, 27, 32, 0.18);
}

[data-theme="dark"] .brand-badge-bn {
  background-color: #ffffff;
  color: #0f1115;
}

.nav-links {
  display: flex;
  width: 100%;
  justify-content: space-around;
  align-items: center;
  list-style: none;
  gap: 0.15rem;
}

.nav-btn {
  flex: 1;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.22rem;
  padding: 0.38rem 0.35rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: clamp(0.66rem, 2.2vw, 0.74rem);
  font-weight: 700;
  transition: var(--transition);
  position: relative;
}

.nav-btn svg {
  width: 21px;
  height: 21px;
  stroke-width: 2.1;
}

.nav-btn:hover {
  color: var(--text-primary);
}

.nav-btn.active {
  color: var(--text-inverse);
  background: var(--primary);
  box-shadow: 0 4px 12px rgba(24, 27, 32, 0.18);
}

.nav-badge {
  position: absolute;
  top: 3px;
  right: max(4px, 14%);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--rose);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-badge:empty {
  display: none;
}

@media (min-width: 820px) {
  .app-nav {
    position: sticky;
    top: 0;
    width: 248px;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 1.35rem 1rem;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    flex-shrink: 0;
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.4rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 1.1rem;
  }

  .nav-brand-title {
    font-weight: 800;
    font-size: 0.96rem;
    color: var(--text-primary);
  }

  .nav-brand-sub {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
  }

  .nav-links {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .nav-btn {
    flex: initial;
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.8rem;
    padding: 0.8rem 0.95rem;
    font-size: 0.88rem;
    border-radius: var(--radius-md);
  }

  .nav-badge {
    position: static;
    margin-left: auto;
  }
}

/* ==========================================================================
   MAIN CONTENT AREA & TOP HEADER (Mobile-First)
   ========================================================================== */

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 5rem);
  min-width: 0;
}

@media (min-width: 820px) {
  .app-main {
    padding-bottom: 2.5rem;
  }
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 0.85rem 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

@media (min-width: 580px) {
  .top-header {
    padding: 0.8rem 1.25rem;
  }
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}

.header-logo-mobile {
  display: inline-flex;
}

@media (min-width: 820px) {
  .header-logo-mobile {
    display: none;
  }
}

.header-title-wrap {
  min-width: 0;
}

.header-title-wrap h1 {
  font-size: clamp(0.95rem, 3.5vw, 1.08rem);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title-wrap p {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* On Z Fold Cover Screen (< 380px), hide subtitle so header stays super clean */
@media (max-width: 380px) {
  .header-title-wrap p {
    display: none;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.38rem 0.68rem;
  min-height: 38px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  flex-shrink: 0;
}

.sync-pill[data-status="offline"] .sync-dot {
  background: var(--amber);
}

.sync-pill[data-status="syncing"] .sync-dot {
  background: var(--accent-slate);
  animation: pulseDot 1s infinite alternate;
}

.sync-pill[data-status="cloud_synced"] .sync-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

.sync-pill[data-status="sync_error"] .sync-dot {
  background: var(--rose);
}

@keyframes pulseDot {
  from { opacity: 0.35; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1.2); }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* ==========================================================================
   SUMMARY KPI STRIP (Mobile 2x2 -> Z Fold Unfolded 4x1)
   ========================================================================== */

.view-container {
  padding: 0.8rem;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  container-type: inline-size;
}

@media (min-width: 580px) {
  .view-container {
    padding: 1.15rem;
  }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.95rem;
}

/* Z Fold Unfolded (580px+) shows all 4 KPIs in 1 sleek horizontal bar */
@media (min-width: 580px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.15rem;
  }
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  min-width: 0;
}

@media (min-width: 580px) {
  .kpi-card {
    padding: 0.85rem 1rem;
  }
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.kpi-label {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: clamp(1.15rem, 3.8vw, 1.45rem);
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.kpi-sub {
  font-size: 0.71rem;
  font-weight: 600;
  letter-spacing: normal;
  color: var(--text-muted);
}

.kpi-card.kpi-alert-amber {
  border-color: var(--amber-border);
  background: linear-gradient(145deg, var(--bg-surface), var(--amber-soft));
}

.kpi-card.kpi-alert-rose {
  border-color: var(--rose-border);
  background: linear-gradient(145deg, var(--bg-surface), var(--rose-soft));
}

/* ==========================================================================
   PROGRESS RING (Compliant with Modern Web Guidance `progress-ring`)
   ========================================================================== */

.progress-ring-wrapper {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}

progress.progress-ring {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

progress.progress-ring::-webkit-progress-bar {
  display: none;
  background: none;
}

progress.progress-ring::-webkit-progress-value {
  display: none;
  background: none;
}

progress.progress-ring::-moz-progress-bar {
  display: none;
  background: none;
}

progress.progress-ring::slider-fill {
  display: none;
  background: none;
}

progress.progress-ring {
  --size: 62px;
  --thickness: 6.5px;
  --track-color: var(--border-subtle);
  --fill-color: var(--primary);
  --value: attr(value type(<number>));
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: conic-gradient(
    var(--fill-color) calc(var(--value) * 1%),
    var(--track-color) 0
  );
  background-clip: border-area;
  border: var(--thickness) solid transparent;
  background-origin: border-box;
  transition: --value 0s ease-in-out;
}

@media (prefers-reduced-motion: no-preference) {
  progress.progress-ring {
    transition-duration: 0.4s;
  }
}

@supports not (background-clip: border-area) {
  progress.progress-ring {
    mask-image: radial-gradient(
      transparent calc(50% - var(--thickness)),
      black calc(50% - var(--thickness) + 0.5px)
    );
    -webkit-mask-image: radial-gradient(
      transparent calc(50% - var(--thickness)),
      black calc(50% - var(--thickness) + 0.5px)
    );
    border: 0;
  }
}

progress.progress-ring[data-ring-state="warning"] {
  --fill-color: var(--amber);
}

progress.progress-ring[data-ring-state="danger"] {
  --fill-color: var(--rose);
}

.progress-ring-content {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  pointer-events: none;
}

.ring-main-num {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-primary);
}

.ring-sub-label {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ==========================================================================
   CALENDAR VIEW (Mobile-First + Samsung Galaxy Z Fold Cover & Main Screen)
   ========================================================================== */

.calendar-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.calendar-toolbar > div:last-child {
  display: flex;
  width: 100%;
}

.date-nav-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  width: 100%;
}

.date-display-title {
  font-size: clamp(0.92rem, 3.6vw, 1.05rem);
  font-weight: 800;
  flex: 1;
  min-width: 0;
  text-align: center;
  text-transform: capitalize;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.seg-btn {
  padding: 0.45rem 0.5rem;
  min-height: 38px;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 7px;
  color: var(--text-muted);
  transition: all 0.15s ease;
  text-align: center;
}

/* Z Fold Unfolded (580px+) & Tablet/Desktop: Single horizontal toolbar row */
@media (min-width: 580px) {
  .calendar-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .calendar-toolbar > div:last-child {
    width: auto;
  }

  .date-nav-group {
    width: auto;
    justify-content: flex-start;
    gap: 0.5rem;
  }

  .date-display-title {
    min-width: 165px;
    flex: initial;
  }

  .segmented-control {
    display: inline-flex;
    width: auto;
  }

  .seg-btn {
    padding: 0.42rem 0.9rem;
  }
}

.seg-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.28rem;
  margin-bottom: 0.9rem;
}

.day-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.48rem 0.15rem;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  position: relative;
}

@media (min-width: 580px) {
  .week-strip {
    gap: 0.45rem;
    margin-bottom: 1.15rem;
  }

  .day-pill {
    border-radius: var(--radius-md);
    padding: 0.6rem 0.25rem;
    min-height: 64px;
  }
}

.day-pill:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.day-pill.today {
  border-color: var(--primary);
  border-width: 1.5px;
}

.day-pill.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 6px 16px rgba(24, 27, 32, 0.24);
}

.day-pill-name {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  opacity: 0.75;
}

.day-pill-num {
  font-size: clamp(0.92rem, 3vw, 1.05rem);
  font-weight: 800;
}

.day-pill-dots {
  display: flex;
  gap: 2.5px;
  min-height: 6px;
  align-items: center;
}

.day-dot {
  width: 4.5px;
  height: 4.5px;
  border-radius: 50%;
  background: var(--primary);
}

.day-pill.selected .day-dot {
  background: var(--text-inverse);
}

/* Container query host for Calendar Content (per Modern Web Guidance `size-aware-styling`) */
#calendarContentArea {
  container-type: inline-size;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* Mobile-First & Z Fold Cover Screen (narrow) default slot layout */
.slot-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 0.5rem;
  align-items: stretch;
}

.slot-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.2rem;
  box-shadow: var(--shadow-sm);
}

.slot-time span:last-child {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
}

.slot-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 0.78rem 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.65rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  min-width: 0;
}

.slot-card.slot-free {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
  padding: 0.75rem 0.9rem;
  min-height: 52px;
  flex-direction: row;
  align-items: center;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.slot-card.slot-free:hover {
  border-color: var(--primary);
  background: var(--accent-soft);
  color: var(--text-primary);
}

.slot-card.slot-booked {
  border-left: 4px solid var(--primary);
}

.slot-card.slot-completed {
  border-left: 4px solid var(--emerald);
  background: linear-gradient(90deg, var(--emerald-soft), var(--bg-surface) 35%);
}

.slot-card.slot-warning {
  border-left: 4px solid var(--amber);
}

.slot-card.slot-danger {
  border-left: 4px solid var(--rose);
}

.slot-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.slot-client-details {
  min-width: 0;
  flex: 1;
}

.slot-client-name {
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.38rem;
  cursor: pointer;
}

.slot-client-name:hover {
  text-decoration: underline;
}

.slot-meta {
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* On Mobile & Z Fold Cover Screen: full-width thumb-friendly action bar */
.slot-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border-subtle);
}

.slot-actions .btn:first-child {
  flex: 1;
  min-height: 42px;
  font-size: 0.82rem;
}

.slot-actions .btn:last-child {
  min-height: 42px;
  min-width: 42px;
}

/* Media query fallback + @container query for Z Fold Unfolded (520px+ container) */
@media (min-width: 580px) {
  .slot-row {
    grid-template-columns: 68px 1fr;
    gap: 0.7rem;
  }
  .slot-card {
    flex-direction: row;
    align-items: center;
    padding: 0.9rem 1.05rem;
  }
  .slot-actions {
    width: auto;
    padding-top: 0;
    border-top: none;
  }
  .slot-actions .btn:first-child {
    flex: initial;
    padding: 0.5rem 0.95rem;
  }
}

@supports (container-type: inline-size) {
  @container (min-width: 510px) {
    .slot-row {
      grid-template-columns: 68px 1fr;
      gap: 0.7rem;
    }
    .slot-card {
      flex-direction: row;
      align-items: center;
      padding: 0.9rem 1.05rem;
    }
    .slot-actions {
      width: auto;
      padding-top: 0;
      border-top: none;
    }
    .slot-actions .btn:first-child {
      flex: initial;
      padding: 0.5rem 0.95rem;
    }
  }
}

/* Z Fold Unfolded shows 2 columns of week days automatically */
.week-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 0.75rem;
}

.week-day-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  box-shadow: var(--shadow-sm);
}

.week-day-box.today {
  border-color: var(--primary);
  border-width: 1.5px;
}

.week-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 800;
  font-size: 0.88rem;
}

.week-mini-appt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.52rem 0.65rem;
  min-height: 40px;
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  font-size: 0.79rem;
  cursor: pointer;
}

.week-mini-appt.completed {
  border-left: 3px solid var(--emerald);
}

.week-mini-appt.scheduled {
  border-left: 3px solid var(--primary);
}

/* Month Calendar Grid (Optimized for Z Fold Cover, Standard Phones & Z Fold Unfolded) */
.month-calendar-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.55rem;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 580px) {
  .month-calendar-wrap {
    padding: 0.9rem;
  }
}

.month-weekdays-header {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.25rem;
}

@media (min-width: 580px) {
  .month-weekdays-header,
  .month-grid {
    gap: 0.38rem;
  }
}

.month-day-cell {
  min-height: 68px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  padding: 0.28rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  overflow: hidden;
}

@media (min-width: 580px) {
  .month-day-cell {
    min-height: 94px;
    border-radius: var(--radius-sm);
    padding: 0.45rem;
    gap: 0.28rem;
  }
}

.month-day-cell:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-hover);
}

.month-day-cell.outside-month {
  opacity: 0.4;
  background: var(--bg-subtle);
}

.month-day-cell.today {
  border-color: var(--primary);
  border-width: 1.5px;
}

.month-day-cell.selected {
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

.month-day-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.15rem;
}

.month-day-num {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text-primary);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.month-day-cell.today .month-day-num {
  background: var(--primary);
  color: var(--text-inverse);
}

.month-day-count {
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--text-muted);
}

.month-day-appts {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.month-appt-pill {
  font-size: 0.58rem;
  font-weight: 700;
  padding: 0.12rem 0.24rem;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-left: 2.5px solid var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 580px) {
  .month-day-num {
    font-size: 0.82rem;
    width: 24px;
    height: 24px;
  }
  .month-appt-pill {
    font-size: 0.68rem;
    padding: 0.16rem 0.35rem;
    border-radius: 5px;
  }
}

.month-appt-pill.completed {
  border-left-color: var(--emerald);
  background: var(--emerald-soft);
  color: var(--emerald-text);
}

/* ==========================================================================
   BADGES & BUTTONS (Stile BN Personal Training — Mobile Touch Friendly)
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.22rem 0.58rem;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: normal;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-green {
  background: var(--emerald-soft);
  color: var(--emerald-text);
  border: 1px solid var(--emerald-border);
}

.badge-blue {
  background: var(--slate-badge-bg);
  color: var(--slate-badge-text);
  border: 1px solid var(--slate-badge-border);
}

.badge-amber {
  background: var(--amber-soft);
  color: var(--amber-text);
  border: 1px solid var(--amber-border);
}

.badge-rose {
  background: var(--rose-soft);
  color: var(--rose-text);
  border: 1px solid var(--rose-border);
}

.badge-purple {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.cf-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.48rem;
  border-radius: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 42px;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  font-weight: 700;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-sm {
  min-height: 38px;
  padding: 0.42rem 0.74rem;
  font-size: 0.76rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background-color: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 4px 12px rgba(24, 27, 32, 0.2);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.btn-amber {
  background: var(--amber);
  color: #0f1115;
}

.btn-danger {
  background: var(--rose-soft);
  color: var(--rose-text);
  border: 1px solid var(--rose-border);
}

/* ==========================================================================
   CLIENTS & PACKAGES GRID (1 col on Cover Screen -> 2 cols on Z Fold Unfolded)
   ========================================================================== */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.95rem;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 190px;
}

.search-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem 0.65rem 2.35rem;
  font-size: 1rem; /* 16px on mobile prevents browser auto-zoom */
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 580px) {
  .search-input {
    font-size: 0.88rem;
  }
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.search-icon {
  position: absolute;
  left: 0.82rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Auto-fits 1 column on phones/Cover Screen, 2 columns on Z Fold Unfolded (580px+) */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 275px), 1fr));
  gap: 0.8rem;
}

.client-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  min-width: 0;
}

.client-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.client-card-top {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.client-card-info {
  flex: 1;
  min-width: 0;
}

.client-card-name {
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.client-card-name:hover {
  text-decoration: underline;
}

.client-card-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.22rem;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.client-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.42rem;
}

/* 3-column balanced button grid inside client card (Vedi, Modifica, Elimina) */
.client-card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  padding-top: 0.75rem;
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
}

.client-card-actions .btn {
  width: 100%;
  min-height: 40px;
  padding: 0.45rem 0.35rem;
  font-size: 0.75rem;
  justify-content: center;
}

/* ==========================================================================
   MODALS / NATIVE DIALOGS (Bottom Sheet on Phones -> Centered Modal on Z Fold Unfolded)
   ========================================================================== */

html:has(dialog[open]),
body:has(dialog[open]),
body.modal-open {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

dialog.app-dialog {
  margin: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-xl);
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
}

dialog.app-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog.app-dialog > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: inherit;
  overflow: hidden;
}

/* Centered modal on Z Fold Unfolded (580px+) & Desktop */
@media (min-width: 580px) {
  dialog.app-dialog {
    margin: auto;
    width: min(92vw, 550px);
    max-height: 90dvh;
    border-radius: var(--radius-lg);
  }

  dialog.app-dialog.dialog-wide {
    width: min(94vw, 680px);
  }
}

dialog.app-dialog::backdrop {
  background: rgba(15, 17, 21, 0.62);
  backdrop-filter: blur(4px);
  touch-action: none;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.95rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  flex-shrink: 0;
}

.dialog-header h2 {
  font-size: 1.02rem;
  font-weight: 800;
}

.dialog-body {
  padding: 1.05rem 1.1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(92dvh - 135px);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0.85rem 1.1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  flex-shrink: 0;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.7rem;
}

@media (min-width: 500px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

.form-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  min-height: 44px;
  padding: 0.62rem 0.82rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 1rem; /* 16px prevents mobile keyboard auto-zoom */
}

@media (min-width: 580px) {
  .form-control {
    font-size: 0.9rem;
  }
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.pkg-preset-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.pkg-preset-card {
  border: 2px solid var(--border-subtle);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.35rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pkg-preset-card.active {
  border-color: var(--primary);
  background: var(--accent-soft);
}

.pkg-preset-num {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-primary);
}

.pkg-preset-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.pkg-preset-price {
  font-size: 0.72rem;
  color: var(--text-primary);
  font-weight: 800;
  margin-top: 0.18rem;
}

/* ==========================================================================
   TOAST NOTIFICATIONS (`popover="manual"` per Modern Web Guidance)
   ========================================================================== */

.toast-stack {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}

.toast-item[popover] {
  position: fixed;
  inset: auto 0.85rem calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 4.5rem) 0.85rem;
  margin: 0 auto;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow-xl);
  pointer-events: auto;
  max-width: 420px;
  transition: opacity 0.22s ease, transform 0.22s ease, overlay 0.22s allow-discrete, display 0.22s allow-discrete;
  opacity: 0;
  transform: translateY(10px);
}

.toast-item[popover]:is(:popover-open, .\:popover-open) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  opacity: 1;
  transform: translateY(0);
}

.toast-item[popover] + .toast-item[popover] {
  margin-top: 0.75rem;
}

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.95rem;
  margin-bottom: 0.9rem;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 580px) {
  .section-card {
    padding: 1.2rem;
    margin-bottom: 1rem;
  }
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.section-title {
  font-size: 0.96rem;
  font-weight: 800;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.empty-state {
  text-align: center;
  padding: 1.8rem 0.85rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.fab-btn {
  position: fixed;
  right: 0.95rem;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 0.85rem);
  height: 50px;
  padding: 0 1.2rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--text-inverse);
  font-weight: 800;
  font-size: 0.86rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 8px 24px rgba(24, 27, 32, 0.32);
  z-index: 35;
  transition: var(--transition);
}

.fab-btn:hover {
  transform: translateY(-2px);
}

@media (min-width: 820px) {
  .fab-btn {
    bottom: 1.5rem;
    right: 1.75rem;
  }
}

/* Samsung Galaxy Z Fold Dual-Segment / Hinge Crease Protection */
@media (horizontal-viewport-segments: 2) {
  .clients-grid,
  .week-overview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: max(1rem, calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px)));
  }
}
