/* Screen-only containment: never change receipts, DTE or print paper sizing. */
@media screen {
  main, main .view, main .view > *, main .panel,
  .report-grid > *, .settings-grid > *, .business-grid > *,
  .dialog-content, .dialog-content > *, .form-grid > * {
    min-width: 0;
  }
  main .view, main .panel, main .table-panel { max-width: 100%; }
  main .table-panel { overflow-x: auto; overscroll-behavior-x: contain; }
  main .view > .table-panel {
    max-height: 70dvh;
    overflow: auto;
  }
  main .table-panel thead th { position: sticky; top: 0; z-index: 1; background: #f7f9fa; }
  #view-summary .report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-summary .report-grid > .panel { min-width: 0; }
  #view-summary .chart { max-width: 100%; min-width: 0; overflow-x: auto; }
  #view-summary .panel-title, .history-filter-title,
  .quotation-toolbar, .quotation-products-title { flex-wrap: wrap; }
  #view-summary .panel-title > *, .quotation-toolbar > *,
  .filter-grid > *, .purchase-filters > *, .settings-fields > * { min-width: 0; }
  #view-summary .metric-buttons { min-width: 0; max-width: 100%; flex-wrap: wrap; }
  dialog { max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow: auto; }
  dialog .modal-head, dialog .modal-actions { flex-wrap: wrap; }
  dialog .modal-head > :first-child { min-width: 0; overflow-wrap: anywhere; }
  dialog input:not([type="checkbox"]):not([type="radio"]), dialog select,
  dialog textarea { min-width: 0; max-width: 100%; }
  .settings-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); }
  .quotation-bottom, .quote-document-bottom { grid-template-columns: minmax(0, 1fr) minmax(0, 320px); }
}

@media screen and (max-width: 1400px) {
  /* All ten fields remain available; actions no longer sit off-screen. */
  #view-history > .history-table-panel { max-height: none; overflow: visible !important; background: transparent; border: 0; box-shadow: none; }
  #view-history > .history-table-panel table { display: block; min-width: 0 !important; width: 100%; }
  #view-history > .history-table-panel thead { display: none; }
  #view-history > .history-table-panel tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 0; }
  #view-history > .history-table-panel tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
  #view-history > .history-table-panel tbody td { display: block; min-width: 0 !important; padding: 0; border: 0; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
  #view-history > .history-table-panel tbody td::before { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: none; }
  #view-history > .history-table-panel tbody td:nth-child(1) { grid-column: 1 / -1; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  #view-history > .history-table-panel tbody td:nth-child(1)::before { content: 'Venta'; }
  #view-history > .history-table-panel tbody td:nth-child(2)::before { content: 'Fecha'; }
  #view-history > .history-table-panel tbody td:nth-child(3)::before { content: 'Documento'; }
  #view-history > .history-table-panel tbody td:nth-child(4)::before { content: 'Caja / operador'; }
  #view-history > .history-table-panel tbody td:nth-child(5)::before { content: 'Pago'; }
  #view-history > .history-table-panel tbody td:nth-child(6)::before { content: 'Subtotal'; }
  #view-history > .history-table-panel tbody td:nth-child(7)::before { content: 'Descuento'; }
  #view-history > .history-table-panel tbody td:nth-child(8)::before { content: 'Total'; }
  #view-history > .history-table-panel tbody td:nth-child(9) { grid-column: auto !important; display: block !important; padding-top: 0 !important; border-top: 0 !important; }
  #view-history > .history-table-panel tbody td:nth-child(9)::before { content: 'Ganancia bruta est.'; }
  #view-history > .history-table-panel tbody td:nth-child(10) { grid-column: 1 / -1 !important; display: block !important; padding-top: 12px !important; border-top: 1px solid var(--line) !important; }
  #view-history > .history-table-panel tbody td:nth-child(10)::before { content: 'Acciones'; }
  #view-history .pg-history-actions { flex-direction: row; flex-wrap: wrap; gap: 8px 16px; }
  #view-history > .history-table-panel tbody tr:has(td[colspan]) { grid-column: 1 / -1; }
  #view-history > .history-table-panel tbody td[colspan] { grid-column: 1 / -1 !important; border: 0; }
  #view-history > .history-table-panel tbody td[colspan]::before { content: none; }
}

@media screen and (max-width: 1050px) {
  #view-summary .report-grid { grid-template-columns: minmax(0, 1fr); }
  #view-summary .report-grid .span2 { grid-column: 1 / -1; }
  .quotation-bottom, .quote-document-bottom { grid-template-columns: minmax(0, 1fr); }
  dialog .quotation-line.compact-quotation-line { grid-template-columns: minmax(0, 1fr) minmax(0, 90px); }
  dialog .quotation-lines-head { display: none; }
  dialog .compact-quotation-line > :first-child { grid-column: 1 / -1; }
}

@media screen and (max-width: 1000px) {
  #view-history > .history-table-panel tbody { grid-template-columns: minmax(0, 1fr); }
  #view-history .history-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  #view-history .history-kpi { padding: 14px; }
  #view-history .history-kpi small { min-height: 0; }
  #view-history .history-kpi strong { font-size: 22px; }
}

@media screen and (max-width: 800px) {
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  #view-history .history-command-bar { grid-template-columns: minmax(0, 1fr); }
  #view-history .history-export { grid-column: auto; grid-row: auto; justify-self: start; }
  #view-history .history-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-history > .history-table-panel tbody tr { padding: 14px; gap: 10px 12px; }
  #view-history .history-page-size-control { flex-wrap: wrap; white-space: normal; }
}

@media screen and (max-width: 520px) {
  #view-history .history-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-history .history-kpi strong { font-size: 20px; }
  #view-history .history-filter-title { align-items: flex-start; gap: 8px; }
  .quotation-toolbar select { width: 100%; }
  dialog .form-grid, dialog .quote-client { grid-template-columns: minmax(0, 1fr); }
}
