:root {
    --ledhcar-red: #e63329;
    --ledhcar-red-dark: #c0221a;
    --ledhcar-dark: #1a1a2e;
    --ledhcar-sidebar: #16213e;
    --ledhcar-sidebar-hover: #0f3460;
    --ledhcar-gray: #2d2d2d;
    --ledhcar-light: #f8f9fa;
    --ledhcar-border: #dee2e6;
    --text-muted: #6c757d;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f2f5;
    color: #2d2d2d;
    overflow-x: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
    width: 260px;
    /* ALTURA FIJA, no min-height: con min-height el sidebar crecía con el menú y,
       al ser position:fixed, los últimos ítems quedaban fuera de la pantalla sin
       forma de alcanzarlos. Con height fija, el que scrollea es .sidebar-menu. */
    height: 100vh;
    height: 100dvh;            /* respeta la barra del navegador en móviles */
    background: var(--ledhcar-dark);
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: transform .3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;          /* el scroll vive en .sidebar-menu */
}

#sidebar .sidebar-logo {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;            /* el logo no se comprime cuando el menú es largo */
}

#sidebar .sidebar-logo .brand-icon {
    width: 40px;
    height: 40px;
    background: var(--ledhcar-red);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

#sidebar .sidebar-logo h5 {
    margin: 0;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .5px;
}

#sidebar .sidebar-logo small {
    color: rgba(255,255,255,.5);
    font-size: 11px;
    display: block;
}

#sidebar .sidebar-logo .sidebar-logo-img {
    max-width: 100%;
    max-height: 56px;
    width: auto;
    height: auto;
    background: #fff;
    border-radius: 8px;
    padding: 6px 10px;
}

.sidebar-menu {
    padding: 12px 0;
    flex: 1 1 auto;
    /* `scroll` y no `auto`: así la barra está SIEMPRE a la vista y se ve que el
       menú continúa, en lugar de aparecer solo al pasar el ratón por encima. */
    overflow-y: scroll;
    overflow-x: hidden;
    min-height: 0;             /* sin esto, un hijo flex no puede encogerse y no scrollea */
    overscroll-behavior: contain;
    scrollbar-gutter: stable;  /* reserva el espacio: el menú no “salta” al aparecer */
}

/* ── Barra de desplazamiento del menú ────────────────────────────────────────
   Ancha y con buen contraste sobre el fondo oscuro, para que se vea y se pueda
   arrastrar con el ratón sin apuntar a un hilo de 4px. */
.sidebar-menu::-webkit-scrollbar {
    width: 12px;
    background: rgba(0,0,0,.28);
}
.sidebar-menu::-webkit-scrollbar-track {
    background: rgba(0,0,0,.28);
    border-radius: 0;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.42);
    border-radius: 8px;
    border: 3px solid transparent;
    background-clip: padding-box;
    min-height: 44px;          /* agarre cómodo aunque el menú sea muy largo */
}
.sidebar-menu::-webkit-scrollbar-thumb:hover  { background: rgba(255,255,255,.70); background-clip: padding-box; }
.sidebar-menu::-webkit-scrollbar-thumb:active { background: var(--ledhcar-red);    background-clip: padding-box; }

/* Propiedades estándar (Chrome 121+, Edge, Firefox). Ojo: cuando el navegador
   las soporta, IGNORA los ::-webkit-scrollbar de arriba — que quedan solo como
   respaldo para versiones antiguas y Safari. El color visible sale de aquí. */
.sidebar-menu {
    scrollbar-width: auto;                                  /* barra ancha, no fina */
    scrollbar-color: rgba(255,255,255,.55) rgba(0,0,0,.35); /* pulgar / fondo */
}

/* Degradados que avisan de que el menú continúa fuera de la vista.
   Las clases las pone/quita el script del footer según la posición del scroll. */
.sidebar-menu { position: relative; }
#sidebar::before,
#sidebar::after {
    content: '';
    position: absolute;
    left: 0; right: 17px;      /* deja libre el ancho de la barra de desplazamiento */
    height: 26px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s ease;
    z-index: 2;
}
#sidebar::before {
    top: 89px;                 /* justo debajo del logo */
    background: linear-gradient(to bottom, var(--ledhcar-dark), transparent);
}
#sidebar::after {
    bottom: 0;
    background: linear-gradient(to top, var(--ledhcar-dark), transparent);
}
#sidebar.has-more-above::before { opacity: 1; }
#sidebar.has-more-below::after  { opacity: 1; }

