/* Reset essenziale */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--thumb-size) + var(--thumb-offset-bottom) + 16px);
}

/* Header contenuto */
.content-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--color-border);
}
.app-title { margin: 0; font-size: 1.5rem; font-weight: 700; }
.app-tagline { margin: 4px 0 0; font-size: 0.9rem; color: var(--color-text-muted); }

/* Schermate / pagine */
.main-content { flex: 1; position: relative; }
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-out), visibility var(--duration-normal);
}
.screen-active {
  position: relative;
  opacity: 1;
  visibility: visible;
}
.screen[hidden] { display: none !important; }

.page-content {
  padding: 24px 20px 48px;
  max-width: 640px;
  margin: 0 auto;
}
.page-content h2 { margin: 0 0 12px; font-size: 1.35rem; }
.page-content p { margin: 0; line-height: 1.55; color: var(--color-text-muted); }
.page-section { margin-top: 24px; }
.page-section:first-of-type { margin-top: 0; }
.page-section h3 { margin: 0 0 8px; font-size: 1.1rem; color: var(--color-text); }

/* Zona pollice: due pulsanti (pie + burger) */
.thumb-dock {
  position: fixed;
  right: var(--thumb-offset-right);
  bottom: var(--thumb-offset-bottom);
  z-index: 100;
  padding: env(safe-area-inset-bottom) env(safe-area-inset-right) 0 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--thumb-gap);
}
.thumb-action {
  width: var(--thumb-size);
  height: var(--thumb-size);
  border-radius: var(--thumb-radius);
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--thumb-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: transform var(--duration-fast), background var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}
.thumb-action:active { transform: scale(0.96); }
.thumb-action--pie { font-size: 1.35rem; }
.thumb-action--pie[aria-expanded="true"] { background: var(--color-border); }
.thumb-action--primary { background: var(--color-accent); color: #fff; }
.thumb-action--primary:hover { background: var(--color-accent-hover); }

/* Pie menu: ruota circolare che si ruota (trascina per girare) */
.pie-menu {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-out), visibility var(--duration-normal);
}
.pie-menu.is-open {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}
.pie-menu__backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-bg);
  cursor: default;
}
/* Viewport: mostra solo la metà inferiore della ruota, sfondo opaco */
.pie-menu__viewport {
  position: fixed;
  left: 50%;
  bottom: calc(var(--thumb-offset-bottom) + var(--thumb-size) + 24px + env(safe-area-inset-bottom, 0));
  width: var(--pie-wheel-size);
  height: var(--pie-viewport-height);
  margin-left: calc(var(--pie-wheel-size) / -2);
  overflow: hidden;
  pointer-events: none;
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease-out);
  background: var(--color-bg-elevated);
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}
.pie-menu.is-open .pie-menu__viewport { transform: translateY(0); pointer-events: auto; }

.pie-menu__header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 44px 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-bg-elevated);
  z-index: 2;
}
.pie-menu__title { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--color-text-muted); }
.pie-menu__close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast);
}
.pie-menu__close:hover { background: var(--color-border); }

/* Ruota: cerchio che ruota (trascinamento) - centro in basso, sfondo opaco */
.pie-menu__wheel {
  position: absolute;
  left: 0;
  bottom: 0;
  width: var(--pie-wheel-size);
  height: var(--pie-wheel-size);
  transform-origin: 50% 100%;
  will-change: transform;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  background: var(--color-bg-elevated);
}
.pie-menu__wheel:active { cursor: grabbing; }

/* Ogni voce: rettangolo arrotondato, testo sempre dritto (contro-rotazione in JS) */
.pie-item {
  position: absolute;
  width: var(--pie-item-width);
  height: var(--pie-item-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: none;
  border-radius: var(--pie-item-radius);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.25;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  box-sizing: border-box;
}
.pie-item:hover { filter: brightness(1.1); }
.pie-item:active { filter: brightness(0.95); }
.pie-item__label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
  max-height: 100%;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
}
.pie-item__icon { display: none !important; }

