/* Piena larghezza e menu rapido compatto, interamente contenuto nel cerchio. */
.desktop {
  width: 100%;
  max-width: none;
  margin: 0;
}

.main {
  width: 100%;
}

.tab-page {
  width: 100%;
  max-width: none;
}

@media (max-width: 760px) {
  .mobile-wrap,
  .phone,
  .mobile-content {
    width: 100%;
  }

  .phone {
    max-width: none;
  }

  /* Bottom navigation bar: griglia a 5 colonne perfettamente simmetrica */
  .bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-bottom-nav-height, 96px);
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    align-items: start;
    justify-items: center;
    padding: 12px 2px 0 !important;
    background: #fbfbf9;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.05);
    z-index: 5;
    box-sizing: border-box;
    column-gap: 0;
  }

  .bottom-nav button[data-tab] {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    background: none;
    color: #a4a9a0;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
  }

  .bottom-nav button[data-tab].active {
    color: var(--green, #4e7a4e);
    font-weight: 700;
  }

  .bottom-nav button[data-tab] b {
    display: grid;
    place-items: center;
    width: 25px;
    height: 25px;
    margin: 0 auto;
    line-height: 1;
  }

  .bottom-nav button[data-tab] b .ui-icon {
    display: block;
    width: 22px;
    height: 22px;
  }

  .bottom-nav button[data-tab] span {
    display: block;
    width: 100%;
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    letter-spacing: -0.1px;
  }

  .bottom-nav button[data-tab="home"] {
    grid-column: 1 !important;
  }

  .bottom-nav button[data-tab="movimenti"] {
    grid-column: 2 !important;
  }

  /* Centrato in colonna 3 in-flow, con overhang negativo verso l'alto */
  .bottom-nav .fab {
    grid-column: 3 !important;
    position: relative !important;
    top: -24px !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    justify-self: center !important;
    align-self: start !important;
    width: 62px;
    height: 62px;
    margin: 0 auto !important;
    padding: 0;
    border: 5px solid var(--paper, #fff);
    border-radius: 50%;
    background: #4e7a4e;
    color: #fff;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 28px;
    box-shadow: 0 8px 20px rgba(78, 122, 78, 0.4);
    cursor: pointer;
    touch-action: manipulation;
    z-index: 6;
  }

  .bottom-nav .fab .ui-icon {
    display: block !important;
    width: 28px;
    height: 28px;
    color: #fff;
  }

  .bottom-nav button[data-tab="forecast"] {
    grid-column: 4 !important;
  }

  .bottom-nav button[data-tab="documents"] {
    grid-column: 5 !important;
  }

  /* Overlay FAB Speed-Dial */
  #mobile-fab-menu {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    transition: opacity 220ms var(--ui-ease);
  }

  #mobile-fab-menu.open {
    opacity: 1;
    pointer-events: auto;
  }

  #mobile-fab-menu .mobile-fab-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(18, 26, 16, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
    touch-action: manipulation;
  }

  #mobile-fab-menu .mobile-fab-circle {
    position: absolute;
    left: 50%;
    right: auto;
    top: auto;
    width: min(360px, calc(100vw - 16px));
    height: min(360px, calc(100vw - 16px));
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: visible;
    background: linear-gradient(180deg, rgba(62, 107, 62, 0.97) 0%, rgba(62, 107, 62, 0.92) 55%, rgba(62, 107, 62, 0.55) 82%, rgba(62, 107, 62, 0.1) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 -8px 36px rgba(30, 55, 30, 0.28);
    opacity: 1;
    transform: translateX(-50%) scale(0.15);
    transform-origin: center bottom;
    transition: transform 0.38s cubic-bezier(0.34, 1.35, 0.5, 1);
  }

  #mobile-fab-menu.open .mobile-fab-circle {
    transform: translateX(-50%) scale(1);
  }

  #mobile-fab-menu .mobile-fab-actions {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  #mobile-fab-menu .mobile-fab-actions button {
    position: absolute;
    left: var(--fab-x) !important;
    top: var(--fab-y) !important;
    right: auto !important;
    bottom: auto !important;
    width: auto;
    min-width: 92px;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    color: #fff;
    text-align: center;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    transform: translate(-50%, -28px);
  }

  #mobile-fab-menu .mobile-fab-actions i {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 56px;
    font-style: normal;
    line-height: 0;
  }

  #mobile-fab-menu .mobile-fab-actions i .ui-icon {
    display: block;
    width: 24px;
    height: 24px;
    margin: 0;
    padding: 0;
    flex: none;
  }

  #mobile-fab-menu .mobile-fab-actions i.orange,
  #mobile-fab-menu .mobile-fab-actions .orange {
    color: #ea723d;
  }

  #mobile-fab-menu .mobile-fab-actions i.green-icon,
  #mobile-fab-menu .mobile-fab-actions .green-icon {
    color: #3e6b3e;
  }

  #mobile-fab-menu .mobile-fab-actions i.blue,
  #mobile-fab-menu .mobile-fab-actions .blue {
    color: #4a97c4;
  }

  #mobile-fab-menu .mobile-fab-actions i.purple,
  #mobile-fab-menu .mobile-fab-actions .purple {
    color: #8b7fb5;
  }

  #mobile-fab-menu .mobile-fab-actions button > span {
    display: block;
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: #fff;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
    letter-spacing: 0.2px;
  }

  /* STATO 1 (DEFAULT): Azioni primarie visibili (Documenti, Fattura, Spesa, Assistente) */
  #mobile-fab-main-actions {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: scale(1);
    transition: opacity 0.2s ease, transform 0.22s var(--ui-ease);
  }

  #mobile-fab-menu.open:not(.show-documents) #mobile-fab-main-actions button {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    animation: polar-action-in 0.3s var(--ui-ease) both !important;
  }

  #mobile-fab-menu.open:not(.show-documents) #mobile-fab-main-actions button:nth-child(1) { animation-delay: 0.04s !important; }
  #mobile-fab-menu.open:not(.show-documents) #mobile-fab-main-actions button:nth-child(2) { animation-delay: 0.08s !important; }
  #mobile-fab-menu.open:not(.show-documents) #mobile-fab-main-actions button:nth-child(3) { animation-delay: 0.12s !important; }
  #mobile-fab-menu.open:not(.show-documents) #mobile-fab-main-actions button:nth-child(4) { animation-delay: 0.16s !important; }

  /* Subactions RIGOROSAMENTE NASCOSTE fino a .show-documents */
  #mobile-fab-documents-sub {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: scale(0.88);
    transition: opacity 0.2s ease, transform 0.22s var(--ui-ease);
  }

  #mobile-fab-documents-sub button {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    animation: none !important;
  }

  /* STATO 2: Documenti subactions aperte (.show-documents) */
  #mobile-fab-menu.show-documents #mobile-fab-main-actions {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: scale(0.85);
  }

  #mobile-fab-menu.show-documents #mobile-fab-main-actions button {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    animation: none !important;
  }

  #mobile-fab-menu.show-documents #mobile-fab-documents-sub {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: scale(1);
  }

  #mobile-fab-menu.show-documents #mobile-fab-documents-sub button {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    animation: polar-action-in 0.28s var(--ui-ease) both !important;
  }

  #mobile-fab-menu.show-documents #mobile-fab-documents-sub button:nth-child(1) { animation-delay: 0.04s !important; }
  #mobile-fab-menu.show-documents #mobile-fab-documents-sub button:nth-child(2) { animation-delay: 0.08s !important; }
  #mobile-fab-menu.show-documents #mobile-fab-documents-sub button:nth-child(3) { animation-delay: 0.12s !important; }

  /* Pulsante centrale close ('X') / back ('chevron-left') */
  #mobile-fab-close-button .back-icon { display: none !important; }
  #mobile-fab-close-button .close-icon { display: block !important; }
  #mobile-fab-menu.show-documents #mobile-fab-close-button .close-icon { display: none !important; }
  #mobile-fab-menu.show-documents #mobile-fab-close-button .back-icon { display: block !important; }

  #mobile-fab-menu .mobile-fab-close,
  #mobile-fab-menu .mobile-fab-close:hover,
  #mobile-fab-menu .mobile-fab-close:active {
    position: absolute;
    left: 50%;
    bottom: calc(var(--fab-center-from-bottom, 89px) - 34px);
    width: 68px;
    height: 68px;
    transform: translateX(-50%) !important;
    border-radius: 50%;
    border: 5px solid rgba(255, 255, 255, 0.25);
    background: #3d4a3a;
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    touch-action: manipulation;
    z-index: 35;
    animation: none !important;
    transition: background 0.18s ease;
  }

  #mobile-fab-menu .mobile-fab-close .ui-icon {
    width: 24px;
    height: 24px;
    color: #fff;
  }
}