.sidebar-section {
    padding: 12px 20px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.3);
    font-weight: 600;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: rgba(255,255,255,.7);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: all .2s;
    position: relative;
    border-radius: 0;
    cursor: pointer;
}

.sidebar-item i { width: 18px; font-size: 15px; }

.sidebar-item:hover,
.sidebar-item.active {
    color: #fff;
    background: var(--ledhcar-sidebar-hover);
    text-decoration: none;
}

.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--ledhcar-red);
}

.sidebar-item .badge-count {
    margin-left: auto;
    background: var(--ledhcar-red);
    color: #fff;
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 20px;
    font-weight: 600;
}

.sidebar-submenu { display: none; }
.sidebar-submenu.open { display: block; }
.sidebar-submenu .sidebar-item {
    padding-left: 48px;
    font-size: 13px;
    color: rgba(255,255,255,.55);
}

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--ledhcar-red);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user .user-info small { color: rgba(255,255,255,.5); font-size: 11px; }
.sidebar-user .user-info span { color: #fff; font-size: 13px; font-weight: 600; display: block; }

/* Avatar del usuario en la barra superior */
.navbar-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ledhcar-red);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── MAIN CONTENT ── */
#main-content {
    margin-left: 260px;
    min-height: 100vh;
    transition: margin .3s ease;
}

/* ── TOP NAVBAR ── */
.top-navbar {
    background: #fff;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    position: sticky;
    top: 0;
    z-index: 900;
}

.top-navbar .page-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--ledhcar-gray);
    margin: 0;
}

.top-navbar .breadcrumb { margin: 0; font-size: 12px; }

.navbar-right { display: flex; align-items: center; gap: 12px; }

.btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--ledhcar-gray);
    cursor: pointer;
}

/* ── PAGE CONTENT ── */
.page-content { padding: 24px; }

/* ── CARDS KPI ── */
.kpi-card {
    background: #fff;
    border-radius: 14px;
    padding: 22px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    display: flex;
    align-items: center;
    gap: 18px;
    transition: transform .2s, box-shadow .2s;
    height: 100%;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,.1);
}

