/* ── iPhone / mobile browser compatibility ───────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Safe areas (notch, home indicator) */
@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-bottom-nav {
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom));
  }

  .mobile-top-bar {
    padding-top: env(safe-area-inset-top);
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .main-with-status--mobile .main-content {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
}

/* Prevent iOS Safari zoom on focus (needs ≥16px) */
@media (max-width: 768px) {
  input,
  select,
  textarea,
  .input {
    font-size: 16px !important;
  }

  .btn,
  .nav-item,
  .mobile-bottom-nav-item,
  button {
    min-height: 44px;
    touch-action: manipulation;
  }

  .cursor-fire-fx {
    display: none !important;
  }

  /* Reduce GPU load on phones */
  .ambient-bg,
  .ambient-bg canvas {
    opacity: 0.35;
  }

  .table-wrap,
  .agents-table-wrap,
  .crucible-terminal,
  pre,
  code {
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap,
  .agents-table-wrap {
    overflow-x: auto;
    max-width: 100%;
  }

  .system-status-bar {
    padding: 0.45rem 0.75rem;
    gap: 0.5rem;
    font-size: 0.65rem;
  }

  .system-status-bar .status-pill:last-child {
    margin-left: 0;
  }

  .fleet-toolbar {
    padding: 0.65rem 0.75rem;
  }

  .fleet-toolbar-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .fleet-filter-search,
  .fleet-filter-select {
    min-width: 0;
    width: 100%;
  }

  .fleet-bulk-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  .fleet-bulk-bar .btn {
    flex-shrink: 0;
  }

  .page-header,
  .deck-hero {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .page-header h1,
  .deck-hero h1 {
    font-size: 1.35rem;
  }

  .neon-card,
  .card {
    padding: 1rem;
  }

  .guide-code-pre {
    font-size: 0.72rem;
    overflow-x: auto;
  }

  .modal-overlay,
  .pt-qr-overlay {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .crucible-layout,
  .crucible-main,
  .crucible-sidebar {
    min-width: 0;
  }

  .crucible-agent-col {
    min-width: 0 !important;
    max-width: none !important;
  }

  .builder-grid,
  .forge-form-grid {
    grid-template-columns: 1fr !important;
  }

  .topology-map-wrap {
    min-height: 200px;
    max-height: 40vh;
  }

  .hashrate-chart-wrap {
    min-width: 0;
    overflow: hidden;
  }
}

@media (max-width: 768px) {
  .layout--mobile .sidebar--desktop {
    display: none !important;
  }

  .layout--mobile .main-with-status {
    margin-left: 0;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .layout--mobile .main-with-status .main-content {
    padding: 0.75rem;
    padding-top: 0.5rem;
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    min-height: auto;
  }
}
