/* Portal de Pedidos — identidad propia, distinta del panel admin y del portal de colaboradores */
:root {
    --cli-primary: #1e3a5f;
    --cli-primary-dark: #16293f;
    --cli-accent: #f97316;
    --cli-bg: #f8fafc;
    --cli-card-bg: #ffffff;
    --cli-text-muted: #64748b;
    --cli-border: #e2e8f0;
}
:root[data-theme="dark"] {
    --cli-bg: #0f172a;
    --cli-card-bg: #1e293b;
    --cli-text-muted: #94a3b8;
    --cli-border: #334155;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --cli-bg: #0f172a;
        --cli-card-bg: #1e293b;
        --cli-text-muted: #94a3b8;
        --cli-border: #334155;
    }
}

body { background: var(--cli-bg); color: inherit; padding-bottom: 5rem; }

/* En pantallas grandes (PC), la app se muestra centrada con ancho de "teléfono"
   en vez de estirarse a lo ancho de la ventana. */
@media (min-width: 576px) {
    html { background: #cbd5e1; }
    body:not(.cli-login-body) {
        max-width: 480px;
        margin: 0 auto;
        min-height: 100vh;
        box-shadow: 0 0 40px rgba(0,0,0,.15);
    }
    .bottom-nav, .sheet-overlay {
        left: 50% !important;
        right: auto !important;
        width: 100%;
        max-width: 480px;
        transform: translateX(-50%);
    }
    .sheet {
        left: 50% !important;
        right: auto !important;
        width: 100%;
        max-width: 480px;
        transform: translateX(-50%) translateY(100%);
    }
    .sheet.show { transform: translateX(-50%) translateY(0); }
}

.cli-login-body {
    background: linear-gradient(135deg, var(--cli-primary) 0%, var(--cli-primary-dark) 100%);
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.cli-card { width: 100%; max-width: 400px; border-radius: 1.25rem; border: 0; }
.cli-logo {
    width: 64px; height: 64px; border-radius: 1rem; background: var(--cli-primary);
    display: flex; align-items: center; justify-content: center; font-size: 2rem; color: #fff; margin: 0 auto 1rem;
}
.cli-btn-primary { background: var(--cli-primary); }
.cli-btn-primary:hover { background: var(--cli-primary-dark); color: #fff; }

/* Navbar */
.cli-navbar {
    background: var(--cli-primary); color: #fff; padding: .75rem 1rem;
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.cli-navbar .brand { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: .5rem; }
.cli-navbar .user { font-size: .82rem; opacity: .9; }
.cli-navbar .logout { background: rgba(255,255,255,.18); border: 0; color: #fff; border-radius: .5rem; padding: .3rem .7rem; font-size: .85rem; }

/* Links de navegación en el navbar — reemplazan al bottom-nav en desktop */
.cli-navbar-links { display: none; align-items: center; gap: .25rem; }
.cli-navbar-links a {
    color: #fff; text-decoration: none; font-size: .85rem; font-weight: 600; opacity: .8;
    padding: .4rem .8rem; border-radius: .5rem; display: flex; align-items: center; gap: .4rem;
}
.cli-navbar-links a:hover, .cli-navbar-links a.active { opacity: 1; background: rgba(255,255,255,.16); }

/* Bottom nav */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--cli-card-bg); border-top: 1px solid var(--cli-border);
    display: flex; z-index: 200; padding-bottom: env(safe-area-inset-bottom);
}
.bnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: .5rem .25rem; text-decoration: none; color: var(--cli-text-muted);
    font-size: .62rem; font-weight: 600; gap: .1rem; min-height: 48px;
}
.bnav-item i { font-size: 1.3rem; }
.bnav-item.active { color: var(--cli-accent); }

/* Cards genéricas */
.cli-card-item {
    background: var(--cli-card-bg); border-radius: 1rem; margin: .5rem 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08); overflow: hidden; padding: .9rem 1rem;
}

/* Artículo: jerarquía tipográfica en 2 líneas + badge rubro + packaging */
.art-nombre { font-weight: 700; font-size: .95rem; line-height: 1.3; }
.art-detalle { font-size: .78rem; color: var(--cli-text-muted); margin-top: .1rem; }
.art-rubro-badge {
    display: inline-block; font-size: .68rem; font-weight: 700; border-radius: .4rem;
    padding: .1rem .4rem; background: var(--cli-primary); color: #fff; opacity: .85;
}
.art-packaging {
    font-size: .72rem; color: var(--cli-text-muted); display: inline-flex; align-items: center; gap: .25rem;
}

/* Cantidad — touch targets grandes */
.qty-control { display: flex; align-items: center; gap: .4rem; }
.qty-btn {
    width: 44px; height: 44px; flex-shrink: 0; border-radius: .6rem; border: 1px solid var(--cli-border);
    background: var(--cli-card-bg); font-size: 1.2rem; font-weight: 700; display: flex;
    align-items: center; justify-content: center;
}
.qty-input {
    width: 100px; min-width: 0; flex: 1 1 auto; text-align: center; font-weight: 700;
    font-size: 1rem; height: 44px; padding: 0 .25rem;
}
/* Ocultar las flechitas nativas del input number para ganar espacio para los dígitos */
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* Precio y cantidad — alto contraste */
.cli-precio { font-weight: 700; font-size: 1rem; }

/* Tabs */
.tab-pills { display: flex; overflow-x: auto; gap: .5rem; padding: .75rem 1rem; scrollbar-width: none; }
.tab-pills::-webkit-scrollbar { display: none; }
.tab-pill {
    flex-shrink: 0; border: 0; border-radius: 2rem; padding: .45rem .9rem; font-size: .82rem;
    font-weight: 600; background: var(--cli-border); color: var(--cli-text-muted); cursor: pointer;
    min-height: 44px;
}
.tab-pill.active { background: var(--cli-primary); color: #fff; }

/* Bottom sheet */
.sheet-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 500;
    opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sheet-overlay.show { opacity: 1; pointer-events: all; }
.sheet {
    position: fixed; bottom: 0; left: 0; right: 0; background: var(--cli-card-bg);
    border-radius: 1.25rem 1.25rem 0 0; z-index: 501; max-height: 85vh; overflow-y: auto;
    transform: translateY(100%); transition: transform .3s ease; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
.sheet.show { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; background: var(--cli-border); border-radius: 2px; margin: 0 auto .75rem; }

/* Toast */
.toast-cli {
    position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%);
    background: #1e293b; color: #fff; border-radius: .75rem; padding: .6rem 1.2rem;
    font-size: .85rem; font-weight: 600; z-index: 9999; opacity: 0; transition: opacity .25s;
    white-space: nowrap; pointer-events: none;
}
.toast-cli.show { opacity: 1; }

.carrito-badge {
    position: absolute; top: -.3rem; right: -.3rem; background: var(--cli-accent); color: #fff;
    font-size: .65rem; font-weight: 700; border-radius: 1rem; min-width: 18px; height: 18px;
    display: flex; align-items: center; justify-content: center; padding: 0 .3rem;
}

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--cli-text-muted); }
.empty-state i { font-size: 3rem; display: block; margin-bottom: .75rem; }

