:root {
    --primary: #D57F9F;
    --primary-dark: #c06588;
    --primary-light: #f0c4c2;
    --primary-soft: #fef5f4;
    --blush: #f7e4e8;
    --bg: #fbf6f7;
    --bg-deep: #f3e6ea;
    --surface: #ffffff;
    --text: #2f2a2c;
    --text-muted: #6f6468;
    --border: #ece2e5;
    --ok: #2e7d32;
    --ok-bg: #e8f5e9;
    --error: #c62828;
    --error-bg: #ffebee;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 10px 28px rgba(80, 40, 55, 0.08);
    --shadow-soft: 0 4px 14px rgba(80, 40, 55, 0.06);
    --font: 'Nunito', 'Segoe UI', system-ui, sans-serif;
    --header-h: 4.25rem;
    --nav-inferior-h: 4.35rem;
    --touch: 44px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font);
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(213, 127, 159, 0.18), transparent 55%),
        radial-gradient(900px 420px at 100% 0%, rgba(240, 196, 194, 0.35), transparent 50%),
        linear-gradient(180deg, var(--bg) 0%, #fff9fa 45%, var(--bg-deep) 100%);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
}

button,
input,
select,
textarea {
    font: inherit;
}

:focus-visible {
    outline: 3px solid rgba(213, 127, 159, 0.45);
    outline-offset: 2px;
}

/* ---------- Header / navbar ---------- */

.app-header {
    background: linear-gradient(120deg, rgba(240, 196, 194, 0.95), rgba(245, 212, 210, 0.92) 55%, rgba(253, 232, 230, 0.95));
    backdrop-filter: blur(10px);
    padding: 0.7rem 1.1rem;
    box-shadow: 0 2px 16px rgba(80, 40, 55, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.55);
}

.app-header-inner {
    max-width: 1180px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    flex-wrap: wrap;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.app-brand img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(80, 40, 55, 0.12);
}

.app-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.app-nav a,
.app-nav button,
.nav-mas-btn {
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.7);
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.app-nav a:hover,
.app-nav button:hover,
.nav-mas-btn:hover {
    background: #fff;
    box-shadow: var(--shadow-soft);
}

.app-nav a.activo {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: var(--shadow-soft);
}

.nav-mas {
    position: relative;
}

.nav-mas-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.45rem);
    min-width: 240px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: 0 16px 40px rgba(80, 40, 55, 0.16);
    border: 1px solid var(--border);
    padding: 0.45rem;
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    animation: fadeSlide 0.16s ease;
}

.nav-mas-panel[hidden] {
    display: none !important;
}

.nav-mas-panel a,
.nav-mas-panel button {
    width: 100%;
    justify-content: flex-start;
    border-radius: 10px;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text);
    min-height: 42px;
}

.nav-mas-panel a:hover,
.nav-mas-panel button:hover {
    background: var(--primary-soft);
}

