/* ==========================================================================
   POS STORE - Tema profesional claro (Junior Mota)
   Sistema de diseño sobre Bootstrap 5.3.3: paleta, superficies y layout.
   ========================================================================== */

:root {
    --ps-primary: #2563eb;
    --ps-primary-strong: #1d4ed8;
    --ps-primary-soft: #eff6ff;
    --ps-accent: #0ea5e9;
    --ps-success: #16a34a;
    --ps-warning: #d97706;
    --ps-danger: #dc2626;
    --ps-text: #0f172a;
    --ps-text-muted: #64748b;
    --ps-surface: #ffffff;
    --ps-bg: #f1f5f9;
    --ps-border: #e2e8f0;
    --ps-shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 6px rgba(15, 23, 42, .04);
    --ps-shadow-md: 0 4px 14px rgba(15, 23, 42, .08);
    --ps-shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
    --ps-radius: .875rem;
    --ps-topbar-h: 64px;
    --ps-sidebar-w: 264px;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--ps-bg);
    color: var(--ps-text);
    font-size: .925rem;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -.01em;
    color: var(--ps-text);
}

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

/* ------------------------------ Layout shell ---------------------------- */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-body {
    flex: 1 1 auto;
    display: flex;
    width: 100%;
}

.app-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.5rem 1.75rem 2rem;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

@media (max-width: 991.98px) {
    .app-content {
        padding: 1rem 1rem 2rem;
    }
}

@media (max-width: 575.98px) {
    .app-content {
        padding: .85rem .75rem 1.5rem;
    }
}

/* -------------------------------- Topbar -------------------------------- */
.topbar {
    height: var(--ps-topbar-h);
    background: var(--ps-surface);
    border-bottom: 1px solid var(--ps-border);
    box-shadow: var(--ps-shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1030;
    flex: 0 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--ps-text);
    text-decoration: none;
}

.topbar .brand {
    margin: 0;
}

.brand img {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: contain;
    background: var(--ps-primary-soft);
    padding: 3px;
}

.topbar .topbar-link {
    color: var(--ps-text-muted);
    border-radius: .625rem;
    padding: .35rem .7rem;
    font-size: .875rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    transition: background .15s ease, color .15s ease;
}

.topbar .topbar-link:hover {
    background: var(--ps-primary-soft);
    color: var(--ps-primary);
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--ps-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .8rem;
}

/* -------------------------------- Sidebar ------------------------------- */
.sidebar {
    --bs-offcanvas-width: 288px;
    background: var(--ps-surface);
    border-right: 1px solid var(--ps-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar .nav-title {
    font-size: .685rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--ps-text-muted);
    padding: 1.15rem 1.35rem .35rem;
    font-weight: 600;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    color: #334155;
    font-weight: 500;
    font-size: .875rem;
    border-radius: .625rem;
    margin: .125rem .7rem;
    padding: .55rem .85rem;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}

.sidebar .nav-link i {
    width: 1.1rem;
    text-align: center;
    color: var(--ps-text-muted);
    transition: color .15s ease;
}

.sidebar .nav-link:hover {
    background: var(--ps-bg);
    color: var(--ps-text);
}

.sidebar .nav-link.active {
    background: var(--ps-primary-soft);
    color: var(--ps-primary-strong);
}

.sidebar .nav-link.active i {
    color: var(--ps-primary);
}

/* --------------------------------- Footer ------------------------------- */
.footer {
    background: var(--ps-surface);
    border-top: 1px solid var(--ps-border);
    color: var(--ps-text-muted);
    font-size: .825rem;
    padding: .9rem 1.5rem;
}

.footer .author {
    font-weight: 600;
    color: var(--ps-text);
    text-decoration: none;
}

/* ------------------------------- Componentes ---------------------------- */

/* Cards */
.card {
    border: 1px solid var(--ps-border);
    border-radius: var(--ps-radius);
    box-shadow: var(--ps-shadow-sm);
    background: var(--ps-surface);
}

.card-header {
    background: var(--ps-surface);
    border-bottom: 1px solid var(--ps-border);
    padding: .9rem 1.25rem;
    border-radius: calc(var(--ps-radius) - 1px) calc(var(--ps-radius) - 1px) 0 0;
}

.card-title {
    font-weight: 600;
    font-size: .95rem;
    display: flex;
    align-items: center;
    gap: .55rem;
}

.card-footer {
    background: #f8fafc;
    border-top: 1px solid var(--ps-border);
    padding: .85rem 1.25rem;
}

/* Botones */
.btn {
    border-radius: .625rem;
    font-weight: 500;
    font-size: .85rem;
    padding: .5rem 1rem;
    transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--ps-primary);
    border-color: var(--ps-primary);
    box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
}