.pie-item--c1 { background: var(--pie-color-1); }
.pie-item--c2 { background: var(--pie-color-2); }
.pie-item--c3 { background: var(--pie-color-3); }
.pie-item--c4 { background: var(--pie-color-4); }
.pie-item--c5 { background: var(--pie-color-5); }
.pie-item--c6 { background: var(--pie-color-6); }
.pie-item--c7 { background: var(--pie-color-7); }
.pie-item--c8 { background: var(--pie-color-8); }

/* Overlay task switcher (stile “app recenti”) */
.overlay-switcher {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-out), visibility var(--duration-normal);
}
.overlay-switcher.is-open {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
}
.overlay-switcher.is-open .switcher-container {
  transform: translateY(0);
}

.switcher-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--duration-normal);
}
.overlay-switcher.is-open .switcher-backdrop { opacity: 1; }

.switcher-container {
  position: relative;
  width: 100%;
  max-height: 85vh;
  background: var(--color-bg-elevated);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
  padding: 16px 0 max(env(safe-area-inset-bottom), 20px);
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease-out);
  display: flex;
  flex-direction: column;
}

.switcher-header {
  padding: 0 20px 12px;
  flex-shrink: 0;
}
.switcher-title { margin: 0; font-size: 1.1rem; font-weight: 600; }
.switcher-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.switcher-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast);
}
.switcher-close:hover { background: var(--color-border); }

/* Track orizzontale delle card (scorri per vedere tutte le pagine) */
.switcher-track {
  display: flex;
  gap: var(--switcher-card-gap);
  padding: 8px 20px 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.switcher-track::-webkit-scrollbar { display: none; }

/* Card singola anteprima */
.switcher-card {
  flex: 0 0 var(--switcher-card-width);
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  text-align: center;
  transition: transform var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}
.switcher-card:hover { transform: scale(1.02); }
.switcher-card:active { transform: scale(0.98); }
.switcher-card:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 4px; }

.switcher-card__preview {
  width: var(--switcher-card-width);
  height: var(--switcher-card-height);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Tile anteprima (icona + titolo + sottotitolo) */
.preview-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  text-align: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}
.preview-tile__icon {
  font-size: 2.8rem;
  line-height: 1;
  opacity: 0.95;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
.preview-tile__title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.preview-tile__sub {
  font-size: 0.75rem;
  opacity: 0.85;
}

/* Anteprima Home: gradiente caldo */
.switcher-card__preview--home {
  background: linear-gradient(145deg, #2d1f3d 0%, #1a1425 50%, #0f0d14 100%);
  color: #e8ddf5;
}
.switcher-card__preview--home .preview-tile__icon { color: #c9a8f0; }
.switcher-card__preview--home .preview-tile__sub { color: #b8a0d0; }

/* Anteprima Chi siamo: gradiente blu/teal */
.switcher-card__preview--chi-siamo {
  background: linear-gradient(145deg, #0f2a38 0%, #0a1c26 50%, #061218 100%);
  color: #d4eaf0;
}
.switcher-card__preview--chi-siamo .preview-tile__icon { color: #6ec4d8; }
.switcher-card__preview--chi-siamo .preview-tile__sub { color: #8bb8c4; }

/* Anteprima Contatti: gradiente verde/forest */
.switcher-card__preview--contatti {
  background: linear-gradient(145deg, #1a2e1f 0%, #0f1c12 50%, #0a1410 100%);
  color: #d8ecd8;
}
.switcher-card__preview--contatti .preview-tile__icon { color: #7bc97b; }
.switcher-card__preview--contatti .preview-tile__sub { color: #9bc49b; }

/* Anteprima Servizi: gradiente ambra/arancione */
.switcher-card__preview--servizi {
  background: linear-gradient(145deg, #2e2518 0%, #1c1610 50%, #14100a 100%);
  color: #f0e6d4;
}
.switcher-card__preview--servizi .preview-tile__icon { color: #e8b85c; }
.switcher-card__preview--servizi .preview-tile__sub { color: #c4a86b; }

.switcher-card__label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
}
