/* NFC & QR mobile — UX ottimizzata (#nfc-wrap) ≤900px */

@media (max-width: 900px) {
  .mt-dashboard #nfc-panel-nfc > .mob-nfc {
    display: none !important;
  }

  .mt-dashboard #nfc-panel-nfc > #nfc-wrap {
    display: flex !important;
    flex-direction: column !important;
  }

  .mt-dashboard #nfc-panel-nfc > #deskNfcGroupOverlay.open,
  .mt-dashboard #nfc-panel-nfc > #deskNfcHelpOverlay.open,
  .mt-dashboard #nfc-panel-nfc > #mobNfcStatsOverlay.stats-open {
    display: flex !important;
  }

  .mt-dashboard #view-nfc.view,
  .mt-dashboard #view-nfc.view.active {
    position: relative;
    background: var(--mt-bg) !important;
    overflow-x: hidden;
    padding: 0 !important;
  }

  .mt-dashboard #view-nfc::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
      radial-gradient(ellipse 95% 55% at 100% -8%, rgba(124, 92, 246, 0.14), transparent 58%),
      radial-gradient(ellipse 75% 50% at -8% 32%, rgba(167, 139, 250, 0.09), transparent 52%);
  }

  .mt-dashboard .mob-nfc {
    display: none !important;
  }

  #nfc-wrap {
    display: flex !important;
    flex-direction: column;
    position: relative;
    z-index: 1;
    padding: 40px 12px calc(20px + env(safe-area-inset-bottom, 0));
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 10px;
  }

  .mt-dashboard #nfc-panel-nfc {
    padding: 0 !important;
    margin: 0 !important;
  }

  #nfc-wrap .mt-glass {
    background: var(--mt-glass-bg-strong);
    backdrop-filter: blur(28px) saturate(195%);
    -webkit-backdrop-filter: blur(28px) saturate(195%);
    border: 1px solid rgba(255, 255, 255, 0.82);
    border-radius: var(--mt-radius-lg);
    box-shadow:
      0 8px 28px rgba(31, 38, 68, 0.09),
      0 2px 10px rgba(124, 92, 246, 0.06),
      inset 0 1px 0 rgba(255, 255, 255, 0.96);
    position: relative;
    overflow: hidden;
    isolation: isolate;
  }

  #nfc-wrap .mt-glass > * {
    position: relative;
    z-index: 1;
  }

  /* ── Hero compatto (meno spazio in alto) ── */
  #nfc-wrap > .mt-dash-grid:first-child {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    margin: 0 !important;
    grid-template-columns: none !important;
  }

  #nfc-wrap > .mt-dash-grid:first-child .mt-span-3,
  #nfc-wrap > .mt-dash-grid:first-child .mt-span-1 {
    grid-column: auto !important;
    width: 100%;
  }

  #nfc-wrap .mt-hero {
    padding: 12px 14px 10px;
  }

  #nfc-wrap .mt-hero-wave {
    display: none;
  }

  #nfc-wrap .mt-hero-top {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
  }

  #nfc-wrap .mt-hero-name {
    font-size: 20px;
    letter-spacing: -0.02em;
    line-height: 1.1;
  }

  #nfc-wrap .mt-hero-insight {
    font-size: 12px;
    line-height: 1.35;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  #nfc-wrap .mt-scope-tag {
    flex-shrink: 0;
    font-size: 10px;
    padding: 4px 8px;
    white-space: nowrap;
  }

  #nfc-wrap .mt-hero-bottom {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
  }

  #nfc-wrap .mt-hero-ring {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
  }

  #nfc-wrap .mt-hero-ring-value {
    font-size: 16px;
  }

  #nfc-wrap .mt-hero-ring-label {
    padding: 0;
    border: none;
    flex: 1;
    min-width: 0;
  }

  #nfc-wrap .mt-hero-ring-title {
    font-size: 12px;
    white-space: normal;
  }

  #nfc-wrap .mt-hero-ring-trend {
    font-size: 11px;
    color: var(--mt-text-tertiary);
  }

  /* Metriche duplicate — già in card Attività */
  #nfc-wrap .mt-hero-metrics-rest {
    display: none !important;
  }

  /* Rail azioni — riga compatta */
  #nfc-wrap .mt-nfc-rail {
    padding: 10px 12px;
  }

  #nfc-wrap .mt-nfc-rail-title {
    font-size: 10px;
    margin-bottom: 6px;
  }

  #nfc-wrap .mt-nfc-rail-list {
    flex-direction: row;
    gap: 8px;
  }

  #nfc-wrap .mt-nfc-btn-rail {
    flex: 1;
    min-height: 40px;
    font-size: 12px;
    padding: 8px 10px;
    -webkit-tap-highlight-color: transparent;
  }

  /* ── Sezioni: QR + batch ── */
  #nfc-wrap .mt-dash-grid {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 0 !important;
    grid-template-columns: none !important;
  }

  #nfc-wrap .mt-dash-grid .mt-span-4,
  #nfc-wrap .mt-dash-grid .mt-span-1 {
    grid-column: auto !important;
    width: 100%;
  }

  #nfc-wrap .mt-nfc-row-label {
    margin: 2px 0 0;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--mt-text-tertiary);
  }

  #nfc-wrap .mt-nfc-section-head {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(124, 92, 246, 0.1);
  }

  #nfc-wrap .mt-nfc-section-title,
  #nfc-wrap .section-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  #nfc-wrap .mt-nfc-panel {
    padding: 14px;
  }

  /* Attività — sempre 2 colonne */
  #nfc-wrap > .mt-nfc-row-label + .mt-dash-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
    flex-direction: unset !important;
  }

  #nfc-wrap > .mt-nfc-row-label + .mt-dash-grid > .mt-nfc-stat-card,
  #nfc-wrap > .mt-nfc-row-label + .mt-dash-grid > .mt-span-1 {
    width: auto !important;
    max-width: none !important;
    grid-column: span 1 !important;
    min-width: 0;
  }

  #nfc-wrap .mt-nfc-stat-card {
    padding: 14px 12px;
    min-height: 0;
  }

  #nfc-wrap .mt-nfc-stat-icon {
    width: 30px;
    height: 30px;
    margin-bottom: 8px;
  }

  #nfc-wrap .mt-nfc-stat-title {
    font-size: 10px;
    margin-bottom: 6px;
    line-height: 1.25;
  }

  #nfc-wrap .mt-nfc-stat-value {
    font-size: 20px;
    line-height: 1.1;
  }

  #nfc-wrap .mt-nfc-stat-label {
    font-size: 10px;
    line-height: 1.3;
    margin-top: 2px;
  }

  #nfc-wrap .mt-nfc-stat-split {
    gap: 8px;
    margin-top: 4px;
  }

  #nfc-wrap .mt-nfc-stat-split .mt-nfc-stat-value {
    font-size: 17px;
  }

  #nfc-wrap .mt-nfc-stat-badge {
    font-size: 10px;
    margin-top: 6px;
    padding: 3px 8px;
  }

  /* QR — quadrato fisso, niente deformazione */
  #nfc-wrap .mt-nfc-qr-layout,
  #nfc-wrap .qr-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  #nfc-wrap .mt-nfc-qr-info,
  #nfc-wrap .qr-info {
    width: 100%;
    text-align: left;
  }

  #nfc-wrap .mt-nfc-qr-image,
  #nfc-wrap .qr-thumb-wrap {
    width: 140px;
    height: 140px;
    min-width: 140px;
    min-height: 140px;
    max-width: 140px;
    max-height: 140px;
    margin: 0 auto;
    flex: 0 0 140px;
    padding: 14px;
    box-sizing: border-box;
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(124, 92, 246, 0.12);
    overflow: hidden;
  }

  #nfc-wrap #nfcQrThumb {
    width: 112px !important;
    height: 112px !important;
    max-width: 112px !important;
    max-height: 112px !important;
    flex: 0 0 112px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  #nfc-wrap #nfcQrThumb canvas,
  #nfc-wrap #nfcQrThumb img,
  #nfc-wrap #nfcQrThumb svg {
    display: block !important;
    width: 112px !important;
    height: 112px !important;
    max-width: 112px !important;
    max-height: 112px !important;
    object-fit: contain !important;
    border-radius: 4px;
  }

  #nfc-wrap .mt-nfc-qr-status,
  #nfc-wrap .qr-status {
    justify-content: flex-start;
    font-size: 12px;
    margin-bottom: 6px;
  }

  #nfc-wrap .mt-nfc-qr-link,
  #nfc-wrap .qr-link {
    font-size: 12px;
    line-height: 1.4;
    margin-bottom: 12px;
    word-break: break-word;
  }

  #nfc-wrap .mt-nfc-qr-link a,
  #nfc-wrap .qr-link a {
    font-weight: 600;
  }

  #nfc-wrap .qr-widget-title {
    font-size: 14px !important;
    font-weight: 700;
  }

  #nfc-wrap .qr-widget-sub {
    font-size: 12px !important;
    line-height: 1.45;
    color: var(--mt-text-secondary);
  }

  #nfc-wrap #nfcQrWidget > div {
    gap: 12px !important;
  }

  #nfc-wrap .mt-nfc-qr-controls,
  #nfc-wrap .qr-controls,
  #nfc-wrap .qr-change-row,
  #nfc-wrap #nfcQrPageRow,
  #nfc-wrap #nfcQrUrlRow {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    width: 100%;
  }

  #nfc-wrap .mt-nfc-mode-toggle,
  #nfc-wrap .nfcv-type-toggle {
    width: 100%;
    display: flex;
    padding: 3px;
    border-radius: 12px;
  }

  #nfc-wrap .mt-nfc-mode-btn,
  #nfc-wrap .nfcv-type-btn {
    flex: 1;
    min-height: 42px;
    font-size: 13px;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
  }

  #nfc-wrap .mt-nfc-field-select,
  #nfc-wrap .qr-page-select,
  #nfc-wrap .nfcv-ext-input {
    width: 100%;
    max-width: none;
    min-height: 48px;
    font-size: 16px;
    box-sizing: border-box;
    border-radius: 12px;
  }

  #nfc-wrap .mt-nfc-btn-update,
  #nfc-wrap .qr-btn-change,
  #nfc-wrap .qr-btn-generate {
    width: 100%;
    min-height: 48px;
    justify-content: center;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
  }

  #nfc-wrap .qr-no-pages {
    font-size: 13px;
    text-align: center;
    padding: 8px 0;
  }

  /* Batch NFC */
  #nfc-wrap .nfc-batch-grid {
    gap: 10px;
    margin-bottom: 0;
  }

  #nfc-wrap .nfc-batch-card {
    padding: 14px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.48);
    border: 1px solid rgba(124, 92, 246, 0.12);
    box-shadow: none;
  }

  #nfc-wrap .nfc-batch-top,
  #nfc-wrap .batch-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 0;
  }

  #nfc-wrap .nfc-batch-icon {
    display: none;
  }

  #nfc-wrap .nfc-batch-name,
  #nfc-wrap .batch-name {
    font-size: 15px;
    line-height: 1.25;
    margin-bottom: 4px;
  }

  #nfc-wrap .nfc-batch-url,
  #nfc-wrap .batch-url {
    font-size: 11px;
    max-width: 100%;
    margin-bottom: 8px;
    color: var(--mt-text-tertiary);
  }

  #nfc-wrap .nfc-stat-pills,
  #nfc-wrap .batch-pills {
    gap: 5px;
    flex-wrap: wrap;
  }

  #nfc-wrap .pill,
  #nfc-wrap .mob-nfc-pill,
  #nfc-wrap .nfc-pill {
    font-size: 10px;
    padding: 4px 9px;
  }

  #nfc-wrap .mob-nfc-batch-btns,
  #nfc-wrap .nfc-batch-actions {
    flex-direction: row;
    width: 100%;
    gap: 8px;
    margin-top: 4px;
  }

  #nfc-wrap .mob-nfc-batch-btn,
  #nfc-wrap .btn-batch {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 10px 8px;
    font-size: 12px;
    justify-content: center;
    border-radius: 12px !important;
    -webkit-tap-highlight-color: transparent;
  }

  #nfc-wrap .mob-nfc-batch-btn svg,
  #nfc-wrap .btn-batch svg {
    flex-shrink: 0;
  }

  /* Stato vuoto / locked */
  #nfc-wrap .nfcv-locked-wrapper {
    border-radius: 14px;
  }

  #nfc-wrap .nfcv-locked-blur {
    min-height: 200px !important;
    padding: 16px !important;
  }

  #nfc-wrap .nfcv-lock-overlay {
    padding: 28px 18px !important;
    gap: 10px !important;
  }

  #nfc-wrap .nfcv-lock-overlay a {
    background: linear-gradient(135deg, #7C5CF6, #6647E0) !important;
    border-radius: 12px !important;
    min-height: 44px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 12px 22px !important;
  }

  /* Modale gestisci gruppo */
  #deskNfcGroupOverlay.open {
    align-items: flex-end !important;
    justify-content: flex-end !important;
    padding: 0 !important;
  }

  #deskNfcGroupOverlay.open .mt-nfc-modal-card--wide {
    max-width: 100% !important;
    width: 100% !important;
    max-height: min(92dvh, 900px) !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
  }

  #deskNfcGroupOverlay .mt-nfc-modal-body {
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0));
  }

  #deskNfcGroupOverlay .mt-nfc-modal-title {
    font-size: 17px;
  }

  #deskNfcGroupOverlay .mt-nfc-group-batch-name {
    font-size: 13px;
    margin-bottom: 8px;
  }

  #deskNfcGroupOverlay .mt-nfc-group-pills {
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
  }

  #deskNfcGroupOverlay .nfc-groups-bar,
  #deskNfcGroupOverlay .mt-nfc-filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-bottom: 10px;
  }

  #deskNfcGroupOverlay .nfc-groups-bar::-webkit-scrollbar {
    display: none;
  }

  #deskNfcGroupOverlay .mt-nfc-chip-card {
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 12px;
  }

  #deskNfcGroupOverlay .mt-nfc-chip-head-name {
    font-size: 14px;
  }

  #deskNfcGroupOverlay .mt-nfc-qr-controls,
  #deskNfcGroupOverlay .qr-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  #deskNfcGroupOverlay .qr-page-select,
  #deskNfcGroupOverlay .nfcv-ext-input,
  #deskNfcGroupOverlay .field-select {
    width: 100%;
    max-width: none;
    min-height: 48px;
    font-size: 16px;
    border-radius: 12px;
  }

  #deskNfcGroupOverlay .mt-nfc-btn-save,
  #deskNfcGroupOverlay .btn-update,
  #deskNfcGroupOverlay .mob-nfc-chip-save-btn {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
  }

  #deskNfcGroupOverlay .mt-nfc-mode-toggle {
    width: 100%;
  }

  #deskNfcGroupOverlay .mt-nfc-mode-btn,
  #deskNfcGroupOverlay .mob-nfc-qr-mode {
    flex: 1;
    min-height: 40px;
  }

  /* Modale statistiche */
  #mobNfcStatsOverlay.stats-open {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  #mobNfcStatsOverlay.stats-open .mt-nfc-modal-card {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: min(82dvh, 560px) !important;
  }

  #mobNfcStatsOverlay .mob-nfc-stats-kpi-grid,
  #mobNfcStatsOverlay .mt-nfc-stat-grid-modal {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  #mobNfcStatsOverlay .mob-nfc-stats-kpi,
  #mobNfcStatsOverlay .mt-nfc-stat-tile-modal {
    padding: 12px 8px !important;
    border-radius: 12px;
  }

  #mobNfcStatsOverlay .mob-nfc-stats-kpi-val,
  #mobNfcStatsOverlay .mt-nfc-stat-tile-modal .v {
    font-size: 22px !important;
  }

  #mobNfcStatsOverlay .mob-nfc-stats-manage-btn,
  #mobNfcStatsOverlay .mt-nfc-btn-modal.primary {
    min-height: 48px;
    border-radius: 14px !important;
    font-size: 15px;
  }
}

@media (max-width: 380px) {
  #nfc-wrap .mob-nfc-batch-btn,
  #nfc-wrap .btn-batch {
    font-size: 11px;
    padding: 10px 6px;
    gap: 4px;
  }
}

/* Empty state mobile */
.mt-dashboard .mob-nfc-empty-state .mt-nfc-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: rgba(124, 92, 246, 0.08);
  color: var(--mt-purple-deep);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mt-dashboard .mob-nfc-empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--mt-text-secondary);
  margin: 12px 0 8px;
}

.mt-dashboard .mob-nfc-empty-sub {
  font-size: 13px;
  color: var(--mt-text-secondary);
  margin-bottom: 20px;
  line-height: 1.55;
}
