/* ── Reset y base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    background: #f0f2f5;
    -webkit-text-size-adjust: 100%;
}

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
    padding: 0.5rem 1rem;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.navbar-brand {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 55vw;
}
.navbar .btn-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    white-space: nowrap;
}
.navbar .username-label {
    font-size: 0.8rem;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Contenedor principal ──────────────────────────────────────────────────── */
.main-container {
    padding: 0.75rem;
}
@media (min-width: 768px) {
    .main-container { padding: 1.25rem; }
}

/* ── Tabs principales ──────────────────────────────────────────────────────── */
#mainTabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: 2px solid #dee2e6;
    margin-bottom: 0 !important;
    gap: 2px;
}
#mainTabs::-webkit-scrollbar { display: none; }
#mainTabs .nav-link {
    white-space: nowrap;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 6px 6px 0 0;
    color: #555;
    border: 1px solid transparent;
    border-bottom: none;
}
#mainTabs .nav-link.active {
    color: #0d6efd;
    background: #fff;
    border-color: #dee2e6 #dee2e6 #fff;
}
@media (min-width: 768px) {
    #mainTabs .nav-link { padding: 0.6rem 1rem; font-size: 0.9rem; }
}

/* ── Tab content ───────────────────────────────────────────────────────────── */
.tab-content {
    background: #fff;
    padding: 0.75rem;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid #dee2e6;
    border-top: none;
}
@media (min-width: 768px) {
    .tab-content { padding: 1.25rem; }
}

/* ── Punto de Venta ────────────────────────────────────────────────────────── */
#search-product {
    font-size: 1rem;
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
}
@media (max-width: 767px) {
    /* En móvil: buscador + tabla arriba, carrito abajo como panel fijo */
    #venta .row { margin: 0; }
    #venta .col-md-7,
    #venta .col-md-5 { padding: 0; }
    #venta .col-md-5 { margin-top: 0.75rem; }
}

/* Tabla de productos del POS */
#products-table-body tr { cursor: pointer; }
#products-table-body tr:hover,
#products-table-body tr:active { background-color: #e8f5e9; }
#products-table-body td { padding: 0.5rem 0.4rem; vertical-align: middle; }
@media (max-width: 575px) {
    #products-table-body td:nth-child(3),   /* Stock */
    .pos-table thead th:nth-child(3) { display: none; } /* ocultar stock en xs */
}

/* Carrito */
.cart-row { transition: background 0.15s; }
.cart-row:hover { background: #f1f5f9; }
#cart-body td { padding: 0.35rem 0.3rem; vertical-align: middle; font-size: 0.85rem; }

/* Total y botón confirmar */
#btn-checkout {
    min-width: 120px;
    font-size: 1rem;
    padding: 0.5rem 1rem;
    touch-action: manipulation;
}
@media (max-width: 575px) {
    #btn-checkout { width: 100%; margin-top: 0.5rem; }
    .checkout-footer { flex-direction: column !important; gap: 0.5rem; }
    .checkout-footer h4 { margin-bottom: 0; }
}

/* ── Carrito fijo en móvil (colapsable) ────────────────────────────────────── */
@media (max-width: 767px) {
    #cart-collapse-btn { display: block !important; }
    #cart-body-wrap { transition: max-height 0.3s ease; overflow: hidden; }
}
@media (min-width: 768px) {
    #cart-collapse-btn { display: none !important; }
    #cart-body-wrap { max-height: none !important; }
}

/* ── Tablas generales ──────────────────────────────────────────────────────── */
.table { font-size: 0.85rem; }
.table td, .table th { vertical-align: middle; padding: 0.4rem 0.5rem; }
@media (max-width: 575px) {
    .table { font-size: 0.78rem; }
    .table td, .table th { padding: 0.3rem 0.35rem; }
}

/* ── Cards / Modales ───────────────────────────────────────────────────────── */
.card { border-radius: 8px; }
.card-header { padding: 0.5rem 0.75rem; font-size: 0.88rem; }
.modal-body { padding: 1rem; }
@media (max-width: 575px) {
    .modal-dialog { margin: 0.5rem; }
    .modal-dialog.modal-lg { max-width: 100%; margin: 0.25rem; }
    .modal-dialog.modal-sm { max-width: 100%; margin: 0.5rem; }
}

