/* RC DOMOTIC admin: capa responsive local, sin alterar lógica ni datos. */
:root {
  /* Densidad móvil: el cromo fijo se paga en TODAS las pantallas.
   * Barra inferior 72 -> 54 px y header 60 -> 48 px libera 30 px de alto útil. */
  --mobile-nav-height: 54px;
  --mobile-gutter: 10px;
  --mobile-header-height: 48px;
}

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

.mobile-bottom-nav,
.mobile-more-sheet,
.preview-toggle-btn,
.mobile-preview-close {
  display: none;
}

.nav-utility {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.cot-preview-col {
  position: sticky;
  top: 120px;
  min-width: 0;
}

/* Los hijos de una rejilla tienen min-width:auto, así que se estiran hasta el
 * ancho mínimo de su contenido y pueden desbordar la pista. #cotFormCol es un
 * div sin clase y no entraba en la lista de min-width:0 de más abajo: a 320 px
 * medía 428 px y arrastraba todo el formulario fuera de la pantalla.
 * El desbordamiento no se veía como scroll porque html/body llevan
 * overflow-x: clip en móvil, pero el contenido quedaba cortado. */
.cot-editor-grid > * {
  min-width: 0;
  max-width: 100%;
}

#cotFormCol {
  min-width: 0;
  max-width: 100%;
}

