:root {
  --app-primary: #1e40af;
  --app-secondary: #3b82f6;
  --app-tab-height: 52px;
  --app-header-height: 52px;
  --app-header-content-ios: 58px;
  --app-safe-top: env(safe-area-inset-top, 0px);
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1e40af;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
}

.app-root {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.app-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f1f5f9;
}

.app-header {
  flex: 0 0 auto;
  min-height: var(--app-header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0 1rem;
  position: relative;
  background-color: #1e40af;
  background-image: linear-gradient(135deg, var(--app-primary) 0%, var(--app-secondary) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.25);
  z-index: 100;
  flex-shrink: 0;
}

@supports (-webkit-touch-callout: none) {
  .app-header {
    padding-top: calc(var(--app-safe-top) + 6px);
    min-height: calc(var(--app-safe-top) + var(--app-header-content-ios) + 6px);
    padding-bottom: 10px;
    background-image: none;
    background-color: #1e40af;
    align-items: center;
  }

  .app-header img {
    position: relative;
    top: 0;
  }

  .app-header__back,
  .app-header__logout {
    top: auto;
    bottom: 1px;
    transform: none;
  }

  .app-header__back:active {
    transform: scale(0.96);
  }

  .app-header__logout:active {
    transform: scale(0.96);
  }

  .app-tabbar {
    flex-shrink: 0;
    padding-top: 0;
    padding-bottom: 0;
    min-height: 0;
    align-items: stretch;
  }

  .app-tabbar--cliente {
    padding-top: 0;
    padding-bottom: 0;
  }

  .app-tabbar--cliente .app-tab {
    padding: 0.28rem 0.1rem calc(0.1rem + var(--app-safe-bottom));
  }

  .app-tab {
    padding-bottom: calc(0.35rem + var(--app-safe-bottom));
  }

  .app-tab--prenota {
    transform: translateY(0);
    margin-bottom: 0;
    padding: 8px 6px calc(4px + var(--app-safe-bottom)) !important;
  }
}

.app-header img {
  height: 32px;
  width: auto;
}

.app-header__back,
.app-header__logout {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-header__back svg,
.app-header__logout svg {
  width: 22px;
  height: 22px;
}

.app-header__back {
  left: 10px;
  background: #fff;
  color: #dc2626;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.app-header__back[hidden] {
  display: none !important;
}

.app-header__back:active {
  background: #fef2f2;
  color: #b91c1c;
  transform: translateY(-50%) scale(0.96);
}

.app-header__logout {
  right: 10px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.app-header__logout[hidden] {
  display: none !important;
}

.app-header__logout:active {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-50%) scale(0.96);
}

.app-frame-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  background: #fff;
  overflow: hidden;
}

.app-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.app-frame-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  z-index: 5;
  transition: opacity 0.2s ease;
}

.app-frame-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.app-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #dbeafe;
  border-top-color: var(--app-primary);
  border-radius: 50%;
  animation: app-spin 0.7s linear infinite;
}

@keyframes app-spin {
  to { transform: rotate(360deg); }
}

.app-tabbar {
  flex: 0 0 auto;
  z-index: 100;
  display: flex;
  align-items: stretch;
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.06);
}

.app-tab {
  flex: 1 1 25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.45rem 0.25rem calc(0.35rem + var(--app-safe-bottom));
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.app-tab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.app-tab.active {
  color: var(--app-primary);
  background: #eff6ff;
}

.app-tab:active {
  background: #dbeafe;
}

@media (min-width: 480px) {
  .app-tab {
    font-size: 0.72rem;
  }
}

/* Splash primo avvio */
.app-splash {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--app-safe-top);
  padding-bottom: var(--app-safe-bottom);
  background: linear-gradient(145deg, #1e3a8a 0%, #1e40af 45%, #3b82f6 100%);
  transition: opacity 0.75s ease, visibility 0.75s ease;
}

.app-splash--out {
  opacity: 0;
  visibility: hidden;
}

.app-splash--out .app-splash__logo {
  transform: translateY(-72px) scale(0.88);
  opacity: 0;
}

.app-splash__logo {
  width: min(220px, 70vw);
  height: auto;
  transition: transform 0.85s ease, opacity 0.75s ease;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.25));
}

/* Tab bar area clienti (5 voci + Prenota centrale) */
.app-tabbar--cliente {
  align-items: stretch;
  padding: 0;
}

.app-tabbar--cliente .app-tab {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.52rem;
  padding: 0.28rem 0.05rem calc(0.1rem + var(--app-safe-bottom));
}

.app-tabbar--cliente .app-tab svg {
  width: 20px;
  height: 20px;
}

.app-tab--prenota {
  flex: 0 0 68px !important;
  align-self: stretch;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center;
  margin: 0 2px 0;
  padding: 8px 6px calc(4px + var(--app-safe-bottom)) !important;
  border-radius: 18px;
  background: linear-gradient(145deg, #1e40af 0%, #3b82f6 100%);
  color: #fff !important;
  box-shadow: 0 6px 20px rgba(30, 64, 175, 0.45);
  transform: translateY(0);
  margin-bottom: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.app-tab--prenota svg {
  width: 26px !important;
  height: 26px !important;
  margin-bottom: 2px;
}

.app-tab--prenota span {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 0.65rem !important;
  font-weight: 800;
  letter-spacing: 0;
}

.app-tab--prenota.active {
  background: linear-gradient(145deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff !important;
  box-shadow: 0 8px 24px rgba(30, 64, 175, 0.55);
}

.app-tab--prenota:active {
  transform: translateY(0) scale(0.96);
  background: linear-gradient(145deg, #1e3a8a 0%, #3b82f6 100%);
}

.app-tabbar--1 .app-tab {
  flex: 1 1 100%;
  font-size: 0.8rem;
}

/* PWA standalone: niente fascia vuota sotto le icone (iOS conta gi� la safe area) */
@media (display-mode: standalone) {
  .app-tab {
    padding-bottom: 0.35rem;
  }

  .app-tabbar--cliente .app-tab {
    padding-bottom: 0.1rem;
  }

  .app-tab--prenota {
    padding-bottom: 4px !important;
  }
}

.app-tab--logout {
  color: #b91c1c;
}

.app-tab--logout.active {
  color: #b91c1c;
  background: #fef2f2;
}

/* Guida Aggiungi a Home (iPhone) */
.app-addhome-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(15, 23, 42, 0.55);
}

.app-addhome-overlay[hidden] {
  display: none !important;
}

.app-addhome-overlay__card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 18px;
  padding: 18px 16px 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
}

.app-addhome-overlay__title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #1e40af;
}

.app-addhome-overlay__sub {
  margin: 0 0 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: #334155;
}

.app-addhome-overlay__steps {
  margin: 0 0 12px;
  padding-left: 20px;
  color: #475569;
  font-size: 0.88rem;
  line-height: 1.5;
}

.app-addhome-overlay__steps li {
  margin-bottom: 8px;
}

.app-addhome-overlay__note {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  font-size: 0.84rem;
  line-height: 1.45;
}

.app-addhome-overlay__btn {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

/* Calendario: nessun blocco layout app shell */
