/* ============================================================
   POS Chicharrones
   Pensado para tableta en horizontal o vertical, en mostrador,
   con luz fuerte y manos ocupadas: contraste alto, objetivos
   grandes (minimo 60px) y cero animaciones que distraigan.
   ============================================================ */

:root {
    --ink:        #1b1614;   /* chrome oscuro */
    --ink-soft:   #3a322e;
    --paper:      #edeae5;   /* fondo de trabajo */
    --card:       #ffffff;
    --line:       #d9d3ca;

    --achiote:    #d94215;   /* acento principal */
    --achiote-dk: #ad3310;
    --lima:       #6f9410;   /* confirmaciones */
    --lima-dk:    #5a7a0b;
    --alert:      #b3261e;

    --txt:        #1b1614;
    --txt-muted:  #79706a;

    --r:          10px;
    --shadow:     0 1px 2px rgba(27,22,20,.10), 0 8px 24px rgba(27,22,20,.08);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: var(--font);
    background: var(--paper);
    color: var(--txt);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Los numeros de dinero siempre alineados */
.money, .amount-display, .total-row strong, .big-total,
.chip, .receipt, td, .item-sub { font-variant-numeric: tabular-nums; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Barra superior ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: var(--ink);
    color: #f6f2ec;
    flex: 0 0 auto;
    position: relative;
    z-index: 55;   /* por encima del ticket, por debajo de los modales */
}
.brand {
    font-weight: 700;
    letter-spacing: .02em;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.mark { color: var(--achiote); font-size: 1.1em; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.who { font-size: .9rem; opacity: .8; }
.chip {
    background: rgba(255,255,255,.10);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: .85rem;
    white-space: nowrap;
}
.chip-sales { background: rgba(111,148,16,.28); }

.btn-ghost {
    background: transparent;
    border: 1px solid rgba(255,255,255,.28);
    color: inherit;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: .9rem;
    font-weight: 600;
}
.btn-ghost:active { background: rgba(255,255,255,.12); }
.btn-danger { border-color: rgba(217,66,21,.7); color: #ffb69c; }

/* ---------- Layout POS ---------- */
.pos {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 390px;
    min-height: 0;
}
.pos[hidden] { display: none; }

/* ---------- Catalogo ---------- */
.catalog {
    overflow-y: auto;
    padding: 20px 20px 40px;
    -webkit-overflow-scrolling: touch;
}
.catalog-loading { color: var(--txt-muted); padding: 40px; text-align: center; }

.cat-title {
    margin: 4px 0 12px;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--txt-muted);
    display: flex;
    align-items: center;
    gap: 12px;
}
.cat-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}
.cat-group + .cat-group { margin-top: 26px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.product {
    position: relative;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 16px 14px 14px;
    text-align: left;
    min-height: 108px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: var(--shadow);
    transition: transform .06s ease;
}
.product:active { transform: scale(.97); border-color: var(--achiote); }
.product-name { font-weight: 700; font-size: 1rem; line-height: 1.25; }
.product-meta { display: flex; align-items: baseline; gap: 6px; margin-top: 10px; }
.product-price { font-size: 1.15rem; font-weight: 700; color: var(--achiote); }
.product-unit { font-size: .78rem; color: var(--txt-muted); }

/* Marca de "se pesa" */
.tag-weight {
    position: absolute;
    top: 10px; right: 10px;
    background: var(--ink);
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 3px 7px;
    border-radius: 4px;
}

/* ---------- Ticket ---------- */
.ticket {
    background: var(--card);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.ticket-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--txt-muted);
}
.link-btn {
    background: none; border: 0;
    color: var(--alert);
    font-weight: 600;
    font-size: .8rem;
    letter-spacing: 0;
    text-transform: none;
    padding: 4px;
}
.ticket-body { flex: 1; overflow-y: auto; padding: 6px 0; }
.empty { color: var(--txt-muted); text-align: center; padding: 48px 24px; margin: 0; }

.item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid #f0ece6;
}
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-calc { font-size: .82rem; color: var(--txt-muted); margin-top: 2px; }
.item-sub { font-weight: 700; }
.item-del {
    background: none;
    border: 0;
    color: var(--txt-muted);
    font-size: 1.4rem;
    line-height: 1;
    padding: 8px 4px;
    min-width: 40px;
}
.item-del:active { color: var(--alert); }

.ticket-foot { border-top: 1px solid var(--line); padding: 16px 18px calc(16px + env(safe-area-inset-bottom)); background: #fbf9f6; }
.total-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 14px;
}
.total-row span { font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--txt-muted); }
.total-row strong { font-size: 2.4rem; letter-spacing: -.02em; }

