/* ==========================================================================
   March Preventa — sistema visual
   Mobile-first. Marca March: rojo #A92F2E, grafito #232323.
   Tipografía: Inter (local). Iconos: Lucide SVG inline (currentColor).
   ========================================================================== */

:root {
    /* Marca */
    --rojo: #a92f2e;
    --rojo-fuerte: #8f2422;
    --rojo-suave: #fdf1f1;
    --rojo-borde: #f2d4d3;
    --grafito: #232323;
    --grafito-claro: #4a4a4a;
    --gris: #70747a;
    --gris-claro: #9aa0a6;

    /* Superficies */
    --fondo: #f5f6f7;
    --superficie: #ffffff;
    --superficie-2: #fafafb;
    --borde: #e5e6e9;
    --borde-fuerte: #d3d5da;

    /* Semánticos */
    --ok: #1f7a3d;
    --ok-fondo: #e9f6ee;
    --ok-borde: #bfe3cc;
    --warn: #a86a00;
    --warn-fondo: #fdf4e3;
    --warn-borde: #f0dcb0;
    --info: #23417a;
    --info-fondo: #eef2fb;
    --info-borde: #c9d5ef;

    /* Forma */
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-full: 999px;

    --sombra-1: 0 1px 2px rgba(16, 20, 28, .05), 0 1px 3px rgba(16, 20, 28, .06);
    --sombra-2: 0 2px 6px rgba(16, 20, 28, .07), 0 8px 20px rgba(16, 20, 28, .07);
    --sombra-3: 0 10px 30px rgba(16, 20, 28, .16);

    --tap: 44px;              /* alto minimo de un control tactil */
    --nav-h: 60px;            /* alto de la barra inferior movil */
    --max: 1240px;

    --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--fondo);
    color: var(--grafito);
    font-size: 16px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--rojo); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

.mp-ico { flex: 0 0 auto; vertical-align: middle; }

/* ------------------------------------------------------------------ layout */
.shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky; top: 0; z-index: 60;
    background: var(--grafito);
    color: #fff;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .06), 0 4px 14px rgba(0, 0, 0, .18);
}
.topbar-inner {
    max-width: var(--max); margin: 0 auto; padding: .45rem .85rem;
    display: flex; align-items: center; gap: .7rem;
    min-width: 0;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; flex: 0 0 auto; }
.brand:hover { text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }
.brand-name { font-weight: 700; font-size: .98rem; letter-spacing: -.01em; }
.brand-sep { width: 1px; height: 22px; background: rgba(255, 255, 255, .22); }
.brand-sub { font-size: .78rem; color: #b9bcc0; font-weight: 500; }

.topbar-spacer { flex: 1 1 auto; min-width: 0; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--tap); height: var(--tap);
    border: 0; border-radius: var(--r-full);
    background: rgba(255, 255, 255, .1); color: #fff;
    cursor: pointer; font-family: inherit;
    transition: background .14s var(--ease);
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }
.icon-btn.bare { background: transparent; }

.user-chip {
    display: inline-flex; align-items: center; gap: .45rem;
    background: rgba(255, 255, 255, .1); border: 0; border-radius: var(--r-full);
    padding: .3rem .7rem .3rem .35rem; color: #fff; font: inherit; font-size: .82rem;
    font-weight: 600; cursor: pointer;
}
.user-chip .avatar {
    width: 26px; height: 26px; border-radius: var(--r-full);
    background: var(--rojo); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .74rem; font-weight: 700;
}

.main {
    flex: 1 1 auto;
    width: 100%; max-width: var(--max); margin: 0 auto;
    padding: .9rem .85rem calc(var(--nav-h) + 1.5rem);
    min-width: 0;
}

/* Barra inferior de navegación (movil) */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    background: var(--superficie);
    border-top: 1px solid var(--borde);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 14px rgba(16, 20, 28, .07);
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .12rem; min-height: var(--nav-h);
    color: var(--gris); font-size: .68rem; font-weight: 600; text-decoration: none;
    position: relative; min-width: 0;
}
/* La etiqueta se recorta antes de empujar el ancho del documento. */
.tabbar .tb-lbl {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: .64rem; line-height: 1.1;
}
.tabbar a:hover { text-decoration: none; }
.tabbar a.active { color: var(--rojo); }
.tabbar a.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--rojo);
}
.tabbar .badge-dot {
    position: absolute; top: 8px; left: 50%; margin-left: 6px;
    min-width: 16px; height: 16px; padding: 0 4px;
    background: var(--rojo); color: #fff; border-radius: var(--r-full);
    font-size: .62rem; font-weight: 700; line-height: 16px; text-align: center;
}

