/* ==========================================================================
   MARCOFLY APP SWITCHER v1.0
   --------------------------------------------------------------------------
   Cross-environment navigation widget (sito ↔ pwa ↔ admin).
   Stili condivisi tra web component vanilla e componente React.
   --------------------------------------------------------------------------
   Dipendenze: mff-tokens.css (tokens, motion, z-index)
   ========================================================================== */

/* ── Trigger button ─────────────────────────────────────────────────────── */
.mff-switcher {
  position: relative;
  display: inline-flex;
}

.mff-switcher__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}

.mff-switcher__trigger:hover {
  border-color: var(--copper);
  color: var(--copper);
  background: var(--copper-dim);
}

.mff-switcher__trigger[aria-expanded="true"] {
  border-color: var(--copper);
  color: var(--copper);
  background: var(--copper-dim);
}

.mff-switcher__trigger svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* ── Popover ────────────────────────────────────────────────────────────── */
.mff-switcher__popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 300px;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lift);
  padding: 6px;
  z-index: var(--z-popover);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              visibility 0s linear var(--dur-fast);
}

.mff-switcher__popover[data-open="true"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-spring),
              visibility 0s linear 0s;
}

/* ── Popover header ─────────────────────────────────────────────────────── */
.mff-switcher__label {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-eyebrow);
  text-transform: uppercase;
  color: var(--copper);
  padding: 12px 14px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mff-switcher__label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

/* ── Item ───────────────────────────────────────────────────────────────── */
.mff-switcher__item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font: inherit;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease-out);
}

.mff-switcher__item:hover,
.mff-switcher__item:focus-visible {
  background: var(--copper-dim);
  outline: none;
}

/* Current environment — copper accent bar + dot */
.mff-switcher__item[aria-current="page"] {
  background: var(--copper-dim);
}

.mff-switcher__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--copper);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.mff-switcher__item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-section);
  border: 1px solid var(--border-light);
  color: var(--copper);
  flex-shrink: 0;
}

.mff-switcher__item-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.75;
}

.mff-switcher__item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mff-switcher__item-label {
  font-family: var(--font-serif);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  line-height: 1.15;
  color: var(--text-main);
}

.mff-switcher__item-sub {
  font-size: var(--fs-2xs);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: var(--fw-normal);
  letter-spacing: 0;
  text-transform: none;
}

.mff-switcher__item-marker {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--copper);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.mff-switcher__item[aria-current="page"] .mff-switcher__item-marker {
  opacity: 1;
}

/* ── Disabled / coming-soon item ────────────────────────────────────────── */
.mff-switcher__item[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.mff-switcher__item-soon {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: var(--fw-bold);
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--copper-dim);
  color: var(--copper);
  border: 1px solid var(--border-light);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.mff-switcher__footer {
  padding: 8px 14px 10px;
  margin-top: 4px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-faint);
}

.mff-switcher__footer-version {
  font-weight: var(--fw-semi);
}

.mff-switcher__footer-domain {
  color: var(--copper);
  opacity: 0.7;
}

/* ── Backdrop (mobile-only, optional) ───────────────────────────────────── */
@media (max-width: 560px) {
  .mff-switcher__popover[data-open="true"] {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    min-width: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(0);
    box-shadow: var(--shadow-lift);
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .mff-switcher__popover {
    transform: translateY(100%);
  }
}

/* ── Reduce motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .mff-switcher__popover {
    transition: opacity 0.01ms, visibility 0s linear 0.01ms;
    transform: none !important;
  }
}