/* Imagen de artículo + fallback de rubro */
.art-imagen-wrap { position: relative; flex-shrink: 0; }
.art-imagen-vacia {
    background: var(--cli-bg); border-radius: .5rem; display: flex; align-items: center;
    justify-content: center; color: var(--cli-text-muted); flex-shrink: 0;
}
/* Preview de imagen ampliada (click en la miniatura del catálogo) */
.img-preview-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 700;
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
.img-preview-overlay.show { opacity: 1; pointer-events: all; }
.img-preview-modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.95);
    z-index: 701; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
    max-width: min(90vw, 480px); max-height: 85vh; text-align: center;
}
.img-preview-modal.show { opacity: 1; pointer-events: all; transform: translate(-50%, -50%) scale(1); }
.img-preview-modal img {
    max-width: 100%; max-height: 75vh; border-radius: .75rem; object-fit: contain;
    background: var(--cli-card-bg); box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.img-preview-close {
    position: absolute; top: -1.2rem; right: -.6rem; width: 36px; height: 36px; border-radius: 50%;
    background: #fff; border: 0; color: #1e293b; font-size: 1rem; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.img-preview-badge {
    margin-top: .6rem; display: inline-block; background: rgba(0,0,0,.6); color: #fff;
    font-size: .78rem; border-radius: .4rem; padding: .3rem .7rem;
}

/* ── Resto del portal (index.php, mis_pedidos.php): también pensado
   para PC — deja de achicarse al ancho de "teléfono" a partir de 992px,
   usa un ancho cómodo de escritorio y cambia el bottom-nav por links
   normales en el navbar. */
@media (min-width: 992px) {
    body.portal-page {
        max-width: none;
        margin: 0;
        box-shadow: none;
    }
    .portal-container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 1.5rem 2rem;
    }
    body.portal-page .bottom-nav { display: none; }
    .cli-navbar-links { display: flex !important; }
    .cli-navbar .user { display: inline !important; }

    /* Bottom sheets que no sean el carrito de pedido.php (que tiene su
       propio override más abajo): se muestran como panel centrado, no
       como hoja que sube desde abajo. */
    .sheet:not(.pedido-carrito) {
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        top: 8vh;
        width: 100%;
        max-width: 560px;
        max-height: 82vh;
        border-radius: 1rem;
        transform: translateX(-50%) translateY(-12px);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease, transform .2s ease;
    }
    .sheet:not(.pedido-carrito).show {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
        pointer-events: all;
    }

    /* Grilla de accesos en el home (index.php) */
    .cards-grid-desktop { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
}

/* ── Catálogo desktop-first (portal_clientes/pedido.php) ─────────
   En mobile (<992px) el layout de abajo no aplica: se ve el buscador +
   tab-pills + cards apiladas + bottom-sheet, tal como en el resto del portal.
   A partir de 992px se activa el layout de 3 columnas (sidebar rubros,
   tabla densa, carrito fijo). */
@media (min-width: 992px) {
    body.pedido-page { max-width: none; margin: 0; box-shadow: none; }

    .pedido-layout {
        display: grid;
        grid-template-columns: clamp(190px, 15vw, 260px) minmax(0, 1fr) clamp(250px, 20vw, 320px);
        max-width: 1800px;
        margin: 0 auto;
        align-items: start;
    }

    .pedido-sidebar {
        display: flex !important;
        flex-direction: column;
        position: sticky;
        top: 56px;
        height: calc(100vh - 56px);
        padding: 1rem;
        border-right: 1px solid var(--cli-border);
        background: var(--cli-card-bg);
        min-width: 0;
    }
    .sidebar-rubro-list { overflow-y: auto; flex: 1; }
    .sidebar-rubro-item {
        display: flex; justify-content: space-between; align-items: center; width: 100%;
        border: 0; background: none; text-align: left; padding: .5rem .6rem; border-radius: .5rem;
        font-size: .85rem; color: inherit; cursor: pointer; min-height: 0;
    }
    .sidebar-rubro-item:hover { background: var(--cli-bg); }
    .sidebar-rubro-item.active { background: var(--cli-primary); color: #fff; }

    .pedido-center { min-height: calc(100vh - 56px); min-width: 0; }

    .center-tabs {
        display: flex !important; gap: .25rem; padding: .75rem 1rem 0;
        border-bottom: 1px solid var(--cli-border);
    }
    .ctab {
        border: 0; background: none; padding: .6rem 1rem; font-weight: 600; font-size: .85rem;
        color: var(--cli-text-muted); border-bottom: 2px solid transparent; cursor: pointer;
    }
    .ctab.active { color: var(--cli-primary); border-color: var(--cli-primary); }

    #tablaWrap { min-width: 0; }
    .tabla-catalogo { width: 100%; min-width: 880px; border-collapse: collapse; font-size: .85rem; }
    .tabla-catalogo thead th {
        text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
        color: var(--cli-text-muted); padding: .5rem; border-bottom: 1px solid var(--cli-border);
        position: sticky; top: 0; background: var(--cli-bg); z-index: 1;
    }
    .tabla-catalogo tbody td { padding: .5rem; border-bottom: 1px solid var(--cli-border); vertical-align: middle; }
    .tabla-catalogo tbody tr:hover { background: var(--cli-bg); }
    .tabla-catalogo .qty-control { gap: .25rem; }
    .tabla-catalogo .qty-btn { width: 32px; height: 32px; font-size: 1rem; }
    .tabla-catalogo .qty-input { width: 70px; height: 32px; font-size: .85rem; }

    /* Carrito: pasa de bottom-sheet a panel lateral fijo, siempre visible */
    .pedido-carrito.sheet {
        position: sticky !important;
        top: 56px !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        width: auto;
        max-width: none;
        height: calc(100vh - 56px);
        transform: none !important;
        border-radius: 0;
        border-left: 1px solid var(--cli-border);
        box-shadow: none;
        min-width: 0;
        overflow-y: auto;
    }
    #sheetOverlay { display: none !important; }
}