.product-picker {
  display: grid;
  grid-template-columns: minmax(160px, .9fr) minmax(150px, .7fr) minmax(240px, 1.5fr) auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.product-picker .fg {
  min-width: 0;
  margin: 0;
}

.product-add-btn {
  min-width: 48px;
  height: 42px;
  justify-content: center;
  font-size: 17px;
  font-weight: 900;
}

.selected-product {
  display: none;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin: 4px 0 12px;
  padding: 10px;
  border: 1px solid var(--brd);
  border-radius: var(--R-lg);
  background: linear-gradient(135deg, #f8fafc, #fff);
}

.selected-product.show {
  display: grid;
}

.selected-product .product-visual {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  border: 1px solid var(--brd-light);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.selected-product img,
.product-visual img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.preview-product-img {
  width: 24px;
  height: 24px;
  display: block;
  border-radius: 4px;
  object-fit: contain;
}

.selected-product-name {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
}

.selected-product-meta {
  margin-top: 3px;
  color: var(--txtL);
  font-size: 11px;
}

.cot-item-input {
  width: 82px;
  min-height: 38px;
  padding: 6px 8px;
  border: 1.5px solid var(--brd);
  border-radius: 8px;
  background: #fff;
}

.cot-item-input.qty {
  width: 58px;
  text-align: center;
}

.cot-form-actions {
  display: flex;
  gap: 10px;
  padding: 4px 0 16px;
}

.cot-form-actions .primary-action {
  flex: 1;
  justify-content: center;
  padding: 12px;
  font-size: 14px;
}

.img-th,
.cmdv-thumb img,
.inv-img img,
.thumb img,
.itemCard img,
.preview img {
  object-fit: contain !important;
}

img.is-fallback {
  padding: 5px;
  opacity: .82;
}

@media (max-width: 1100px) {
  .cot-preview-col {
    display: none;
  }

  .cot-preview-col.show-m {
    display: block;
    position: fixed;
    inset: 64px 0 calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)) 0;
    z-index: 1500;
    overflow-y: auto;
    padding: 12px;
    background: rgba(243, 245, 248, .98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .cot-preview-col.show-m .cot-section {
    max-width: 680px;
    margin: 0 auto;
    box-shadow: var(--S-lg);
  }

  .preview-toggle-btn,
  .mobile-preview-close {
    display: inline-flex;
  }
}

/* BREAKPOINT ÚNICO: 820 px. Debe coincidir con el bloque @media(max-width:820px)
 * del <style> de static/index.html. Si se cambia uno, cambiar el otro: cuando
 * difieren aparece una franja con maquetación mixta (ver comentario allí). */
@media (max-width: 820px) {
  html,
  body {
    width: 100%;
    overflow-x: clip;
  }

  body {
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }

  .nav {
    height: var(--mobile-header-height);
    min-height: var(--mobile-header-height);
    padding: 0 var(--mobile-gutter);
    flex-wrap: nowrap;
    gap: 6px;
  }

  .nav img.logo {
    width: 26px;
    height: 26px;
    margin: 0;
  }

  .nav .brand {
    font-size: 13px;
  }

  .nav #mainNav,
  .nav #userBadge,
  .nav .nav-logout {
    display: none;
  }

  .nav-utility {
    order: initial !important;
    margin-left: auto !important;
  }

  .nav .nav-refresh {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
    font-size: 15px;
  }

  .wrap {
    width: 100%;
    max-width: 100%;
    padding: 8px var(--mobile-gutter) 12px;
  }

  .page,
  .card,
  .cot-editor-grid,
  .cot-section,
  .cot-section-body,
  .tbl-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .mobile-bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 1400;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 3px 4px calc(3px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(15, 23, 42, .1);
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .07);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  /* 44 px de alto táctil real, con el ancho de la celda completa: sigue siendo
   * un objetivo cómodo sin gastar los 56 px de antes. */
  .mobile-bottom-nav button {
    min-width: 0;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #667085;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 2px;
    /* Navegación: mínimo 11px. */
    font-size: 11px;
    font-weight: 700;
    line-height: 1.1;
  }

  .mobile-bottom-nav button .nav-icon {
    font-size: 15px;
    line-height: 1;
  }

  .mobile-bottom-nav button.act {
    background: var(--acc-soft);
    color: #067a35;
  }

  /* El botón central deja de sobresalir y de robar alto: mismo alto que el
   * resto, destacado solo por color. */
  .mobile-bottom-nav .new-quote {
    width: auto;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    justify-self: stretch;
    align-self: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--acc), var(--acc2));
    color: #052e16;
    box-shadow: 0 2px 8px rgba(37, 211, 102, .28);
    transform: none;
    font-weight: 800;
  }

  .mobile-bottom-nav .new-quote .nav-icon {
    font-size: 16px;
  }

  .mobile-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 1900;
  }

  .mobile-more-sheet.show {
    display: block;
  }

  .mobile-more-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, .48);
  }

  .mobile-more-panel {
    position: absolute;
    inset: auto 0 0;
    max-height: min(82dvh, 680px);
    overflow-y: auto;
    padding: 12px 14px calc(20px + env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
    background: #fff;
    box-shadow: 0 -20px 50px rgba(15, 23, 42, .2);
  }

  .mobile-more-handle {
    width: 44px;
    height: 4px;
    margin: 0 auto 12px;
    border-radius: 99px;
    background: #d0d5dd;
  }

  .mobile-more-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .mobile-more-heading strong {
    font-size: 17px;
  }

  .mobile-more-heading button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: #f2f4f7;
    font-size: 18px;
  }

  .mobile-more-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .mobile-more-grid button {
    min-height: 56px;
    border: 1px solid var(--brd);
    border-radius: 14px;
    background: #fff;
    color: var(--txt);
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-more-grid .wide {
    grid-column: 1 / -1;
  }

  .mobile-more-grid .danger {
    color: #b42318;
    background: #fff5f4;
    border-color: #fecdca;
  }

  button,
  .btn,
  [role="button"] {
    min-width: 44px;
    min-height: 44px;
  }

  input,
  select,
  textarea,
  .inp,
  .fg input,
  .fg select,
  .fg textarea,
  .toolbar input,
  .toolbar select {
    min-height: 44px;
    font-size: 16px !important;
  }

  textarea {
    min-height: 88px;
  }

  /* ── Densidad general ────────────────────────────────────────────────────
   * Menos padding y menos margen entre tarjetas: más contenido útil por
   * pantalla sin perder legibilidad. */
  .card {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 12px;
  }

  .card h2 {
    font-size: 13px;
    margin-bottom: 8px;
  }

  /* ── Hero de Inicio compacto ─────────────────────────────────────────────
   * Antes 153 px (206 px a 320 px) solo para saludar. Sin envolver, el saludo y
   * el CTA comparten fila en lugar de apilarse. */
  #pg-dash > div:first-child {
    padding: 9px 11px !important;
    border-radius: 12px !important;
    margin-bottom: 8px !important;
    gap: 8px !important;
    flex-wrap: nowrap !important;
  }

  #pg-dash > div:first-child > div:first-child {
    min-width: 0;
  }

  #pg-dash > div:first-child > div:first-child > div:first-child {
    font-size: 15px !important;
    letter-spacing: -.2px !important;
  }

  #dashHeroSub {
    font-size: 11.5px !important;
    margin-top: 2px !important;
  }

  #pg-dash > div:first-child .btn {
    width: auto;
    padding: 0 14px !important;
    font-size: 12.5px !important;
    justify-content: center;
    white-space: nowrap;
  }

  .stats,
  #opsCards {
    gap: 6px !important;
  }

  /* Tarjetas de métrica cortas: de 104-112 px a ~62 px. */
  .stat {
    padding: 8px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-radius: 11px;
    border-top-width: 2.5px;
  }

  .stat .n {
    overflow-wrap: anywhere;
    font-size: 16px;
    letter-spacing: -.3px;
  }

  .stat .l {
    font-size: 11px;
    margin-top: 1px;
    letter-spacing: .2px;
    text-transform: none;
  }

  .stat::after { display: none }        /* degradado decorativo innecesario */
  .stat:hover { transform: none }

  /* Los KPI operativos en dos columnas: cuatro cifras visibles sin bajar. */
  #opsCards {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── Header del editor compacto ──────────────────────────────────────────*/
  .cot-editor-hdr {
    top: var(--mobile-header-height);
    width: 100%;
    padding: 5px 8px;
    gap: 6px;
    margin-bottom: 8px;
    border-radius: 11px;
  }

  .cot-editor-hdr h2 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }

  .cot-editor-hdr .no-cot {
    display: none;
  }

  .cot-editor-hdr .btn {
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px !important;
    font-size: 13px;
    justify-content: center;
  }

  /* El Guardar de la cabecera es redundante: la barra resumen inferior lo tiene
   * siempre visible. Se oculta para dar ancho al título. */
  .cot-editor-hdr .btn-p { display: none }

  .cot-section {
    border-radius: 12px;
    margin-bottom: 8px;
  }

  .cot-section-hdr {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 10px;
  }

  .cot-section-body {
    padding: 9px 10px;
  }

  /* Campos más juntos: 10 px de separación era casi el alto de una etiqueta. */
  .cot-section-body .fg { margin-bottom: 7px }
  .cot-section-body .row { gap: 7px }
  .fg label { font-size: 10px; margin-bottom: 2px }
  .fg input, .fg select, .fg textarea { padding: 8px 10px }
  .fg textarea { min-height: 44px }

  .product-picker {
    grid-template-columns: 1fr 1fr;
  }

  .product-picker .product-search,
  .product-picker .product-select {
    grid-column: 1 / -1;
  }

  .product-picker .product-add-btn {
    width: 100%;
    min-height: 48px;
  }

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

  .cot-items-wrap {
    max-height: none !important;
    overflow: visible !important;
  }

  table.cot-items-table {
    display: block;
    width: 100%;
    overflow: visible;
  }

  table.cot-items-table thead {
    display: none;
  }

  table.cot-items-table tbody {
    display: grid;
    gap: 10px;
  }

  table.cot-items-table tbody tr {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) 54px;
    gap: 8px 10px;
    padding: 12px;
    border: 1px solid var(--brd);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--S);
  }

  table.cot-items-table tbody td {
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .cot-item-image {
    grid-row: 1 / 3;
    width: 58px;
    height: 58px;
  }

  .cot-item-image .img-th,
  .cot-item-image .no-img {
    width: 58px;
    height: 58px;
  }

  .cot-item-name {
    align-self: center;
    overflow-wrap: anywhere;
  }

  .cot-item-qty {
    align-self: center;
  }

  .cot-item-qty .cot-item-input {
    width: 54px;
  }

  .cot-item-value {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(96px, .8fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }

  .cot-item-value::before {
    content: attr(data-label);
    color: var(--txtL);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .4px;
    text-transform: uppercase;
  }

  .cot-item-value .cot-item-input {
    width: 100%;
  }

  .cot-item-remove {
    grid-column: 1 / -1;
  }

  .cot-item-remove .btn {
    width: 100%;
    justify-content: center;
  }

  /* ── Barra resumen compacta y fija ───────────────────────────────────────
   * Dos filas muy bajas: cifras arriba, acciones abajo. Se apoya justo encima
   * de la barra inferior y respeta el área segura, así que no tapa campos ni
   * pelea con la navegación. */
  .cot-form-actions {
    position: sticky;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 4px);
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 6px 8px;
    margin: 0 0 4px;
    border: 1px solid var(--brd);
    border-radius: 12px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 -3px 14px rgba(15, 23, 42, .08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .cot-resumen {
    gap: 8px;
    font-size: 11px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }
  .cot-resumen::-webkit-scrollbar { height: 0 }
  .cot-resumen > span { white-space: nowrap }
  .cot-resumen .total b { font-size: 13px }

  /* Acciones: 44 px de alto táctil, compactadas a lo ancho. */
  .cot-acciones .primary-action {
    min-height: 44px;
    padding: 0 12px;
    font-size: 13px;
  }
  .cot-acciones .icon-only {
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px;
  }
  /* El texto largo del botón principal sobra en móvil: el icono ya lo dice. */
  .cot-acciones .primary-action .lbl { display: none }
  .cot-acciones .primary-action::after { content: 'Guardar' }

  /* El aviso de cambios sin guardar deja de ser una franja: solo un punto y una
   * palabra dentro de la fila de cifras. */
  .cot-dirty-badge {
    padding: 2px 7px;
    font-size: 10px;
    border-radius: 8px;
  }

  .preview {
    max-width: 100%;
    overflow: hidden;
  }

  .preview table {
    width: 100%;
    table-layout: fixed;
  }

  .preview th,
  .preview td {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tbl-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  /* ── Fila de la lista de cotizaciones ────────────────────────────────────
   * Antes eran cuatro subfilas apiladas: 212 px por cotización, 4 por pantalla.
   * Ahora tres filas con áreas nombradas:
   *
   *   [ n.º + fecha        ][ estado ]
   *   [ cliente + proyecto ][ total  ]
   *   [        acciones (5)          ]
   *
   * La rentabilidad (dato interno) pasa al detalle 👁 y a escritorio; no está
   * entre los datos que deben verse en la lista. */
  .cot-table-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "num    estado"
      "cli    total"
      "acc    acc";
    align-items: start;
    padding: 8px 10px;
    border: 1px solid var(--brd);
    border-radius: 11px;
    margin-bottom: 7px;
    background: #fff;
    box-shadow: var(--S);
    gap: 3px 10px;
  }

  .cot-table-row > div:nth-child(1) { grid-area: num }
  .cot-table-row > div:nth-child(2) { grid-area: cli; min-width: 0 }
  .cot-table-row > div:nth-child(3) { grid-area: total; text-align: right }
  .cot-table-row > div:nth-child(4) { display: none }   /* rentabilidad -> detalle */
  .cot-table-row > div:nth-child(5) { grid-area: estado; text-align: right }

  .cot-table-row > div:nth-child(6) {
    grid-area: acc;
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px !important;
    margin-top: 3px;
  }

  .cot-table-row > div:nth-child(6) .btn {
    justify-content: center;
    padding: 0 !important;
  }

  /* Tipografía: nada por debajo de 11 px, total y estado bien visibles. */
  .cot-table-row > div:nth-child(1) > div:first-child { font-size: 13px !important; line-height: 1.2 }
  .cot-table-row > div:nth-child(1) > div:last-child  { font-size: 11px !important; margin-top: 0 !important }
  .cot-table-row > div:nth-child(2) > div:first-child { font-size: 12.5px !important; line-height: 1.2 }
  .cot-table-row > div:nth-child(2) > div:last-child  { font-size: 11px !important }
  .cot-table-row > div:nth-child(3) > div { font-size: 14px !important; line-height: 1.2 }

  .overlay {
    align-items: flex-end;
    padding: 0;
    overscroll-behavior: contain;
  }

  .modal,
  .modal-lg {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top)));
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .modal-hdr {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 58px;
    border-radius: 22px 22px 0 0;
  }

  .modal-hdr .close {
    width: 44px;
    height: 44px;
  }

  #loginMask {
    padding: 12px;
  }

  #loginMask .card {
    width: 100% !important;
    max-width: 420px;
    margin: auto;
  }
}

