/* =====================================================
   INVENTARIO CONGELADO UMD - Estilos v2.2
   Drawer lateral + vistas globales de palets
   ===================================================== */

/* --- VARIABLES --- */
:root {
    --bg: #1a1a1f;
    --bg2: #222228;
    --card: #2a2a32;
    --card-h: #32323c;
    --inbg: #1e1e24;
    --bd: #3a3a44;
    --bd2: #44444f;
    --tx: #e8e4df;
    --tx2: #a09a92;
    --tx3: #706a62;
    --rojo: #e53030;
    --verde: #5cb87a;
    --verde-t: rgba(92,184,122,.12);
    --amarillo: #d4a83a;
    --amarillo-t: rgba(212,168,58,.12);
    --naranja: #d48a3a;
    --naranja-t: rgba(212,138,58,.12);
    --rojo-a: #d44a3a;
    --rojo-at: rgba(212,74,58,.12);
    --cs: #c49a6c;
    --cc: #d48a3a;
    --cp: #5cb87a;
    --cpc: #d4a83a;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'DM Sans', -apple-system, sans-serif;
    --r: 10px;
    --rs: 6px;
    --navh: 62px;
    --drawer-w: 270px;
}

/* --- RESET --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--sans); background: var(--bg); color: var(--tx); min-height: 100dvh; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
button { font-family: var(--sans); }

/* --- SVG ICONS --- */
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.ico-sm { width: 14px; height: 14px; }
.ico-xs { width: 12px; height: 12px; }
.drawer-ico { width: 18px; height: 18px; opacity: .7; }
.drawer-item.on .drawer-ico { opacity: 1; }
.sort-btn .ico { margin-right: 4px; }

/* --- VISTAS --- */
.vista { display: none; flex-direction: column; min-height: 100dvh; }
.vista.on { display: flex; }

/* --- DRAWER OVERLAY --- */
.drawer-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 199; background: rgba(0,0,0,.55);
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
    -webkit-tap-highlight-color: transparent;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

/* --- DRAWER LATERAL --- */
.drawer {
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 200; width: var(--drawer-w);
    background: var(--bg2);
    border-right: 1px solid var(--bd);
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 14px 14px;
    border-bottom: 1px solid var(--bd);
}
.drawer-logo {
    width: 32px; height: 32px; border-radius: 8px;
    overflow: hidden; flex-shrink: 0;
}
.drawer-logo img { width: 100%; height: 100%; object-fit: contain; }
.drawer-title { flex: 1; min-width: 0; }
.drawer-app { font-size: .92rem; font-weight: 700; }
.drawer-ver { font-family: var(--mono); font-size: .64rem; color: var(--tx3); }
.drawer-close {
    background: none; border: none; color: var(--tx3);
    cursor: pointer; width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--rs); transition: .15s;
    -webkit-tap-highlight-color: transparent;
}
.drawer-close .ico { width: 16px; height: 16px; }
.drawer-close:hover { color: var(--tx); background: var(--card); }

.drawer-nav {
    flex: 1; padding: 8px 0; overflow-y: auto;
}
.drawer-item {
    display: flex; align-items: center; gap: 12px;
    width: 100%; padding: 13px 18px;
    background: none; border: none;
    color: var(--tx2); font-size: .84rem; font-weight: 500;
    text-align: left; cursor: pointer;
    transition: .15s; position: relative;
    -webkit-tap-highlight-color: transparent;
}
.drawer-item:hover { background: var(--card); color: var(--tx); }
.drawer-item.on {
    color: var(--tx); font-weight: 600;
    background: rgba(229,48,48,.08);
}
.drawer-item.on::before {
    content: ''; position: absolute;
    left: 0; top: 6px; bottom: 6px; width: 3px;
    background: var(--rojo); border-radius: 0 3px 3px 0;
}
.drawer-label { flex: 1; }

.drawer-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--bd);
    font-size: .72rem; color: var(--tx3);
}
.drawer-sync-label { margin-bottom: 2px; }
.drawer-sync-time { font-family: var(--mono); color: var(--tx2); }