/* ---------- Botones ---------- */
.btn {
    border: 0;
    border-radius: var(--r);
    padding: 16px 20px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    background: var(--ink);
    width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--achiote); }
.btn-primary:active { background: var(--achiote-dk); }
.btn-lg { padding: 20px; font-size: 1.15rem; }
.btn-pay {
    background: var(--lima);
    padding: 22px;
    font-size: 1.3rem;
    letter-spacing: .02em;
}
.btn-pay:active { background: var(--lima-dk); }
.btn:disabled { background: #cfc8c0; color: #fff; }
.btn-ghost-lg {
    background: transparent;
    color: var(--txt-muted);
    border: 1px solid var(--line);
}

/* Barra flotante del ticket (solo pantallas angostas) */
.cart-fab {
    display: none;
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 40;
    align-items: center;
    gap: 12px;
    background: var(--lima);
    color: #fff;
    border: 0;
    border-radius: 12px;
    padding: 16px 18px;
    font-size: 1.05rem;
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(27,22,20,.28);
}
.fab-count {
    background: rgba(0,0,0,.22);
    border-radius: 999px;
    min-width: 28px;
    padding: 3px 8px;
    text-align: center;
}
.cart-fab strong { margin-left: auto; font-size: 1.2rem; }

/* ---------- Overlays / hojas ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(27,22,20,.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 60;
}
.overlay.is-open { display: flex; }

.sheet {
    background: var(--card);
    border-radius: 14px;
    padding: 22px;
    width: 100%;
    max-width: 460px;
    max-height: 94vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(27,22,20,.35);
}
.sheet-narrow { max-width: 380px; }
.sheet h2 { margin: 0 0 4px; font-size: 1.35rem; }
.muted { color: var(--txt-muted); margin: 0 0 16px; font-size: .92rem; }

.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 16px; }

/* Pantalla de apertura: fondo opaco, es lo unico que se puede hacer */
#openingScreen { background: var(--paper); }

/* ---------- Display de monto (elemento firma) ---------- */
.amount-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    background: #faf7f3;
    border-bottom: 4px solid var(--achiote);
    border-radius: 8px 8px 0 0;
    padding: 14px 16px;
    margin: 14px 0 16px;
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: -.02em;
    min-height: 84px;
    overflow: hidden;
}
.amount-display .cur { font-size: 1.1rem; font-weight: 600; color: var(--txt-muted); }
.amount-display.is-ok { border-bottom-color: var(--lima); }
.amount-display.is-low { border-bottom-color: var(--alert); }

.line-preview {
    display: flex;
    justify-content: space-between;
    font-size: .95rem;
    color: var(--txt-muted);
    margin: -6px 0 14px;
}
.line-preview strong { color: var(--txt); font-size: 1.15rem; }

/* ---------- Teclado ---------- */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.key {
    background: #f4f1ec;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--txt);
    min-height: 62px;
}
.key:active { background: #e4dfd7; }
.key-muted { background: #e9e4dc; }

/* ---------- Formularios ---------- */
.field-label {
    display: block;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--txt-muted);
    margin: 12px 0 6px;
}
.field {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px;
    font-size: 1.1rem;
    font-family: inherit;
    background: #fbf9f6;
}
.field:focus { outline: 3px solid rgba(217,66,21,.35); border-color: var(--achiote); }

/* ---------- Cobro ---------- */
.big-total {
    font-size: 3.2rem;
    font-weight: 700;
    letter-spacing: -.03em;
    text-align: center;
    margin: 10px 0 22px;
}
.pay-options { display: grid; gap: 10px; margin-bottom: 18px; }
.pay-option {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--lima);
    color: #fff;
    border: 0;
    border-radius: var(--r);
    padding: 22px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: left;
}
.pay-option.po-alt { background: var(--ink-soft); }
.po-icon { font-size: 1.5rem; }