/* ═══════════ DENSIDAD MÓVIL POR MÓDULO ═══════════
 * Regla general: compactar a lo ancho y en padding, nunca bajar de 44 px el
 * alto táctil de las acciones principales. Los botones secundarios de listas
 * repetidas bajan a 38 px, por encima del mínimo de WCAG 2.5.8 (24 px). */
@media (max-width: 820px) {
  /* ── Comandos: el JSON no debe ocupar media pantalla ───────────────────── */
  .cmd-area {
    min-height: 110px;
    max-height: 40vh;
    font-size: 12px;
    padding: 10px;
    border-radius: 12px;
    border-width: 1.5px;
  }
  /* Al enfocarlo se expande: se edita cómodo solo cuando hace falta. */
  .cmd-area:focus { min-height: 220px }

  #pg-cmd .btn { min-height: 44px; padding: 0 12px; font-size: 12.5px }
  #pg-cmd .fg { margin: 0; min-width: 0 !important }
  #pg-cmd .fg label { font-size: 10px }
  /* Descuento y anticipo en una fila de tres, no dos bloques altos. */
  #pg-cmd .card > div[style*="margin-top:8px"] > div[style*="margin-left:auto"] {
    width: 100%;
    display: grid !important;
    grid-template-columns: 1fr 1fr auto;
    gap: 6px !important;
    margin-left: 0 !important;
  }
  .cmd-result { padding: 9px 11px; font-size: 12px; margin-top: 8px }
  .cmdv-totals { gap: 6px; padding-top: 8px; margin-top: 8px }
  .cmdv-totals .k { font-size: 11px }
  .cmdv-totals .v { font-size: 12.5px }
  .cmdv-cart { max-height: 240px }
  .cmdv-cart-item { padding: 8px; gap: 8px }
  .cmdv-h3 { font-size: 12px; margin-bottom: 7px }

  /* ── Catálogo y tarjetas de producto: más productos por pantalla ───────── */
  .cmdv-item { border-radius: 12px }
  .cmdv-thumb { aspect-ratio: auto; height: 84px; padding: 5px }
  .cmdv-meta { padding: 7px 8px 8px }
  .cmdv-name { font-size: 11.5px; min-height: 0; -webkit-line-clamp: 2 }
  .cmdv-code { font-size: 10.5px }
  .cmdv-price { font-size: 12.5px; margin-top: 3px }
  .cmdv-plus { width: 30px; height: 30px; font-size: 15px; top: 5px; right: 5px }
  .cmdv-badge { font-size: 10px; padding: 2px 7px; top: 5px; left: 5px }
  .cmdv-item:hover { transform: none }

  /* ── Inventario ────────────────────────────────────────────────────────── */
  .inv-card { border-radius: 12px }
  .inv-card .inv-img { height: 78px }
  .inv-card .inv-body { padding: 8px }
  .inv-card .inv-name { font-size: 12px; margin-bottom: 1px }
  .inv-card .inv-code { font-size: 10.5px; margin-bottom: 5px }
  .inv-card .inv-stats { padding: 5px 4px; margin-bottom: 5px; gap: 3px }
  .inv-card .inv-stats b { font-size: 12px }
  .inv-card:hover { transform: none }

  /* ── Filas de listas: Compras, Proveedores, Paquetes ──────────────────── */
  .rowItem { padding: 7px 0 }
  .itemName, .buyCartName { font-size: 12.5px }
  .buyCartCode { font-size: 10.5px }
  .buyCartRow { padding: 7px 0; gap: 8px }
  .buyCartRight input { height: 38px; font-size: 12.5px }

  /* La fila de cotizaciones se define arriba, con áreas de rejilla. */

  /* ── CRM ──────────────────────────────────────────────────────────────── */
  .crm-card { padding: 9px; border-radius: 11px }
  .crm-card:hover { transform: none }
  .crm-colhead { font-size: 11.5px; margin-bottom: 7px }

  /* ── Toolbars, botones y modales ─────────────────────────────────────── */
  .toolbar { gap: 6px; margin-bottom: 8px }
  .btn { min-height: 44px; padding: 0 13px; font-size: 12.5px }

  /* ── ÁREA TÁCTIL DE 44 × 44 SIN INFLAR LO VISUAL ─────────────────────────
   * Los botones secundarios se ven compactos (38 px de caja, icono 16-18 px)
   * pero su zona interactiva se extiende con un pseudo-elemento centrado hasta
   * 44 × 44 px como mínimo. El clic sobre el pseudo-elemento cae dentro del
   * propio botón, así que no hace falta JavaScript.
   *
   * Es la técnica que pide el requisito: "Icono visual 16-18 px, botón visual
   * compacto, área táctil real mínimo 44 × 44 px", sin volver a inflar tarjetas,
   * márgenes ni iconos.
   *
   * La medición automática lee la altura y el ancho de este ::before, no solo
   * el rectángulo visible (ver collectMetrics en local_admin_visual_check.mjs). */
  .btn-sm {
    min-height: 38px;
    padding: 0 10px;
    font-size: 11.5px;
    position: relative;
  }

  .btn-sm::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    min-width: 44px;
    height: 44px;
    /* Invisible y sin capturar nada por su cuenta: el clic llega al botón. */
    pointer-events: none;
  }

  /* Los botones de peligro y los de solo icono conservan 44 px visibles. */
  .btn-d,
  .icon-only,
  .modal-hdr .close {
    min-height: 44px;
    min-width: 44px;
  }
  .modal-body { padding: 10px }
  .modal-hdr { min-height: 48px; padding: 9px 12px }
  .modal-hdr h3 { font-size: 14px }
  .modal-hdr .close { width: 44px; height: 44px }

  /* Configuración: dos columnas de parámetros en lugar de una lista larga. */
  #configForm { display: grid; grid-template-columns: 1fr 1fr; gap: 7px }
  #configForm .fg { margin: 0 }

  /* Selector de producto del editor. */
  .product-add-btn { min-height: 44px; font-size: 16px }
  .selected-product { padding: 7px; margin: 2px 0 8px }
  .selected-product .product-visual { width: 46px; height: 46px }
  .selected-product-name { font-size: 12px }
  .selected-product-meta { font-size: 10.5px }
}