.foot { text-align: center; color: var(--gris-claro); font-size: .76rem; padding: 1rem .5rem 1.2rem; }
/* En celular el pie no puede quedar debajo de la barra de navegacion. */
@media (max-width: 1023px) {
    .foot { padding-bottom: calc(var(--nav-h) + 1rem); }
}

/* Navegación de escritorio */
.desknav {
    display: none; gap: .1rem; margin-left: auto;
    min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none;
}
.desknav::-webkit-scrollbar { display: none; }
.desknav a {
    display: inline-flex; align-items: center; gap: .35rem;
    color: #d3d5d8; padding: .45rem .6rem; border-radius: var(--r-full);
    font-size: .84rem; font-weight: 600; white-space: nowrap;
}
.desknav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.desknav a.active { background: var(--rojo); color: #fff; }

/* --------------------------------------------------------------- tipografía */
.page-head { margin-bottom: .9rem; }
.page-title {
    display: flex; align-items: center; gap: .5rem;
    font-size: 1.3rem; line-height: 1.2;
}
.page-sub { color: var(--gris); font-size: .86rem; margin-top: .2rem; }

.section-title {
    display: flex; align-items: center; gap: .45rem;
    font-size: .78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; color: var(--gris);
    margin: 1.1rem .1rem .5rem;
}

/* ------------------------------------------------------------------- cards */
.card {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: var(--r-lg);
    box-shadow: var(--sombra-1);
    padding: .9rem .95rem;
    margin-bottom: .8rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: .6rem; flex-wrap: wrap; margin-bottom: .7rem;
}
.card-head h2, .card-head h3 { font-size: 1rem; }

.panel {
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: var(--r-lg); box-shadow: var(--sombra-1);
}

/* ---------------------------------------------------------------- botones */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    min-height: var(--tap); padding: .55rem 1.05rem;
    border: 1px solid transparent; border-radius: var(--r-full);
    font-family: inherit; font-size: .92rem; font-weight: 600;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .14s var(--ease), box-shadow .14s var(--ease), transform .08s var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(.985); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: .5; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; }

