/* Shell mobile tipo app — tab bar, header compatto, foglio Altro */

@media (max-width: 768px) {
  :root {
    --mobile-tab-bar-height: calc(3.35rem + env(safe-area-inset-bottom, 0px));
  }

  body.app-has-mobile-tab-bar {
    --mobile-tab-bar-offset: var(--mobile-tab-bar-height);
  }

  body.app-has-mobile-tab-bar .main-content {
    padding-bottom: calc(1rem + var(--mobile-tab-bar-offset, 0px));
  }

  body.app-has-mobile-tab-bar .app-legal-footer {
    padding-bottom: calc(0.75rem + var(--mobile-tab-bar-offset, 0px));
  }

  /* Top: nascondi cloud tabs orizzontali (sostituiti da tab bar) */
  body.app-has-mobile-tab-bar .main-sticky-chrome .crm-cloud-tabs--chrome {
    display: none !important;
  }

  body.app-has-mobile-tab-bar .main-sticky-chrome .main-chrome-fallback-brand {
    display: none;
  }

  body.app-has-mobile-tab-bar .main-chrome__inner {
    gap: 0.25rem;
  }

  .mobile-chrome-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0 0.15rem;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--text, #0f172a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.app-has-mobile-tab-bar :root {
    --mobile-chrome-inset-left: calc(3.5rem + env(safe-area-inset-left, 0px));
    --main-chrome-height: calc(var(--mobile-header-y) + var(--mobile-header-hit) + 0.2rem);
  }

  /* Tab bar inferiore */
  .app-mobile-tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1002;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 0;
    min-height: 3.35rem;
    padding: 0.35rem max(0.25rem, env(safe-area-inset-right, 0px))
      calc(0.35rem + env(safe-area-inset-bottom, 0px))
      max(0.25rem, env(safe-area-inset-left, 0px));
    background: color-mix(in srgb, var(--bg-card, #fff) 92%, transparent);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .app-mobile-tab {
    flex: 1 1 0;
    min-width: 0;
    max-width: 5.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.2rem 0.15rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    text-decoration: none;
    font: inherit;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.01em;
    border-radius: 10px;
    min-height: 44px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .app-mobile-tab__icon {
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
  }

  .app-mobile-tab__icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .app-mobile-tab--active {
    color: var(--accent, #2563eb);
  }

  .app-mobile-tab--active .app-mobile-tab__icon {
    transform: scale(1.05);
  }

  /* Foglio Altro */
  .app-mobile-sheet {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0.2s;
  }

  .app-mobile-sheet.is-open {
    pointer-events: auto;
    visibility: visible;
  }

  .app-mobile-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.25s;
  }

  .app-mobile-sheet.is-open .app-mobile-sheet__backdrop {
    opacity: 1;
  }

  .app-mobile-sheet__panel {
    position: relative;
    max-height: min(78dvh, 520px);
    margin-bottom: var(--mobile-tab-bar-height, 3.35rem);
    padding: 0.85rem max(1rem, env(safe-area-inset-right, 0px))
      calc(1rem + env(safe-area-inset-bottom, 0px))
      max(1rem, env(safe-area-inset-left, 0px));
    background: var(--bg-card, #fff);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.18);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-mobile-sheet.is-open .app-mobile-sheet__panel {
    transform: translateY(0);
  }

  .app-mobile-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .app-mobile-sheet__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
  }

  .app-mobile-sheet__close {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--surface-muted, #f1f5f9);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
  }

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

  .app-mobile-quick-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 4.5rem;
    padding: 0.55rem 0.35rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-muted, #f8fafc);
    color: var(--text);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
  }

  .app-mobile-quick-item--active {
    border-color: color-mix(in srgb, var(--accent, #2563eb) 50%, var(--border));
    background: color-mix(in srgb, var(--accent, #2563eb) 8%, var(--bg-card, #fff));
    color: var(--accent, #2563eb);
  }

  .app-mobile-quick-item__icon {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--accent, #2563eb);
  }

  .app-mobile-quick-item__icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
  }

  .app-mobile-sheet__foot {
    margin-top: 0.85rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
  }

  .app-mobile-sheet__menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    min-height: 48px;
    padding: 0.65rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-card, #fff);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
  }

  body.app-mobile-sheet-open {
    overflow: hidden;
  }

  body.app-mobile-sheet-open .app-mobile-tab-bar {
    z-index: 1101;
  }

  /* FAB assistente sopra tab bar */
  body.app-has-mobile-tab-bar #crm-assistant-fab {
    bottom: calc(var(--mobile-tab-bar-height, 3.35rem) + 0.75rem);
  }

  body.app-has-mobile-tab-bar .crm-filters-drawer-tab {
    bottom: calc(var(--mobile-tab-bar-height, 3.35rem) + 0.5rem);
  }

  body.app-has-mobile-tab-bar .posta-layout.posta-layout--webmail {
    height: calc(
      100dvh - var(--main-chrome-height, 3.5rem) - var(--mobile-tab-bar-height, 3.35rem) - 0.35rem
    );
  }

  body.app-has-mobile-tab-bar .inapp-notif-panel {
    max-height: min(
      420px,
      calc(100dvh - var(--main-chrome-height, 3.5rem) - var(--mobile-tab-bar-height, 3.35rem) - 1rem)
    );
  }

  body.app-has-mobile-tab-bar #crm-assistant-panel {
    max-height: min(70dvh, calc(100dvh - var(--main-chrome-height, 3.5rem) - var(--mobile-tab-bar-height, 3.35rem) - 2rem));
  }
}

@media (min-width: 769px) {
  .app-mobile-tab-bar,
  .app-mobile-sheet {
    display: none !important;
  }
}

/* PWA: banner installazione + modalità standalone */
.hermes-pwa-install {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: calc(0.75rem + var(--mobile-tab-bar-height, 0px) + env(safe-area-inset-bottom, 0px));
  z-index: 2350;
  pointer-events: none;
}

.hermes-pwa-install__inner {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent, #1a73e8) 35%, var(--border, #dadce0));
  background: var(--bg-card, #fff);
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.14);
}

.hermes-pwa-install__text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
  flex: 1 1 12rem;
}

