/* --- VISTA 1: TERMINAL POS --- */
#view-terminal {
    flex-direction: row;
}

.catalog-section {
    flex: 2;
    padding: 30px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* RESTORE IOS SCROLL */
    width: 100%;
    scrollbar-gutter: stable;
    border-right: none;
    display: flex;
    flex-direction: column;
}

/* Switch Terminal */
.terminal-switch-container {
    display: flex;
    background: #ffffff;
    padding: 8px;
    border-radius: 20px;
    margin-bottom: 25px;
    flex-shrink: 0;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.05);
    /* Sombra flotante */
    border: 1px solid #f0f0f0;
}

.term-switch-btn {
    flex: 1;
    border: none;
    padding: 14px 12px;
    /* INCREASED TAP AREA */
    border-radius: 14px;
    font-weight: 700;
    color: #999;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 14px;
    background: transparent;
    letter-spacing: 0.5px;
    -webkit-tap-highlight-color: transparent;
}

.term-switch-btn:hover {
    background: #f9f9f9;
    color: #666;
}

.term-switch-btn.active {
    background: var(--vino);
    color: white;
    box-shadow: 0 5px 15px rgba(94, 28, 38, 0.25);
    transform: translateY(-2px);
}

#term-catalog-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#term-orders-view {
    flex: 1;
    display: none;
    flex-direction: column;
    overflow-y: auto;
}

/* Grid Productos POS */
.pos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* RESTORE IOS SCROLL */
    padding-bottom: 20px;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 480px) {
    .pos-grid {
        grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
        gap: 10px;
    }
}

.pos-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    cursor: default;
    /* Default para agotados */
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    /* Animación fluida */
    border: 2px solid transparent;
    position: relative;
}

/* Efectos solo para productos disponibles */
.pos-card:not(.out-stock) {
    cursor: pointer;
}

.pos-card:not(.out-stock):hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.1);
    border-color: rgba(94, 28, 38, 0.05);
}

.pos-card:not(.out-stock):active {
    transform: scale(0.95) translateY(-5px);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.05);
}

.pos-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.pos-card-info {
    padding: 15px;
    text-align: center;
}

.pos-card-name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.2;
    height: 38px;
    overflow: hidden;
}

.stock-tag {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--rojo);
    color: white;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: bold;
}

.out-stock {
    opacity: 0.6;
    filter: grayscale(100%);
}

/* Alerta visual en tarjeta (Stock bajo) */
.card-alert-low {
    border: 2px solid #e74c3c !important;
    background: #fff5f5 !important;
    position: relative;
}

.card-alert-low::after {
    content: '⚠️ STOCK BAJO';
    position: absolute;
    top: -10px;
    right: 10px;
    background: #e74c3c;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 4px;
}

/* Ticket & Scanner */
.ticket-section {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    max-width: 450px;
    min-width: 340px;
    position: relative;
    overflow: hidden;
    margin: 15px 20px 20px 0;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(94, 28, 38, 0.15);
    border: none;
}

.ticket-header {
    padding: 25px;
    background: linear-gradient(135deg, #8a3b49 0%, #5e1c26 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 18px;
    z-index: 10;
}

.ticket-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* RESTORE IOS SCROLL */
    padding: 25px;
    transition: opacity 0.3s;
}

/* Estilos Ticket Moderno */
.ticket-container-visual {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #eee;
    overflow: hidden;
}

.ticket-item-modern {
    display: grid;
    grid-template-columns: 50px 1fr auto;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px dashed #eee;
    position: relative;
    overflow: hidden;
    /* Vital para que la animación de altura funcione */
    transition: background-color 0.2s;
}

.ticket-img {
    width: 50px !important;
    height: 50px !important;
    min-width: 50px;
    border-radius: 8px;
    object-fit: cover;
    background: #eee;
}

.ticket-details h4 {
    margin: 0;
    font-size: 14px;
    color: #333;
}