/* --- HEADER --- */
.hdr { position: sticky; top: 0; z-index: 100; background: var(--bg2); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--bd); }
.hdr-r { height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; gap: 8px; }
.hdr-l { display: flex; align-items: center; gap: 8px; min-width: 0; }
.logo { width: 26px; height: 26px; border-radius: 6px; flex-shrink: 0; overflow: hidden; }
.logo img { width: 100%; height: 100%; object-fit: contain; }
.hdr-t { font-size: .84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-ri { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

/* --- SYNC INDICATOR --- */
.sync { display: flex; align-items: center; gap: 5px; font-size: .72rem; color: var(--tx2); flex-shrink: 0; }
.sd { width: 7px; height: 7px; border-radius: 50%; background: var(--verde); box-shadow: 0 0 6px var(--verde); }
.sd.w { background: var(--amarillo); box-shadow: 0 0 6px var(--amarillo); }
.sd.b { background: var(--rojo-a); box-shadow: 0 0 6px var(--rojo-a); }
.st { font-family: var(--mono); font-size: .72rem; }

/* --- ICON BUTTONS --- */
.ib { display: flex; align-items: center; justify-content: center; background: 0; border: 0; color: var(--tx2); width: 36px; height: 36px; border-radius: var(--rs); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: .15s; }
.ib:hover { color: var(--rojo); }
.ib:active { transform: scale(.92); }
.ib.on { color: var(--rojo); }
.ibr { border: 1px solid var(--bd2); }
.ibr:hover { border-color: var(--rojo); }
.ibr.sp .is { animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* --- BACK BUTTON --- */
.bk { display: flex; align-items: center; gap: 3px; background: 0; border: 0; color: var(--rojo); font-family: var(--sans); font-size: .78rem; font-weight: 600; cursor: pointer; padding: 4px 0; -webkit-tap-highlight-color: transparent; }
.bk:active { opacity: .7; }
.bk svg { width: 18px; height: 18px; }

/* --- SEARCH BAR --- */
.sb { padding: 0 12px; overflow: hidden; max-height: 0; transition: max-height .25s, padding .25s; background: var(--bg2); }
.sb.op { max-height: 56px; padding: 6px 12px 8px; border-bottom: 1px solid var(--bd); }
.sw { position: relative; display: flex; align-items: center; gap: 8px; }
.si-i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--tx3); pointer-events: none; display: flex; align-items: center; }
.si { width: 100%; padding: 8px 34px 8px 32px; background: var(--inbg); border: 1px solid var(--bd); border-radius: var(--r); color: var(--tx); font-family: var(--sans); font-size: .82rem; outline: 0; transition: .2s; }
.si:focus { border-color: var(--rojo); }
.si::placeholder { color: var(--tx3); }
.sx { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: var(--card); border: 0; color: var(--tx3); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; display: none; align-items: center; justify-content: center; }
.sx.v { display: flex; }
.sn { font-family: var(--mono); font-size: .66rem; color: var(--tx3); white-space: nowrap; min-width: 48px; text-align: right; display: none; }
.sn.v { display: block; }

/* --- SORT BAR (ordenacion disponibles) --- */
.sort-bar {
    display: flex; gap: 6px;
    padding: 6px 12px 8px;
    background: var(--bg2);
    border-bottom: 1px solid var(--bd);
}
.sort-btn {
    flex: 1; padding: 7px 10px;
    background: var(--inbg); border: 1px solid var(--bd);
    border-radius: var(--rs); color: var(--tx3);
    font-family: var(--sans); font-size: .74rem; font-weight: 500;
    cursor: pointer; transition: .15s;
    -webkit-tap-highlight-color: transparent;
    display: flex; align-items: center; justify-content: center; gap: 4px;
}
.sort-btn:hover { border-color: var(--bd2); color: var(--tx2); }
.sort-btn.on {
    background: rgba(229,48,48,.1);
    border-color: var(--rojo);
    color: var(--rojo);
    font-weight: 600;
}

/* --- BODY AREAS --- */
.ba { flex: 1; padding: 8px 10px 16px; padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }

/* --- GRUPO HEADER (separador de producto en listados globales) --- */
.grupo-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 4px 6px;
    margin-top: 4px;
    border-bottom: 1px solid var(--bd);
    margin-bottom: 8px;
}
.grupo-header:first-child { margin-top: 0; }
.grupo-nombre {
    font-size: .78rem; font-weight: 700;
    color: var(--tx); text-transform: uppercase;
    letter-spacing: .3px;
}
.grupo-count {
    font-family: var(--mono); font-size: .68rem;
    color: var(--tx3); background: var(--card);
    padding: 2px 8px; border-radius: 10px;
}

