/* =============================================================================
   Tech-Rex — Cart Drawer
   Variables de color alineadas con search.css (--tr-blue, etc.)
============================================================================= */

:root {
    --tr-blue:        #2271b1;
    --tr-blue-dark:   #135e96;
    --tr-blue-light:  #f0f6fc;
    --tr-red:         #d63638;
    --tr-green:       #1a7a2e;
    --tr-text:        #1d2327;
    --tr-muted:       #646970;
    --tr-border:      #e0e0e0;
    --tr-bg:          #f6f7f7;
    --tr-white:       #ffffff;
    --tr-shadow:      0 8px 40px rgba(0, 0, 0, 0.18);
    --tr-radius:      12px;
    --tr-drawer-w:    420px;
    --tr-transition:  0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================================
   TRIGGER (shortcode [techrex_minicart])
============================================================================= */

.techrex-cart-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--tr-text);
    border-radius: 8px;
    transition: background var(--tr-transition), color var(--tr-transition);
    line-height: 1;
}

.techrex-cart-trigger:hover,
.techrex-cart-trigger[aria-expanded="true"] {
    background: var(--tr-blue-light);
    color: var(--tr-blue);
}

.techrex-cart-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--tr-red);
    color: var(--tr-white);
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    border-radius: 9px;
    pointer-events: none;
    transition: transform 0.2s;
}

.techrex-cart-badge:empty,
.techrex-cart-badge[data-count="0"] {
    transform: scale(0);
}

/* =============================================================================
   OVERLAY
============================================================================= */

.techrex-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 99998;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--tr-transition);
}

.techrex-drawer-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

/* =============================================================================
   DRAWER
============================================================================= */

.techrex-cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--tr-drawer-w);
    max-width: 100vw;
    height: 100dvh;          /* dynamic viewport height para móvil */
    background: var(--tr-white);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    box-shadow: var(--tr-shadow);
    transform: translateX(100%);
    transition: transform var(--tr-transition);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.techrex-cart-drawer.is-open {
    transform: translateX(0);
}

/* --- Header --- */

.techrex-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--tr-border);
    flex-shrink: 0;
}

.techrex-drawer-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--tr-text);
    display: flex;
    align-items: baseline;
    gap: 8px;
    line-height: 1;
}

.techrex-drawer-count {
    font-size: 12px;
    font-weight: 400;
    color: var(--tr-muted);
}

.techrex-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--tr-border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--tr-muted);
    transition: all 0.2s;
    flex-shrink: 0;
}

.techrex-drawer-close:hover {
    border-color: var(--tr-red);
    color: var(--tr-red);
    background: #fff5f5;
}

/* --- Body (lista de ítems, scrollable) --- */

.techrex-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.techrex-drawer-body::-webkit-scrollbar {
    width: 4px;
}
.techrex-drawer-body::-webkit-scrollbar-track { background: transparent; }
.techrex-drawer-body::-webkit-scrollbar-thumb {
    background: var(--tr-border);
    border-radius: 4px;
}

/* Estado vacío */

.techrex-cart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 60px 20px;
    text-align: center;
    color: var(--tr-muted);
    flex: 1;
}

.techrex-cart-empty p {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--tr-text);
}

.techrex-cart-empty span {
    font-size: 13px;
    color: var(--tr-muted);
}

/* --- Ítem individual --- */

.techrex-cart-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--tr-border);
    border-radius: var(--tr-radius);
    background: var(--tr-white);
    transition: box-shadow 0.2s;
}

.techrex-cart-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.techrex-item-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.techrex-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--tr-text);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.techrex-item-unit {
    font-size: 12px;
    color: var(--tr-muted);
}

.techrex-item-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Control de cantidad */

.techrex-qty-control {
    display: flex;
    align-items: center;
    border: 1px solid var(--tr-border);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.techrex-qty-minus,
.techrex-qty-plus {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--tr-bg);
    cursor: pointer;
    font-size: 16px;
    color: var(--tr-text);
    transition: background 0.15s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.techrex-qty-minus:hover,
.techrex-qty-plus:hover {
    background: var(--tr-blue-light);
    color: var(--tr-blue);
}

.techrex-qty-value {
    min-width: 32px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--tr-text);
    padding: 0 4px;
    user-select: none;
}

/* Subtotal del ítem */

.techrex-item-subtotal {
    font-size: 14px;
    font-weight: 700;
    color: var(--tr-text);
    margin-left: auto;
}

/* Botón eliminar */

.techrex-btn-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--tr-muted);
    border-radius: 6px;
    flex-shrink: 0;
    transition: all 0.15s;
}

.techrex-btn-remove:hover {
    background: #fff5f5;
    color: var(--tr-red);
}

/* --- Footer --- */

.techrex-drawer-footer {
    flex-direction: column;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid var(--tr-border);
    background: var(--tr-white);
    flex-shrink: 0;
}

.techrex-drawer-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
    color: var(--tr-text);
}

.techrex-drawer-total-row span {
    font-weight: 500;
    color: var(--tr-muted);
}

.techrex-drawer-total-row strong {
    font-size: 20px;
    font-weight: 700;
    color: var(--tr-text);
}

.techrex-btn-checkout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 20px;
    background: var(--tr-blue);
    color: var(--tr-white);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--tr-transition), transform 0.15s;
}

.techrex-btn-checkout:hover {
    background: var(--tr-blue-dark);
    transform: translateY(-1px);
}

.techrex-btn-checkout:active {
    transform: translateY(0);
}

.techrex-btn-continue {
    width: 100%;
    padding: 10px;
    background: none;
    border: 1px solid var(--tr-border);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--tr-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.techrex-btn-continue:hover {
    border-color: var(--tr-blue);
    color: var(--tr-blue);
    background: var(--tr-blue-light);
}

/* =============================================================================
   TOAST NOTIFICATION
============================================================================= */

.techrex-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--tr-white);
    z-index: 100000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
}

.techrex-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.techrex-toast--success { background: var(--tr-green); }
.techrex-toast--error   { background: var(--tr-red); }
.techrex-toast--warning { background: #f0a500; }

/* =============================================================================
   RESPONSIVE
============================================================================= */

@media (max-width: 480px) {
    :root { --tr-drawer-w: 100vw; }

    .techrex-drawer-header { padding: 16px 20px; }
    .techrex-drawer-body   { padding: 12px 16px; }
    .techrex-drawer-footer { padding: 16px 20px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVO MÓVIL — Drawer a pantalla completa en móviles
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 520px) {
    .techrex-cart-drawer {
        width: 100vw;
        right: -100vw;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .techrex-cart-drawer.is-open { right: 0; }
    .techrex-drawer-footer { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
    .techrex-btn-checkout,
    .techrex-btn-continue {
        width: 100%;
        min-height: 48px;
        justify-content: center;
    }
    .techrex-cart-trigger { min-width: 44px; min-height: 44px; }
}

@media (min-width: 521px) and (max-width: 780px) {
    .techrex-cart-drawer { width: min(440px, 88vw); }
    .techrex-drawer-close,
    .techrex-btn-remove { min-width: 40px; min-height: 40px; }
    .techrex-qty-minus,
    .techrex-qty-plus { width: 38px; height: 38px; }
}

/* El gatillo del carrito siempre tocable */
.techrex-cart-trigger {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