.ticket-details small {
    color: #888;
    font-size: 11px;
}

.ticket-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
}

.btn-trash-modern {
    color: var(--rojo);
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    font-size: 14px;
    position: absolute;
    bottom: 5px;
    right: 5px;
}

/* Clase para el precio animable */
.ticket-price-val {
    display: inline-block;
    /* Necesario para transform: scale */
    transform-origin: right center;
}

/* --- ANIMACIONES TICKET --- */
.slide-in-right {
    animation: slideInRight 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.slide-out-right {
    animation: slideOutRight 0.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    pointer-events: none;
    /* Evitar clics mientras sale */
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    0% {
        transform: translateX(0);
        opacity: 1;
        max-height: 150px;
        margin-bottom: 0;
        padding: 8px;
        border-bottom: 1px dashed #eee;
    }

    50% {
        transform: translateX(100%);
        opacity: 0;
        max-height: 150px;
        margin-bottom: 0;
        padding: 8px;
        border-bottom: 1px dashed #eee;
    }

    100% {
        transform: translateX(100%);
        opacity: 0;
        max-height: 0;
        margin-bottom: 0;
        padding: 0;
        border: none;
    }
}

.pulse-price {
    animation: pulsePrice 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-block;
}

@keyframes pulsePrice {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.4);
        color: var(--vino);
        text-shadow: 0 0 5px rgba(94, 28, 38, 0.3);
    }

    100% {
        transform: scale(1);
    }
}

.btn-qty {
    width: 24px;
    height: 24px;
    background: #eee;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: 0.2s;
}

.ticket-footer {
    padding: 25px 30px;
    background: #f9f9f9;
    border-top: 1px solid #ddd;
    z-index: 10;
}

.total-display {
    font-size: 34px;
    font-weight: 800;
    color: var(--vino);
    text-align: right;
    margin-bottom: 20px;
}

.btn-charge {
    width: 100%;
    padding: 18px;
    background: var(--verde);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    transition: 0.2s;
}

/* Scanner Overlay */
#scanner-overlay {
    position: absolute;
    top: 80px;
    left: 0;
    width: 100%;
    height: calc(100% - 80px);
    background: #222;
    z-index: 20;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

#reader {
    width: 300px;
    height: 300px;
    border: 2px solid white;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
    position: relative;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

.btn-validate-client {
    width: 100%;
    padding: 12px;
    background: var(--vino);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: 0.2s;
    box-shadow: 0 4px 10px rgba(94, 28, 38, 0.2);
}

.btn-validate-client:hover {
    background: #4a151d;
    transform: translateY(-2px);
}

/* Tarjetas Kanban Pedidos */
.order-card-pos {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border-left: 6px solid #ccc;
    cursor: pointer;
    transition: 0.2s;
}

.order-card-pos:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.status-preparacion {
    border-color: #f39c12;
}

.status-reparto {
    border-color: #2980b9;
}

.status-listo {
    border-color: #8e44ad;
}

/* =========================================
   ESTILOS DINÁMICOS (MIGRADOS DE JS)
   ========================================= */

/* --- Animaciones --- */
.fade-in-up {
    animation: fadeInUp 0.3s ease-out forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.scale-in {
    animation: scaleIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Animación corregida para Agotados (Evita salto de opacidad 1 -> 0.6) */
@keyframes scaleInOutStock {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 0.6;
    }
}

.pos-card.scale-in.out-stock {
    animation-name: scaleInOutStock;
}

/* --- CMS Editor (Gestión de Productos) --- */
.cms-group {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin-bottom: 15px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.03);
}

.cms-group-header {
    background: #f8f9fa;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cms-opt-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    background: #fff;
}

.cms-opt-row:hover {
    background: #fafafa;
}

/* Inputs CMS */
.cms-input {
    border: 1px solid #ddd;
    padding: 8px;
    border-radius: 6px;
    font-size: 14px;
    flex-grow: 1;
    min-width: 120px;
}