/* ── Modal de cobro ────────────────────────────────────────────────────────── */
#pay-amount {
    font-size: 1.6rem;
    font-weight: 700;
    text-align: right;
    height: 3rem;
    touch-action: manipulation;
}
#pay-confirm-btn {
    font-size: 1.1rem;
    padding: 0.6rem 1.5rem;
    touch-action: manipulation;
}
#pay-quick-btns .btn {
    font-size: 0.85rem;
    padding: 0.4rem 0.7rem;
    touch-action: manipulation;
    min-width: 70px;
}
.btn-check + label {
    font-size: 0.95rem;
    padding: 0.6rem;
    touch-action: manipulation;
}
#pay-vuelto-wrap, #pay-vuelto-error {
    font-size: 1.1rem;
    padding: 0.75rem;
}
#pay-vuelto { font-size: 2rem; display: block; }

/* ── Sub-tabs de reportes ──────────────────────────────────────────────────── */
#reportTabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
    padding-bottom: 4px;
}
#reportTabs::-webkit-scrollbar { display: none; }
#reportTabs .nav-link {
    white-space: nowrap;
    font-size: 0.82rem;
    padding: 0.4rem 0.75rem;
    touch-action: manipulation;
}

/* ── KPI cards de reportes ─────────────────────────────────────────────────── */
@media (max-width: 575px) {
    /* 2 columnas en xs */
    #report-resumen .row.g-3 > [class*="col-md-"],
    #range-result   .row.g-3 > [class*="col-md-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }
    #report-resumen .row.g-3 > .col-md-8,
    #report-resumen .row.g-3 > .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ── Formularios en móvil ──────────────────────────────────────────────────── */
@media (max-width: 575px) {
    .form-control, .form-select {
        font-size: 1rem;   /* evita zoom automático en iOS */
        padding: 0.45rem 0.6rem;
    }
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        font-size: 1rem;
    }
}

/* ── Botones táctiles ──────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    .btn { touch-action: manipulation; }
    .btn-sm { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
}

/* ── Compras — input-group en móvil ────────────────────────────────────────── */
@media (max-width: 575px) {
    #purchase-form .input-group { flex-wrap: wrap; gap: 4px; }
    #purchase-form .input-group .form-control { border-radius: 6px !important; }
    #purchase-form .input-group .btn { border-radius: 6px !important; width: 100%; }
}

/* ── Stock bajo — tabla scrolleable ───────────────────────────────────────── */
#stockbajo-body td,
#stockbajo-body th { white-space: nowrap; }

/* ── Alertas ───────────────────────────────────────────────────────────────── */
.alert { font-size: 0.88rem; padding: 0.6rem 0.9rem; }

/* ── Impresión térmica 80mm ────────────────────────────────────────────────── */
@media print {
    body * { visibility: hidden; }
    #ticket-content, #ticket-content * { visibility: visible; }
    #ticket-content {
        position: absolute; left: 0; top: 0;
        width: 75mm; padding: 5mm;
        font-family: monospace; font-size: 12px;
    }
    .no-print, .modal-footer, .navbar, .main-container { display: none !important; }
    @page { margin: 0; size: 80mm auto; }
}

/* ── Ticket ────────────────────────────────────────────────────────────────── */
.ticket h3 { margin: 0 0 5px; }
.line { border-top: 1px dashed #000; margin: 6px 0; }
.item { display: flex; justify-content: space-between; margin: 3px 0; }
.total { font-weight: bold; text-align: center; margin-top: 8px; font-size: 1.1em; }

/* ── Utilidades extra ──────────────────────────────────────────────────────── */
.text-truncate-sm {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (min-width: 768px) { .text-truncate-sm { max-width: none; } }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.app-footer {
    background: #212529;
    color: #adb5bd;
    font-size: 0.75rem;
    padding: 0.55rem 1rem;
    margin-top: auto;
}
.app-footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    max-width: 100%;
}
.app-footer strong { color: #dee2e6; }
.app-footer-visits {
    color: #6c757d;
    white-space: nowrap;
}

/* Login page: footer pegado al fondo */
body.login-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    justify-content: center;
}
body.login-page .login-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
