/* AquaControl V79.17.22.9 - mobile responsive hardening.
   Visual-only layer: no business rules or data logic. */

html,
body,
#app {
  max-width: 100%;
}

@supports (height: 100dvh) {
  body.app-locked-scroll,
  body:has(#mainScreen:not(.hidden)),
  #mainScreen {
    height: 100dvh;
  }
}

@media (max-width: 900px) {
  html,
  body {
    overflow-x: hidden;
  }

  #mainScreen,
  #mainScreen .layout,
  #mainScreen .content,
  #mainScreen .view,
  #mainScreen .panel,
  #mainScreen .card,
  #mainScreen form,
  #mainScreen fieldset,
  #mainScreen .table-wrap,
  #mainScreen .compact-table-wrap {
    min-width: 0;
    max-width: 100%;
  }

  #mainScreen .content {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    scroll-padding-bottom: max(32px, env(safe-area-inset-bottom));
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }

  input,
  select,
  textarea {
    min-width: 0;
    max-width: 100%;
    font-size: 16px;
  }

  button,
  [role="button"],
  .mini-btn,
  .module-workspace-tab,
  .enterprise-live-tab {
    min-height: 42px;
  }

  .table-wrap,
  .compact-table-wrap,
  .config-table-wrap,
  .cart-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .module-workspace-tabs,
  #deliveryView .module-workspace-tabs,
  #deliveryView .enterprise-live-tabs,
  .maintenance-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    padding-bottom: 6px;
  }

  .module-workspace-tabs > *,
  #deliveryView .module-workspace-tabs > *,
  #deliveryView .enterprise-live-tabs > *,
  .maintenance-tabs > * {
    flex: 0 0 auto;
  }

  /* Domicilio: one stage at a time horizontally, cards vertically. */
  #deliveryView .delivery-card-board.delivery-kanban-board {
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-gutter: auto;
    padding: 0 0 12px;
  }

  #deliveryView .delivery-kanban {
    display: flex !important;
    align-items: flex-start !important;
    gap: 10px;
    width: max-content !important;
    min-width: 100% !important;
    height: auto !important;
  }

  #deliveryView .delivery-kanban-column {
    flex: 0 0 min(78vw, 320px);
    width: min(78vw, 320px) !important;
    min-width: min(78vw, 320px) !important;
    height: auto !important;
    min-height: 200px !important;
    max-height: min(68dvh, 620px);
    scroll-snap-align: start;
  }

  #deliveryView .delivery-kanban-stack {
    min-height: 0;
    max-height: min(58dvh, 540px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto !important;
    touch-action: pan-x pan-y;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  #deliveryView .delivery-order-card,
  #deliveryView .delivery-card-top,
  #deliveryView .delivery-card-customer,
  #deliveryView .delivery-card-order-summary,
  #deliveryView .aq-card-detail-body {
    min-width: 0;
    max-width: 100%;
  }

  #deliveryView .delivery-order-card :is(strong, small, span, p, a) {
    overflow-wrap: anywhere;
  }

  /* Domicilio capture dialog: the dialog owns vertical scrolling on phones. */
  .aq-visual #deliveryOrderDialog {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .aq-visual #deliveryOrderForm {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .aq-visual #deliveryOrderForm .delivery-order-actions {
    position: static !important;
    bottom: auto !important;
    z-index: auto;
  }

  /* Driver cut: one natural modal scroller instead of stacked scroll traps. */
  .corporate-theme .driver-cut-capture-dialog {
    width: calc(100vw - 8px) !important;
    max-width: calc(100vw - 8px) !important;
    height: calc(100dvh - 8px) !important;
    max-height: calc(100dvh - 8px) !important;
    overflow: hidden;
    border-radius: 10px;
  }

  .driver-cut-modal-shell {
    height: 100%;
    min-height: 0;
  }

  .driver-cut-modal-header {
    flex-direction: column;
    gap: 10px;
  }

  .driver-cut-modal-header-actions {
    width: 100%;
  }

  .driver-cut-modal-header-actions > button {
    flex: 1 1 auto;
  }

  .driver-cut-modal-grid {
    display: block !important;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    scroll-padding-bottom: max(28px, env(safe-area-inset-bottom));
    padding: 8px;
  }

  .driver-cut-modal-pane {
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
    margin-bottom: 10px;
  }

  .driver-cut-pane-scroll {
    flex: none;
    min-height: 0;
    overflow: visible !important;
    overscroll-behavior: auto !important;
  }

  .driver-cut-modal-form {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) !important;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .driver-cut-modal-form > *,
  .driver-cut-date-actions,
  .driver-cut-modal-form .form-grid,
  .driver-cut-modal-form .driver-debt-payment-box,
  .driver-cut-modal-form .compact-table-wrap {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .driver-cut-modal-form :is(input, select, textarea, button) {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
  }

  .driver-cut-form-spacer {
    height: 0;
  }

  .driver-cut-sticky-actions {
    position: static !important;
    left: auto;
    right: auto;
    bottom: auto !important;
    margin: 12px -14px 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  /* Maintenance dialogs: footer follows content and cannot cover fields. */
  .maintenance-dialog {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    overflow: hidden;
  }

  .maintenance-dialog > .dialog-form {
    max-height: calc(100dvh - 28px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    scroll-padding-bottom: max(28px, env(safe-area-inset-bottom));
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .maintenance-dialog-actions {
    position: static !important;
    bottom: auto !important;
  }

  /* Cash workspace: dynamic viewport and non-obstructive mobile actions. */
  .cash-cut-workspace-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }

  .cash-workspace-shell {
    height: 100%;
    min-height: 0;
  }

  .cash-workspace-stage {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    scroll-padding-bottom: max(32px, env(safe-area-inset-bottom));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .cash-workspace-form > .dialog-actions {
    position: static !important;
    bottom: auto !important;
    margin-bottom: 0 !important;
    box-shadow: none;
    backdrop-filter: none;
  }

  /* Global search: use the real phone viewport, including browser chrome. */
  .global-search-dialog {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    height: calc(100dvh - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    border-radius: 10px;
  }

  .global-search-shell,
  .global-search-body,
  .global-search-results-panel,
  .global-trace-panel {
    min-width: 0;
    min-height: 0;
  }

  .global-search-results,
  .global-trace-panel {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
  }

  /* Generic native dialogs. Specific full-screen workspaces above keep their own layout. */
  dialog:not(.driver-cut-capture-dialog):not(.cash-cut-workspace-dialog):not(.global-search-dialog):not(#deliveryOrderDialog) {
    max-width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    scroll-padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .audit-detail-dialog {
    max-height: calc(100dvh - 12px) !important;
  }

  .audit-detail-body {
    max-height: calc(100dvh - 116px) !important;
    overscroll-behavior-y: auto;
  }
}

@media (max-width: 620px) {
  .aq-visual .topbar {
    min-height: 0;
    padding-top: max(9px, env(safe-area-inset-top));
  }

  .aq-visual .content {
    padding-left: 10px;
    padding-right: 10px;
  }

  #deliveryView .delivery-filters,
  #deliveryView .delivery-stats,
  .maintenance-kpis,
  .cash-workspace-kpis {
    min-width: 0;
  }

  #deliveryView .delivery-kanban-column {
    flex-basis: min(86vw, 320px);
    width: min(86vw, 320px) !important;
    min-width: min(86vw, 320px) !important;
  }

  #deliveryView .delivery-filters {
    grid-template-columns: 1fr !important;
  }

  #deliveryView #deliverySearch {
    grid-column: auto !important;
  }

  .dialog-actions,
  .ticket-actions,
  .driver-cut-sticky-actions,
  .cash-workspace-header-actions,
  #deliveryView .header-actions {
    flex-wrap: wrap;
  }

  .dialog-actions > button,
  .driver-cut-sticky-actions > button,
  .cash-workspace-header-actions > button {
    min-height: 44px;
  }

  .maintenance-dialog-title,
  .delivery-inline-customer-head,
  .delivery-dispatch-head {
    flex-direction: column;
    align-items: stretch;
  }

  .global-search-header {
    gap: 8px;
  }

  .global-search-input-wrap input {
    font-size: 16px;
  }
}

@media (max-width: 390px) {
  #deliveryView .delivery-stats {
    grid-template-columns: 1fr !important;
  }

  #deliveryView .delivery-stats .aq-kpi:last-child {
    grid-column: auto !important;
  }

  .cash-workspace-kpis {
    grid-template-columns: 1fr 1fr !important;
  }

  .driver-cut-modal-header h3,
  .aq-order-header h3 {
    font-size: 20px !important;
  }
}
