/**
 * Caja POS — solo iPhone / móvil
 * REGLA: fuera de @media (max-width: 900px) casi no hay estilos.
 * En PC (>900px) este archivo no debe alterar el layout.
 */

/* Barra móvil: oculta siempre en desktop */
.caja-mbar {
    display: none !important;
}

@media (max-width: 900px) {
    /* ========== Página ========== */
    html {
        height: 100%;
        height: -webkit-fill-available;
    }

    body.caja-page {
        display: block !important;
        height: auto !important;
        min-height: 100vh;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding:
            env(safe-area-inset-top, 0px)
            env(safe-area-inset-right, 0px)
            calc(76px + env(safe-area-inset-bottom, 0px))
            env(safe-area-inset-left, 0px);
        touch-action: manipulation;
    }

    /* ========== Layout: una columna ========== */
    body.caja-page .main-layout {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        width: 100%;
        height: auto !important;
        min-height: 0;
        gap: 12px;
        padding: 10px;
        padding-bottom: 8px;
    }

    body.caja-page .main-layout > .panel {
        width: 100%;
        min-height: 0;
        height: auto;
        max-height: none;
        overflow: visible;
        padding: 14px;
        border-radius: 16px;
        -webkit-overflow-scrolling: touch;
    }

    body.caja-page .main-layout > .panel::-webkit-scrollbar {
        width: 0;
        height: 0;
    }

    /* Pedido primero, carrito después (orden natural del HTML) */
    body.caja-page .main-layout > .panel:not(.panel--detalle) {
        order: 1;
    }

    body.caja-page .panel--detalle {
        order: 2;
        min-height: auto;
        scroll-margin-top: 12px;
        scroll-margin-bottom: 90px;
    }

    /* ========== Toolbar / header ========== */
    body.caja-page .panel-header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 8px;
    }

    body.caja-page .caja-panel-title {
        font-size: 1.15rem;
        margin: 0;
    }

    body.caja-page .caja-toolbar {
        width: 100%;
        justify-content: stretch;
        gap: 6px;
    }

    body.caja-page .caja-toolbar__divider {
        display: none;
    }

    body.caja-page .caja-tool {
        flex: 1;
        min-height: 48px;
        padding: 8px 6px;
        border-radius: 12px;
    }

    body.caja-page .caja-tool__label {
        font-size: 0.68rem;
        line-height: 1.15;
    }

    body.caja-page .caja-tool__icon-wrap {
        font-size: 1.15rem;
    }

    /* ========== Tipo / sabor / tamaño ========== */
    body.caja-page .type-switch {
        gap: 8px;
        margin-bottom: 14px;
        flex-wrap: wrap;
    }

    body.caja-page .type-btn {
        padding: 12px 6px;
        border-radius: 14px;
        gap: 4px;
        min-height: 72px;
        flex: 1 1 calc(50% - 8px);
        min-width: calc(50% - 8px);
    }

    body.caja-page .type-emoji {
        font-size: 1.75rem;
    }

    body.caja-page .type-name {
        font-size: 0.72rem;
    }

    body.caja-page .flavor-switch {
        gap: 8px;
    }

    body.caja-page .flavor-btn {
        padding: 12px 8px;
        font-size: 0.82rem;
        min-height: 48px;
        border-radius: 12px;
    }

    body.caja-page .sizes-container {
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 8px;
        min-height: 0;
        margin-bottom: 8px;
    }

    body.caja-page .cup-wrapper {
        flex: 1 1 30%;
        min-width: 0;
        padding: 8px 4px;
    }

    body.caja-page .cup-shape {
        transform: scale(0.85);
        transform-origin: center bottom;
    }

    /* ========== Toppings / salsas ========== */
    body.caja-page .toppings-grid {
        grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
        gap: 8px;
    }

    body.caja-page .smoothie-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    body.caja-page .sugar-switch {
        gap: 8px;
    }

    body.caja-page .sugar-btn {
        min-height: 52px;
        padding: 12px 8px;
    }

    /* ========== Agregar item ========== */
    body.caja-page .btn-add {
        margin-top: 12px;
        min-height: 52px;
        padding: 14px 16px;
        font-size: 0.95rem;
        border-radius: 14px;
        position: sticky;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        z-index: 5;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    }

    /* ========== Carrito / detalle ========== */
    body.caja-page .detalle-title {
        font-size: 1.05rem;
        position: sticky;
        top: 0;
        z-index: 2;
        background: rgba(15, 12, 41, 0.92);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        padding: 4px 0 10px;
        margin-bottom: 4px;
    }

    body.caja-page .panel--detalle .cart-list {
        flex: none;
        max-height: none;
        overflow: visible;
        padding-right: 0;
        min-height: 48px;
    }

    body.caja-page .panel--detalle .cart-item {
        padding: 12px;
        gap: 10px;
    }

    body.caja-page .panel--detalle .cart-item__btns {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
        width: 100%;
    }

    body.caja-page .panel--detalle .cart-item__btns button {
        min-height: 40px;
        font-size: 0.78rem;
        padding: 8px 4px;
        border-radius: 10px;
    }

    body.caja-page .detalle-footer {
        gap: 10px;
        padding-top: 12px;
    }

    body.caja-page .detalle-input {
        font-size: 16px; /* evita zoom iOS */
        min-height: 48px;
        padding: 12px 14px;
        border-radius: 12px;
    }

    body.caja-page .detalle-quick-btns {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    body.caja-page .detalle-quick-btn {
        min-height: 48px;
        font-size: 0.9rem;
        border-radius: 12px;
    }

    body.caja-page .detalle-ticket {
        border-radius: 14px;
        padding: 12px;
    }

    body.caja-page .detalle-ticket__cash-row input {
        font-size: 16px;
        min-height: 44px;
    }

    body.caja-page .btn-checkout {
        min-height: 56px;
        font-size: 1rem;
        border-radius: 14px;
        margin-top: 8px;
        margin-bottom: 4px;
        position: sticky;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        z-index: 6;
    }

    /* ========== Barra fija inferior ========== */
    body.caja-page .caja-mbar {
        display: flex !important;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1500;
        align-items: center;
        gap: 10px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        background: rgba(15, 12, 41, 0.94);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid rgba(255, 255, 255, 0.14);
        box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
    }

    body.caja-page .caja-mbar__info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    body.caja-page .caja-mbar__meta {
        color: #94a3b8;
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    body.caja-page .caja-mbar__total {
        color: #fff;
        font-size: 1.2rem;
        font-weight: 800;
        line-height: 1.1;
    }

    body.caja-page .caja-mbar__btn {
        flex-shrink: 0;
        border: none;
        border-radius: 12px;
        min-height: 48px;
        padding: 0 16px;
        font-family: inherit;
        font-size: 0.88rem;
        font-weight: 800;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    body.caja-page .caja-mbar__btn--cart {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.18);
    }

    body.caja-page .caja-mbar__btn--pay {
        background: var(--accent, #00e676);
        color: #000;
        box-shadow: 0 4px 14px rgba(0, 230, 118, 0.35);
    }

    /* ========== Historial ========== */
    body.caja-page .history-sidebar,
    body.caja-page .history-sidebar--pro {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: 100%;
        height: 100dvh;
        padding-top: max(14px, env(safe-area-inset-top, 0px));
        padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
        border-radius: 0;
    }

    body.caja-page .history-sidebar__head h2 {
        font-size: 1.05rem;
    }

    body.caja-page .caja-historial-filters {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        padding-bottom: 4px;
    }

    body.caja-page .caja-historial-filters .filter-btn {
        flex: 0 0 auto;
        min-height: 40px;
        white-space: nowrap;
    }

    /* ========== Modales → sheet inferior ========== */
    body.caja-page .settings-modal {
        align-items: flex-end;
        justify-content: center;
        padding: 0;
        padding-top: env(safe-area-inset-top, 0px);
    }

    body.caja-page .settings-modal .settings-content {
        width: 100%;
        max-width: 100%;
        max-height: min(92dvh, 92vh);
        border-radius: 18px 18px 0 0;
        margin: 0;
    }

    body.caja-page .settings-body {
        padding: 16px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        -webkit-overflow-scrolling: touch;
    }

    body.caja-page .settings-header {
        padding: 14px 16px;
    }

    body.caja-page .caja-historial-modal {
        align-items: flex-end;
        padding: 0;
    }

    body.caja-page .caja-historial-modal__panel {
        width: 100%;
        max-width: 100%;
        max-height: min(90dvh, 90vh);
        border-radius: 18px 18px 0 0;
        margin: 0;
    }

    body.caja-page .caja-historial-modal__body {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        -webkit-overflow-scrolling: touch;
    }

    /* Inputs genéricos en modales: sin zoom iOS */
    body.caja-page .settings-modal input,
    body.caja-page .settings-modal textarea,
    body.caja-page .settings-modal select {
        font-size: 16px;
    }

    /* Menos hover “fantasma” en touch */
    body.caja-page .type-btn:hover,
    body.caja-page .panel:hover {
        transform: none;
    }
}

/* iPhone estrecho */
@media (max-width: 390px) {
    body.caja-page .caja-mbar__btn--cart {
        padding: 0 12px;
        font-size: 0.8rem;
    }

    body.caja-page .caja-mbar__total {
        font-size: 1.05rem;
    }

    body.caja-page .type-name {
        font-size: 0.65rem;
    }
}