@keyframes polar-action-in {
  from {
    opacity: 0;
    transform: translate(-50%, -20px) scale(0.88);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -28px) scale(1);
  }
}

/* Popover compatto Movimenti (Fatture e Spese) */
.mobile-movimenti-popover {
  position: absolute;
  bottom: calc(var(--mobile-bottom-nav-height, 96px) + 8px);
  left: 30%;
  transform: translateX(-50%) translateY(8px) scale(0.92);
  transform-origin: center bottom;
  opacity: 0;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 6px;
  z-index: 25;
  min-width: 168px;
  transition: opacity 0.22s var(--ui-ease), transform 0.22s var(--ui-ease);
}

.mobile-movimenti-popover.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) scale(1);
}

.movimenti-popover-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.movimenti-popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #1f231f;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease;
}

.movimenti-popover-item:active {
  background: #edf3eb;
  transform: scale(0.98);
}

.movimenti-popover-badge {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 16px;
}

.movimenti-popover-badge.green {
  background: rgba(62, 107, 62, 0.14);
  color: #2e592e;
}

.movimenti-popover-badge.orange {
  background: rgba(234, 114, 61, 0.14);
  color: #ea723d;
}

.movimenti-popover-badge .ui-icon {
  width: 18px;
  height: 18px;
}

.movimenti-popover-label {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.movimenti-popover-label strong {
  font-size: 13.5px;
  font-weight: 700;
  color: #1f231f;
}

.movimenti-popover-label small {
  font-size: 11px;
  font-weight: 500;
  color: #7a8277;
}

.movimenti-popover-sep {
  height: 1px;
  background: rgba(0, 0, 0, 0.06);
  margin: 1px 6px;
}

.movimenti-popover-caret {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: #fff;
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

@media (max-width: 350px) {
  .bottom-nav {
    padding: 10px 0 0 !important;
  }

  .bottom-nav button[data-tab] span {
    font-size: 9.5px;
  }

  .bottom-nav .fab {
    width: 56px !important;
    height: 56px !important;
    top: -20px !important;
  }

  .bottom-nav .fab .ui-icon {
    width: 24px !important;
    height: 24px !important;
  }
}