.btn-primary:hover {
    background: var(--ps-primary-strong);
    border-color: var(--ps-primary-strong);
}

.btn-success {
    background: var(--ps-success);
    border-color: var(--ps-success);
}

.btn-warning {
    background: var(--ps-warning);
    border-color: var(--ps-warning);
}

/* Secundario en versión clara (touchspin, grupos de entrada, etc.) */
.btn-secondary {
    --bs-btn-bg: #e2e8f0;
    --bs-btn-border-color: #e2e8f0;
    --bs-btn-color: #475569;
    --bs-btn-hover-bg: #cbd5e1;
    --bs-btn-hover-border-color: #cbd5e1;
    --bs-btn-hover-color: #334155;
    --bs-btn-active-bg: #cbd5e1;
    --bs-btn-active-border-color: #b6c2d2;
    --bs-btn-active-color: #334155;
    background: #e2e8f0;
    border-color: #e2e8f0;
    color: #475569;
}

.btn-secondary:hover {
    background: #cbd5e1;
    border-color: #cbd5e1;
    color: #334155;
}

/* Botones verticales +/- de touchspin */
.input-group-btn-vertical > .btn {
    border-radius: 0 .5rem .5rem 0;
    padding: .25rem .45rem;
}

.btn-danger {
    background: var(--ps-danger);
    border-color: var(--ps-danger);
}

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Formularios */
.form-control, .form-select {
    border-radius: .625rem;
    border-color: #cbd5e1;
    padding: .55rem .85rem;
    font-size: .875rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--ps-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.form-label {
    font-size: .8rem;
    font-weight: 600;
    color: #475569;
    letter-spacing: .01em;
    margin-bottom: .3rem;
}

textarea.form-control {
    min-height: 96px;
}

input[type=file].form-control {
    background: #f8fafc;
}

/* Tablas */
.table {
    font-size: .85rem;
    --bs-table-border-color: var(--ps-border);
}

.table > thead th {
    background: #f8fafc;
    color: var(--ps-text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    border-bottom: 1px solid var(--ps-border);
    padding: .7rem .85rem;
    white-space: nowrap;
}

.table > tbody td {
    padding: .65rem .85rem;
    vertical-align: middle;
}

.table > tbody tr:hover {
    background: var(--ps-primary-soft);
}

.table-hover > tbody > tr:hover > * {
    --bs-table-accent-bg: var(--ps-primary-soft);
}

/* Breadcrumb */
.breadcrumb {
    background: var(--ps-surface);
    border: 1px solid var(--ps-border);
    border-radius: .625rem;
    padding: .55rem 1rem;
    font-size: .825rem;
    margin-bottom: 1.25rem;
}

.breadcrumb a {
    color: var(--ps-text-muted) !important;
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--ps-primary) !important;
}

/* Dropdowns */
.dropdown-menu {
    border: 1px solid var(--ps-border);
    border-radius: .75rem;
    box-shadow: var(--ps-shadow-lg);
    font-size: .85rem;
    padding: .35rem;
}

.dropdown-item {
    border-radius: .5rem;
    padding: .5rem .75rem;
}

.dropdown-item:hover {
    background: var(--ps-primary-soft);
    color: var(--ps-primary-strong);
}

.dropdown-header {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
}

/* Badges / estados */
.badge-soft-success {
    background: #dcfce7;
    color: #15803d;
    font-weight: 600;
}

.badge-soft-danger {
    background: #fee2e2;
    color: #b91c1c;
    font-weight: 600;
}

/* ------------------------------ Nueva venta ----------------------------- */
.search-product .form-control {
    border-left: none;
}

.search-product .input-group-text {
    background: #fff;
    color: var(--ps-text-muted);
    border-radius: .625rem 0 0 .625rem;
}

.search-product .btn {
    border-radius: 0 .625rem .625rem 0;
}

.btn-link-link {
    background: transparent;
    border: 1px solid transparent;
    color: var(--ps-text-muted);
    font-size: .8rem;
    font-weight: 500;
    padding: .25rem .6rem;
    border-radius: .5rem;
}

.btn-link-link:hover {
    background: var(--ps-bg);
    color: var(--ps-text);
}

.sale-totals {
    position: sticky;
    top: calc(var(--ps-topbar-h) + 1rem);
}

.total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem 0;
    border-bottom: 1px dashed var(--ps-border);
}

