@media (max-width: 800px) {
  html { scroll-padding-bottom: 82px; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); overflow-x: hidden; }
  body, button, input, select, textarea { font-size: 16px; }

  .sidebar {
    inset: auto 0 0;
    z-index: 70;
    width: 100%;
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 5px 6px env(safe-area-inset-bottom);
    border-top: 1px solid rgba(255,255,255,.14);
  }
  .sidebar .brand, .sidebar .online { display: none; }
  .sidebar nav {
    height: 58px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar .nav {
    flex: 0 0 82px;
    min-width: 0;
    padding: 6px 3px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 1px;
    text-align: center;
    line-height: 1.1;
    font-size: 17px;
  }
  .sidebar .nav span {
    display: block;
    margin: 0;
    max-width: 100%;
    font-size: 10px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  main {
    margin-left: 0;
    padding: max(env(safe-area-inset-top), 22px) 10px 18px;
    width: 100%;
  }
  header {
    height: auto;
    min-height: 76px;
    padding: 10px 2px;
    gap: 8px;
    align-items: flex-start;
  }
  header > div:first-child { min-width: 0; padding-top: 4px; }
  header h1 { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
  header p { display: none; }
  .header-actions { gap: 6px; margin-left: auto; }
  .header-actions .date { display: none; }
  .header-settings { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; }
  .header-settings span { display: none; }
  .notification-button { width: 42px; height: 42px; }
  .notification-panel { position: fixed; top: 62px; left: 10px; right: 10px; width: auto; max-height: calc(100vh - 150px); }
  .user-menu { gap: 5px; }
  .user-chip { max-width: 104px; padding: 6px 8px; }
  .user-chip strong, .user-chip small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-menu > .secondary { padding: 8px; font-size: 12px; }

  .panel { border-radius: 12px; }
  .pos-grid { display: grid; grid-template-columns: 1fr; height: auto; gap: 10px; }
  .catalog-panel { max-height: 42vh; min-height: 250px; padding: 10px; }
  .search-wrap { min-height: 46px; height: auto; padding: 7px 10px; }
  .search-wrap input { min-width: 0; font-size: 16px; }
  .search-wrap kbd { display: none; }
  .chips { padding: 10px 0 8px; }
  .chip { padding: 7px 11px; }
  .product-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
  .product-card { min-height: 118px; padding: 11px; overflow: hidden; }
  .product-card strong { overflow-wrap: anywhere; }

  .cart-panel { margin-top: 0; min-height: 58vh; }
  .panel-title { padding: 12px; gap: 9px; flex-wrap: wrap; align-items: flex-start; }
  .panel-title > div:first-child { min-width: 110px; }
  .cart-heading {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0 !important;
  }
  .cart-heading h2, .cart-heading small { white-space: nowrap; }
  .cart-actions { width: 100%; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .cart-actions > * { flex: 0 0 auto; white-space: nowrap; }
  .cart-items { padding: 5px 12px; max-height: none; }
  .cart-line { grid-template-columns: minmax(0,1fr); gap: 7px; padding: 11px 0; }
  .cart-line strong, .cart-line small { overflow-wrap: anywhere; }
  .line-right { text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .qty { flex-wrap: wrap; }
  .checkout { padding: 12px; gap: 10px; }
  .checkout-fields { grid-template-columns: 1fr !important; }
  .discount-row { gap: 10px; }
  .discount-row > div { min-width: 0; }
  .discount-row input { width: 78px; }
  .primary.large { min-height: 50px; }

  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar > div { min-width: 0; }
  .toolbar button, .toolbar .button { width: 100%; text-align: center; }
  .summary-cards, #inventory-cards, .customer-kpis, .quotation-kpis { grid-template-columns: 1fr 1fr !important; }
  .summary-card, .customer-kpi, .quotation-kpi { min-width: 0; padding: 13px; }
  .summary-card strong, .customer-kpi strong, .quotation-kpi strong { font-size: 19px; overflow-wrap: anywhere; }
  .filter-grid, .inventory-toolbar { grid-template-columns: 1fr !important; }
  .product-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .product-actions > * { min-width: 0; white-space: normal; }
  .catalog-section-tabs { grid-template-columns: 1fr 1fr; }
  .catalog-section-tabs button { padding: 10px; }
  .catalog-section-tabs button span { font-size: 13px; overflow-wrap: anywhere; }

  .table-panel { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 680px; }
  th, td { padding: 10px; white-space: normal; overflow-wrap: normal; word-break: normal; }

  /* En móvil, los catálogos extensos se leen como fichas y no como tablas comprimidas. */
  #view-products > .table-panel,
  #view-purchases > .table-panel { overflow: visible; }
  #view-products > .table-panel table,
  #view-purchases > .table-panel table { min-width: 0; width: 100%; }
  #view-products > .table-panel thead,
  #view-purchases > .table-panel thead { display: none; }
  #view-products > .table-panel tbody,
  #view-purchases > .table-panel tbody { display: grid; gap: 9px; padding: 9px; }
  #view-products > .table-panel tbody tr,
  #view-purchases > .table-panel tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px 12px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fff;
  }
  #view-products > .table-panel tbody td,
  #view-purchases > .table-panel tbody td {
    min-width: 0;
    padding: 0;
    border: 0;
    overflow-wrap: break-word;
  }
  #view-products > .table-panel tbody td::before,
  #view-purchases > .table-panel tbody td::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 9px;
    font-weight: 750;
    letter-spacing: .04em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  #view-products > .table-panel tbody tr { grid-template-columns: 28px 1fr 1fr; }
  #view-products > .table-panel tbody td:nth-child(1) { grid-column: 1; grid-row: 1; }
  #view-products > .table-panel tbody td:nth-child(2) { grid-column: 2 / -1; grid-row: 1; }
  #view-products > .table-panel tbody td:nth-child(3) { grid-column: 1 / 3; }
  #view-products > .table-panel tbody td:nth-child(5) { grid-column: 3; }
  #view-products > .table-panel tbody td:nth-child(9) { grid-column: 1 / 3; }
  #view-products > .table-panel tbody td:nth-child(10) { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
  #view-products > .table-panel tbody td:nth-child(4),
  #view-products > .table-panel tbody td:nth-child(6),
  #view-products > .table-panel tbody td:nth-child(7),
  #view-products > .table-panel tbody td:nth-child(8) { display: none; }
  #view-products > .table-panel tbody td:nth-child(3)::before { content: "Código"; }
  #view-products > .table-panel tbody td:nth-child(5)::before { content: "Precio"; }
  #view-products > .table-panel tbody td:nth-child(9)::before { content: "Stock"; }
  #view-products > .table-panel .badge { max-width: 100%; overflow-wrap: anywhere; }

  #view-purchases > .table-panel tbody td:nth-child(1) { grid-column: 1 / -1; }
  #view-purchases > .table-panel tbody td:nth-child(8) { grid-column: 1 / -1; padding-top: 4px; border-top: 1px solid var(--line); }
  #view-purchases > .table-panel tbody td:nth-child(1)::before { content: "Orden"; }
  #view-purchases > .table-panel tbody td:nth-child(2)::before { content: "Proveedor"; }
  #view-purchases > .table-panel tbody td:nth-child(3)::before { content: "Documento"; }
  #view-purchases > .table-panel tbody td:nth-child(4)::before { content: "Unidades"; }
  #view-purchases > .table-panel tbody td:nth-child(5)::before { content: "Total"; }
  #view-purchases > .table-panel tbody td:nth-child(6)::before { content: "Estado"; }
  #view-purchases > .table-panel tbody td:nth-child(7)::before { content: "Fecha"; }
  .payment-row { grid-template-columns: minmax(90px,130px) 1fr auto; gap: 8px; }
  .report-grid, .business-grid, .quotation-bottom, .quote-document-bottom {
    width: 100%;
    min-width: 0;
    grid-template-columns: minmax(0,1fr) !important;
  }
  .report-grid > *, .business-grid > *, .detailed-evolution { min-width: 0; max-width: 100%; }
  .report-grid .span2 { grid-column: auto; }

  dialog, dialog.wide-modal, dialog.quotation-modal, dialog.quotation-detail-modal {
    width: calc(100% - 12px);
    max-width: none;
    max-height: calc(100dvh - 12px);
    margin: auto;
  }
  dialog form, dialog .dialog-content { padding: 15px; max-height: calc(100dvh - 12px); overflow-y: auto; }
  .modal-head { gap: 10px; margin-bottom: 14px; }
  .modal-head > div { min-width: 0; }
  .modal-head h2, .modal-head p { overflow-wrap: anywhere; }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .modal-actions { position: sticky; bottom: -15px; z-index: 2; padding: 10px 0 15px; background: #fff; flex-wrap: wrap; }
  .modal-actions > * { flex: 1; min-width: 120px; }
  .quotation-line, .quotation-line.compact-quotation-line, .purchase-line { grid-template-columns: 1fr 1fr !important; }
  .quotation-line > *:first-child, .purchase-line > *:first-child { grid-column: 1/-1; }
  .quote-client { grid-template-columns: 1fr; }
  .quotation-document { padding: 14px; }
  .quotation-document > header { gap: 12px; flex-direction: column; }
  .quote-number { text-align: left; }

  .auth-overlay { padding: 10px; }
  .auth-card { padding: 20px; border-radius: 14px; }
  .auth-first { display: none; }
}

@media (max-width: 430px) {
  .summary-cards, #inventory-cards, .customer-kpis, .quotation-kpis { grid-template-columns: 1fr !important; }
  .product-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .catalog-section-tabs { grid-template-columns: 1fr; }
  .product-actions { grid-template-columns: 1fr; }
  .payment-row { grid-template-columns: 1fr auto; }
  .payment-row .bar { grid-column: 1/-1; }
}
