:root {
    --primary: #6C4FF6;
    --primary-dark: #5638d6;
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #222;
    --muted: #6b7280;
    --error: #c0392b;
    --error-bg: #fdecea;
    --border: #e2e5ec;
}
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
input, select, textarea, button { max-width: 100%; }
body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
.topbar {
    background: var(--primary);
    color: #fff;
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar .brand { color: #fff; font-weight: bold; text-decoration: none; font-size: 18px; }
.brand-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.negocio-activo-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,.15);
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}
.negocio-logo { width: 18px; height: 18px; object-fit: cover; border-radius: 4px; }
.topbar nav { display: flex; align-items: center; gap: 14px; }
.topbar a { color: #fff; text-decoration: none; opacity: .9; }
.topbar a:hover { opacity: 1; text-decoration: underline; }
.user-chip { background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 12px; font-size: 13px; }

.container { max-width: 900px; margin: 0 auto; padding: 30px 16px 60px; }

h1 { font-size: 24px; margin-bottom: 6px; }
h2 { font-size: 18px; margin-top: 36px; }

.auth-box {
    max-width: 380px;
    margin: 40px auto;
    background: var(--card);
    padding: 28px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.auth-box h1 { text-align: center; }

form label {
    display: block;
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--muted);
}
form input {
    width: 100%;
    padding: 10px 12px;
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
}
form input:focus { outline: none; border-color: var(--primary); }

.btn {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-small { background: var(--primary); color: #fff; padding: 6px 12px; font-size: 13px; }

.muted { color: var(--muted); font-size: 14px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-error { background: var(--error-bg); color: var(--error); }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 16px;
}
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}
.card h3 { margin: 0 0 4px; }
.card-active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(68,114,196,.15); }

.inline-form {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
    margin-top: 10px;
    max-width: 420px;
}

.notice {
    margin-top: 24px;
    padding: 14px 16px;
    background: #eaf2ff;
    border: 1px solid #c6dcff;
    border-radius: 10px;
    font-size: 14px;
}

.oculto { display: none; }

.panel-accesos {
    margin-top: 26px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
}
.panel-accesos-info { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 12px; }
.panel-accesos-botones { display: flex; flex-wrap: wrap; gap: 10px; }
.acceso-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 10px;
    background: #eaf2ff;
    color: var(--primary-dark);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    border: 1px solid transparent;
    transition: border-color .15s;
}
.acceso-card:hover { border-color: var(--primary); }
.acceso-proximo { background: #f0f2f8; color: var(--muted); cursor: default; }
.acceso-proximo em { font-style: normal; font-weight: 400; font-size: 12px; }

/* Inventario */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.alert-ok { background: #e6f7ee; color: #1e7e45; }

.table-wrap { overflow-x: auto; background: var(--card); border-radius: 10px; border: 1px solid var(--border); }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tabla th { background: #f0f2f8; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.tabla tbody tr:hover { background: #fafbfe; }

.badge { padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-warn { background: #fdecea; color: #c0392b; }
.badge-ok { background: #e6f7ee; color: #1e7e45; }
.badge-producto { background: #eaf2ff; color: #2f56a3; }
.badge-servicio { background: #f3e8ff; color: #7c3aed; }
.badge-rol { background: #f0f2f8; color: var(--muted); font-weight: 500; }

.radio-group { display: flex; gap: 18px; margin-top: 6px; }
.radio-inline { display: flex !important; align-items: center; gap: 6px; font-size: 14px; color: var(--text); margin-bottom: 0 !important; }
.radio-inline input { width: auto; margin: 0; }
.input-mini { width: 70px !important; display: inline-block; }

.form-box-ancho { max-width: 640px; }

.lista-productos {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
}
.producto-opcion {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 0 !important;
}
.producto-opcion:last-child { border-bottom: none; }
.producto-opcion:hover { background: #fafbfe; }
.producto-opcion input { width: auto !important; margin-top: 3px; }
.producto-sin-stock { opacity: .5; cursor: not-allowed; }

.producto-seleccionado { font-weight: 600; margin-bottom: 12px; }

.resumen-seleccion {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #eaf2ff;
    border: 1px solid #c6dcff;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: 600;
    margin-bottom: 16px;
}
.btn-cambiar { padding: 4px 12px; font-size: 13px; }

.resumen-venta {
    background: #eaf2ff;
    border: 1px solid #c6dcff;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    margin: 14px 0;
}

.fila-anulada { opacity: .5; text-decoration: line-through; }
.fila-anulada .badge { text-decoration: none; }

/* Vender: layout carrito */
.venta-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .venta-layout { grid-template-columns: 1fr; }
}
.panel-buscador, .panel-carrito {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
}
.panel-carrito h2 { margin-top: 0; font-size: 16px; }
.btn-agregar-mini {
    background: var(--primary);
    color: #fff;
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}
.producto-sin-stock .btn-agregar-mini { background: var(--muted); }
.carrito-item {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 13px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.carrito-item-nombre { font-weight: 600; width: 100%; }
.carrito-total { font-size: 16px; margin: 14px 0; text-align: right; }

/* Boleta imprimible */
.boleta {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 700px;
}
.boleta-header { display: flex; justify-content: space-between; margin-bottom: 18px; }
.boleta-negocio { font-size: 18px; }
.boleta-tabla { margin-bottom: 14px; }
.boleta-totales { text-align: right; font-size: 14px; }
.boleta-totales strong { font-size: 18px; }
.boleta-pie { text-align: center; margin-top: 18px; }

@media print {
    .sidebar, .sidebar-overlay, .topbar-app, .topbar-simple, .no-imprimir { display: none !important; }
    body { background: #fff; }
    .app-shell { display: block !important; }
    .main-area { margin-left: 0 !important; }
    .container { padding: 0; max-width: 100%; }
    .boleta { border: none; padding: 0; }
}

.filtros-ventas {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px 6px;
    margin-bottom: 16px;
}

.panel-totales {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
}
.panel-totales > div {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 18px;
    flex: 1;
    min-width: 130px;
}
.panel-totales span { display: block; font-size: 12px; margin-bottom: 4px; }
.panel-totales strong { font-size: 18px; }
.texto-warn { color: #c0392b; }

.credenciales-box { display: flex; flex-direction: column; gap: 8px; }
.credenciales-datos { display: flex; gap: 18px; font-family: monospace; font-size: 15px; background: rgba(255,255,255,.6); padding: 8px 12px; border-radius: 6px; }
.btn-small-full { width: 100%; margin: -6px 0 14px; font-size: 13px; padding: 8px; }

.acciones { display: flex; gap: 10px; }
.acciones a, .acciones button { font-size: 13px; }
.inline { display: inline; }
.link-danger { background: none; border: none; color: #c0392b; cursor: pointer; padding: 0; text-decoration: underline; font-size: 13px; }

.form-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 22px;
    max-width: 520px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f0f2f8; }

@media (max-width: 720px) {
    .form-row { grid-template-columns: 1fr; }
}

/* ===== Responsivo ===== */
.topbar { flex-wrap: wrap; gap: 10px; }
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
}

@media (max-width: 720px) {
    .container { padding: 18px 12px 50px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .btn, .page-head .acciones { width: 100%; }
    .page-head .acciones { flex-direction: column; }

    .nav-toggle { display: block; }
    .topbar nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding-top: 8px;
        border-top: 1px solid rgba(255,255,255,.2);
    }
    .topbar nav.nav-abierto { display: flex; }
    .topbar nav a, .topbar nav span { padding: 6px 0; width: 100%; }

    .grid-cards { grid-template-columns: 1fr; }
    .panel-accesos-botones { flex-direction: column; }
    .acceso-card { width: 100%; }

    /* Tablas -> tarjetas apiladas */
    .table-wrap { overflow-x: visible; border: none; background: none; }
    .tabla thead { display: none; }
    .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
    .tabla tr {
        background: var(--card);
        border: 1px solid var(--border);
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 10px 14px;
    }
    .tabla td {
        border-bottom: none;
        padding: 6px 0;
        white-space: normal;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        text-align: right;
    }
    .tabla td::before {
        content: attr(data-label);
        font-size: 11px;
        text-transform: uppercase;
        color: var(--muted);
        font-weight: 600;
        text-align: left;
        flex-shrink: 0;
    }
    .tabla td.acciones { justify-content: flex-end; }
    .tabla td.acciones::before { content: ''; }
    .tabla td:empty { display: none; }
}

/* ===== Buscador grande + botones grandes ===== */
.label-chico { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.input-grande {
    font-size: 17px !important;
    padding: 14px 16px !important;
    border-radius: 10px !important;
}
.btn-grande { padding: 14px 22px; font-size: 16px; width: 100%; }

.buscador-inventario {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.buscador-inventario label:first-child { flex: 1; min-width: 240px; }
.filtro-tipo-label { font-size: 13px; color: var(--muted); }
.filtro-tipo-label select { padding: 12px 10px; border-radius: 8px; border: 1px solid var(--border); }

/* ===== Atajos de fecha en Ventas ===== */
.atajos-fecha { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip-atajo {
    padding: 6px 14px;
    border-radius: 20px;
    background: #f0f2f8;
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
    border: 1px solid var(--border);
}
.chip-atajo:hover { border-color: var(--primary); }
.chip-activo { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Buscador de clientes (autocompletar) ===== */
.lista-clientes {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 6px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--card);
}
.cliente-resultado {
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.cliente-resultado:last-child { border-bottom: none; }
.cliente-resultado:hover { background: #eaf2ff; }
.cliente-resultado-vacio { padding: 10px 14px; font-size: 13px; }

/* ===== Boleta: botón volver al inicio ===== */
.btn-volver-inicio { margin-bottom: 8px; display: inline-block; font-size: 13px; padding: 6px 12px; }

.acceso-card-grande {
    font-size: 18px;
    padding: 18px 24px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}
.acceso-card-grande:hover { border-color: transparent; opacity: .92; }

/* ===== Layout tipo app con sidebar (fijo de verdad, no depende del alto del contenido) ===== */
.app-shell { min-height: 100vh; }
.sidebar {
    width: 232px;
    background: #fff;
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}
.sidebar-cerrar {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    background: #f5f3ff;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 15px;
    cursor: pointer;
    color: var(--primary);
}
.sidebar-brand {
    font-weight: 800;
    font-size: 15px;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    padding: 0 8px;
}
.sidebar-negocio {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f5f2ff;
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 18px;
}
.negocio-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.negocio-logo-sidebar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.sidebar-negocio-nombre { font-weight: 700; font-size: 13px; line-height: 1.3; }
.sidebar-negocio-rol { font-size: 11px; color: var(--muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #444;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}
.sidebar-link span { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-link:hover { background: #f5f3ff; }
.sidebar-link-activo { background: var(--primary); color: #fff !important; font-weight: 700; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}

.main-area { margin-left: 232px; min-height: 100vh; }
.topbar-app {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 26px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-titulo { font-weight: 700; font-size: 16px; flex: 1; color: #222; }
.topbar-user .user-chip { background: #f5f3ff; color: var(--primary); }
.nav-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: #444; }

.topbar-simple { background: var(--primary); padding: 16px 20px; }
.topbar-simple .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }

@media (max-width: 900px) {
    .main-area { margin-left: 0; }
    .sidebar {
        left: -260px;
        width: 240px;
        transition: left .2s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,.15);
    }
    .sidebar.sidebar-abierto { left: 0; }
    .sidebar-overlay.overlay-visible { display: block; }
    .sidebar-cerrar { display: flex; align-items: center; justify-content: center; }
    .sidebar-link { padding: 8px 10px; font-size: 13px; }
    .sidebar-negocio { padding: 8px 10px; margin-bottom: 10px; }
    .sidebar-brand { margin-bottom: 12px; }
    .nav-toggle { display: block; }
    .topbar-app { padding: 12px 14px; }
    .container { padding: 16px 12px 50px; }
}

/* ===== Tarjetas móviles más compactas ===== */
@media (max-width: 720px) {
    .tabla tr { padding: 8px 12px; margin-bottom: 8px; }
    .tabla td {
        padding: 3px 0;
        font-size: 13px;
    }
    .tabla td::before {
        font-size: 10px;
    }
    .page-head h1 { font-size: 19px; }
}

/* ===== Carrito estilo "app de ventas" con steppers ===== */
.carrito-item-v2 {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.carrito-item-icono {
    width: 38px; height: 38px; border-radius: 10px;
    background: #f5f3ff; color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; flex-shrink: 0;
}
.carrito-item-info { flex: 1; min-width: 0; }
.carrito-item-info .nombre { font-weight: 600; font-size: 13px; }
.carrito-item-info .precio-unit { font-size: 12px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
    width: 26px; height: 26px; border-radius: 50%;
    border: 1px solid var(--border); background: #fff;
    font-size: 14px; cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.stepper button:hover { background: #f5f3ff; border-color: var(--primary); }
.carrito-item-subtotal { font-weight: 700; font-size: 13px; min-width: 70px; text-align: right; }
.carrito-item-quitar { background: none; border: none; color: #c0392b; font-size: 16px; cursor: pointer; padding: 0 0 0 4px; }

.producto-card-v2 {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 10px;
    cursor: pointer;
}
.producto-card-v2:hover { background: #f9f8ff; }
.producto-card-icono {
    width: 40px; height: 40px; border-radius: 10px;
    background: #f5f3ff; color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.producto-card-boton {
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    font-size: 16px; flex-shrink: 0; cursor: pointer;
}
.producto-sin-stock .producto-card-boton { background: var(--muted); }

.tabs-tipo { display: flex; gap: 6px; margin: 10px 0 14px; }
.tab-tipo {
    padding: 6px 16px;
    border-radius: 20px;
    background: #f0f2f8;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}
.tab-tipo.tab-activo { background: var(--primary); color: #fff; }

.input-precio-carrito {
    width: 55px !important;
    display: inline-block;
    border: none;
    border-bottom: 1px dashed var(--border);
    padding: 0 2px !important;
    font-size: 12px;
    background: transparent;
}
.input-precio-carrito:focus { border-bottom-color: var(--primary); outline: none; }

/* ===== Secciones dentro del formulario de venta ===== */
.seccion-venta {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}
.seccion-venta:last-of-type { border-bottom: none; }
.seccion-venta-titulo {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    margin: 0 0 12px;
    font-weight: 700;
}
.input-pagado-grande { font-size: 18px !important; font-weight: 700; padding: 12px 14px !important; }

.carrito-vacio-estado { text-align: center; padding: 30px 10px; }
.carrito-vacio-icono { font-size: 34px; display: block; margin-bottom: 8px; opacity: .5; }

/* ===== Más compacto en celular (segunda pasada) ===== */
@media (max-width: 720px) {
    .panel-totales { gap: 8px; }
    .panel-totales > div { padding: 8px 12px; min-width: 100px; }
    .panel-totales span { font-size: 11px; margin-bottom: 2px; }
    .panel-totales strong { font-size: 14px; }

    .filtros-ventas { padding: 12px 14px 4px; }
    .atajos-fecha { margin-bottom: 10px; }
    .chip-atajo { padding: 5px 12px; font-size: 12px; }

    .card, .inline-form, .form-box, .panel-buscador, .panel-carrito { padding: 14px; }
    .acceso-card { padding: 10px 14px; font-size: 13px; }
    .acceso-card-grande { padding: 14px 18px; font-size: 15px; }

    .grid-cards { gap: 10px; }

    .seccion-venta-titulo { font-size: 11px; }
}