.cms-input-price {
    width: 80px;
    flex-grow: 0;
}

.cms-input-img {
    width: 100px;
    flex-grow: 1;
    font-size: 11px;
    color: #777;
}

/* Herramientas CMS */
.cms-tools-row {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px dashed #eee;
}

/* Checkboxes personalizados */
.cms-icon-check {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 6px 12px;
    border-radius: 20px;
    transition: 0.2s;
    border: 1px solid transparent;
    user-select: none;
}

.cms-icon-check:hover {
    background: #e0e0e0;
}

.cms-icon-check.checked {
    background: #fff3e0;
    color: #d35400;
    border-color: #d35400;
    font-weight: bold;
}

.cms-icon-check input {
    display: none;
}

/* Botones Mini */
.btn-upload-mini {
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    width: 30px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-upload-mini:hover {
    background: #2980b9;
}

.btn-mini-add {
    background: #e8f5e9;
    color: #27ae60;
    border: none;
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
}

.btn-mini-del {
    color: #e74c3c;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 0 10px;
}

.btn-mini-del:hover {
    transform: scale(1.2);
}

/* --- Ticket --- */
.ticket-container-visual {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #eee;
    overflow: hidden;
}

.ticket-item-modern {
    display: grid;
    grid-template-columns: 50px 1fr auto;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px dashed #eee;
    position: relative;
}

/* Botón de pago animado */
.btn-pay-anim.confirm-state {
    background: #27ae60 !important;
    transform: scale(1.02);
}

.btn-pay-anim.confirm-state::after {
    content: '  ¿Confirmar?';
    font-weight: bold;
}

/* --- NUEVOS ESTILOS PARA BOTONES DE HEADER (CAJA Y QR) --- */
.btn-icon-header {
    width: 45px;
    height: 45px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    backdrop-filter: blur(5px);
}

.btn-icon-header:hover {
    transform: translateY(-3px) scale(1.1);
    background: rgba(255, 255, 255, 0.25);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.btn-icon-header:active {
    transform: scale(0.95);
}

.btn-glass {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.btn-glass:hover {
    background: rgba(255, 255, 255, 0.25);
}

.btn-white {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid #eee;
    border: none;
    box-shadow: none;
}

.btn-white:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* --- BOTÓN BORRAR TICKET (HEADER) --- */
i[data-action='clear-cart'] {
    width: 45px;
    height: 45px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.15);
    margin-top: 0 !important;
    font-size: 18px !important;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

i[data-action='clear-cart']:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(15deg) scale(1.1);
    color: #ffcdd2 !important;
}

/* --- ESTADO CAJA ABIERTA (VINO) --- */
#btnCashControl.active {
    background: white !important;
    color: var(--vino) !important;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
    animation: pulse-white 2s infinite;
}

@keyframes pulse-white {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

/* --- FILTROS DE CATEGORÍA (TEXTO SUBRAYADO) --- */
.pos-filters-wrapper {
    padding: 0 20px 15px 20px;
    overflow-x: auto;
    white-space: nowrap;
    margin-bottom: 5px;
    scrollbar-width: none;
    /* Firefox */
}

.pos-filters-wrapper::-webkit-scrollbar {
    display: none;
}

#categoryFiltersContainer {
    display: flex;
    gap: 30px;
}

.filter-pill {
    background: transparent;
    border: none;
    padding: 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: #aaa;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-pill:hover {
    color: var(--vino);
}

.filter-pill.active {
    color: var(--vino);
    font-weight: 800;
}

.filter-pill.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--vino);
    border-radius: 2px;
    animation: expandWidth 0.3s ease;
}

@keyframes expandWidth {
    from {
        width: 0;
    }

    to {
        width: 100%;
    }
}

/* =========================================
   RESPONSIVE POS LAYOUT (Stack & Modal)
   Target: Tablets & Mobile (< 1100px)
   ========================================= */
