/* Pedidos (el carrito del cliente).
 *
 * Una tarjeta por proveedor —dos columnas en escritorio, una en móvil— y una
 * barra fija abajo con el total y el botón de revisar, justo encima del dock.
 * Letra de 14 px como mínimo en todo lo que hay que leer: quien pide puede
 * tener 60 años y estar en la cocina con el móvil (reunión del 30/09). */
body.in-orders-view { background: #f8fafc; color: #0b1c30; font-family: 'ComPRO Brand', Inter, sans-serif; }
body.in-orders-view .app-container { padding: 0; }

/* El dock ocupa 74 px a 16 px del borde: la barra del total va encima. */
#view-cart { --cbt-sobre-dock: calc(102px + env(safe-area-inset-bottom)); width: min(1280px, calc(100% - 32px)); max-width: none; margin: 0 auto; padding: 28px 0 140px; }
#view-cart.active:not(.es-venta):not([data-paso="resumen"]):not([data-paso="enviado"]) { display: flex; flex-direction: column; gap: 16px; padding-bottom: calc(var(--cbt-sobre-dock) + 24px); }

/* ── Cabecera ─────────────────────────────────────────────────────────── */
.orders-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
#view-cart .orders-heading .view-title { flex: 1 1 auto; padding: 0; margin: 0; text-align: left; color: #0b1c30; font-size: 32px; line-height: 40px; font-weight: 800; letter-spacing: -.8px; }
.orders-professional { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 7px 12px; border: 1px solid #e2e8f0; border-radius: 999px; background: #f1f5f9; color: #424656; font-size: 14px; font-weight: 600; white-space: normal; }
.orders-professional::before { content: '✓'; color: #0066ff; }
#view-cart .orders-save-list { min-height: 44px; padding: 10px 16px; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; color: #0b1c30; box-shadow: none; font-size: 14px; font-weight: 600; cursor: pointer; }
#view-cart .orders-save-list:hover { border-color: #0066ff; color: #0050cb; }
#view-cart:has(#cart-view-footer:not(.es-visible)) .orders-save-list,
#view-cart:is([data-paso="resumen"], [data-paso="enviado"]) .orders-save-list,
#view-cart.es-venta .orders-save-list { display: none; }

/* ── Filtro por proveedor y selección ─────────────────────────────────── */
#view-cart #cart-filtro-proveedor { width: 100%; max-width: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; overflow: visible; }
#view-cart #cart-filtro-proveedor[hidden] { display: none; }
#view-cart .cart-chip { min-height: 44px; padding: 8px 14px; font-size: 14px; border-color: #e2e8f0; box-shadow: 0 1px 2px #0f172a08; }
#view-cart .cart-chip.es-activo { background: #0f172a; border-color: #0f172a; }
#view-cart .cart-chip-n { font-size: 14px; background: #f1f5f9; color: #424656; }
#view-cart .cart-chip.es-activo .cart-chip-n { background: #ffffff30; color: #fff; }
#view-cart #cart-barra-sel { width: 100%; max-width: none; margin: 0; padding: 12px 16px; min-height: 55px; border: 1px solid #e2e8f0; border-radius: 16px; background: #fff; box-shadow: 0 1px 2px #0f172a08; gap: 10px; }
#view-cart .barra-sel-todo { color: #0b1c30; font-size: 14px; font-weight: 700; }
#view-cart .barra-sel .sel-corto { font-size: 14px; }
#view-cart .barra-sel-info { padding: 5px 10px; border-radius: 999px; background: #f1f5f9; color: #424656; font-size: 14px; }
#view-cart .barra-sel-borrar { font-size: 14px; padding: 8px; }

/* ── Tarjetas por proveedor ───────────────────────────────────────────── */
#view-cart > .cart-items-scroll,
#view-cart:has(#cart-filtro-proveedor:not([hidden])) > .cart-items-scroll { width: 100%; max-width: none; height: auto; max-height: none; margin: 0; padding: 0; overflow: visible; }
#view-cart #cart-view-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
#view-cart #cart-view-list:has(> .orders-provider-group:only-child) { grid-template-columns: minmax(0, 760px); }
#view-cart .orders-provider-group { margin: 0; padding: 20px; background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 1px 3px #0f172a0a; }
#view-cart .cart-provider-header { display: flex; align-items: center; gap: 12px; margin: 0; padding: 0 0 14px; border-bottom: 1px solid #e2e8f0; background: transparent; }
#view-cart .cart-provider-header > img { width: 44px; height: 44px; border-radius: 10px; object-fit: contain; flex-shrink: 0; background: #fff; border: 1px solid #e2e8f0; }
.orders-provider-copy { min-width: 0; flex: 1; }
.orders-provider-copy h3 { margin: 0; color: #0b1c30; font-size: 18px; line-height: 24px; font-weight: 800; overflow-wrap: break-word; }
.orders-provider-copy p { margin: 2px 0 0; color: #424656; font-size: 14px; line-height: 20px; }
#view-cart .cart-provider-subtotal { display: flex; flex-direction: column; align-items: flex-end; margin: 0; white-space: nowrap; }
#view-cart .cart-provider-subtotal small { color: #424656; font-size: 14px; font-weight: 500; }
#view-cart .cart-provider-subtotal strong { color: #0b1c30; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Lo que falta para el pedido mínimo o para los portes gratis. */
.orders-provider-conditions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; color: #424656; font-size: 14px; line-height: 20px; }
.orders-provider-conditions.is-free { background: #ecfdf5; border-color: #a7f3d0; color: #005236; font-weight: 600; }
.orders-provider-conditions.is-free .opc-texto::before { content: '✓ '; }
.orders-provider-conditions.is-pending { background: #fffbeb; border-color: #fde68a; color: #8a4b00; font-weight: 600; }
.cart-progreso { display: block; height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.cart-progreso > span { display: block; height: 100%; border-radius: inherit; background: #d97706; transition: width .25s ease; }
.is-free .cart-progreso > span { background: #059669; }

/* Las líneas: arriba qué es, abajo cuánto. Así caben en media pantalla. */
#view-cart .bag-item { display: grid; grid-template-columns: 22px 56px minmax(0, 1fr) 36px; grid-template-rows: auto auto; align-items: center; column-gap: 12px; row-gap: 10px; margin: 0 0 10px; padding: 14px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; box-shadow: none; }
#view-cart .bag-item:last-of-type { margin-bottom: 0; }
#view-cart .bag-item.es-marcado { background: #eff6ff; border-color: #b3c5ff; }
#view-cart .bag-item > img { width: 56px; height: 56px; border-radius: 10px; object-fit: contain; background: #fff; }
#view-cart .bag-item-check { width: 22px; height: 22px; border-color: #cbd5e1; opacity: 1; }
#view-cart .bag-item-check:checked { border-color: #0066ff; background: #0066ff; }
.orders-item-heading { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px; }
#view-cart .bag-item-name { display: block; overflow: visible; overflow-wrap: break-word; margin: 0; color: #0b1c30; font-size: 16px; line-height: 22px; font-weight: 700; text-transform: none; }
.orders-family { max-width: 100%; padding: 2px 8px; border-radius: 999px; background: #e5eeff; color: #0050cb; font-size: 14px; line-height: 18px; overflow-wrap: anywhere; }
#view-cart .bag-item-ref { margin: 0 0 2px; font-size: 14px; color: #424656; }
#view-cart .bag-item-info > p { font-size: 14px; line-height: 20px; margin-bottom: 0 !important; }
#view-cart .bag-item-precio { color: #0b1c30; font-weight: 600; }
#view-cart .bag-item-desglose { color: #424656; }
#view-cart .bag-item-right { grid-column: 2 / 4; grid-row: 2; display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; border-top: 1px solid #e2e8f0; }
#view-cart .qty-stepper { display: flex; align-items: center; gap: 0; padding: 4px; border: 1px solid #cbd5e1; border-radius: 999px; background: #fff; }
#view-cart .qty-stepper button { display: flex; justify-content: center; align-items: center; width: 40px; height: 40px; min-width: 40px; min-height: 40px; border: 0; border-radius: 50%; background: #f1f5f9; color: #0b1c30; font-size: 20px; cursor: pointer; }
#view-cart .qty-stepper .qty-number { min-width: 64px; padding: 0 8px; font-size: 16px; font-weight: 700; text-align: center; white-space: nowrap; color: #0b1c30; }
#view-cart .qty-unidad { font-size: inherit; font-weight: 600; }
#view-cart .bag-item-total { min-width: 72px; font-size: 18px; font-weight: 800; color: #0b1c30; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
#view-cart .remove-item-btn { grid-column: 4; grid-row: 1; position: relative; top: auto; right: auto; width: 36px; height: 44px; margin: 0; padding: 8px; display: flex; align-items: center; justify-content: center; color: #424656; background: transparent; }
#view-cart .remove-item-btn::before { inset: -4px; }
#view-cart .remove-item-btn:hover { color: #ba1a1a; }

/* Nota para la entrega, una por proveedor. */
#view-cart .cart-nota { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed #cbd5e1; }
#view-cart .cart-nota-rotulo { color: #0b1c30; font-size: 14px; font-weight: 700; }
#view-cart .cart-nota-rotulo small { color: #424656; font-size: 14px; font-weight: 400; }
#view-cart .cart-nota input { width: 100%; min-height: 48px; box-sizing: border-box; padding: 10px 14px; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; color: #0b1c30; font: inherit; font-size: 16px; }
#view-cart .cart-nota input::placeholder { color: #727687; }

/* ── Barra fija del total ─────────────────────────────────────────────── */
/* El asistente y los avisos flotan por encima de la barra, no encima. */
body.in-orders-view:has(#cart-view-footer.es-visible) #pila-flotantes { bottom: calc(196px + env(safe-area-inset-bottom)); }
#view-cart #cart-view-footer { position: sticky; bottom: var(--cbt-sobre-dock); top: auto; left: auto; right: auto; transform: none; z-index: 20; display: flex; align-items: center; gap: 20px; width: 100%; max-width: none; margin: 8px 0 0; padding: 16px 20px; border: 1px solid #e2e8f0; border-radius: 20px; background: #fff; box-shadow: 0 20px 30px -10px #0066ff1f, 0 4px 6px -2px #0f172a0d; pointer-events: auto; }
#view-cart #cart-view-footer:not(.es-visible) { display: none; }
#view-cart #cart-summary-container { display: flex !important; align-items: center; gap: 20px; flex: 1; min-width: 0; width: auto; margin: 0; padding: 0; }
.cbt-total { display: grid; grid-template-columns: auto auto; column-gap: 12px; align-items: baseline; flex-shrink: 0; }
.cbt-rotulo { grid-column: 1 / -1; color: #424656; font-size: 14px; line-height: 20px; font-weight: 700; }
.cbt-cuenta { font-weight: 400; }
.cbt-importe { color: #0b1c30; font-size: 28px; line-height: 34px; font-weight: 800; letter-spacing: -.6px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cbt-detalle { color: #424656; font-size: 14px; line-height: 20px; }
.cbt-proveedores { display: flex; flex-wrap: nowrap; gap: 8px; min-width: 0; margin: 0; padding: 4px 0 4px 20px; border-left: 1px solid #e2e8f0; list-style: none; overflow-x: auto; scrollbar-width: thin; }
.cbt-proveedores li { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid #e2e8f0; border-radius: 999px; background: #f8fafc; color: #0b1c30; font-size: 14px; white-space: nowrap; }
.cbt-proveedores img { width: 20px; height: 20px; border-radius: 5px; object-fit: contain; }
.cbt-proveedores strong { font-variant-numeric: tabular-nums; }
#view-cart #cart-view-footer .btn-checkout { flex-shrink: 0; width: auto; min-width: 240px; min-height: 56px; padding: 14px 24px; border-radius: 14px; background: #0066ff; color: #fff; box-shadow: 0 3px 8px #0066ff26; font-size: 16px; font-weight: 700; }
#view-cart #cart-view-footer .btn-checkout:hover { background: #0050cb; }
#view-cart #cart-view-footer .btn-checkout:disabled { opacity: .6; cursor: wait; }

#view-cart #cart-view-empty { width: 100%; }
#view-cart.es-venta .orders-professional { display: none; }
body.in-orders-view .bottom-nav [data-nav="cart"].active svg { fill: #0066ff18; }
#view-cart :is(button, input):focus-visible { outline: 2px solid #0066ff; outline-offset: 3px; }

/* La nota también se lee en el resumen, antes de enviar. */
.rp-nota-entrega { margin: 10px 0 0; padding: 10px 12px; border: 1px solid #b3c5ff; border-radius: 10px; background: #eff4ff; color: #0b1c30; font-size: 15px; line-height: 21px; }

@media (max-width: 1100px) {
    .cbt-proveedores { display: none; }
}
@media (max-width: 900px) {
    #view-cart #cart-view-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
    #view-cart { width: calc(100% - 24px); padding-top: 24px; }
    #view-cart .orders-heading .view-title { font-size: 26px; line-height: 34px; }
    #view-cart .orders-save-list { width: 100%; }
    #view-cart .orders-provider-group { padding: 14px; }
    #view-cart .cart-provider-header { gap: 10px; align-items: flex-start; }
    #view-cart .cart-provider-header > img { width: 40px; height: 40px; }
    .orders-provider-copy h3 { font-size: 16px; line-height: 22px; }
    #view-cart .cart-provider-subtotal strong { font-size: 18px; }
    #view-cart .bag-item { grid-template-columns: 22px 48px minmax(0, 1fr) 32px; column-gap: 10px; padding: 12px; }
    #view-cart .bag-item > img { width: 48px; height: 48px; }
    #view-cart .bag-item-right { grid-column: 1 / 4; }
    #view-cart .remove-item-btn { width: 32px; }
    #view-cart .qty-stepper .qty-number { min-width: 56px; }
    #view-cart #cart-barra-sel { flex-wrap: wrap; padding: 10px 12px; gap: 6px; }
    #view-cart .barra-sel-borrar:not(.es-visible) { display: none; }
    /* En el móvil la barra se queda en lo justo: el total y el botón. */
    #view-cart #cart-view-footer { gap: 12px; padding: 12px 14px; border-radius: 16px; }
    #view-cart #cart-summary-container { flex: 0 0 auto; }
    .cbt-total { grid-template-columns: auto; }
    .cbt-importe { font-size: 24px; line-height: 30px; }
    .cbt-cuenta, .cbt-portes { display: none; }
    #view-cart #cart-view-footer .btn-checkout { min-width: 0; flex: 1 1 auto; min-height: 52px; padding: 12px; font-size: 15px; }
}

/* Pedido mínimo sin alcanzar: el botón no se puede pulsar y dice cuánto falta;
   en la tarjeta del proveedor, un enlace a su catálogo. */
#view-cart #cart-view-footer .btn-checkout[data-bloqueo="minimo"]:disabled { opacity: 1; cursor: not-allowed; background: #e2e8f0; color: #475569; box-shadow: none; }
.orders-provider-conditions .opc-enlace { align-self: flex-start; min-height: 44px; padding: 10px 0; border: 0; background: none; color: #0050cb; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.orders-provider-conditions .opc-enlace:hover { color: #003a94; }
.orders-provider-conditions .opc-enlace:focus-visible { outline: 2px solid #0066ff; outline-offset: 2px; border-radius: 4px; }

/* Historial: desglose del pedido (base, IVA, portes y total). */
.order-desglose { display: grid; gap: 4px; margin: 12px 0 0 auto; padding: 10px 0 0; max-width: 320px; border-top: 1px solid #f2f2f7; font-size: 14px; line-height: 20px; }
.order-desglose .od-fila { display: flex; justify-content: space-between; gap: 16px; }
.order-desglose dt { color: #64748b; }
.order-desglose dd { margin: 0; color: #0f172a; font-variant-numeric: tabular-nums; }
.order-desglose .od-total { margin-top: 4px; padding-top: 6px; border-top: 1px solid #e2e8f0; font-size: 16px; font-weight: 700; }
.order-desglose .od-total dt { color: #0f172a; }

/* Móvil estrecho (09/10): el subtotal del proveedor baja a su propia línea para
   que el nombre tenga todo el ancho; partir por palabras, nunca por letras. */
@media (max-width: 480px) {
    #view-cart .cart-provider-header { flex-wrap: wrap; row-gap: 8px; }
    #view-cart .cart-provider-header .cart-provider-subtotal { display: flex; flex: 1 0 100%; flex-direction: row; align-items: baseline; justify-content: space-between; gap: 12px; text-align: left; }
}