.nav-mas-panel a.activo {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.nav-mas-sep {
    height: 1px;
    background: var(--border);
    margin: 0.3rem 0.2rem;
}

.nav-mas-usuario {
    margin: 0.25rem 0.55rem 0.15rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* ---------- Layout ---------- */

.app-main {
    flex: 1;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.5rem 1.15rem 2.25rem;
}

.app-titulo {
    margin: 0;
    font-size: clamp(1.45rem, 3.5vw, 1.95rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.app-footer {
    text-align: center;
    padding: 1.1rem 1rem;
    padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid rgba(236, 226, 229, 0.8);
}

/* ---------- Cabeceras de pagina ---------- */

.pagina-cabecera {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.35rem;
}

.pagina-cabecera .app-titulo {
    margin: 0;
}

.pagina-eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-dark);
}

.pagina-ayuda {
    margin: 0.4rem 0 0;
    color: var(--text-muted);
    font-size: 0.98rem;
    max-width: 38rem;
}

.seccion-titulo {
    margin: 1.75rem 0 0.9rem;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text);
}

.titulo-con-accion {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.titulo-con-accion .app-titulo {
    margin-bottom: 0;
}

.titulo-con-accion .seccion-titulo {
    margin-top: 0;
}

/* ---------- Atajos del inicio ---------- */

.atajos {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 0.5rem;
}

.atajo {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    text-decoration: none;
    color: inherit;
    background: var(--surface);
    border: 1px solid rgba(213, 127, 159, 0.16);
    border-radius: var(--radius);
    padding: 1rem 1.05rem;
    box-shadow: var(--shadow-soft);
    min-height: 88px;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.atajo:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: rgba(213, 127, 159, 0.35);
}

.atajo-icono {
    width: 3rem;
    height: 3rem;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.atajo-live .atajo-icono { background: #ffe8ef; color: #c04575; }
.atajo-vender .atajo-icono { background: #e8f7ef; color: #2e7d32; }
.atajo-comprar .atajo-icono { background: #fff0e6; color: #c26a2d; }
.atajo-productos .atajo-icono { background: #e8f2f7; color: #3d6f8a; }
.atajo-listas .atajo-icono { background: #e7f1ea; color: #3f6a4d; }
.atajo-estadisticas .atajo-icono { background: #f3eaf1; color: #8a4a6d; }
.atajo-exportar .atajo-icono { background: #efe8f4; color: #6b4c8a; }

.atajo-texto {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.atajo-texto strong {
    font-size: 1.05rem;
    font-weight: 800;
}

.atajo-texto span {
    font-size: 0.86rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.atajo-flecha {
    margin-left: auto;
    color: var(--primary);
    opacity: 0.7;
}

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(80, 40, 55, 0.05);
    padding: 1.25rem;
}

.card h2 {
    margin: 0 0 0.9rem;
    font-size: 1rem;
    font-weight: 800;
}

.card-stat {
    display: flex;
    align-items: center;
    min-height: 110px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(254, 245, 244, 0.95));
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.stat-valor {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1;
    letter-spacing: -0.03em;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---------- Listas / vacios ---------- */

.lista {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lista li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.lista li:last-child {
    border-bottom: none;
}

.lista .valor {
    font-weight: 800;
    white-space: nowrap;
}

.lista .valor.alerta {
    color: var(--error);
}

.vacio {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.estado-vacio {
    text-align: center;
    padding: 1.25rem 0.5rem 0.5rem;
    color: var(--text-muted);
}

.estado-vacio i {
    font-size: 1.6rem;
    color: var(--primary-light);
    margin-bottom: 0.55rem;
    display: block;
}

.estado-vacio p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.ayuda {
    margin: 0;
    font-size: 0.86rem;
    color: var(--text-muted);
}

/* ---------- Login ---------- */

.guest-body {
    background:
        radial-gradient(900px 420px at 15% 10%, rgba(213, 127, 159, 0.28), transparent 55%),
        radial-gradient(700px 380px at 90% 20%, rgba(240, 196, 194, 0.45), transparent 50%),
        linear-gradient(165deg, #fff7f8 0%, #f7e8ec 55%, #f3dce3 100%);
}

.login-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.25rem;
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 22px;
    box-shadow: 0 18px 50px rgba(80, 40, 55, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.8);
    padding: 2rem 1.7rem 1.6rem;
    text-align: center;
    backdrop-filter: blur(8px);
    animation: fadeSlide 0.28s ease;
}

.login-box img {
    width: 84px;
    height: 84px;
    object-fit: contain;
    margin-bottom: 0.35rem;
}

.login-marca {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
}

.login-box h1 {
    margin: 0.85rem 0 0.35rem;
    font-size: 1.35rem;
    font-weight: 800;
}

.login-ayuda {
    margin: 0 0 1.35rem;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.login-box label {
    display: block;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
}

.login-box input {
    width: 100%;
    padding: 0.85rem 0.95rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: #fff;
    outline-color: var(--primary);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(213, 127, 159, 0.18);
}

.btn-primario {
    width: 100%;
    padding: 0.9rem;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 1.02rem;
    font-weight: 800;
    cursor: pointer;
    min-height: var(--touch);
    box-shadow: 0 8px 18px rgba(213, 127, 159, 0.35);
    transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-primario:hover {
    filter: brightness(1.04);
    transform: translateY(-1px);
}

.alerta-error {
    background: var(--error-bg);
    color: var(--error);
    border-radius: var(--radius-sm);
    padding: 0.8rem 0.95rem;
    margin-bottom: 1.1rem;
    font-size: 0.88rem;
    text-align: left;
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    border: 1px solid rgba(198, 40, 40, 0.12);
}

.alerta-error ul {
    margin: 0;
    padding-left: 1.1rem;
}

.login-link {
    margin: 1.25rem 0 0;
    font-size: 0.9rem;
    font-weight: 700;
}

.login-link a {
    text-decoration: none;
}

.login-link a:hover {
    text-decoration: underline;
}

.credenciales-demo {
    margin-top: 1.5rem;
    padding-top: 1.1rem;
    border-top: 1px dashed var(--border);
    text-align: left;
}

.credenciales-titulo {
    margin: 0 0 0.6rem;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.credencial {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--primary-soft);
    border: 1px solid var(--primary-light);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.8rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.credencial:hover {
    background: #fff;
}

.credencial code {
    display: block;
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.credencial span {
    display: block;
    margin-top: 0.15rem;
    font-size: 0.76rem;
    color: var(--text-muted);
}

/* ---------- Buscador de la navbar ---------- */

.app-buscador {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    padding: 0 0.35rem 0 0.9rem;
    flex: 1 1 220px;
    max-width: 400px;
    min-height: var(--touch);
    box-shadow: inset 0 1px 2px rgba(80, 40, 55, 0.04);
}

.app-buscador i {
    color: var(--primary);
    font-size: 0.9rem;
}

.app-buscador input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.55rem 0;
    font-size: 16px;
    outline: none;
    min-width: 0;
}

.app-buscador button[type="submit"] {
    border: none;
    background: var(--primary);
    color: #fff;
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    font-size: 0.84rem;
    font-weight: 800;
    cursor: pointer;
    min-height: 36px;
}

.app-buscador-camara {
    background: rgba(255, 255, 255, 0.95) !important;
    color: var(--primary) !important;
    padding: 0.45rem 0.65rem !important;
    line-height: 1;
    border: 1px solid var(--primary-light) !important;
}

/* ---------- Avisos ---------- */

.alerta-exito {
    background: var(--ok-bg);
    color: var(--ok);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    margin-bottom: 1.15rem;
    font-size: 0.92rem;
    font-weight: 700;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    border: 1px solid rgba(46, 125, 50, 0.12);
}

.app-main .alerta-error {
    max-width: none;
}

/* ---------- Filtros ---------- */

.filtros {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.9rem;
    background: var(--surface);
    padding: 1rem 1.15rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(80, 40, 55, 0.04);
    margin-bottom: 1.15rem;
}

.filtros label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-right: 0.35rem;
}

.filtros select {
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 0.92rem;
    min-height: 42px;
}

.filtros .filtro-check {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}

.filtros .filtro-check input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.filtros .contador {
    margin-left: auto;
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---------- Tabla ---------- */

.tabla-wrapper {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(80, 40, 55, 0.04);
    overflow-x: auto;
}

.tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.tabla th,
.tabla td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.tabla th {
    background: linear-gradient(180deg, #f8d6d8, var(--primary-light));
    font-weight: 800;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #5a3f47;
}

.tabla td.nombre {
    white-space: normal;
    min-width: 220px;
    font-weight: 600;
}

.tabla tbody tr:last-child td {
    border-bottom: none;
}

.tabla tbody tr {
    transition: background 0.12s ease;
}

.tabla tbody tr:hover {
    background: var(--primary-soft);
}

.tabla .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.tabla .acciones {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.pill {
    display: inline-flex;
    align-items: center;
    font-size: 0.76rem;
    font-weight: 800;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
}

.pill-ok {
    background: var(--ok-bg);
    color: var(--ok);
}

.pill-cero {
    background: var(--error-bg);
    color: var(--error);
}

.pill-neutro {
    background: #f1f1f1;
    color: var(--text-muted);
}

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 800;
    padding: 0.55rem 0.95rem;
    border: none;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    min-height: var(--touch);
    transition: filter 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.btn:hover {
    filter: brightness(1.05);
}

.btn-suave {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border: 1px solid var(--primary-light);
}

.btn-gris {
    background: #eceff1;
    color: var(--text-muted);
}

.btn-bloque {
    width: 100%;
}

.btn-icono {
    padding: 0.5rem 0.7rem;
    line-height: 1;
}

.btn-peligro {
    background: #fdecea;
    color: var(--error);
}

.btn-peligro:hover {
    background: #f9d7d3;
    filter: none;
}

/* ---------- Formularios ---------- */

.form-card {
    max-width: 540px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(80, 40, 55, 0.04);
    padding: 1.75rem;
}

.campo {
    margin-bottom: 1.1rem;
}

.campo label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.campo input,
.campo select {
    width: 100%;
    padding: 0.8rem 0.95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: #fff;
    outline-color: var(--primary);
    font-family: inherit;
    color: var(--text);
}

.campo .ayuda {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.campo-con-boton {
    display: flex;
    gap: 0.5rem;
}

.campo-con-boton input {
    flex: 1;
}

/* ---------- Modales ---------- */

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(40, 24, 30, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    backdrop-filter: blur(2px);
}

.modal-contenido {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 420px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    animation: fadeSlide 0.18s ease;
}

.modal-contenido h2 {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
}

.modal-actual {
    margin: 0 0 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.modal-cerrar {
    position: absolute;
    top: 0.6rem;
    right: 0.8rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    min-width: var(--touch);
    min-height: var(--touch);
}

.modal-botones {
    display: flex;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

.modal-botones .btn {
    flex: 1;
}

/* ---------- Escaner de camara ---------- */

.escaner {
    margin-top: 1.5rem;
}

.escaner-video {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 0.75rem 0;
}

.escaner-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.escaner-estado {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.escaner-estado.ok {
    color: var(--ok);
    font-weight: 700;
}

.escaner-estado.error {
    color: var(--error);
}

.escaner-overlay {
    position: fixed;
    inset: 0;
    z-index: 220;
    background: rgba(20, 12, 16, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.escaner-overlay[hidden] {
    display: none;
}

.escaner-overlay-caja {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.15rem;
    width: 100%;
    max-width: 460px;
    max-height: 100%;
    overflow-y: auto;
    animation: fadeSlide 0.18s ease;
}

.escaner-overlay-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.escaner-overlay-cabecera h2 {
    margin: 0;
    font-size: 1.1rem;
}

.escaner-overlay-cabecera .modal-cerrar {
    position: static;
}

.escaner-mira {
    position: absolute;
    top: 50%;
    left: 8%;
    right: 8%;
    height: 26%;
    transform: translateY(-50%);
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

.escaner-manual {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.escaner-manual input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    font-size: 16px;
}

body.sin-scroll {
    overflow: hidden;
}

/* ---------- Live ---------- */

.live-cabecera {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.live-cabecera .app-titulo {
    margin-bottom: 0;
}

.live-estado {
    border: 1px solid rgba(213, 127, 159, 0.18);
}

.live-estado-fila {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.live-estado-acciones .btn {
    font-size: 1rem;
}

.live-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.15rem;
    margin-top: 1.15rem;
}

@media (min-width: 960px) {
    .live-grid {
        grid-template-columns: minmax(0, 4fr) minmax(0, 6fr);
        align-items: start;
    }
}

.live-nuevo-pedido {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.live-nuevo-pedido .entrada {
    flex: 1;
}

.tabla .fila-activa {
    background: var(--primary-soft);
}

.live-resultados {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0.5rem 0 1rem;
    max-height: 220px;
    overflow-y: auto;
}

.live-resultado {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    text-align: left;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    cursor: pointer;
    min-height: var(--touch);
    transition: border-color 0.12s ease, background 0.12s ease;
}

.live-resultado:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.live-nuevo-producto {
    margin: 0.75rem 0 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.9rem;
    background: #fff;
}

.live-nuevo-producto summary {
    cursor: pointer;
    font-weight: 800;
    color: var(--primary-dark);
    min-height: 36px;
    display: flex;
    align-items: center;
}

.live-form-nuevo {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

@media (min-width: 640px) {
    .live-form-nuevo {
        grid-template-columns: 2fr 1fr 0.7fr auto;
    }
}

.live-total {
    font-size: 1.2rem;
    margin: 1rem 0;
    font-weight: 800;
}

.live-pedido-historial {
    margin-bottom: 1.25rem;
}

.live-pedido-cabecera {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: baseline;
    margin-bottom: 0.75rem;
}

.live-pedido-cabecera h2 {
    margin: 0;
}

.live-toast {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--nav-inferior-h) + 1rem);
    z-index: 300;
    background: var(--ok);
    color: #fff;
    padding: 0.8rem 1.05rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-weight: 700;
    max-width: min(90vw, 360px);
    animation: fadeSlide 0.18s ease;
}

.live-toast.error {
    background: var(--error);
}

textarea.entrada {
    width: 100%;
    resize: vertical;
    font-family: inherit;
}

/* ---------- Miniaturas de producto ---------- */

.celda-foto {
    width: 3.5rem;
    position: relative;
}

.producto-miniatura {
    width: 2.85rem;
    height: 2.85rem;
    border-radius: 12px;
    object-fit: cover;
    display: block;
    background: var(--primary-soft);
}

.producto-miniatura-inicial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: var(--primary);
    font-size: 1rem;
}

.form-foto {
    margin-top: 0.25rem;
}

.btn-foto {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.85rem;
    height: 1.7rem;
    border-radius: 8px;
    background: rgba(213, 127, 159, 0.12);
    color: var(--primary);
    cursor: pointer;
    font-size: 0.75rem;
}

.btn-foto input {
    display: none;
}

/* ---------- Ventas y compras ---------- */

.operacion-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.15rem;
    align-items: start;
}

@media (min-width: 1000px) {
    .operacion-grid {
        grid-template-columns: minmax(0, 6fr) minmax(0, 6fr);
    }

    .operacion-grid .carrito {
        position: sticky;
        top: 5.5rem;
    }
}

.carrito .contador {
    float: right;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
}

.formulario-venta {
    margin-top: 1rem;
}

.vaciar {
    margin-top: 0.6rem;
}

.barra-escaneo {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}

.barra-escaneo .entrada {
    flex: 1;
    min-width: 0;
}

.entrada,
.entrada-mini {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    font-family: inherit;
    font-size: 16px;
    background: #fff;
    color: var(--text);
    min-height: var(--touch);
}

.entrada-mini {
    width: 5rem;
    padding: 0.4rem 0.5rem;
    text-align: right;
    min-height: 38px;
}

.operacion-grid .tabla th,
.operacion-grid .tabla td {
    padding: 0.55rem 0.5rem;
}

.operacion-grid .tabla .nombre {
    min-width: 8rem;
}

.tabla-scroll {
    max-height: 60vh;
    overflow-y: auto;
}

.tabla-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #fff;
}

.tabla-anidada {
    background: var(--primary-soft);
}

.enlace-detalle {
    font-size: 0.88rem;
    font-weight: 700;
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
    text-align: left;
}

.resumen .cifra {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: -0.02em;
}

.resumen .cifra-ok {
    color: var(--ok);
}

.resumen .cifra-alerta {
    color: #b45309;
}

.grid-graficos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin: 1rem 0 1.5rem;
}

.card-grafico {
    margin-bottom: 1rem;
}

.card-grafico h2 {
    margin-top: 0;
}

.grafico-caja {
    position: relative;
    height: 260px;
    margin-top: 0.5rem;
}

.grafico-caja-lg {
    height: 300px;
}

.grafico-dona {
    position: relative;
    width: 168px;
    height: 168px;
    flex-shrink: 0;
    margin: 0 auto;
}

/* ---------- BI / estadísticas ---------- */

.bi-periodo {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
}

.bi-periodo .filtro-campo {
    min-width: 11rem;
}

.bi-periodo .btn[aria-disabled="true"] {
    opacity: 0.45;
    pointer-events: none;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.15rem;
}

.kpi-grid-stock {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kpi-card {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(80, 40, 55, 0.05);
    padding: 1.1rem 1.15rem;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.kpi-icono {
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.kpi-icono-ventas { background: #fde8ef; color: #c04575; }
.kpi-icono-ok { background: var(--ok-bg); color: var(--ok); }
.kpi-icono-unidades { background: #e8f2f7; color: #3d6f8a; }
.kpi-icono-ticket { background: #fff0e6; color: #c26a2d; }
.kpi-icono-stock { background: #efe8f4; color: #6b4c8a; }
.kpi-icono-alerta { background: #fff4e5; color: #b45309; }

.kpi-cuerpo {
    min-width: 0;
    flex: 1;
}

.kpi-cuerpo h2 {
    margin: 0 0 0.25rem;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.kpi-valor {
    margin: 0;
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--primary-dark);
    line-height: 1.15;
}

.kpi-valor-ok {
    color: var(--ok);
}

.kpi-meta {
    margin: 0.2rem 0 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 700;
}

.kpi-delta {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.45rem;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
}

.kpi-delta-vs {
    font-weight: 700;
    opacity: 0.75;
}

.kpi-delta-up {
    background: var(--ok-bg);
    color: var(--ok);
}

.kpi-delta-down {
    background: var(--error-bg);
    color: var(--error);
}

.kpi-delta-flat {
    background: #f3eef0;
    color: var(--text-muted);
}

.bi-insights {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.7rem;
    margin-bottom: 1.25rem;
}

.bi-insight {
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 0.85rem 0.95rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
}

.bi-insight i {
    margin-top: 0.15rem;
    color: var(--primary-dark);
}

.bi-insight p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.4;
    font-weight: 600;
}

.bi-insight-ok {
    background: #f4fbf6;
    border-color: rgba(46, 125, 50, 0.14);
}

.bi-insight-ok i { color: var(--ok); }

.bi-insight-alerta {
    background: #fff8f0;
    border-color: rgba(180, 83, 9, 0.16);
}

.bi-insight-alerta i { color: #b45309; }

.bi-insight-info {
    background: #fbf6f8;
}

.bi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.15rem;
}

.card-bi h2 {
    margin-bottom: 0.35rem;
}

.card-bi .ayuda {
    margin-bottom: 0.9rem;
}

.bi-canales {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.bi-canal-lista {
    flex: 1;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.bi-canal-cabecera {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-weight: 800;
    font-size: 0.92rem;
}

.bi-canal p {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.ranking {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.ranking-item {
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
}

.ranking-puesto {
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 800;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.ranking-item:nth-child(1) .ranking-puesto {
    background: #f6e2a8;
    color: #8a6a12;
}

.ranking-item:nth-child(2) .ranking-puesto {
    background: #e6e9ee;
    color: #5c6570;
}

.ranking-item:nth-child(3) .ranking-puesto {
    background: #f0d7c4;
    color: #8a5a32;
}

.ranking-cuerpo {
    flex: 1;
    min-width: 0;
}

.ranking-fila {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: baseline;
}

.ranking-nombre {
    font-weight: 800;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking-valor {
    font-weight: 800;
    white-space: nowrap;
    color: var(--primary-dark);
    font-size: 0.88rem;
}

.ranking-meta {
    margin: 0.25rem 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.ranking-barra {
    height: 7px;
    border-radius: 999px;
    background: #f3e6ea;
    overflow: hidden;
    margin-top: 0.4rem;
}

.ranking-barra span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #d57f9f, #c06588);
    min-width: 4px;
}

.ranking-barra-live span {
    background: linear-gradient(90deg, #c04575, #a0335e);
}

.lista a {
    color: inherit;
    text-decoration: none;
    font-weight: 700;
}

.lista a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

.filtro-campo {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
}

.filtro-campo input,
.filtro-campo select {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    font-family: inherit;
    font-size: 16px;
    background: #fff;
    color: var(--text);
    min-height: 42px;
}

.oculto {
    display: none;
}

/* ---------- Paginacion ---------- */

.paginacion {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.85rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.paginacion a {
    color: var(--primary-dark);
    font-weight: 800;
    text-decoration: none;
    padding: 0.55rem 0.95rem;
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow-soft);
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
}

.paginacion a:hover {
    background: var(--primary-soft);
}

.paginacion span {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---------- Nav inferior (mobile) ---------- */

.nav-inferior {
    display: none;
}

.nav-mas-sheet[hidden] {
    display: none;
}

.nav-mas-sheet {
    position: fixed;
    inset: 0;
    z-index: 210;
}

.nav-mas-sheet-fondo {
    position: absolute;
    inset: 0;
    background: rgba(30, 18, 22, 0.45);
}

.nav-mas-sheet-caja {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 22px 22px 0 0;
    padding: 0.85rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    animation: sheetUp 0.2s ease;
}

.nav-mas-sheet-asa {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: #ddd;
    margin: 0.15rem auto 0.55rem;
}

.nav-mas-sheet-caja a,
.nav-mas-sheet-caja button[type="submit"] {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: var(--touch);
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.nav-mas-sheet-caja a:hover,
.nav-mas-sheet-caja button[type="submit"]:hover,
.nav-mas-sheet-caja a.activo {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.nav-mas-sheet-caja .btn {
    margin-top: 0.35rem;
}

@keyframes fadeSlide {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sheetUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
    .app-nav-desktop {
        display: none;
    }

    .nav-inferior {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 150;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom));
        box-shadow: 0 -6px 20px rgba(80, 40, 55, 0.08);
    }

    .nav-inferior a,
    .nav-inferior-mas {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.2rem;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.68rem;
        font-weight: 800;
        background: none;
        border: none;
        min-height: 3.4rem;
        cursor: pointer;
        border-radius: 12px;
        padding: 0.25rem;
    }

    .nav-inferior a i,
    .nav-inferior-mas i {
        font-size: 1.1rem;
    }

    .nav-inferior a.activo,
    .nav-inferior-mas[aria-expanded="true"] {
        color: var(--primary-dark);
        background: var(--primary-soft);
    }

    .nav-inferior a.destacado {
        color: var(--primary-dark);
    }

    .app-main {
        padding-bottom: calc(var(--nav-inferior-h) + 1.5rem);
    }

    .app-footer {
        padding-bottom: calc(var(--nav-inferior-h) + 0.75rem);
    }

    .live-toast {
        bottom: calc(var(--nav-inferior-h) + 0.75rem);
        right: 0.75rem;
        left: 0.75rem;
        max-width: none;
    }

    .atajos {
        grid-template-columns: 1fr;
    }

    .atajo-texto span {
        font-size: 0.84rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bi-grid {
        grid-template-columns: 1fr;
    }

    .grafico-caja-lg {
        height: 240px;
    }
}

@media (max-width: 480px) {
    .app-header-inner {
        gap: 0.65rem;
    }

    .app-buscador {
        max-width: none;
        width: 100%;
        order: 3;
        flex-basis: 100%;
    }

    .app-brand span {
        font-size: 1.1rem;
    }

    .filtros .contador {
        margin-left: 0;
        width: 100%;
    }

    .tabla th,
    .tabla td {
        padding: 0.7rem;
    }

    .pagina-cabecera .btn,
    .titulo-con-accion .btn {
        width: 100%;
    }

    .pagina-cabecera .bi-periodo .btn {
        width: auto;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .bi-periodo {
        width: 100%;
    }
}

@media (min-width: 901px) {
    .nav-inferior,
    .nav-mas-sheet {
        display: none !important;
    }
}
