/* Loaded after the main stylesheet so iPhone/Android never crop modules. */
@media (max-width: 860px) {
  html,
  body,
  .app-shell,
  .workspace,
  .content,
  .view,
  .panel {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .content {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .section-head,
  .section-actions,
  .bulk-footer,
  .cash-month-head,
  .topbar-actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: stretch !important;
    justify-content: stretch !important;
  }

  .section-head > *,
  .section-actions > *,
  .bulk-footer > *,
  .topbar-actions > *,
  .cash-month-head > * {
    width: 100%;
    min-width: 0;
  }

  .sales-layout,
  .split-layout,
  .scanner-grid,
  .form-grid,
  .compact-grid,
  .bulk-actions,
  .metrics-grid,
  .cash-metrics {
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .payment-split {
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .action-row,
  .table-actions {
    width: 100%;
    min-width: 0;
  }

  .bcv-rate-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .bcv-rate-line .btn {
    width: 100%;
  }

  .duplicate-product-warning {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .table-actions .btn {
    width: auto;
    flex: 1 1 120px;
  }

  label,
  input,
  select,
  textarea,
  button,
  .btn,
  .section-actions,
	  .sync-message,
	  .empty-state,
	  .bulk-summary,
	  .sale-return-panel,
	  .sale-form-section,
	  .sale-product-box,
	  .totals-box {
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  input,
  select,
  textarea,
  .btn {
    width: 100%;
  }

  input[type="file"] {
    display: block;
    overflow: hidden;
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  input[type="file"]::file-selector-button,
  input[type="file"]::-webkit-file-upload-button {
    max-width: 58%;
    margin-right: 8px;
    white-space: nowrap;
  }

  .table-wrap,
  .bulk-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  table,
  tbody,
  .bulk-table,
  .cash-table,
  .sale-return-table,
  .sale-items-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  thead {
    display: none !important;
  }

  tbody {
    display: grid !important;
    gap: 10px;
  }

  tr {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }

  td {
    grid-column: 1 / -1 !important;
    width: 100%;
    min-width: 0 !important;
    border: 0;
    padding: 4px 0;
    text-align: left !important;
    overflow-wrap: anywhere;
  }

  td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-weight: 900;
  }

  td input,
  td select,
  td textarea,
  .inline-pay,
  .supplier-pay {
    width: 100%;
    min-width: 0;
  }

  .inline-pay,
  .supplier-pay {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .quick-search-panel {
    place-items: stretch;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  }

  .quick-product {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .quick-product em,
  .quick-product b {
    grid-column: 2;
  }
}

/* Permission visibility must win over every responsive navigation rule. */
html body .permission-hidden,
html body [hidden] {
  display: none !important;
}

/* Final mobile chrome authority: this file loads after styles.css. */
@media (max-width: 860px) {
  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 60 !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 6px !important;
    min-height: 0 !important;
    padding: calc(6px + env(safe-area-inset-top)) 10px 7px !important;
    border-radius: 0 !important;
  }

  .topbar .brand-lockup {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-height: 32px !important;
  }

  .topbar .brand-logo.compact {
    width: 88px !important;
    max-height: 32px !important;
    object-fit: contain !important;
  }

  .topbar .brand-lockup small {
    font-size: 12px !important;
    line-height: 1.1 !important;
  }

  .topbar-actions {
    display: flex !important;
    grid-template-columns: none !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding-bottom: 1px !important;
    scrollbar-width: none !important;
  }

  .topbar-actions::-webkit-scrollbar,
  .sidebar::-webkit-scrollbar,
  .cash-tabs::-webkit-scrollbar {
    display: none !important;
  }

  .topbar-actions > *,
  .topbar-actions .btn {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 0 !important;
    min-height: 34px !important;
    padding: 7px 10px !important;
    font-size: 13px !important;
    white-space: nowrap !important;
  }

  #sessionLabel {
    display: none !important;
  }

  .sidebar {
    position: static !important;
    top: auto !important;
    z-index: 55 !important;
    display: flex !important;
    align-self: auto !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 7px 10px !important;
    scroll-snap-type: x proximity !important;
  }

  .nav-item,
  .cash-tab {
    flex: 0 0 auto !important;
    width: auto !important;
    min-height: 36px !important;
    padding: 7px 10px !important;
    font-size: 13px !important;
    white-space: nowrap !important;
    scroll-snap-align: center !important;
  }

  .content {
    padding-top: 10px !important;
  }
}

/* Final authority for the top module navigation. mobile-fixes.css loads last. */
.app-shell {
  padding-top: 0 !important;
}

.app-shell .topbar {
  position: sticky !important;
  top: 0 !important;
  z-index: 80 !important;
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 12px !important;
  width: 100% !important;
  max-width: none !important;
  min-height: 72px !important;
  margin: 0 !important;
  padding: calc(8px + env(safe-area-inset-top)) 18px 8px !important;
  border-width: 0 0 1px !important;
  border-style: solid !important;
  border-color: var(--line) !important;
  border-radius: 0 !important;
  background: rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.08) !important;
}

.topbar .brand-lockup {
  display: flex !important;
  align-items: center !important;
  min-width: 118px !important;
  gap: 0 !important;
}

.topbar .brand-lockup small {
  display: none !important;
}

.topbar .brand-logo.compact {
  width: 152px !important;
  height: 52px !important;
  max-height: 52px !important;
  object-fit: cover !important;
  object-position: center !important;
  border-radius: 6px !important;
  background: #050505 !important;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18) !important;
}

.top-module-nav {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  min-width: 0 !important;
  overflow-x: auto !important;
  overscroll-behavior-x: contain !important;
  padding: 2px 2px 4px !important;
  scrollbar-width: none !important;
}

.top-module-nav::-webkit-scrollbar,
.app-shell .topbar-actions::-webkit-scrollbar {
  display: none !important;
}

.top-nav-item {
  flex: 0 0 auto !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  min-width: 94px !important;
  min-height: 48px !important;
  padding: 8px 12px !important;
  border: 1px solid var(--line) !important;
  border-radius: 7px !important;
  background: #ffffff !important;
  color: var(--ink) !important;
  font-family: Outfit, Inter, sans-serif !important;
  font-size: 15px !important;
  font-weight: 800 !important;
  line-height: 1.05 !important;
  text-align: center !important;
  white-space: nowrap !important;
  cursor: pointer !important;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05) !important;
}

.top-nav-item.active {
  border-color: rgba(242, 13, 13, 0.42) !important;
  background: rgba(242, 13, 13, 0.11) !important;
  color: #f20d0d !important;
  box-shadow: 0 10px 24px rgba(242, 13, 13, 0.10) !important;
}

.top-nav-icon {
  width: 20px !important;
  height: 20px !important;
  flex: 0 0 20px !important;
  display: inline-grid !important;
  place-items: center !important;
}

.top-nav-icon svg {
  width: 20px !important;
  height: 20px !important;
  fill: none !important;
  stroke: currentColor !important;
  stroke-width: 2 !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

.app-shell .topbar-actions {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  min-width: 0 !important;
}

.workspace {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  min-height: calc(100vh - 72px) !important;
}

.sidebar {
  display: none !important;
}

.content {
  width: 100% !important;
  max-width: none !important;
  margin-left: 0 !important;
  padding: 22px !important;
}

@media (max-width: 1380px) {
  .app-shell .topbar {
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: start !important;
  }

  .app-shell .topbar-actions {
    grid-column: 1 / -1 !important;
    justify-content: flex-start !important;
    overflow-x: auto !important;
    padding-bottom: 2px !important;
    scrollbar-width: none !important;
  }
}

@media (max-width: 760px) {
  .app-shell .topbar {
    grid-template-columns: auto minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 7px !important;
    min-height: 0 !important;
    padding: calc(6px + env(safe-area-inset-top)) 7px 7px !important;
  }

  .topbar .brand-lockup {
    grid-column: 1 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    width: auto !important;
  }

  .topbar .brand-logo.compact {
    width: 104px !important;
    height: 38px !important;
    max-height: 38px !important;
  }

  .top-module-nav {
    grid-column: 2 !important;
    grid-row: 1 !important;
    width: auto !important;
    min-width: 0 !important;
    gap: 5px !important;
    padding: 1px 1px 2px !important;
  }

  .top-nav-item {
    min-width: 72px !important;
    min-height: 38px !important;
    gap: 4px !important;
    padding: 6px 7px !important;
    font-size: 11.5px !important;
  }

  .top-nav-icon,
  .top-nav-icon svg {
    width: 16px !important;
    height: 16px !important;
    flex-basis: 16px !important;
  }

  .top-nav-label {
    max-width: 58px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .app-shell .topbar-actions {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100% !important;
    justify-content: flex-start !important;
    gap: 6px !important;
    padding-top: 0 !important;
  }

  .content {
    padding: 14px 10px calc(24px + env(safe-area-inset-bottom)) !important;
  }
}

@media (max-width: 860px) {
  .quotation-result-card .native-quantity-field,
  .sale-product-result-row .native-quantity-field {
    justify-items: stretch !important;
    min-width: 0 !important;
  }

  .quotation-result-card .native-quantity-field input[type="number"],
  .sale-product-result-row .native-quantity-field input[type="number"],
  .quotation-basket-item .native-quantity-field input[type="number"] {
    width: 68px !important;
    min-width: 0 !important;
    max-width: 100% !important;
    min-height: 38px !important;
    padding: 4px 5px !important;
    text-align: center !important;
    appearance: auto !important;
    -moz-appearance: auto !important;
  }

  .quotation-result-card .native-quantity-field input[type="number"]::-webkit-outer-spin-button,
  .quotation-result-card .native-quantity-field input[type="number"]::-webkit-inner-spin-button,
  .sale-product-result-row .native-quantity-field input[type="number"]::-webkit-outer-spin-button,
  .sale-product-result-row .native-quantity-field input[type="number"]::-webkit-inner-spin-button,
  .quotation-basket-item .native-quantity-field input[type="number"]::-webkit-outer-spin-button,
  .quotation-basket-item .native-quantity-field input[type="number"]::-webkit-inner-spin-button {
    margin: 0 !important;
    opacity: 1 !important;
  }

  .quotation-result-card .quotation-add-btn,
  .sale-product-result-row .sale-result-add {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
    min-height: 42px !important;
  }

  .quotation-external-form .native-quantity-field input[type="number"] {
    width: 100% !important;
  }
}
