/**
 * PackSense mobile layout fixes — analysis, GenAI, word cloud, nav.
 */

/* Hamburger menu: mobile/tablet sidebar only — never on desktop */
.ps-app body > .header .sidebar-toggle {
  display: none !important;
}

@media (max-width: 768px) {
  .ps-app body > .header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    min-height: auto;
  }

  .ps-app body > .header .sidebar-toggle {
    order: 0;
    position: static !important;
    top: auto !important;
    left: auto !important;
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(45, 212, 191, 0.15);
    color: #2dd4bf;
    cursor: pointer;
    z-index: 1002;
  }

  .ps-app body > .header .sidebar-toggle.is-visible {
    display: inline-flex !important;
  }

  .ps-app body > .header .logo {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .ps-app body > .header .logo-image {
    height: var(--ps-logo-height-sm) !important;
    max-height: none !important;
    max-width: min(56vw, 220px) !important;
  }

  .ps-app body > .header .nav-links {
    order: 2;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    flex: 1 1 100%;
    min-width: 0;
  }

  .ps-app body > .header .nav-link {
    padding: 6px 10px !important;
    font-size: 0.75rem !important;
    white-space: nowrap;
    line-height: 1.25;
  }

  .ps-app .main-layout {
    margin-top: calc(var(--ps-header-offset, 104px) + 4px);
  }

  .ps-app .main-content {
    padding: 12px !important;
    overflow-x: hidden;
  }

  .ps-app .metrics-dashboard .metrics-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .ps-app .metric-card {
    padding: 14px 10px !important;
  }

  .ps-app .metric-icon {
    width: 36px !important;
    height: 36px !important;
    margin-bottom: 8px !important;
  }

  .ps-app .metric-value {
    font-size: 1.375rem !important;
    margin-bottom: 4px !important;
  }

  .ps-app .metric-label {
    font-size: 0.6875rem !important;
    letter-spacing: 0.03em !important;
  }

  .ps-app .word-cloud-container {
    padding: 16px !important;
    min-height: auto !important;
    margin-bottom: 20px !important;
  }

  .ps-app .word-cloud-container h3 {
    font-size: 1rem !important;
    letter-spacing: 0.03em !important;
    text-shadow: none !important;
    font-family: inherit !important;
  }

  .ps-app .word-cloud-container p {
    font-size: 0.8125rem !important;
    margin-bottom: 12px !important;
  }

  .ps-app .word-cloud {
    height: auto !important;
    min-height: 160px;
    overflow: visible !important;
  }

  .ps-app .word-cloud.word-cloud--flex {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    gap: 8px;
    padding: 8px 4px 12px;
  }

  .ps-app .word-cloud.word-cloud--flex .word-cloud-word {
    position: static !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    margin: 0 !important;
  }

  .ps-app .analysis-section {
    padding: 0 !important;
  }
}

@media (max-width: 640px) {
  :root {
    --ps-header-offset: 108px;
  }

  /* GenAI analysis page */
  .ps-app .container {
    padding: 16px !important;
    border-radius: 12px !important;
    margin: 8px !important;
    width: auto !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .ps-app .container h1 {
    font-size: 1.375rem !important;
    line-height: 1.25;
    margin-bottom: 8px;
  }

  .ps-app .container .subtitle {
    font-size: 0.875rem !important;
    margin-bottom: 20px;
    line-height: 1.4;
    padding: 0 4px;
  }

  .ps-app .section {
    padding: 16px !important;
    margin-bottom: 24px !important;
  }

  .ps-app .section-title {
    font-size: 1.05rem !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ps-app .priority-map-wrap {
    width: 100%;
    overflow: hidden;
  }

  .ps-app #priority-map {
    width: 100% !important;
    min-height: 320px;
    height: auto !important;
  }

  .ps-app .component-tile {
    margin-bottom: 12px;
  }

  .ps-app .back-link {
    font-size: 0.875rem;
  }
}

@media (max-width: 380px) {
  .ps-app .metrics-dashboard .metrics-row {
    grid-template-columns: 1fr 1fr !important;
  }

  .ps-app body > .header .nav-link {
    padding: 5px 8px !important;
    font-size: 0.6875rem !important;
  }
}