.total-row:last-of-type {
    border-bottom: 0;
}

.total-row label {
    margin: 0;
    font-size: .825rem;
    font-weight: 600;
    color: var(--ps-text-muted);
}

.total-row .totals-view,
.total-row .total-input {
    width: 130px;
    text-align: right;
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: .95rem;
    color: var(--ps-text);
    padding: .1rem 0;
    outline: none;
    box-shadow: none !important;
}

.total-row .total-input {
    border-bottom: 1px solid var(--ps-primary);
    width: 110px;
    color: var(--ps-primary-strong);
}

.total-row input:disabled {
    opacity: 1;
}

.grand-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f1f5f9;
    border: 1px solid var(--ps-border);
    border-left: 4px solid var(--ps-primary);
    color: var(--ps-text);
    border-radius: .875rem;
    padding: .8rem 1.1rem;
    font-weight: 700;
    letter-spacing: .04em;
    box-shadow: none;
}

.grand-total-input {
    width: 140px;
    text-align: right;
    border: none;
    background: transparent !important;
    color: var(--ps-text) !important;
    opacity: 1 !important;
    font-weight: 700;
    font-size: 1.4rem;
    outline: none;
    -webkit-text-fill-color: var(--ps-text);
}

.grand-total-input::placeholder {
    color: var(--ps-text-muted);
    -webkit-text-fill-color: var(--ps-text-muted);
}

.alert-saldo-pendiente {
    background: #fff3e0;
    color: #b45309;
    border: 1px solid #fdba74;
    border-radius: .75rem;
    font-size: .8rem;
    padding: .6rem .9rem;
    margin: 0;
}

.money-input .input-group-text {
    background: #fff;
    color: var(--ps-text-muted);
}

.money-input .form-control {
    font-weight: 600;
}

/* Botones de accion en tablas */
.actions-group {
    display: inline-flex;
    gap: .3rem;
}

.actions-group .btn {
    padding: .3rem .6rem;
    border-radius: .5rem !important;
}

.actions-group .btn + .btn {
    margin-left: 0;
}

@media (max-width: 1399.98px) {
    .sale-totals {
        position: static;
    }
}

/* Paginación */
.pagination .page-link {
    border-radius: .5rem !important;
    margin: 0 .15rem;
    border: none;
    color: var(--ps-text-muted);
    font-size: .85rem;
    padding: .45rem .8rem;
}

.pagination .page-item.active .page-link {
    background: var(--ps-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, .35);
}