.btn-primary { background: var(--rojo); color: #fff; box-shadow: 0 1px 2px rgba(169, 47, 46, .3); }
.btn-primary:hover { background: var(--rojo-fuerte); }
.btn-dark { background: var(--grafito); color: #fff; }
.btn-dark:hover { background: #333; }
.btn-ghost { background: var(--superficie); color: var(--grafito); border-color: var(--borde-fuerte); }
.btn-ghost:hover { background: var(--superficie-2); }
.btn-soft { background: var(--rojo-suave); color: var(--rojo); border-color: var(--rojo-borde); }
.btn-soft:hover { background: #fbe6e5; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { background: #196533; }
.btn-quiet { background: transparent; color: var(--gris); }
.btn-quiet:hover { background: var(--superficie-2); color: var(--grafito); }

/* Todo control que se toca con el dedo mide 44px o mas (--tap). */
.btn-sm { min-height: var(--tap); padding: .4rem .85rem; font-size: .86rem; border-radius: var(--r-full); }
.btn-lg { min-height: 52px; padding: .7rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { width: var(--tap); min-height: var(--tap); padding: 0; border-radius: var(--r-full); }

/* --------------------------------------------------------------- formularios */
.field { margin-bottom: .7rem; }
.field label, .lbl {
    display: block; font-size: .78rem; font-weight: 600;
    color: var(--gris); margin-bottom: .3rem;
}
.input, select.input, textarea.input {
    width: 100%; min-height: var(--tap);
    padding: .55rem .75rem;
    border: 1px solid var(--borde-fuerte); border-radius: var(--r);
    background: var(--superficie); color: var(--grafito);
    font-family: inherit; font-size: 1rem;  /* 16px: evita el zoom automatico en iPhone */
    line-height: 1.3;
    transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.input::placeholder { color: var(--gris-claro); }
.input:focus {
    outline: none; border-color: var(--rojo);
    box-shadow: 0 0 0 3px rgba(169, 47, 46, .13);
}
.input:disabled { background: var(--superficie-2); color: var(--gris); }
textarea.input { min-height: 88px; resize: vertical; }
.input-sm { min-height: 38px; padding: .35rem .6rem; font-size: 1rem; }
.input-num { text-align: right; font-variant-numeric: tabular-nums; }

.search { position: relative; }
/* Solo el icono principal del buscador se posiciona (hijo directo). */
.search > .mp-ico {
    position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
    color: var(--gris-claro); pointer-events: none;
}
.search .input { padding-left: 2.4rem; border-radius: var(--r-full); }
.search .clear {
    position: absolute; right: .2rem; top: 50%; transform: translateY(-50%);
    border: 0; background: transparent; color: var(--gris-claro);
    width: var(--tap); height: var(--tap); border-radius: var(--r-full); cursor: pointer;
    display: none; align-items: center; justify-content: center;
}
.search.has-value .clear { display: inline-flex; align-items: center; justify-content: center; }

.row { display: flex; gap: .55rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 auto; min-width: 0; }
.row > .shrink { flex: 0 0 auto; min-width: auto; }
.row-tight { gap: .35rem; }

.switch-row {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem 0; font-size: .9rem;
}
.switch-row input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--rojo); }

/* --------------------------------------------------------------- resultados */
.result-list { display: flex; flex-direction: column; }
.result {
    display: flex; align-items: flex-start; gap: .75rem;
    width: 100%; text-align: left;
    padding: .75rem .95rem;
    background: var(--superficie); border: 0; border-bottom: 1px solid var(--borde);
    font: inherit; color: inherit; cursor: pointer;
    min-height: var(--tap);
    min-width: 0;
}
/* Ningun hijo del renglon puede empujar el ancho de la pagina. */
.result > * { min-width: 0; }
}
.result:last-child { border-bottom: 0; }
.result:hover { background: var(--superficie-2); }
a.result { text-decoration: none; color: inherit; }
a.result:hover { text-decoration: none; }
.result:focus-visible { outline: 2px solid var(--rojo); outline-offset: -2px; }
.result .r-title { font-weight: 600; font-size: .94rem; }
.result .r-meta { color: var(--gris); font-size: .8rem; margin-top: .1rem; }
.result .r-badge { margin-left: auto; flex: 0 0 auto; }
.result .r-ico {
    width: 36px; height: 36px; border-radius: var(--r); flex: 0 0 auto;
    background: var(--rojo-suave); color: var(--rojo);
    display: inline-flex; align-items: center; justify-content: center;
}
.result .r-ico.grey { background: var(--superficie-2); color: var(--gris); border: 1px solid var(--borde); }

/* ------------------------------------------------------------------- chips */
.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .18rem .55rem; border-radius: var(--r-full);
    font-size: .72rem; font-weight: 700;
    background: var(--rojo-suave); color: var(--rojo); border: 1px solid var(--rojo-borde);
}
.chip-ok { background: var(--ok-fondo); color: var(--ok); border-color: var(--ok-borde); }
.chip-warn { background: var(--warn-fondo); color: var(--warn); border-color: var(--warn-borde); }
.chip-info { background: var(--info-fondo); color: var(--info); border-color: var(--info-borde); }
.chip-grey { background: var(--superficie-2); color: var(--gris); border-color: var(--borde); }

/* ------------------------------------------------------------------ alerts */
.alert {
    display: flex; gap: .6rem; align-items: flex-start;
    padding: .7rem .85rem; border-radius: var(--r);
    font-size: .88rem; margin-bottom: .8rem; border: 1px solid transparent;
}
.alert .mp-ico { margin-top: 1px; }
.alert-ok { background: var(--ok-fondo); color: var(--ok); border-color: var(--ok-borde); }
.alert-error { background: var(--rojo-suave); color: var(--rojo-fuerte); border-color: var(--rojo-borde); }
.alert-warn { background: var(--warn-fondo); color: var(--warn); border-color: var(--warn-borde); }
.alert-info { background: var(--info-fondo); color: var(--info); border-color: var(--info-borde); }

/* -------------------------------------------------------- estados de pagina */
.empty {
    text-align: center; padding: 1.6rem 1rem; color: var(--gris);
}
.empty .e-ico {
    width: 52px; height: 52px; margin: 0 auto .6rem;
    border-radius: var(--r-full); background: var(--superficie-2);
    display: flex; align-items: center; justify-content: center; color: var(--gris-claro);
}
.empty .e-title { font-weight: 700; color: var(--grafito); font-size: .96rem; }
.empty .e-text { font-size: .86rem; margin-top: .2rem; }

.skeleton {
    background: linear-gradient(90deg, #eceef0 25%, #f5f6f7 37%, #eceef0 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
    border-radius: var(--r-sm);
    height: 14px; margin: .45rem 0;
}
.skeleton.lg { height: 44px; }
.skeleton.round { border-radius: var(--r-full); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.spin { animation: spin .8s linear infinite; }

/* Spinnerinline para botones en estado "ocupado". */
.spinner {
    display: inline-block; width: 15px; height: 15px;
    border: 2px solid rgba(255, 255, 255, .45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- stepper */
.stepper { display: flex; align-items: center; gap: .3rem; margin-bottom: .9rem; }
.stepper .st {
    flex: 1 1 0; display: flex; align-items: center; gap: .4rem;
    font-size: .76rem; font-weight: 600; color: var(--gris-claro);
}
.stepper .st .dot {
    width: 24px; height: 24px; border-radius: var(--r-full);
    background: var(--superficie); border: 1.5px solid var(--borde-fuerte);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .72rem; flex: 0 0 auto;
}
.stepper .st.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper .st.current .dot { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.stepper .st.current { color: var(--grafito); }
.stepper .bar { flex: 1 1 auto; height: 2px; background: var(--borde); border-radius: 2px; }

/* ------------------------------------------------------------- seg control */
.segmented {
    display: inline-flex; background: var(--superficie-2);
    border: 1px solid var(--borde); border-radius: var(--r-full); padding: 3px;
    gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button, .segmented a {
    border: 0; background: transparent; border-radius: var(--r-full);
    padding: .42rem .85rem; font: inherit; font-size: .84rem; font-weight: 600;
    color: var(--gris); cursor: pointer; white-space: nowrap; text-decoration: none;
    min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center;
}
.segmented button.active, .segmented a.active {
    background: var(--superficie); color: var(--grafito); box-shadow: var(--sombra-1);
}

/* ------------------------------------------------------- tiles / dashboard */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.tile {
    display: flex; flex-direction: column; gap: .25rem;
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: var(--r-lg); box-shadow: var(--sombra-1);
    padding: .85rem .9rem; color: var(--grafito); text-decoration: none;
    font-family: inherit; cursor: pointer; text-align: left;
    min-height: 92px;
    transition: transform .12s var(--ease), box-shadow .12s var(--ease);
}
.tile:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--sombra-2); }
.tile .t-ico {
    width: 36px; height: 36px; border-radius: var(--r);
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--rojo-suave); color: var(--rojo); margin-bottom: .3rem;
}
.tile .t-ico.green { background: var(--ok-fundo); color: var(--ok); }
.tile .t-ico.dark { background: #ececee; color: var(--grafito); }
.tile .t-ico.amber { background: var(--warn-fondo); color: var(--warn); }
.tile .t-title { font-weight: 700; font-size: .92rem; }
.tile .t-sub { color: var(--gris); font-size: .76rem; line-height: 1.3; }
.tile .t-num { margin-left: auto; font-weight: 700; font-size: .84rem; color: var(--rojo); }

.hello {
    border-radius: var(--r-lg); padding: 1rem 1.1rem; color: #fff; margin-bottom: .9rem;
    background: linear-gradient(135deg, #a92f2e 0%, #7d1f1e 100%);
    box-shadow: 0 6px 18px rgba(125, 31, 30, .25);
}
.hello .h-title { font-size: 1.15rem; font-weight: 700; }
.hello .h-sub { font-size: .82rem; opacity: .9; margin-top: .15rem; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; }
.stat {
    background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r);
    padding: .6rem .65rem; text-align: center;
}
.stat .s-num { font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat .s-lbl { font-size: .7rem; color: var(--gris); text-transform: uppercase; letter-spacing: .04em; }

/* ----------------------------------------------------- catalogo + carrito */
.sell-layout { display: grid; grid-template-columns: 1fr; gap: .7rem; }

.catalog-row {
    border-bottom: 1px solid var(--borde);
}
.catalog-row:last-child { border-bottom: 0; }
.catalog-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .65rem .9rem;
}
.catalog-item .c-main { flex: 1 1 auto; min-width: 0; }
.catalog-item .c-code { font-size: .72rem; color: var(--gris-claro); font-variant-numeric: tabular-nums; }
.catalog-item .c-name { font-weight: 600; font-size: .92rem; line-height: 1.25; }
.catalog-item .c-meta { font-size: .76rem; color: var(--gris); margin-top: .12rem; }
.catalog-item .c-price { font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* La linea del producto se parte en dos: nombre arriba y cantidad/precio abajo.
   En una sola fila el nombre quedaba partido en dos lineas de dos palabras. */
.cart-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "main quitar" "stepper importe";
    gap: .5rem .6rem;
    align-items: center;
    padding: .7rem .9rem; border-bottom: 1px solid var(--borde);
}
.cart-line:last-child { border-bottom: 0; }
.cart-line .l-main { grid-area: main; min-width: 0; }
.cart-line .stepper-qty { grid-area: stepper; justify-self: start; }
.cart-line .l-sub { grid-area: importe; justify-self: end; }
.cart-line .icon-btn { grid-area: quitar; justify-self: end; }
.cart-line .l-name { font-weight: 600; font-size: .88rem; line-height: 1.25; }
.cart-line .l-meta { font-size: .75rem; color: var(--gris); font-variant-numeric: tabular-nums; }
.cart-line .l-sub { font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.stepper-qty {
    display: inline-flex; align-items: center; gap: .1rem;
    background: var(--superficie-2); border: 1px solid var(--borde); border-radius: var(--r-full);
    padding: 2px;
}
.stepper-qty button {
    width: var(--tap); height: var(--tap); border: 0; border-radius: var(--r-full);
    background: var(--superficie); color: var(--grafito);
    font: inherit; font-size: 1rem; line-height: 1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.stepper-qty button:hover { background: var(--rojo-suave); color: var(--rojo); }
.stepper-qty input {
    width: 46px; border: 0; background: transparent; text-align: center;
    font: inherit; font-size: 1rem; font-weight: 600; color: var(--grafito);
    font-variant-numeric: tabular-nums;
}

/* Barra fija del carrito (movil) */
.cart-bar {
    position: fixed; left: 0; right: 0; bottom: var(--nav-h);
    z-index: 65;
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .85rem calc(.55rem + env(safe-area-inset-bottom));
    background: var(--grafito); color: #fff;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, .22);
}
.cart-bar .cb-total { flex: 1 1 auto; min-width: 0; }
.cart-bar .cb-label { font-size: .7rem; opacity: .75; text-transform: uppercase; letter-spacing: .05em; }
.cart-bar .cb-value { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cart-bar .cb-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 5px; margin-left: .4rem;
    background: var(--rojo); border-radius: var(--r-full);
    font-size: .72rem; font-weight: 700;
}

/* --------------------------------------------------------------- cliente */
.client-head {
    display: flex; align-items: center; gap: .75rem;
    padding: .85rem .95rem; border-bottom: 1px solid var(--borde);
}
.client-head .c-avatar {
    width: 44px; height: 44px; border-radius: var(--r-full);
    background: var(--rojo-suave); color: var(--rojo);
    display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.client-head .c-name { font-weight: 700; font-size: 1rem; }
.client-head .c-meta { color: var(--gris); font-size: .8rem; }

.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem .7rem; }
.info-grid .i-item { min-width: 0; }
.info-grid .i-lbl { font-size: .7rem; color: var(--gris); text-transform: uppercase; letter-spacing: .04em; }
.info-grid .i-val { font-size: .88rem; font-weight: 500; word-break: break-word; }

/* ------------------------------------------------------------- timeline */
.timeline { position: relative; padding-left: 1.3rem; }
.timeline::before {
    content: ''; position: absolute; left: .35rem; top: .3rem; bottom: .3rem;
    width: 2px; background: var(--borde);
}
.tl-item { position: relative; padding: .5rem 0 .7rem; }
.tl-item::before {
    content: ''; position: absolute; left: -1.3rem; top: .65rem;
    width: 10px; height: 10px; border-radius: var(--r-full);
    background: var(--superficie); border: 2px solid var(--borde-fuerte);
}
.tl-item.hl::before { background: var(--rojo); border-color: var(--rojo); }
.tl-date { font-size: .74rem; color: var(--gris); }
.tl-title { font-weight: 600; font-size: .9rem; }
.tl-sub { font-size: .82rem; color: var(--gris); }

/* ---------------------------------------------------------------- tabla */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th {
    text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--gris); border-bottom: 1px solid var(--borde); padding: .55rem .5rem; white-space: nowrap;
}
table.data td { padding: .55rem .5rem; border-bottom: 1px solid var(--borde); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--superficie-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- toast */
.toast-zone {
    position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 8px);
    z-index: 90; display: flex; flex-direction: column; align-items: center; gap: .4rem;
    pointer-events: none; padding: 0 .8rem;
}
/* Con la hoja del carrito abierta el aviso sube: abajo queda el boton de
   confirmar y hay que poder tocarlo sin esperar a que se vaya el toast. */
body.no-scroll .toast-zone {
    top: calc(env(safe-area-inset-top) + 4.4rem); bottom: auto;
}
.toast {
    display: flex; align-items: center; gap: .5rem;
    max-width: 420px; width: 100%;
    padding: .6rem .8rem; border-radius: var(--r);
    background: var(--grafito); color: #fff; font-size: .86rem; font-weight: 500;
    box-shadow: var(--sombra-3);
    animation: toast-in .22s var(--ease);
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--rojo-fuerte); }
.toast.warn { background: var(--warn); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----------------------------------------------------------------- modal */
.modal-back {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(20, 22, 26, .55);
    display: none; align-items: flex-end; justify-content: center;
    padding: 0;
}
.modal-back.open { display: flex; }
.modal {
    background: var(--superficie); width: 100%; max-width: 560px;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 92vh; overflow-y: auto;
    box-shadow: var(--sombra-3);
    animation: sheet-in .22s var(--ease);
    padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .9rem 1rem; border-bottom: 1px solid var(--borde);
    position: sticky; top: 0; background: var(--superficie); z-index: 1;
}
.modal-head h3 { font-size: 1rem; }
.modal-body { padding: 1rem; }
.modal-foot {
    padding: .8rem 1rem; border-top: 1px solid var(--borde);
    display: flex; gap: .5rem; justify-content: flex-end;
    position: sticky; bottom: 0; background: var(--superficie);
}

/* ------------------------------------------------------------------- mapa */
.map { height: 260px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--borde); }
.map-lg { height: 380px; }

/* ------------------------------------------------------- menu de usuario */
.mp-user { position: relative; flex: 0 0 auto; }
.mp-user > summary { list-style: none; }
.mp-user > summary::-webkit-details-marker { display: none; }
.mp-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-user-menu {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 80;
    width: 240px; max-width: calc(100vw - 1.5rem);
    padding: .7rem;
    background: var(--superficie); color: var(--grafito);
    border: 1px solid var(--borde); border-radius: var(--r);
    box-shadow: var(--sombra-3);
}
/* While el menu esta cerrado no debe ocupar lugar (ni desbordar). */
.mp-user:not([open]) .mp-user-menu { display: none; }
.mp-user-info { padding: .2rem .25rem .55rem; border-bottom: 1px solid var(--borde); margin-bottom: .55rem; }
.mp-user-info > * { overflow-wrap: anywhere; }
.mp-user-menu form { margin: 0; }

/* ------------------------------------------------- pantalla de confirmacion */
.confirm-form { margin-top: .8rem; }
.confirm-bar {
    display: flex; align-items: center; gap: .7rem;
    padding: .65rem .85rem;
    background: var(--superficie);
    border: 1px solid var(--borde); border-radius: var(--r-lg);
    box-shadow: var(--sombra-2);
}
.confirm-bar .btn { flex: 1 1 auto; }
.cb-total { display: flex; flex-direction: column; line-height: 1.15; flex: 0 0 auto; }
.cb-lbl { font-size: .68rem; color: var(--gris); text-transform: uppercase; letter-spacing: .04em; }
.cb-precio { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* En celular la barra queda FIJA abajo, arriba de la barra de navegacion: el
   boton de confirmar esta siempre a mano, sin depender de hasta donde se haya
   scrolleado ni de cuantos productos tenga el pedido. */
@media (max-width: 1023px) {
    .confirm-form {
        position: fixed; left: 0; right: 0; bottom: var(--nav-h);
        z-index: 68; margin: 0; padding: .6rem .85rem;
        background: var(--superficie);
        border-top: 1px solid var(--borde);
        box-shadow: 0 -4px 18px rgba(16, 20, 28, .12);
    }
    .confirm-bar { border-radius: var(--r-lg); }
    /* Aire al pie de la pagina para que la barra fija no tape el cierre. */
    body.mp-confirm { padding-bottom: calc(env(safe-area-inset-bottom) + 4.6rem); }
}

.exito-card { text-align: center; padding: 1.6rem 1.1rem 1.3rem; }
.exito-ico {
    width: 68px; height: 68px; margin: 0 auto .7rem;
    border-radius: var(--r-full);
    background: var(--ok-fondo); color: var(--ok);
    display: flex; align-items: center; justify-content: center;
    animation: pop .3s var(--ease);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
.exito-title { font-size: 1.3rem; margin-bottom: .25rem; }
.exito-datos {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem;
    margin-top: 1rem; padding: .8rem .6rem;
    background: var(--superficie-2); border: 1px solid var(--borde); border-radius: var(--r);
}
.exito-datos .i-lbl { font-size: .68rem; color: var(--gris); text-transform: uppercase; letter-spacing: .04em; }
.exito-datos .i-val { font-weight: 700; font-size: .88rem; word-break: break-word; }

/* --------------------------------------------------------------- utilidades */
.muted { color: var(--gris); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .84rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.flex { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hidden { display: none !important; }
.price { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ================================================================== login */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
    background:
        radial-gradient(1000px 520px at 15% -10%, rgba(169, 47, 46, .35), transparent 60%),
        radial-gradient(800px 420px at 110% 110%, rgba(169, 47, 46, .22), transparent 60%),
        var(--grafito);
}
.login-card {
    width: 100%; max-width: 400px;
    background: var(--superficie);
    border-radius: var(--r-xl);
    box-shadow: 0 24px 60px rgba(0, 0, 0, .38);
    overflow: hidden;
}
.login-brand { text-align: center; padding: 1.6rem 1.2rem .4rem; }
.login-logo { width: 62px; height: 62px; border-radius: var(--r-full); box-shadow: 0 6px 18px rgba(169, 47, 46, .3); }
.login-title { font-size: 1.2rem; font-weight: 700; margin-top: .6rem; letter-spacing: -.02em; }
.login-sub { color: var(--gris); font-size: .84rem; margin-top: .1rem; }
.login-body { padding: 1.1rem 1.3rem 1.3rem; }
.login-foot {
    text-align: center; padding: .9rem 1rem 1.1rem;
    border-top: 1px solid var(--borde); color: var(--gris-claro);
}
.login-mills { height: 26px; width: auto; opacity: .85; margin-bottom: .3rem; }
.login-hint {
    margin-top: .8rem; padding: .6rem .7rem;
    background: var(--superficie-2); border: 1px solid var(--borde);
    border-radius: var(--r); font-size: .8rem; color: var(--gris);
}

/* --------------------------------------------------------------- cartesian */
.cart-lines { min-height: 40px; }
.cart-total-row {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: .6rem; padding: .7rem .95rem;
    border-top: 1px solid var(--borde);
    background: var(--superficie-2);
}
.cart-total-row:first-child { border-top: 0; }

.catalog-actions {
    display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
    padding: 0 .9rem .7rem;
}
.catalog-actions .input-num { flex: 0 0 78px; }
.catalog-actions select { flex: 1 1 auto; max-width: 160px; min-width: 0; }
.catalog-actions .btn { flex: 0 0 auto; margin-left: auto; }

.cliente-actual {
    display: flex; align-items: center; gap: .7rem;
    padding: .7rem .9rem;
    border-left: 3px solid var(--rojo);
}

/* Pie del carrito: la acción principal (confirmar) queda siempre a la vista,
   tanto en la hoja del celular como en el panel de escritorio. */
.cart-foot {
    flex: 0 0 auto;
    margin: .8rem -.95rem -.9rem;
    padding: .7rem .95rem .9rem;
    border-top: 1px solid var(--borde);
    background: var(--superficie);
}

.cart-backdrop {
    position: fixed; inset: 0; z-index: 64;
    background: rgba(20, 22, 26, .5);
    display: none;
}
.cart-backdrop.open { display: block; }
body.no-scroll { overflow: hidden; }

/* --------------------------------------------------------------- dialogos */
dialog.mp-dialog {
    padding: 0; border: 0;
    width: 100%; max-width: 520px;
    max-height: 92vh;
    margin: auto auto 0;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    background: var(--superficie); color: var(--grafito);
    box-shadow: var(--sombra-3);
    overflow: visible;
}
dialog.mp-dialog::backdrop { background: rgba(20, 22, 26, .55); }
.mp-dialog-head {
    display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    padding: .85rem 1rem; border-bottom: 1px solid var(--borde);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    background: var(--superficie);
}
.mp-dialog-head h3 { font-size: 1rem; display: flex; align-items: center; gap: .4rem; }
.mp-dialog-body { padding: 1rem; max-height: 62vh; overflow-y: auto; }
.mp-dialog-foot {
    display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap;
    padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--borde);
    background: var(--superficie);
    border-radius: 0 0 var(--r-xl) var(--r-xl);
}

/* --------------------------------------------------------- solo lectores */
.mp-sr {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* --------------------------------------------------------------- estados */
.is-loading { position: relative; }
.is-loading::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(255, 255, 255, .6);
    border-radius: inherit;
}

/* =========================================================== escritorio */
@media (min-width: 768px) {
    .main { padding: 1.2rem 1.1rem calc(var(--nav-h) + 1.5rem); }
    .tiles { grid-template-columns: repeat(4, 1fr); }
    .stat-row { gap: .7rem; }
    .modal-back { align-items: center; padding: 1rem; }
    .modal { border-radius: var(--r-xl); max-height: 86vh; }
    .toast-zone { bottom: 1rem; }
    .page-title { font-size: 1.5rem; }
    .sell-layout { grid-template-columns: minmax(0, 1.35fr) minmax(320px, .9fr); align-items: start; }
    /* El carrito es una columna: la lista scrollea y el pie con el boton de
       confirmar queda siempre a la vista. */
    .cart-panel {
        position: sticky; top: 74px;
        display: flex; flex-direction: column;
        max-height: calc(100vh - 92px);
    }
    .cart-panel #carrito { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
    .cart-bar {
        position: sticky; bottom: 0; left: auto; right: auto;
        border-radius: var(--r-lg); margin: 0; padding: .7rem .9rem;
        background: var(--superficie); color: var(--grafito);
        border: 1px solid var(--borde); box-shadow: var(--sombra-2);
    }
    .cart-bar .cb-label { color: var(--gris); }
    .info-grid { grid-template-columns: repeat(3, 1fr); }
    /* En escritorio el carrito siempre esta a la vista: no hace falta hoja. */
    .cart-bar { display: none !important; }
    .cart-backdrop { display: none !important; }
    dialog.mp-dialog { margin: auto; border-radius: var(--r-xl); }
    .mp-dialog-head { border-radius: var(--r-xl) var(--r-xl) 0 0; }
    .mp-dialog-foot { border-radius: 0 0 var(--r-xl) var(--r-xl); }
}

@media (min-width: 1024px) {
    /* A partir de aca entra la navegacion de escritorio y sale la barra inferior. */
    .tabbar { display: none; }
    .desknav { display: flex; }
    .main { padding: 1.4rem 1.5rem 3rem; }
}

/* En celular el carrito vive en una hoja que se abre desde la barra fija. */
@media (max-width: 767px) {
    /* En el celular todo control tactil se mantiene por encima de 44px. */
    .btn-sm { min-height: var(--tap); padding: .45rem .9rem; }
    .segmented button, .segmented a { min-height: var(--tap); }
    .cart-panel { display: none; }
    /* La hoja se apoya arriba de la barra de navegacion: si bajara hasta el
       fondo, la barra taparia justo el boton de confirmar. */
    .cart-panel.open {
        display: flex; flex-direction: column;
        position: fixed; left: 0; right: 0; bottom: var(--nav-h); z-index: 66;
        max-height: 88vh;
        margin: 0; border-radius: var(--r-xl) var(--r-xl) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: var(--sombra-3);
    }
    /* Scrollea la lista, no la hoja entera: el pie no se va de la vista. */
    .cart-panel.open #carrito { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
    /* El mapa no debe comerse media pantalla del celular. */
    .map-lg { height: 260px; }
}

/* Ajustes finos para pantallas muy angostas */
@media (max-width: 380px) {
    .tiles { gap: .45rem; }
    .tile { padding: .7rem .75rem; min-height: 84px; }
    .main { padding-left: .6rem; padding-right: .6rem; }
}

/* Paises que piden menos movimiento */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
