/* Shared touch layouts. Desktop layouts stay in the page stylesheets. */
@media screen and (max-width: 1024px) {
  :root .ops-app[data-theme] :is(.ops-main, .production-layout, .dosage-chart-card, .weighings-panel, .billing-dashboard-grid > *, .lineup-analysis-charts > *) {
    min-width: 0;
  }

  :root .ops-app[data-theme] .ops-main {
    width: calc(100% - 40px);
  }

  :root .ops-app[data-theme] :is(.ops-page-heading, .weighings-panel-heading, .weighings-toolbar, .weighings-footer) {
    flex-wrap: wrap;
  }

  :root .ops-app[data-theme] :is(.ops-heading-actions, .weighings-title-group, .ops-page-heading > div) {
    min-width: 0;
    max-width: 100%;
  }

  :root .ops-app[data-theme] :is(.billing-table-scroll, .lineup-analysis-table-scroll, .weighing-preview-table-wrap, .lineup-volume-scroll) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media screen and (max-width: 680px) {
  :root .ops-app[data-theme] .ops-header {
    padding-inline: 12px;
    column-gap: 8px;
  }

  :root .ops-app[data-theme] .ops-header-actions {
    gap: 2px;
  }

  :root .ops-app[data-theme] .ops-icon-button {
    width: 36px;
    height: 44px;
  }

  :root .ops-app[data-theme] .ops-user-profile {
    min-height: 44px;
    padding-inline: 4px;
  }

  :root .ops-app[data-theme] .ops-user-menu {
    min-height: 44px;
    padding-inline: 5px;
    font-size: 12px;
  }

  :root .ops-app[data-theme] .ops-primary-nav {
    position: relative;
    height: 48px;
    gap: 8px;
  }

  :root .ops-app[data-theme] .ops-primary-nav .ops-nav-item {
    min-height: 48px;
    gap: 8px;
    padding-inline: 12px;
    font-size: 13px;
  }

  :root .ops-app[data-theme] .ops-home-label {
    display: inline;
  }

  :root .ops-app[data-theme] .ops-operations-menu {
    position: static;
  }

  :root .ops-app[data-theme] .ops-operations-dropdown {
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    width: auto;
    max-height: calc(100dvh - 128px - env(safe-area-inset-bottom, 0px));
  }

  .ops-operations-group-trigger,
  .ops-operations-links a {
    min-height: 46px;
    font-size: 14px;
  }

  :root .ops-app[data-theme] .ops-main {
    width: calc(100% - 28px);
    padding-top: 20px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  :root .ops-app[data-theme] .production-layout {
    width: calc(100% - 28px);
    margin-inline: auto;
  }

  :root .ops-app[data-theme] .production-layout .ops-main {
    width: 100%;
  }

  :root .ops-app[data-theme] .ops-breadcrumb {
    flex-wrap: wrap;
    gap: 5px 8px;
    font-size: 12px;
  }

  :root .ops-app[data-theme] .ops-page-heading {
    align-items: stretch;
    gap: 18px;
  }

  :root .ops-app[data-theme] .ops-page-heading h1 {
    font-size: clamp(24px, 6vw, 28px);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  :root .ops-app[data-theme] :is(.ops-page-heading p, .weighings-panel-heading p, .dosage-chart-heading p, .dosage-data-note, .billing-data-scope) {
    font-size: 12px;
    line-height: 1.65;
    overflow-wrap: anywhere;
  }

  :root .ops-app[data-theme] .ops-heading-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  :root .ops-app[data-theme] .ops-heading-actions > :is(.ops-button, .production-reports-menu) {
    flex: 1 1 130px;
  }

  :root .ops-app[data-theme] .production-reports-trigger {
    width: 100%;
  }

  :root .ops-app[data-theme] :is(.ops-button, .weighings-page-button, .almox-edit-button, .weighing-modal-close) {
    min-height: 44px;
    font-size: 12px;
  }

  :root .ops-app[data-theme] .ops-button {
    padding: 10px 12px;
    line-height: 1.4;
    white-space: normal;
  }

  :root .ops-app[data-theme] :is(input:not([type='checkbox']):not([type='radio']), select, textarea) {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  :root .ops-app[data-theme] .ops-search {
    width: 100%;
    min-width: 0;
    min-height: 46px;
  }

  :root .ops-app[data-theme] .ops-search input {
    width: 100%;
  }

  :root .ops-app[data-theme] .ops-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-block: 18px;
  }

  :root .ops-app[data-theme] .ops-metric-card {
    min-width: 0;
    min-height: 138px;
    padding: 14px;
    gap: 10px;
  }

  :root .ops-app[data-theme] .ops-metric-top {
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    line-height: 1.4;
  }

  :root .ops-app[data-theme] .ops-metric-icon {
    flex-shrink: 0;
  }

  :root .ops-app[data-theme] .ops-metric-value {
    font-size: clamp(21px, 5.4vw, 27px);
    line-height: 1.25;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  :root .ops-app[data-theme] .ops-metric-foot {
    font-size: 11px;
    line-height: 1.5;
  }

  :root .ops-app[data-theme] .weighings-tabs {
    display: flex;
    overflow-x: auto;
    max-width: 100%;
    gap: 8px;
    margin-bottom: 16px;
  }

  :root .ops-app[data-theme] .weighings-tab {
    flex: 1 0 auto;
    min-height: 46px;
    padding: 10px 14px;
    font-size: 13px;
  }

  :root .ops-app[data-theme] .weighings-panel-heading {
    align-items: flex-start;
    gap: 12px;
  }

  :root .ops-app[data-theme] .weighings-panel-heading h2 {
    font-size: 16px;
    line-height: 1.35;
  }

  :root .ops-app[data-theme] .weighings-title-group {
    flex: 1 1 180px;
    align-items: flex-start;
  }

  :root .ops-app[data-theme] .weighings-count {
    font-size: 11px;
    white-space: normal;
  }

  :root .ops-app[data-theme] :is(.weighings-toolbar, .almox-stock-filters) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  :root .ops-app[data-theme] :is(.weighings-date-filter, .import-lineup-date-filter) {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  :root .ops-app[data-theme] .weighings-date-filter {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  :root .ops-app[data-theme] .weighings-date-today {
    grid-column: 1 / -1;
    min-height: 44px;
  }

  :root .ops-app[data-theme] .weighings-date-picker input {
    width: 100%;
  }

  :root .ops-app[data-theme] :is(.weighings-date-button, .weighings-date-picker) {
    min-height: 44px;
  }

  :root .ops-app[data-theme] :is(.weighings-footer, .billing-table-footer) {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
    gap: 14px;
    font-size: 12px;
  }

  :root .ops-app[data-theme] :is(.weighings-pagination, .billing-pagination) {
    max-width: 100%;
    overflow-x: auto;
    padding: 2px;
    gap: 6px;
  }

  :root .ops-app[data-theme] .weighings-page-button {
    min-width: 40px;
    flex-shrink: 0;
  }

  /* Show records as labeled cards so their actions stay within reach. */
  :root .ops-app[data-theme] :is(.weighings-table-wrap, .almox-table-scroll) {
    min-width: 0;
    padding: 12px;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    table-layout: auto;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) tbody {
    display: grid;
    gap: 12px;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) tbody tr {
    display: block;
    height: auto;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-panel);
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td {
    display: grid;
    width: auto;
    min-width: 0;
    min-height: 44px;
    max-width: none;
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    align-items: center;
    column-gap: 12px;
    row-gap: 0;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--ui-border);
    color: var(--ui-secondary);
    font-size: 13px;
    line-height: 1.5;
    white-space: normal;
    text-align: right;
    overflow-wrap: anywhere;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td::before {
    content: attr(data-label);
    grid-column: 1;
    grid-row: 1 / span 5;
    align-self: start;
    color: var(--ui-muted);
    font-size: 12px;
    font-weight: 400;
    text-align: left;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td > * {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td:last-child {
    border-bottom: 0;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td[colspan] {
    display: block;
    text-align: center;
  }

  :root .ops-app[data-theme] :is(.weighings-table, .almox-table, .stoppage-table) td[colspan]::before {
    display: none;
  }

  :root .ops-app[data-theme] :is(.almox-table td[data-label='Ações'], .production-action-cell, .production-order-label-cell) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    text-align: left;
  }

  :root .ops-app[data-theme] .almox-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .almox-row-actions > .ops-button {
    flex: 1;
  }

  :root .ops-app[data-theme] .almox-note-details {
    max-width: 100%;
    text-align: left;
  }

  :root .ops-app[data-theme] .almox-note-details summary {
    padding-block: 8px;
  }

  :root .ops-app[data-theme] .billing-refresh {
    width: 100%;
    justify-content: space-between;
  }

  :root .ops-app[data-theme] .billing-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 16px;
  }

  .responsive-table-hint {
    margin: 0;
    padding: 10px 16px;
    color: var(--ui-muted);
    background: var(--ui-raised);
    font-size: 12px;
  }

  :root .ops-app[data-theme] .billing-table th button {
    min-height: 44px;
  }

  :root .ops-app[data-theme] .billing-table :is(th, td):first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--ui-panel);
    box-shadow: 1px 0 var(--ui-border);
  }

  :root .ops-app[data-theme] .billing-table th:first-child {
    background: var(--ui-raised);
  }

  :root .ops-app[data-theme] :is(.billing-dashboard-grid, .lineup-analysis-charts, .dosage-charts-grid, .dosage-details-grid, .setup-summary, .setup-chart) {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  :root .ops-app[data-theme] :is(.billing-ranking-label, .lineup-product-heading, .lineup-product-values, .dosage-output-legend, .lineup-volume-header, .lineup-analysis-controls, .lineup-analysis-vessel-toolbar) {
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
  }

  :root .ops-app[data-theme] :is(.lineup-analysis-controls label, .lineup-analysis-controls select, .lineup-analysis-vessel-toolbar label) {
    min-width: 0;
    max-width: 100%;
  }

  :root .ops-app[data-theme] .dosage-destination-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    font-size: 12px;
  }

  .dosage-destination-track {
    grid-row: 2;
    grid-column: 1 / -1;
  }

  :root .ops-app[data-theme] .dosage-stoppage-row {
    flex-wrap: wrap;
    font-size: 12px;
  }

  :root .ops-app[data-theme] .almox-branches {
    display: flex;
    gap: 8px;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 5px;
    scroll-snap-type: x proximity;
  }

  .almox-branches button {
    flex: 1 0 140px;
    min-height: 48px;
    font-size: 12px;
    white-space: nowrap;
    scroll-snap-align: start;
  }

  :root .ops-app[data-theme] .almox-history-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 16px;
    gap: 12px;
  }

  .almox-history-filters > :is(.almox-history-search, .ops-button),
  .almox-history-filters > label:has(select) {
    grid-column: 1 / -1;
  }

  .almox-pagination {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
  }

  .users-profile-facts {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .users-profile-identity {
    align-items: flex-start;
    min-width: 0;
  }

  .users-profile-identity h2 {
    overflow-wrap: anywhere;
  }

  :root .ops-app[data-theme] .weighing-modal-backdrop {
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  :root .ops-app[data-theme] .weighing-process-modal {
    width: 100%;
    min-width: 0;
    max-height: calc(100dvh - 16px - env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
  }

  :root .ops-app[data-theme] :is(.weighing-modal-header, .weighing-modal-body, .weighing-modal-footer) {
    padding: 16px;
    min-width: 0;
  }

  .weighing-modal-header > div,
  .weighing-modal-heading > div {
    min-width: 0;
  }

  :root .ops-app[data-theme] .weighing-modal-header h2 {
    font-size: 20px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .weighing-modal-heading-icon {
    display: none;
  }

  :root .ops-app[data-theme] .weighing-modal-body {
    scroll-padding-block: 20px;
  }

  :root .ops-app[data-theme] .almox-fields {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  :root .ops-app[data-theme] .weighing-preview-facts {
    grid-template-columns: minmax(0, 1fr);
  }

  .weighing-preview-facts dd,
  .weighing-modal-header p {
    overflow-wrap: anywhere;
  }

  .stoppage-list-wrap {
    max-height: 38dvh;
    padding: 8px;
    scroll-padding-block: 8px;
  }

  .stoppage-toolbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px;
  }

  .stoppage-toolbar-actions > label {
    grid-column: 1 / -1;
  }

  .stoppage-toolbar-actions > select {
    grid-column: 1 / -1;
    width: 100%;
  }

  :root .ops-app[data-theme] .stoppage-toolbar-actions > .ops-button {
    flex-direction: column;
    padding: 10px 4px;
    font-size: 11px;
  }

  :root .ops-app[data-theme] .vessel-traffic-frame {
    height: clamp(300px, 58dvh, 500px);
    min-height: 0;
    width: 100%;
  }

  .vessel-map-selection > div {
    width: 100%;
  }

  .vessel-map-selection > div > .ops-button {
    flex: 1;
  }

  :root .ops-app[data-theme] .vessel-name-button {
    min-height: 44px;
  }

  :root .ops-app[data-theme] .production-chat {
    width: 100%;
    min-width: 0;
    max-height: none;
  }

  .production-chat-messages {
    max-height: 50dvh;
  }

  .production-chat-message {
    overflow-wrap: anywhere;
  }

  .production-chat-send {
    min-width: 44px;
    min-height: 44px;
  }

  .login-page {
    min-height: 100dvh;
    padding: 72px 16px 28px;
  }

  :root .login-card {
    padding: 28px 22px;
    border-radius: 14px;
  }

  .login-form input,
  .login-submit {
    min-height: 48px;
    font-size: 16px;
  }
}

.responsive-table-hint {
  display: none;
}

@media screen and (max-width: 680px) {
  .responsive-table-hint {
    display: block;
  }
}

@media screen and (max-width: 360px) {
  :root .ops-app[data-theme] .ops-metrics {
    grid-template-columns: minmax(0, 1fr);
  }

  :root .ops-app[data-theme] .ops-metric-card {
    min-height: 120px;
  }

  :root .ops-app[data-theme] .ops-brand {
    font-size: 14px;
    gap: 5px;
  }

  :root .ops-app[data-theme] .ops-header {
    padding-inline: 8px;
  }
}

@media screen and (max-height: 500px) and (max-width: 960px) {
  :root .ops-app[data-theme] .ops-header {
    position: relative;
  }

  :root .login-page {
    align-items: start;
    padding-top: 65px;
  }
}