/* DataTables wrapper */
.dataTables_wrapper {
    font-size: .85rem;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info {
    color: var(--ps-text-muted);
    margin-bottom: .85rem;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #cbd5e1;
    border-radius: .5rem;
    padding: .3rem .7rem;
    margin-left: .4rem;
    outline: none;
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
    border-color: var(--ps-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

.dataTables_wrapper .dataTables_paginate {
    margin-top: .5rem;
}

/* Modal */
.modal-content {
    border: none;
    border-radius: var(--ps-radius);
    box-shadow: var(--ps-shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--ps-border);
    padding: 1rem 1.25rem;
}

.modal-footer {
    border-top: 1px solid var(--ps-border);
}

/* Overlay de carga */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(241, 245, 249, .65);
    backdrop-filter: blur(2px);
    z-index: 1080;
    display: none;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay .loading-box {
    background: var(--ps-surface);
    border: 1px solid var(--ps-border);
    border-radius: var(--ps-radius);
    box-shadow: var(--ps-shadow-md);
    padding: 1.1rem 1.6rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    font-weight: 600;
    color: var(--ps-text);
}

.loading-overlay .spinner-border {
    width: 1.6rem;
    height: 1.6rem;
    border-width: .18em;
    color: var(--ps-primary);
}

/* Sidebar off-canvas responsive: Bootstrap offcanvas-lg maneja el drawer
   en pantallas < lg. En desktop la sidebar es una columna fija (sticky)
   con fondo propio (Bootstrap la fuerza a transparente sobre el breakpoint). */
@media (min-width: 992px) {
    .sidebar {
        width: var(--ps-sidebar-w);
        flex: 0 0 var(--ps-sidebar-w);
        position: sticky;
        top: var(--ps-topbar-h);
        height: calc(100vh - var(--ps-topbar-h));
        background-color: var(--ps-surface) !important;
        transform: none !important;
        visibility: visible !important;
    }
}

/* ---------------------------------- KPIs -------------------------------- */
.kpi-card .card-body {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.25rem;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex: 0 0 48px;
}

.kpi-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ps-text-muted);
    font-weight: 600;
}

.kpi-value {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
    color: var(--ps-text);
}

.bg-primary-soft { background: var(--ps-primary-soft); }
.bg-success-soft { background: #dcfce7; }
.bg-warning-soft { background: #fef3c7; }
.bg-info-soft { background: #e0f2fe; }

/* ------------------------------ Delete card ------------------------------ */
.delete-card {
    max-width: 520px;
}

.delete-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #fee2e2;
    color: var(--ps-danger);
    font-size: 1.6rem;
    align-items: center;
    justify-content: center;
}

/* Grilla de campos: utility suave para formularios personalizados */
.form-input {
    min-width: 0;
}

/* ---------------------- Ventas: estado de pago -------------------------- */
#data tbody td:nth-child(10),
#tblReport tbody td:nth-child(10) {
    font-weight: 600;
}

tr.row-pagado > td {
    background-color: #e8f5e9 !important;
}

tr.row-parcial > td {
    background-color: #fff3e0 !important;
}

tr.row-pendiente > td {
    background-color: #fdecea !important;
}

.badge-pagado {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
    font-weight: 600;
}

.badge-parcial {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
    font-weight: 600;
}

.badge-pendiente {
    background: #fdecea;
    color: #c62828;
    border: 1px solid #f5c6cb;
    font-weight: 600;
}

/* Modal de abonos */
.pay-box {
    background: var(--ps-bg);
    border: 1px solid var(--ps-border);
    border-radius: .75rem;
    padding: .7rem .5rem;
}

.pay-box label {
    display: block;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ps-text-muted);
    font-weight: 600;
    margin: 0 0 .2rem;
}

.pay-box div {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--ps-text);
}

.pay-box.pay-saldo {
    background: #fff3e0;
    border-color: #ffcc80;
}

.pay-box.pay-saldo div {
    color: #e65100;
}

.pay-box.pay-monto {
    background: #f0fdfa;
    border-color: #99f6e4;
}

.pay-box.pay-monto div {
    color: #0f766e;
}

.pay-box.pay-tasa {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.pay-box.pay-tasa div {
    color: #4338ca;
}

.pay-box .tasa-fecha {
    font-size: .68rem;
    font-weight: 500;
    color: var(--ps-text-muted);
}

/* Selector de moneda del abono */
.abono-modo {
    min-width: 54px;
    font-weight: 600;
}

.abono-modo.active {
    background: var(--ps-primary);
    border-color: var(--ps-primary);
    color: #fff;
}

.abono-modo.modo-disabled {
    opacity: .45;
    pointer-events: none;
}

/* Cards simetricas Monto Bs / Tasa */
.pay-monto,
.pay-tasa {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.comprobante-preview {
    max-width: 220px;
    max-height: 160px;
    border: 1px solid var(--ps-border);
    border-radius: .75rem;
    object-fit: cover;
}

.comprobante-full {
    max-width: 100%;
    max-height: 70vh;
    border-radius: .75rem;
}

@media (max-width: 575.98px) {
    .topbar .brand {
        font-size: .95rem;
    }

    .main-content {
        padding: .85rem .75rem 1.5rem;
    }

    .footer {
        font-size: .75rem;
        text-align: center;
    }
}