.kpi-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.kpi-icon.red { background: rgba(230,51,41,.12); color: var(--ledhcar-red); }
.kpi-icon.blue { background: rgba(13,110,253,.12); color: #0d6efd; }
.kpi-icon.green { background: rgba(25,135,84,.12); color: #198754; }
.kpi-icon.orange { background: rgba(253,126,20,.12); color: #fd7e14; }
.kpi-icon.purple { background: rgba(111,66,193,.12); color: #6f42c1; }
.kpi-icon.teal { background: rgba(32,201,151,.12); color: #20c997; }
.kpi-icon.yellow { background: rgba(255,193,7,.15); color: #d4a017; }
.kpi-icon.dark { background: rgba(33,37,41,.1); color: #212529; }

.kpi-body { flex: 1; min-width: 0; }
.kpi-label {
    font-size: 12px; color: var(--text-muted); font-weight: 500;
    text-transform: uppercase; letter-spacing: .5px;
}
/* El importe se adapta al ancho disponible: en móvil las tarjetas van a media
   columna y con un tamaño fijo los montos grandes quedaban cortados. */
.kpi-value {
    font-size: clamp(15px, 4.6vw, 22px);
    font-weight: 700;
    color: var(--ledhcar-gray);
    line-height: 1.2;
    overflow-wrap: anywhere;   /* "$ 23.382.665" parte en vez de desbordarse */
}
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi-trend { font-size: 12px; font-weight: 600; }
.kpi-trend.up { color: #198754; }
.kpi-trend.down { color: var(--ledhcar-red); }

/* ── CHART CARD ── */
.chart-card {
    background: #fff;
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    height: 100%;
}

.chart-card .card-header-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ledhcar-border);
}

.chart-card .card-header-custom h6 {
    margin: 0;
    font-weight: 700;
    font-size: 15px;
}

/* ── TABLES ── */
.table-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    overflow: hidden;
}

.table-card .table-header {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--ledhcar-border);
    flex-wrap: wrap;
    gap: 12px;
}

.table-card .table-header h6 {
    margin: 0;
    font-weight: 700;
    font-size: 15px;
}

.table-striped > tbody > tr:nth-of-type(odd) > * { background-color: rgba(0,0,0,.02); }
.table th { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); border-bottom: 2px solid var(--ledhcar-border); }
.table td { font-size: 13.5px; vertical-align: middle; }

/* ── BUTTONS ── */
.btn-ledhcar {
    background: var(--ledhcar-red);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    padding: 8px 18px;
    transition: all .2s;
}

.btn-ledhcar:hover {
    background: var(--ledhcar-red-dark);
    color: #fff;
    transform: translateY(-1px);
}

.btn-ledhcar-outline {
    background: transparent;
    color: var(--ledhcar-red);
    border: 1.5px solid var(--ledhcar-red);
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    padding: 7px 18px;
    transition: all .2s;
}

.btn-ledhcar-outline:hover {
    background: var(--ledhcar-red);
    color: #fff;
}

/* ── FORMS ── */
.form-card {
    background: #fff;
    border-radius: 14px;
    padding: 28px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.form-label { font-size: 13px; font-weight: 600; color: #495057; }
.form-control, .form-select {
    border: 1.5px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    padding: 8px 12px;
    transition: border-color .2s, box-shadow .2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--ledhcar-red);
    box-shadow: 0 0 0 3px rgba(230,51,41,.12);
    outline: none;
}

/* ── BADGES ── */
.badge { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 6px; }

/* ── MODALS ── */
.modal-header { background: var(--ledhcar-dark); color: #fff; border-radius: 12px 12px 0 0; }
.modal-header .btn-close { filter: invert(1); }
.modal-content { border: none; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }

/* ── LOGIN ── */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--ledhcar-dark) 0%, var(--ledhcar-sidebar) 50%, #0f3460 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 30px 80px rgba(0,0,0,.3);
}

.login-card .brand { text-align: center; margin-bottom: 32px; }
.login-card .brand h1 { font-size: 36px; font-weight: 800; color: var(--ledhcar-red); letter-spacing: -1px; }
.login-card .brand p { color: var(--text-muted); font-size: 13px; margin: 0; }

/* ── ALERTS ── */
.alert { border-radius: 10px; font-size: 14px; border: none; }
.alert-success { background: rgba(25,135,84,.1); color: #0d5c37; }
.alert-danger { background: rgba(220,53,69,.1); color: #842029; }
.alert-warning { background: rgba(255,193,7,.15); color: #664d03; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────────
   Se usan tres cortes: 992px (tablet: el menú pasa a ser deslizable),
   768px (móvil grande) y 576px (móvil). Nada debe provocar scroll horizontal:
   las tablas anchas se desplazan dentro de su propio contenedor. */

/* Ninguna página debe desbordarse a lo ancho */
html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video, canvas { max-width: 100%; height: auto; }
.table-responsive { -webkit-overflow-scrolling: touch; }

@media (max-width: 992px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.open { transform: translateX(0); box-shadow: 0 0 24px rgba(0,0,0,.4); }
    #main-content { margin-left: 0; }
    .btn-sidebar-toggle { display: block; }
    .sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 999;
    }
    .sidebar-overlay.show { display: block; }
    .page-content { padding: 16px; }
}

@media (max-width: 768px) {
    .top-navbar { padding: 0 12px; gap: 8px; }
    .top-navbar .page-title { font-size: 15px; }
    .page-content { padding: 12px; }
    .page-header { align-items: flex-start; }
    .page-header h4 { font-size: 17px; }
    /* Los grupos de botones de cabecera pasan a ocupar el ancho disponible */
    .page-header .d-flex { width: 100%; }
    .form-card, .table-card { padding: 14px; border-radius: 10px; }
    /* En el resumen de venta el panel deja de estar pegado arriba */
    .sticky-top { position: static !important; }
    .modal-dialog { margin: 8px; }
    /* Las tablas de datos respiran menos para que quepa más información */
    #tablaProductos td, #tablaProductos th,
    .table td, .table th { padding: 8px 6px; font-size: 13px; }
}

/* ── MODALES Y AVISOS: que el texto se lea bien en cualquier pantalla ── */
.modal-title { font-size: 17px; overflow-wrap: anywhere; }
.modal-body { overflow-wrap: anywhere; }
.modal-body p, .modal-body li, .modal-body label { overflow-wrap: break-word; }
/* Los diálogos de SweetAlert2 también */
.swal2-popup { font-size: 15px !important; }
.swal2-title { font-size: 20px !important; overflow-wrap: anywhere; }
.swal2-html-container { overflow-wrap: anywhere; word-break: normal; }

@media (max-width: 768px) {
    .modal-dialog { max-width: calc(100% - 16px); }
    .modal-title { font-size: 15px; }
    .modal-body { font-size: 14px; padding: 14px; }
    .modal-header, .modal-footer { padding: 12px 14px; }
    /* Los botones del pie ocupan el ancho: más fáciles de tocar */
    .modal-footer .btn { flex: 1 1 auto; }
    .swal2-popup { width: 92% !important; font-size: 14px !important; padding: 16px !important; }
    .swal2-title { font-size: 17px !important; }
    .swal2-html-container { font-size: 14px !important; margin: 8px 0 !important; }
    .swal2-actions { flex-wrap: wrap; gap: 8px; }
    .swal2-actions .swal2-styled { flex: 1 1 auto; margin: 0 !important; }
}

@media (max-width: 576px) {
    .top-navbar { height: 54px; }
    /* El modal ocupa la pantalla completa: se aprovecha todo el ancho */
    .modal-dialog { margin: 0; max-width: 100%; }
    .modal-content { border-radius: 0; min-height: 100vh; }
    .modal-body { max-height: none; }
    /* Tarjetas del dashboard: etiqueta más compacta para que quepa el monto */
    .kpi-card { padding: 12px; gap: 10px; }
    .kpi-icon { width: 38px; height: 38px; font-size: 16px; }
    .kpi-label { font-size: 10px; letter-spacing: .2px; line-height: 1.25; }
    .kpi-sub { font-size: 11px; }
    .top-navbar .page-title { font-size: 14px; }
    .page-content { padding: 10px; }
    .page-header { gap: 8px; }
    .page-header h4 { font-size: 16px; }
    /* Los botones de la cabecera se reparten el ancho en vez de desbordarse */
    .page-header .btn { flex: 1 1 auto; justify-content: center; }
    .form-card, .table-card { padding: 12px; }
    /* DataTables: buscador y selector de página, uno debajo del otro */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length { float: none; text-align: left; width: 100%; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; margin: 4px 0 0; }
    .dataTables_wrapper .dataTables_paginate { float: none; text-align: center; padding-top: 10px; }
    .action-btns { display: flex; flex-wrap: wrap; gap: 4px; }
    /* Cifras grandes del dashboard: que no rompan la tarjeta */
    .fs-4, .fs-5 { font-size: 1.05rem !important; }
}

/* ── MISC ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h4 { margin: 0; font-weight: 700; font-size: 20px; }

.search-box { position: relative; }
.search-box input { padding-left: 36px; border-radius: 8px; border: 1.5px solid #e0e0e0; }
.search-box i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 14px; }

.dataTables_wrapper .dataTables_filter input { border: 1.5px solid #e0e0e0; border-radius: 8px; padding: 6px 12px; }
.dataTables_wrapper .dataTables_length select { border: 1.5px solid #e0e0e0; border-radius: 8px; padding: 5px 8px; }

.action-btns .btn { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

.stock-low { color: #dc3545; font-weight: 700; }
.stock-ok { color: #198754; }

.currency { font-weight: 600; }
.text-profit { color: #198754; font-weight: 700; }
.text-loss { color: #dc3545; font-weight: 700; }

.spinner-overlay {
    position: fixed; inset: 0;
    background: rgba(255,255,255,.85);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }

/* ── PRINT ── */
@media print {
    #sidebar, .top-navbar, .btn, .no-print { display: none !important; }
    #main-content { margin: 0 !important; }
    .page-content { padding: 0 !important; }
}