@media (max-width: 1100px) {

    /* 1. Layout Vertical */
    /* 1. Layout Vertical */
    body #view-terminal.active {
        flex-direction: column !important;
        display: flex !important;
        /* ONLY WHEN ACTIVE */
        position: relative !important;
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
        /* PREVENT BODY SCROLL */
    }

    /* 2. Catálogo Full Width */
    /* 2. Catálogo Full Width */
    .catalog-section {
        width: 100% !important;
        padding: 15px !important;
        padding-bottom: calc(100px + env(safe-area-inset-bottom)) !important;
        /* SAFE AREA FOR IPHONE */
        flex: 1 !important;
        /* ALLOW TO SHRINK/GROW WITHIN VIEWPORT */
        box-sizing: border-box !important;
        overflow-y: auto !important;
        /* ENABLE SCROLL */
        -webkit-overflow-scrolling: touch !important;
    }

    /* 3. Ticket como Sidebar/Modal */
    .ticket-section {
        position: fixed;
        top: env(safe-area-inset-top, 0);
        /* RESPECT NOTCH */
        right: 0;
        width: 380px;
        /* Better fit for Large Phones */
        height: calc(100vh - env(safe-area-inset-top, 0));
        height: calc(100dvh - env(safe-area-inset-top, 0));
        /* DYNAMIC VIEWPORT */
        background: white;
        z-index: 1050;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.25);

        /* Estado inicial: Oculto a la derecha */
        transform: translateX(110%);
        transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);

        display: flex;
        flex-direction: column;
        border-left: 1px solid #eee;
        box-sizing: border-box;
    }

    /* Ajuste para móviles pequeños */
    @media (max-width: 480px) {
        .ticket-section {
            width: 100%;
        }
    }

    /* Clase activar ticket */
    .ticket-section.ticket-visible {
        transform: translateX(0);
    }

    /* 4. Overlay de Fondo */
    .ticket-overlay {
        display: block !important;
        /* Forzar display si estaba oculto */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        /* Debajo del ticket */

        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        backdrop-filter: blur(2px);
    }

    .ticket-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* 5. Header del Ticket (Botón Cerrar) */
    .ticket-header .btn-close-ticket {
        display: flex !important;
    }

    /* 6. FAB (Botón Flotante) */
    .btn-view-ticket {
        display: flex !important;
        /* Mostrar en Responsive */
        position: fixed;
        bottom: 25px;
        right: 25px;
        width: 65px;
        height: 65px;
        border-radius: 50%;
        background: var(--vino);
        color: white;
        border: none;
        box-shadow: 0 4px 15px rgba(94, 28, 38, 0.4);
        z-index: 1030;
        background-image: linear-gradient(135deg, var(--vino), #802835);

        align-items: center;
        justify-content: center;
        flex-direction: column;
        cursor: pointer;
        transition:
            transform 0.2s ease,
            box-shadow 0.2s ease;
    }

    .btn-view-ticket:active {
        transform: scale(0.92);
    }

    .btn-view-ticket i {
        font-size: 24px;
        margin-bottom: 2px;
    }

    .btn-view-ticket span {
        font-size: 10px;
        font-weight: bold;
    }

    .btn-view-ticket .badge-count {
        position: absolute;
        top: -2px;
        right: -2px;
        background: #e67e22;
        color: white;
        font-size: 11px;
        font-weight: 800;
        min-width: 22px;
        height: 22px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        border: 2px solid white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
}

/* Default state for Desktop */
.btn-view-ticket {
    display: none;
}

.ticket-overlay {
    display: none;
}

.ticket-header .btn-close-ticket {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    color: #666;
    cursor: pointer;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-right: 10px;
}

.ticket-header .btn-close-ticket:hover {
    background: #f0f0f0;
    color: #c0392b;
}

/* Fix para el header del ticket en flex */
.ticket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Badge Animation */
@keyframes pulseBadge {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

.pulse-badge {
    animation: pulseBadge 0.3s ease;
}