/**
 * Shared mobile polish for static planner tools (trailer, warehouse, pallet, air).
 * Load after site-header-next.css and site-chrome.css.
 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.has-site-chrome {
  overflow-x: hidden;
  max-width: 100%;
}

/* —— Site header (static tools) —— */
@media (max-width: 768px) {
  .site-header-next__inner {
    padding: 10px var(--site-gutter);
    gap: 10px;
  }

  .site-header-next__logo {
    width: min(200px, 52vw);
    min-width: 6.5rem;
    max-width: 200px;
  }

  .site-header-next__navTrigger {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 0.8125rem;
  }

  .site-header-next__dropdownPanel {
    min-width: min(15rem, calc(100vw - 2 * var(--site-gutter)));
    max-width: calc(100vw - 2 * var(--site-gutter));
    max-height: min(70vh, 24rem);
    overflow-y: auto;
  }

  .site-header-next__dropdownLink {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 12px 14px;
  }

  /* Header scrolls with the page — not sticky */
  .app-site-header {
    position: relative;
    top: auto;
    z-index: auto;
    box-shadow: none;
  }

  .app-site-header .topbar.topbar--tool {
    padding: 8px var(--site-gutter);
    gap: 8px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .topbar--tool .toolbar-title {
    flex: 1 1 100%;
    min-width: 0;
  }

  .topbar--tool .brand-subtitle {
    display: none;
  }

  .topbar--tool .brand-title {
    font-size: clamp(1rem, 4.2vw, 1.2rem);
    line-height: 1.2;
  }

}

@media (max-width: 400px) {
  .site-header-next__logo {
    width: min(168px, 48vw);
    max-width: 168px;
  }

  .site-header-next__navTrigger {
    padding: 10px 12px;
    font-size: 0.75rem;
  }
}

/* —— Tool topbar: shared base —— */
.topbar--tool .topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.topbar-actions-primary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tool-more-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tool-more-actions__menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* Desktop: inline toolbar (details forced open via tool-topbar.js) */
@media (min-width: 769px) {
  .tool-more-actions__trigger {
    display: none !important;
  }

  .tool-more-actions__menu {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    position: static;
    padding: 0;
    margin: 0;
    border: none;
    box-shadow: none;
    background: transparent;
    min-width: 0;
    max-width: none;
  }
}

/* Mobile: one slim row + expandable panel (no overlap) */
@media (max-width: 768px) {
  .topbar--tool .topbar-actions {
    flex-wrap: wrap;
    align-items: stretch;
    gap: 8px;
    width: 100%;
  }

  .topbar-actions-primary {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .topbar-actions-primary .demo-badge {
    flex-shrink: 0;
    min-height: 0;
    padding: 4px 8px;
    font-size: 0.6875rem;
  }

  .topbar-actions-primary #btnPlan,
  .topbar-actions-primary #btnCompute {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.875rem;
  }

  .tool-more-actions {
    display: block;
    flex: 0 0 auto;
    width: auto;
  }

  .tool-more-actions__trigger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    list-style: none;
    width: auto !important;
    min-width: 4.25rem;
    max-width: none;
    height: 44px;
    max-height: 44px;
    margin: 0;
    padding: 0 14px;
    font-size: 0.875rem;
    font-weight: 700;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
  }

  .tool-more-actions__trigger::-webkit-details-marker {
    display: none;
  }

  /* Panel expands below the row — does not float over the 3D view */
  .tool-more-actions__menu {
    display: none;
    flex-basis: 100%;
    width: 100%;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 8px;
    position: static;
    border-radius: 12px;
    border: 1px solid var(--border, rgba(120, 113, 108, 0.22));
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 4px 16px rgba(28, 25, 23, 0.08);
    box-sizing: border-box;
  }

  .tool-more-actions[open] .tool-more-actions__menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .tool-more-actions__menu .btn,
  .tool-more-actions__menu a.btn {
    width: 100%;
    min-height: 44px;
    margin: 0;
    justify-content: center;
    text-align: center;
    font-size: 0.8125rem;
    box-sizing: border-box;
  }

  .tool-more-actions__menu #nexterra-tour-launch,
  .tool-more-actions__menu #tool-subscribe-cta {
    grid-column: 1 / -1;
  }

  .tool-more-actions__menu #tool-subscribe-cta[hidden] {
    display: none !important;
  }

  .tool-more-actions__menu .wh-drag-toggle {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 44px;
    white-space: normal;
    padding: 8px 10px;
    box-sizing: border-box;
  }
}

/* —— 3D view controls (Reset / Undo / labels / planning mode) —— */
@media (max-width: 768px) {
  .panel-center {
    overflow: visible;
  }

  .view-controls,
  .view-controls.view-controls-wrap,
  .view-controls-wrap {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 14px 0;
  }

  .view-controls .spacer {
    display: none;
  }

  .view-controls .check {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    align-items: flex-start;
  }

  .view-controls .check span {
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .view-controls .compact-field,
  .view-controls .field {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .view-controls .compact-field select,
  .view-controls select {
    width: 100%;
    max-width: 100%;
  }

  .view-controls .deck-move-target {
    width: 100%;
  }

  .view-controls-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .view-controls-actions .btn {
    width: 100%;
    min-width: 0;
    padding: 10px 8px;
    font-size: 0.75rem;
  }

  .view-controls > .btn,
  .view-controls > .btn-small {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .form-grid .field-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid .field-row .check {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
  }

  .load-mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  .load-mode-toggle .btn {
    width: 100%;
    min-width: 0;
  }

  .panel-center .panel-title {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .selected-pallet-toolbar,
  .pdf-import-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .selected-pallet-toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md, 12px);
    border: 1px solid var(--border, rgba(120, 113, 108, 0.18));
    background: rgba(255, 252, 247, 0.75);
  }

  .selected-pallet-toolbar .label {
    grid-column: 1 / -1;
    margin: 0;
  }

  .selected-pallet-toolbar .btn {
    width: 100%;
    min-width: 0;
    font-size: 0.75rem;
    padding: 10px 8px;
  }
}

@media (min-width: 769px) {
  .view-controls-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    width: auto;
  }
}

/* —— Forms: prevent iOS input zoom —— */
@media (max-width: 768px) {
  .has-site-chrome input[type="text"],
  .has-site-chrome input[type="number"],
  .has-site-chrome input[type="email"],
  .has-site-chrome input[type="password"],
  .has-site-chrome select,
  .has-site-chrome textarea {
    font-size: 16px;
  }

  .has-site-chrome .btn,
  .has-site-chrome .btn-small,
  .has-site-chrome .mini-btn {
    min-height: 44px;
  }

  .has-site-chrome .check input {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }
}