.due-row, .change-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f4f1ec;
    margin-bottom: 12px;
}
.due-row strong { font-size: 1.4rem; }
.change-row { background: #eef3e0; border: 1px solid #d5e2b0; }
.change-row strong { font-size: 1.6rem; color: var(--lima-dk); }
.change-row.is-low { background: #fbeceb; border-color: #f0c9c6; }
.change-row.is-low strong { color: var(--alert); font-size: 1.05rem; }

.quick-cash { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.quick-cash button {
    flex: 1 1 auto;
    min-width: 78px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 8px;
    font-weight: 700;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}
.quick-cash button:active { background: #f0ebe4; border-color: var(--achiote); }

/* ---------- Comprobante de transferencia ---------- */
.proof-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border: 2px dashed var(--line);
    border-radius: var(--r);
    padding: 26px 16px;
    text-align: center;
    color: var(--txt-muted);
    font-weight: 600;
    background: #faf7f3;
}
.proof-drop:active { background: #f0ebe4; }
.proof-icon { font-size: 2rem; }
.proof-preview { text-align: center; }
.proof-preview img {
    max-width: 100%;
    max-height: 220px;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: block;
    margin: 0 auto 10px;
}

/* ---------- Corte Z ---------- */
.receipt {
    background: #fbf9f5;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    font-size: .92rem;
    max-height: 46vh;
    overflow-y: auto;
}
.receipt h3 { margin: 0 0 2px; text-align: center; font-size: 1rem; }
.receipt .r-sub { text-align: center; color: var(--txt-muted); font-size: .8rem; margin-bottom: 14px; }
.r-line { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dotted var(--line); }
.r-line.r-strong { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 8px; }
.r-section { margin-top: 14px; font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--txt-muted); }
.r-diff-ok   { color: var(--lima-dk); }
.r-diff-bad  { color: var(--alert); }

/* ---------- Aviso ---------- */
.toast {
    position: fixed;
    left: 50%;
    top: 18px;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    padding: 14px 20px;
    border-radius: 10px;
    font-weight: 600;
    z-index: 200;
    box-shadow: var(--shadow);
    max-width: 90vw;
    text-align: center;
}
.toast.is-error { background: var(--alert); }
.toast.is-ok    { background: var(--lima-dk); }

/* ---------- Login ---------- */
.screen-lock { align-items: center; justify-content: center; }
.lock-card {
    margin: auto;
    background: var(--card);
    border-radius: 16px;
    padding: 26px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}
.lock-brand { text-align: center; margin-bottom: 18px; }
.lock-mark { color: var(--achiote); font-size: 1.6rem; }
.lock-brand h1 { font-size: 1.35rem; margin: 6px 0 4px; }
.lock-brand p { color: var(--txt-muted); font-size: .9rem; margin: 0; }

.user-row { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.user-chip { flex: 1 1 100px; }
.user-chip input { position: absolute; opacity: 0; pointer-events: none; }
.user-chip span {
    display: block;
    text-align: center;
    padding: 14px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 700;
    background: #faf7f3;
}
.user-chip input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.user-chip input:focus-visible + span { outline: 3px solid rgba(217,66,21,.5); }

.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 8px 0 18px; }
.pin-dots i {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--line);
}
.pin-dots i.on { background: var(--achiote); border-color: var(--achiote); }

.alert {
    background: #fbeceb;
    border: 1px solid #f0c9c6;
    color: var(--alert);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: .9rem;
    text-align: center;
    margin: 0 0 14px;
}

/* ============================================================
   Tableta vertical y telefono: el ticket pasa a hoja inferior
   ============================================================ */
@media (max-width: 900px) {
    .pos { grid-template-columns: 1fr; }
    .catalog { padding-bottom: 96px; }

    .ticket {
        position: fixed;
        inset: auto 0 0 0;
        max-height: 88vh;
        border-left: 0;
        border-top: 1px solid var(--line);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(27,22,20,.25);
        transform: translateY(100%);
        transition: transform .18s ease-out;
        z-index: 50;
    }
    .ticket.is-open { transform: translateY(0); }
    .ticket-head::after {
        content: "Cerrar";
        color: var(--achiote);
        font-size: .8rem;
        letter-spacing: 0;
        text-transform: none;
    }
    .cart-fab { display: flex; }
    .cart-fab[hidden] { display: none; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; gap: 8px; }
    .chip { font-size: .78rem; padding: 5px 10px; }
    .amount-display { font-size: 2.2rem; }
    .big-total { font-size: 2.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ---------- Impresion del corte ---------- */
@media print {
    body { background: #fff; display: block; overflow: visible; }
    .topbar, .pos, .cart-fab, .toast, .sheet-actions { display: none !important; }
    .overlay { position: static; background: none; display: block; padding: 0; }
    #payModal, #expenseModal, #closeModal, #weightModal, #openingScreen { display: none !important; }
    .sheet { box-shadow: none; max-height: none; max-width: 100%; padding: 0; }
    .receipt { max-height: none; border: 0; background: #fff; font-size: 12px; }
}


/* ---------- Salidas siempre alcanzables ---------- */
.sheet-footnote {
    margin: 16px 0 0;
    text-align: center;
    font-size: .9rem;
    color: var(--txt-muted);
}
.sheet-footnote a { color: var(--achiote); font-weight: 700; }

.session-open p { color: var(--txt-muted); margin: 0 0 18px; }
.session-open .modal-btn { text-decoration: none; }