.hermes-pwa-install__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

html.hermes-pwa-standalone .hermes-pwa-install {
  display: none !important;
}

html.hermes-pwa-standalone .hermes-pwa-sheet {
  display: none !important;
}

html.hermes-pwa-standalone .hermes-pwa-ios-bar {
  display: none !important;
}

html.hermes-pwa-standalone .hermes-pwa-install-menu,
html.hermes-pwa-standalone .hermes-pwa-chrome-btn {
  display: none !important;
}

html.hermes-pwa-ios-browser.hermes-pwa-ios-chrome:not(.hermes-pwa-standalone) .hermes-pwa-ios-bar {
  background: linear-gradient(180deg, #fef3c7 0%, #fde68a 100%);
  border-bottom-color: #f59e0b;
}

html.hermes-pwa-ios-browser.hermes-pwa-ios-chrome:not(.hermes-pwa-standalone) .hermes-pwa-ios-bar__close {
  display: none;
}

html.hermes-pwa-mobile-app .hermes-pwa-install,
html.hermes-pwa-mobile-app .hermes-pwa-ios-bar {
  display: none !important;
}

html.hermes-pwa-mobile-app .hermes-pwa-install-menu {
  display: none !important;
}

@media (max-width: 768px) {
  html.hermes-pwa-mobile-app body.hermes-ui-light .light-sidebar__foot .ui-light-mode-switch {
    display: none;
  }

  html.hermes-pwa-mobile-app body.hermes-ui-light .light-chrome__actions .ui-light-mode-switch {
    display: none !important;
  }

  /* UI completa: sidebar mobile solo footer utente (navigazione = tab bar) */
  html.hermes-pwa-mobile-app body:not(.hermes-ui-light) .sidebar .sidebar-nav,
  html.hermes-pwa-mobile-app body:not(.hermes-ui-light) .sidebar-admin-pack,
  html.hermes-pwa-mobile-app body:not(.hermes-ui-light) hr.sidebar-section-divider,
  html.hermes-pwa-mobile-app body:not(.hermes-ui-light) hr.sidebar-nav-divider {
    display: none !important;
  }

  html.hermes-pwa-mobile-app body:not(.hermes-ui-light) .sidebar-user-footer__ui-mode {
    display: none !important;
  }

  html.hermes-pwa-mobile-app .crm-cloud-tabs,
  html.hermes-pwa-mobile-app .crm-area-header .crm-cloud-tabs,
  html.hermes-pwa-mobile-app .main-content > .crm-cloud-tabs {
    display: none !important;
  }
}

.app-mobile-pwa-status {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-mobile-pwa-status__badge {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.app-mobile-pwa-status__badge--pwa { color: #1a73e8; }
.app-mobile-pwa-status__badge--light { color: #0f766e; }
.app-mobile-pwa-status__badge--full { color: #b45309; }

.app-mobile-pwa-status__meta {
  font-size: 0.75rem;
  color: #64748b;
}

.app-mobile-pwa-status__hint {
  font-size: 0.75rem;
  color: #64748b;
  line-height: 1.35;
}

.app-mobile-sheet__empty {
  margin: 0 0 0.85rem;
  font-size: 0.86rem;
}

body.hermes-ui-light .light-sidebar__pwa-badge {
  margin: 0 0 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

@media (min-width: 769px) {
  .hermes-pwa-ios-bar,
  .hermes-pwa-install-menu,
  .hermes-pwa-chrome-btn {
    display: none !important;
  }
}

/* PWA: barra guida iPhone in cima */
.hermes-pwa-ios-bar {
  position: sticky;
  top: 0;
  z-index: 2300;
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.55rem max(0.65rem, env(safe-area-inset-right, 0px)) 0.55rem max(0.65rem, env(safe-area-inset-left, 0px));
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  border-bottom: 1px solid #93c5fd;
  font-size: 0.78rem;
  line-height: 1.35;
}

.hermes-pwa-ios-bar[hidden] {
  display: none !important;
}

.hermes-pwa-ios-bar__text {
  margin: 0;
  flex: 1 1 auto;
  padding-top: 0.15rem;
}

.hermes-pwa-ios-bar__btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: none;
  background: #1a73e8;
  color: #fff;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.hermes-pwa-ios-bar__close {
  flex: 0 0 auto;
  min-width: 36px;
  min-height: 36px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.hermes-pwa-sheet__note--warn {
  background: #fef3c7;
  border-color: #fcd34d;
}

.hermes-pwa-sheet__em {
  display: block;
  margin-top: 0.15rem;
  font-style: normal;
  color: #64748b;
  font-size: 0.8rem;
}

.hermes-pwa-sheet__link {
  display: inline-block;
  margin-top: 0.55rem;
  font-size: 0.84rem;
  font-weight: 600;
  color: #1a73e8;
  text-decoration: none;
}

.hermes-pwa-sheet__link:hover {
  text-decoration: underline;
}

/* PWA: foglio guida installazione */
.hermes-pwa-sheet {
  position: fixed;
  inset: 0;
  z-index: 2450;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hermes-pwa-sheet[hidden] {
  display: none !important;
}

body.hermes-pwa-sheet-open {
  overflow: hidden;
}

.hermes-pwa-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.hermes-pwa-sheet__panel {
  position: relative;
  width: min(100%, 480px);
  max-height: min(92dvh, 640px);
  overflow: auto;
  background: var(--bg-card, #fff);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
}

.hermes-pwa-sheet__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem 0.75rem;
  align-items: start;
  margin-bottom: 0.85rem;
}

.hermes-pwa-sheet__icon {
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(26, 115, 232, 0.25);
}

.hermes-pwa-sheet__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.hermes-pwa-sheet__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: #64748b;
  line-height: 1.35;
}

.hermes-pwa-sheet__close {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
}

.hermes-pwa-sheet__note {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  font-size: 0.82rem;
  line-height: 1.4;
}

.hermes-pwa-sheet__lead {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  line-height: 1.45;
}

.hermes-pwa-sheet__steps {
  margin: 0 0 0.75rem;
  padding-left: 1.15rem;
  font-size: 0.86rem;
  line-height: 1.45;
}

.hermes-pwa-sheet__steps--ios {
  list-style: none;
  padding-left: 0;
}

.hermes-pwa-sheet__steps--ios li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  margin-bottom: 0.65rem;
}

.hermes-pwa-sheet__step-icon {
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #f1f5f9;
  color: #1a73e8;
  font-weight: 700;
  font-size: 0.95rem;
}

.hermes-pwa-sheet__hint {
  margin: 0;
  font-size: 0.8rem;
  color: #64748b;
  line-height: 1.4;
}

.hermes-pwa-sheet__copy-row {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
}

.hermes-pwa-sheet__url {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  font: inherit;
  font-size: 0.82rem;
}

.hermes-pwa-sheet__install-btn {
  width: 100%;
  min-height: 44px;
  margin-bottom: 0.55rem;
}

.hermes-pwa-sheet__foot {
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: center;
}

@media (min-width: 769px) {
  .hermes-pwa-install {
    bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    max-width: 420px;
    left: auto;
  }
}
