:root {
    --farma: #0f766e;
    --farma-oscuro: #115e59;
    --farma-claro: #ccfbf1;
    --fondo: #f4f6f8;
    --borde: #e2e8f0;
    --texto-suave: #64748b;
}

body { background: var(--fondo); font-size: .925rem; }
.bg-farma { background: var(--farma) !important; }
.btn-farma { background: var(--farma); border-color: var(--farma); color: #fff; }
.btn-farma:hover, .btn-farma:focus { background: var(--farma-oscuro); border-color: var(--farma-oscuro); color: #fff; }
.text-farma { color: var(--farma) !important; }

/* ------------------------------------------------ Menú lateral */
.sidebar { width: 230px; min-height: calc(100vh - 48px); background: #fff; border-right: 1px solid var(--borde); }
@media (min-width: 992px) { .sidebar { position: sticky; top: 48px; height: calc(100vh - 48px); overflow-y: auto; } }
.sidebar .nav-link { color: #334155; padding: .45rem 1rem; display: flex; gap: .6rem; align-items: center; border-left: 3px solid transparent; }
.sidebar .nav-link:hover { background: #f1f5f9; }
.sidebar .nav-link.active { background: var(--farma-claro); color: var(--farma-oscuro); border-left-color: var(--farma); font-weight: 600; }
.sidebar .nav-titulo { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--texto-suave); padding: .9rem 1rem .25rem; }
.contenido { min-width: 0; }

/* ------------------------------------------------ Login */
.bg-login { background: linear-gradient(135deg, var(--farma) 0%, #134e4a 100%); }
.login-card { width: 100%; max-width: 380px; border: 0; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--farma-claro); color: var(--farma); display: inline-flex; align-items: center; justify-content: center; font-size: 1.8rem; }

/* ------------------------------------------------ Tarjetas de indicadores */
.kpi { border: 1px solid var(--borde); border-radius: .6rem; background: #fff; padding: 1rem; height: 100%; }
.kpi .valor { font-size: 1.5rem; font-weight: 600; line-height: 1.2; }
.kpi .etiqueta { color: var(--texto-suave); font-size: .8rem; }
.card { border-color: var(--borde); }
.table > :not(caption) > * > * { padding: .45rem .6rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); font-weight: 600; background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------ POS */
body.pos { overflow: hidden; }
.pos-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: .75rem; height: calc(100vh - 48px); padding: .75rem; }
@media (max-width: 991px) { body.pos { overflow: auto; } .pos-wrap { grid-template-columns: 1fr; height: auto; } }
.pos-izq { display: flex; flex-direction: column; min-height: 0; gap: .6rem; }
.pos-der { display: flex; flex-direction: column; gap: .6rem; min-height: 0; }
.pos-scan { position: relative; }
.pos-scan input { font-size: 1.25rem; padding: .7rem 1rem .7rem 2.8rem; border: 2px solid var(--farma); }
.pos-scan input:focus { box-shadow: 0 0 0 .25rem rgba(15, 118, 110, .2); }
.pos-scan .bi { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); font-size: 1.3rem; color: var(--farma); }
.pos-carrito { flex: 1; overflow-y: auto; background: #fff; border: 1px solid var(--borde); border-radius: .5rem; }
.pos-carrito table { margin: 0; }
.pos-carrito tbody tr.sel { background: #f0fdfa; }
.pos-carrito .cant { width: 76px; }
.pos-carrito .pres { width: 140px; }
.pos-vacio { color: var(--texto-suave); text-align: center; padding: 3rem 1rem; }
.pos-vacio .bi { font-size: 3rem; display: block; margin-bottom: .5rem; opacity: .4; }
.pos-total { background: #0f172a; color: #fff; border-radius: .5rem; padding: .9rem 1rem; }
.pos-total .monto { font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-panel { background: #fff; border: 1px solid var(--borde); border-radius: .5rem; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.pos-panel .titulo { padding: .5rem .75rem; font-weight: 600; border-bottom: 1px solid var(--borde); font-size: .85rem; background: #f8fafc; }
.pos-panel .cuerpo { overflow-y: auto; flex: 1; }
.alt-item { padding: .5rem .75rem; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.alt-item:hover { background: #f0fdfa; }
.atajos kbd { background: #e2e8f0; color: #0f172a; font-size: .7rem; }
.badge-ctrl { background: #7c3aed; }
.resultado-busqueda { cursor: pointer; }
.resultado-busqueda.activo, .resultado-busqueda:hover { background: #f0fdfa; }
.pago-fila { background: #f8fafc; border: 1px solid var(--borde); border-radius: .4rem; padding: .5rem; }
.vuelto { font-size: 1.6rem; font-weight: 700; color: var(--farma); }

/* ------------------------------------------------ Ticket térmico */
.ticket { font-family: "Courier New", monospace; font-size: 12px; color: #000; margin: 0 auto; background: #fff; padding: 4mm 3mm; }
.ticket.w80 { width: 80mm; }
.ticket.w58 { width: 58mm; font-size: 10.5px; }
.ticket .c { text-align: center; }
.ticket .r { text-align: right; }
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; opacity: 1; }
.ticket table { width: 100%; border-collapse: collapse; }
.ticket td { vertical-align: top; padding: 1px 0; }
.ticket .qr svg { width: 32mm; height: 32mm; }
@media print {
    @page { margin: 0; }
    body { background: #fff; }
    .no-print { display: none !important; }
}

/* ------------------------------------------------ Aviso de modo demo */
.aviso-demo { background: #fef3c7; color: #78350f; border-bottom: 1px solid #fcd34d; font-size: .8rem; padding: .3rem 1rem; text-align: center; }

/* ------------------------------------------------ POS: ocupa la pantalla (navbar + aviso + área de trabajo) */
body.pos { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
body.pos .pos-wrap { flex: 1; min-height: 0; height: auto; }
.pos-scan .btn-buscar { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); }
.pos-scan input { padding-right: 6.5rem; }
.pos-barra-movil { display: none; }

/* ------------------------------------------------ Tablet y celular */
@media (max-width: 991.98px) {
    body.pos { height: auto; overflow: auto; padding-bottom: 76px; }
    body.pos .pos-wrap { display: flex; flex-direction: column; padding: .5rem; }
    .pos-carrito { flex: none; min-height: 160px; }
    .pos-der .pos-total { display: none; }               /* el total va en la barra inferior */
    .pos-der .pos-panel:last-child { max-height: 320px; }
    .pos-barra-movil {
        display: flex; align-items: center; gap: .75rem; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
        background: #0f172a; color: #fff; padding: .6rem .9rem calc(.6rem + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 12px rgba(0, 0, 0, .15);
    }
    .pos-barra-movil .monto { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; line-height: 1.1; }
    .pos-barra-movil small { display: block; font-size: .7rem; color: #94a3b8; font-weight: 400; }
}

@media (max-width: 767.98px) {
    /* Inputs de 16px: iOS no hace zoom al enfocarlos */
    .form-control, .form-select { font-size: 16px; }
    .kpi .valor { font-size: 1.2rem; }
    h1.h4 { font-size: 1.15rem; }
    /* Tablas de listados: se desplazan dentro de su tarjeta en lugar de romper el diseño */
    .card > table, .card > .card-body > table { display: block; overflow-x: auto; white-space: nowrap; }
    .card > .table-responsive > table { white-space: nowrap; }
    .pos-scan input { font-size: 1.05rem; }

    /* Carrito del POS como tarjetas: producto arriba, presentación y cantidad, precio y total */
    .pos-carrito thead { display: none; }
    .pos-carrito table, .pos-carrito tbody { display: block; }
    .pos-carrito tbody tr {
        display: grid; grid-template-columns: 1fr 1fr 32px;
        grid-template-areas: "prod prod quitar" "pres cant cant" "pu total total";
        gap: .25rem .5rem; padding: .55rem .6rem; border-bottom: 1px solid var(--borde);
    }
    .pos-carrito tbody td { display: block; border: 0; padding: 0 !important; width: auto !important; }
    .pos-carrito tbody td:nth-child(1) { grid-area: prod; }
    .pos-carrito tbody td:nth-child(2) { grid-area: pres; }
    .pos-carrito tbody td:nth-child(3) { grid-area: cant; }
    .pos-carrito tbody td:nth-child(4) { grid-area: pu; text-align: left; color: var(--texto-suave); font-size: .85rem; }
    .pos-carrito tbody td:nth-child(4)::before { content: "P. unit. "; }
    .pos-carrito tbody td:nth-child(5) { grid-area: total; font-size: 1.05rem; }
    .pos-carrito tbody td:nth-child(6) { grid-area: quitar; text-align: right; }
    .pos-carrito tbody td:nth-child(6) .btn { font-size: 1.2rem; }

    .ticket.w80, .ticket.w58 { max-width: 100%; }
}