/* --- PRODUCT NAME INSIDE PALET CARD (vista por caducidad) --- */
.xprod {
    font-size: .68rem; font-weight: 600;
    color: var(--rojo); text-transform: uppercase;
    letter-spacing: .3px; margin-bottom: 2px;
}

/* --- PRODUCT CARDS (RESUMEN) --- */
.pc { background: var(--card); border: 1px solid var(--bd); border-radius: var(--r); padding: 14px 16px 12px; margin-bottom: 10px; cursor: pointer; transition: background .1s, border-color .15s; -webkit-tap-highlight-color: transparent; }
.pc:hover { background: var(--card-h); border-color: var(--bd2); }
.pc:active { background: var(--card); }
.pn { font-size: .92rem; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.pn .ar { color: var(--tx3); font-size: .8rem; }
.pv { display: flex; gap: 0; }
.pvl { flex: 1; text-align: center; padding: 4px 0; }
.pvl:not(:last-child) { border-right: 1px solid var(--bd); }
.pvn { font-family: var(--mono); font-size: 1rem; font-weight: 700; line-height: 1.2; }
.pvt { font-size: .6rem; text-transform: uppercase; letter-spacing: .4px; color: var(--tx3); margin-top: 2px; }

/* --- DETAIL VIEW --- */
.dt { padding: 14px 14px 8px; font-size: 1.15rem; font-weight: 700; }
.db { flex: 1; padding: 0 10px; padding-bottom: calc(var(--navh) + env(safe-area-inset-bottom) + 12px); padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }

/* --- LOTE CARD --- */
.lc { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; margin-bottom: 8px; background: var(--card); border-radius: var(--rs); border: 1px solid var(--bd); gap: 10px; }
.li { flex: 1; min-width: 0; }
.lk { font-family: var(--mono); font-size: .84rem; color: var(--tx2); }
.ls { font-size: .72rem; color: var(--tx3); margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.lq { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; color: var(--cs); white-space: nowrap; }

/* --- PALET CARD (expandable) --- */
.xc { background: var(--card); border-radius: var(--r); border: 1px solid var(--bd); margin-bottom: 10px; overflow: hidden; transition: border-color .2s; }
.xc.ex { border-color: var(--bd2); }
.xh { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; cursor: pointer; gap: 12px; -webkit-tap-highlight-color: transparent; }
.xh:active { background: var(--card-h); }
.xl { flex: 1; min-width: 0; }
.xk { font-family: var(--mono); font-size: .88rem; font-weight: 600; margin-bottom: 4px; }
.xm { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .72rem; color: var(--tx3); }
.xsp { color: var(--bd2); }
.xpesos { display: flex; gap: 12px; margin-top: 5px; font-size: .7rem; color: var(--tx3); }
.xpesos span { font-family: var(--mono); }
.xpw { color: var(--tx2); font-weight: 600; }
.xr { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.xq { font-family: var(--mono); font-size: .95rem; font-weight: 700; white-space: nowrap; }
.xv { color: var(--tx3); font-size: .65rem; transition: transform .2s; }
.xc.ex .xv { transform: rotate(180deg); }

/* --- PROGRESS BAR (consumo) --- */
.br { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.bt { flex: 1; height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.bf { height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--naranja), var(--amarillo)); transition: width .5s; }
.bp { font-family: var(--mono); font-size: .66rem; color: var(--naranja); min-width: 30px; text-align: right; }

/* --- COMPOSITION (expandable content) --- */
.xd { max-height: 0; overflow: hidden; transition: max-height .3s ease; background: var(--bg); }
.xc.ex .xd { max-height: 800px; }
.ct { font-size: .64rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--tx3); padding: 8px 14px 4px; border-top: 1px solid var(--bd); }
.cr { display: flex; align-items: center; justify-content: space-between; padding: 5px 14px; font-size: .78rem; }
.cr:last-of-type { padding-bottom: 10px; }
.ck { font-family: var(--mono); font-size: .74rem; color: var(--tx2); }
.cq { font-family: var(--mono); font-size: .78rem; font-weight: 600; color: var(--cs); }
/* Lote agotado en composicion consumo */
.cr.agotado .ck { color: var(--tx3); text-decoration: line-through; opacity: .6; }
.cr.agotado .cq { color: var(--tx3); opacity: .6; }

/* --- PALET ACTIONS --- */
.xa { padding: 8px 14px 12px; border-top: 1px solid var(--bd); background: var(--bg); display: flex; gap: 8px; flex-wrap: wrap; }
.bp2 { display: inline-flex; align-items: center; gap: 5px; padding: 8px 16px; border-radius: var(--rs); background: var(--rojo); color: #fff; border: 0; font-family: var(--sans); font-size: .76rem; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: .15s; }
.bp2:hover { opacity: .9; }
.bp2:active { transform: scale(.97); }
.bp2:disabled { opacity: .5; cursor: not-allowed; }
.bp2 svg { width: 15px; height: 15px; }

/* --- AGE INDICATORS --- */
.ed { display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono); font-size: .66rem; font-weight: 600; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.eo { background: var(--verde-t); color: var(--verde); }
.ew { background: var(--amarillo-t); color: var(--amarillo); }
.ec { background: var(--rojo-at); color: var(--rojo-a); }
.bw { border-left: 3px solid var(--amarillo); }
.bc { border-left: 3px solid var(--rojo-a); }

/* --- BOTTOM NAV --- */
.nb { position: fixed; bottom: 0; left: 0; right: 0; z-index: 100; background: var(--bg2); border-top: 1px solid var(--bd); padding: 0 8px; padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: space-around; backdrop-filter: blur(12px); }
.nn { flex: 1; text-align: center; padding: 12px 4px 10px; background: 0; border: 0; cursor: pointer; font-family: var(--sans); position: relative; transition: .2s; -webkit-tap-highlight-color: transparent; }
.nn::before { content: ''; position: absolute; top: 0; left: 25%; right: 25%; height: 2px; background: transparent; transition: .2s; }
.nn.on::before { background: var(--rojo); left: 15%; right: 15%; }
.nv { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; color: var(--cs); line-height: 1.1; }
.nl { font-size: .64rem; color: var(--tx3); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }
.nn.on .nl { color: var(--tx); font-weight: 600; }
.nn:not(.on):active { opacity: .7; }
.pa { display: none; }
.pa.on { display: block; }

/* --- LOADING & EMPTY STATES --- */
.ld, .em { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 50px 20px; text-align: center; color: var(--tx3); }
.spi { width: 28px; height: 28px; border: 3px solid var(--bd); border-top-color: var(--rojo); border-radius: 50%; animation: sp .8s linear infinite; margin-bottom: 10px; }
.ei { font-size: 1.8rem; margin-bottom: 8px; opacity: .5; }

/* --- RESPONSIVE --- */
@media (min-width: 640px) { .ba, .db { padding-left: 16px; padding-right: 16px; } .pc { padding: 14px 18px 12px; } }
@media (min-width: 900px) { .ba, .db { max-width: 700px; margin-left: auto; margin-right: auto; } }