@media (max-width: 480px) {
  :root {
    --mobile-gutter: 8px;
  }
  /* En pantallas muy angostas, la configuración vuelve a una columna. */
  #configForm { grid-template-columns: 1fr }

  .nav .brand {
    font-size: 13px;
  }

  .cot-editor-hdr h2 {
    font-size: 15px;
  }

  .cot-editor-hdr .action-label,
  .cot-editor-hdr .back-label {
    display: none;
  }

  .product-picker {
    grid-template-columns: 1fr;
  }

  .product-picker > * {
    grid-column: 1 / -1;
  }

  .stats {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Antes 104 px. Las tarjetas cortas son el cambio que más alto libera en
   * Inicio, así que aquí no se vuelve a imponer un mínimo alto. */
  .stat {
    min-height: 0;
  }

  .mobile-more-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* El editor a 480 px: el resumen ya no cabe en una fila con el descuento. */
  .cot-resumen { font-size: 10.5px; gap: 7px }

  /* Solo se oculta la columna de imagen. La columna 5 es el precio unitario y
   * antes también se ocultaba: información financiera que no debe desaparecer
   * en pantallas pequeñas. */
  .preview table th:nth-child(2),
  .preview table td:nth-child(2) {
    display: none;
  }
}

/* ─── Movimiento reducido ──────────────────────────────────────────────────
 * Respeta la preferencia del sistema: se conservan los cambios de estado
 * (color, foco) pero se eliminan animaciones y desplazamientos suaves.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }

  .page { animation: none !important }
  .overlay.show .modal { animation: none !important }
  .stat:hover,
  .card:hover,
  .crm-card:hover,
  .cmdv-item:hover,
  .itemCard:hover { transform: none !important }
  #dashMetaBar { transition: none !important }
}

@media (min-width: 821px) and (max-width: 1100px) {
  .preview-toggle-btn {
    display: inline-flex;
  }

  .product-picker {
    grid-template-columns: 1fr 1fr;
  }

  .product-picker .product-search,
  .product-picker .product-select {
    grid-column: span 1;
  }
}
