/* =====================================================================
   Sistema de Inventario · Tema minimalista con modo claro / oscuro
   ===================================================================== */

:root,
[data-bs-theme="light"] {
    --app-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --app-bg: #f5f6fa;
    --app-surface: #ffffff;
    --app-surface-2: #f8f9fc;
    --app-border: #e7e9f0;
    --app-text: #111827;
    --app-muted: #6b7280;
    --app-primary: #4f46e5;
    --app-primary-hover: #4338ca;
    --app-primary-soft: rgba(79, 70, 229, .09);
    --app-sidebar-w: 256px;
    --app-radius: 14px;

    --bs-body-font-family: var(--app-font);
    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-primary: #4f46e5;
    --bs-primary-rgb: 79, 70, 229;
    --bs-link-color: #4f46e5;
    --bs-link-color-rgb: 79, 70, 229;
    --bs-link-hover-color: #4338ca;
    --bs-link-hover-color-rgb: 67, 56, 202;
    --bs-border-radius: .6rem;
    --bs-focus-ring-color: rgba(79, 70, 229, .25);

    --c-indigo: #6366f1;
    --c-emerald: #10b981;
    --c-amber: #f59e0b;
    --c-rose: #f43f5e;
    --c-sky: #0ea5e9;
    --c-slate: #64748b;
}

[data-bs-theme="dark"] {
    --app-bg: #0c0e13;
    --app-surface: #14171f;
    --app-surface-2: #1a1e28;
    --app-border: #242938;
    --app-text: #e6e8ee;
    --app-muted: #9199ab;
    --app-primary: #818cf8;
    --app-primary-hover: #a5b4fc;
    --app-primary-soft: rgba(129, 140, 248, .13);

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-secondary-bg: #1a1e28;
    --bs-tertiary-bg: #14171f;
    --bs-primary: #818cf8;
    --bs-primary-rgb: 129, 140, 248;
    --bs-link-color: #a5b4fc;
    --bs-link-color-rgb: 165, 180, 252;
    --bs-link-hover-color: #c7d2fe;
    --bs-link-hover-color-rgb: 199, 210, 254;
    --bs-focus-ring-color: rgba(129, 140, 248, .3);
}

html { scroll-behavior: smooth; }

body {
    background: var(--app-bg);
    color: var(--app-text);
    font-size: .925rem;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--app-primary-soft); }

/* ---------- Botones ---------- */
.btn { font-weight: 500; }
.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-hover);
    --bs-btn-hover-border-color: var(--app-primary-hover);
    --bs-btn-active-bg: var(--app-primary-hover);
    --bs-btn-active-border-color: var(--app-primary-hover);
    --bs-btn-disabled-bg: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
}
[data-bs-theme="dark"] .btn-primary {
    --bs-btn-color: #0c0e13;
    --bs-btn-hover-color: #0c0e13;
    --bs-btn-active-color: #0c0e13;
    --bs-btn-disabled-color: #0c0e13;
}
.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary);
}
.btn-light-soft {
    background: var(--app-surface-2);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}
.btn-light-soft:hover { background: var(--app-primary-soft); color: var(--app-primary); border-color: transparent; }

.btn-icon {
    width: 38px; height: 38px;
    display: inline-grid; place-items: center;
    padding: 0; border: 0; border-radius: 10px;
    color: var(--app-muted); background: transparent;
}
.btn-icon:hover { background: var(--app-surface-2); color: var(--app-text); }
.btn-icon .dot {
    position: absolute; top: 8px; right: 9px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--c-amber); box-shadow: 0 0 0 2px var(--app-bg);
}

/* ---------- Sidebar ---------- */
.sidebar {
    background: var(--app-surface) !important;
    border-right: 1px solid var(--app-border);
    --bs-offcanvas-width: 280px;
    --bs-offcanvas-bg: var(--app-surface);
}
.sidebar.offcanvas-lg { display: flex; flex-direction: column; }
@media (min-width: 992px) {
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0;
        width: var(--app-sidebar-w);
        z-index: 1030;
        display: flex !important; flex-direction: column;
    }
    .app-main { margin-left: var(--app-sidebar-w); }
}
@media (max-width: 991.98px) {
    .sidebar.offcanvas-lg { height: 100%; }
}
.brand {
    display: flex; align-items: center; gap: .75rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--app-border);
}
.brand img { height: 36px; width: auto; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .25rem 0 1rem; }
.nav-section {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
    color: var(--app-muted); font-weight: 600;
    padding: 1.1rem 1.4rem .4rem;
}
.side-link {
    display: flex; align-items: center; gap: .75rem;
    margin: 1px .7rem; padding: .55rem .8rem;
    border-radius: 10px;
    color: var(--app-text); text-decoration: none; font-weight: 500;
    transition: background .15s, color .15s;
}
.side-link i { font-size: 1.05rem; color: var(--app-muted); transition: color .15s; }
.side-link:hover { background: var(--app-surface-2); color: var(--app-text); }
.side-link.active { background: var(--app-primary-soft); color: var(--app-primary); }
.side-link.active i { color: var(--app-primary); }
.sidebar-footer { border-top: 1px solid var(--app-border); padding: .7rem; }
.user-chip {
    display: flex; align-items: center; gap: .65rem;
    width: 100%; padding: .5rem; border: 0; border-radius: 10px;
    background: transparent; color: var(--app-text); text-align: left;
}
.user-chip:hover { background: var(--app-surface-2); }
.user-chip::after { margin-left: auto; }
.avatar {
    flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px;
    display: grid; place-items: center; font-weight: 600;
    background: var(--app-primary-soft); color: var(--app-primary);
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 1020;
    height: 60px; display: flex; align-items: center; gap: .5rem;
    padding: 0 1rem;
    background: color-mix(in srgb, var(--app-bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(10px);
    -webkit-backdrop-filter: saturate(160%) blur(10px);
    border-bottom: 1px solid var(--app-border);
}
@media (min-width: 768px) { .topbar { padding: 0 1.75rem; } }

.page { padding: 1.1rem; max-width: 1500px; }
@media (min-width: 768px) { .page { padding: 1.75rem; } }

.page-header {
    display: flex; flex-wrap: wrap; gap: .75rem;
    align-items: center; justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.35rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--app-muted); font-size: .875rem; margin: .15rem 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
@media (max-width: 575.98px) {
    .page-actions { width: 100%; }
    .page-actions > .btn, .page-actions > a { flex: 1 1 auto; }
}

/* ---------- Cards ---------- */
.card {
    --bs-card-bg: var(--app-surface);
    --bs-card-border-color: var(--app-border);
    --bs-card-border-radius: var(--app-radius);
    --bs-card-inner-border-radius: calc(var(--app-radius) - 1px);
    --bs-card-cap-bg: transparent;
    --bs-card-cap-padding-y: .9rem;
    --bs-card-cap-padding-x: 1.2rem;
    --bs-card-spacer-x: 1.2rem;
}
.card-header { font-weight: 600; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.card-header .ms-auto { font-weight: 400; }

.stat { display: flex; align-items: center; gap: 1rem; }
.stat-icon {
    flex: 0 0 44px; width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center; font-size: 1.2rem;
}
.stat-value { font-size: 1.55rem; font-weight: 650; line-height: 1.1; letter-spacing: -.02em; }
.stat-label { color: var(--app-muted); font-size: .8rem; font-weight: 500; }
a.card-link-plain { color: inherit; text-decoration: none; }
a.card-link-plain .card { transition: border-color .15s, transform .15s; }
a.card-link-plain:hover .card { border-color: var(--app-primary); transform: translateY(-1px); }

/* ---------- Colores suaves ---------- */
.soft-primary, .soft-indigo { background: rgba(99, 102, 241, .12) !important; color: #4f46e5 !important; }
.soft-success { background: rgba(16, 185, 129, .13) !important; color: #047857 !important; }
.soft-warning { background: rgba(245, 158, 11, .16) !important; color: #b45309 !important; }
.soft-danger  { background: rgba(244, 63, 94, .13) !important; color: #be123c !important; }
.soft-info    { background: rgba(14, 165, 233, .13) !important; color: #0369a1 !important; }
.soft-secondary { background: rgba(100, 116, 139, .14) !important; color: #475569 !important; }
[data-bs-theme="dark"] .soft-primary, [data-bs-theme="dark"] .soft-indigo { color: #a5b4fc !important; }
[data-bs-theme="dark"] .soft-success { color: #6ee7b7 !important; }
[data-bs-theme="dark"] .soft-warning { color: #fcd34d !important; }
[data-bs-theme="dark"] .soft-danger  { color: #fda4af !important; }
[data-bs-theme="dark"] .soft-info    { color: #7dd3fc !important; }
[data-bs-theme="dark"] .soft-secondary { color: #cbd5e1 !important; }
.badge { font-weight: 600; padding: .38em .6em; border-radius: 6px; }

/* ---------- Tablas ---------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--app-border);
    --bs-table-hover-bg: var(--app-surface-2);
    --bs-table-striped-bg: transparent;
    margin: 0;
    vertical-align: middle;
}
.table > thead > tr > th {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--app-muted); font-weight: 600;
    background: var(--app-surface-2);
    border-bottom-width: 1px; white-space: nowrap;
}
.table > :not(caption) > * > * { padding: .7rem .9rem; }
.table-card { border: 1px solid var(--app-border); border-radius: var(--app-radius); overflow: hidden; background: var(--app-surface); }
.card > .table-responsive:last-child, .card > .table:last-child { border-radius: 0 0 var(--app-radius) var(--app-radius); }
.cell-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; color: var(--app-muted); }
.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 9px; border: 1px solid var(--app-border); background: var(--app-surface-2); }
.thumb-empty { display: grid; place-items: center; color: var(--app-muted); }

/* DataTables */
div.dataTables_wrapper { padding: .9rem 1rem 1rem; }
div.dataTables_wrapper div.dataTables_filter input { margin-left: .4rem; width: 220px; max-width: 100%; }
div.dataTables_wrapper div.dataTables_info { color: var(--app-muted); font-size: .82rem; }
div.dataTables_wrapper .row { --bs-gutter-y: .6rem; }
.page-link { --bs-pagination-bg: var(--app-surface); --bs-pagination-border-color: var(--app-border); --bs-pagination-active-bg: var(--app-primary); --bs-pagination-active-border-color: var(--app-primary); }
table.dataTable > tbody > tr.child ul.dtr-details { width: 100%; }
table.dataTable > tbody > tr.child span.dtr-title { color: var(--app-muted); font-weight: 500; min-width: 110px; }
@media (max-width: 575.98px) {
    div.dataTables_wrapper { padding: .75rem; }
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter { text-align: left !important; }
    div.dataTables_wrapper div.dataTables_filter input { width: 100%; margin-left: 0; margin-top: .25rem; }
    div.dataTables_wrapper div.dataTables_filter label { width: 100%; }
}

/* ---------- Formularios ---------- */
.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .35rem; }
.form-control, .form-select {
    background-color: var(--app-surface);
    border-color: var(--app-border);
    padding-top: .5rem; padding-bottom: .5rem;
}
.form-control:focus, .form-select:focus { border-color: var(--app-primary); }
.form-text { color: var(--app-muted); }
.req::after { content: ' *'; color: var(--c-rose); }

/* Tom Select */
.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0 !important; }
.ts-control { background: var(--app-surface) !important; border-color: var(--app-border) !important; color: var(--app-text) !important; min-height: 40px; padding: .45rem .75rem !important; border-radius: var(--bs-border-radius) !important; }
.ts-control input { color: var(--app-text) !important; }
.ts-dropdown { background: var(--app-surface); color: var(--app-text); border-color: var(--app-border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 1060; }
.ts-dropdown .active { background: var(--app-primary-soft); color: var(--app-text); }
.ts-dropdown .option { padding: .5rem .75rem; }
.ts-wrapper.focus .ts-control { border-color: var(--app-primary) !important; box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color) !important; }

/* ---------- Líneas de productos (formularios de ingreso / salida) ---------- */
.table-lineas td { vertical-align: top; }
.table-lineas .col-prod { min-width: 260px; }
.table-lineas .col-pres { width: 190px; }
.table-lineas .col-cant { width: 150px; }
.table-lineas .col-acc { width: 56px; }
.table-lineas tr.fila-kit > td:first-child { box-shadow: inset 3px 0 0 var(--c-indigo); }
.kit-tag { font-size: .7rem; }
@media (max-width: 767.98px) {
    .table-lineas thead { display: none; }
    .table-lineas, .table-lineas tbody { display: block; }
    .table-lineas tr {
        display: grid; grid-template-columns: 1fr 1fr auto; gap: .6rem;
        padding: .9rem .9rem; border-bottom: 1px solid var(--app-border);
    }
    .table-lineas td { display: block; border: 0 !important; padding: 0 !important; width: auto !important; }
    .table-lineas .col-prod { grid-column: 1 / -1; min-width: 0; }
    .table-lineas .col-acc { align-self: start; }
    .table-lineas tr.fila-kit { box-shadow: inset 3px 0 0 var(--c-indigo); }
    .table-lineas tr.fila-kit > td:first-child { box-shadow: none; }
}

/* ---------- Varios ---------- */
.empty-state { text-align: center; padding: 4rem 1rem; color: var(--app-muted); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .75rem; }
.empty-state h2 { font-size: 1.2rem; color: var(--app-text); }

.dl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem 1.5rem; margin: 0; }
.dl-grid dt { font-size: .75rem; color: var(--app-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.dl-grid dd { margin: .15rem 0 0; font-weight: 500; word-break: break-word; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.6rem; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--app-border); }
.timeline li::after { content: ''; position: absolute; left: 9px; top: 18px; bottom: 0; width: 2px; background: var(--app-border); }
.timeline li:last-child::after { display: none; }
.timeline li.ok::before { background: var(--c-emerald); }
.timeline li.warn::before { background: var(--c-amber); }
.timeline li.bad::before { background: var(--c-rose); }

.firma-preview {
    max-height: 110px; max-width: 100%;
    background: #fff; border-radius: 10px; padding: .5rem;
    border: 1px dashed var(--app-border);
}
.evidencia { max-width: 280px; width: 100%; border-radius: 10px; border: 1px solid var(--app-border); }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 240px; }
.list-compact .list-group-item { background: transparent; border-color: var(--app-border); padding: .7rem 1.2rem; }
.progress { --bs-progress-bg: var(--app-surface-2); height: 6px; }

.auth-card { border-left: 3px solid var(--c-amber); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 992px) { .login-wrap { grid-template-columns: 1.15fr 1fr; } }
.login-side { display: none; position: relative; background: #111 url('../img/fondo.jpg') center / cover no-repeat; }
.login-side::after { content: ''; position: absolute; inset: 0; background: linear-gradient(145deg, rgba(79, 70, 229, .55), rgba(12, 14, 19, .85)); }
.login-side .contenido { position: absolute; z-index: 1; bottom: 3rem; left: 3rem; right: 3rem; color: #fff; }
.login-side h2 { font-weight: 650; font-size: 2rem; letter-spacing: -.02em; }
@media (min-width: 992px) { .login-side { display: block; } }
.login-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; position: relative; }
.login-box { width: 100%; max-width: 370px; }
.login-box .logo { height: 64px; }
.login-tema { position: absolute; top: 1rem; right: 1rem; }

/* ---------- Impresión ---------- */
@media print {
    .sidebar, .topbar, .no-print, .btn { display: none !important; }
    .app-main { margin: 0 !important; }
    .card { border: 0; }
}
.min-w-0 { min-width: 0; }
.kit-adder { width: auto; flex-wrap: nowrap; }
.kit-adder .kit-cant { max-width: 70px; }
@media (max-width: 575.98px) { .kit-adder { width: 100%; } }

/* Precios */
.precio-input { min-width: 170px; max-width: 220px; }
.table-precios tr.fila-cambiada > td { background: rgba(245, 158, 11, .07); }
.table-precios tr.fila-cambiada > td:first-child { box-shadow: inset 3px 0 0 var(--c-amber); }
.total-row td { font-weight: 700; background: var(--app-surface-2); }
.table-lineas .col-precio { width: 170px; }
@media (max-width: 767.98px) {
    .table-lineas .col-acc { grid-row: 2; grid-column: 3; }
    .table-lineas .col-precio { grid-column: 1 / 3; }
}

/* Auditoría física */
.table-auditoria tr.fila-dif > td:first-child { box-shadow: inset 3px 0 0 var(--c-rose); }
.table-auditoria tr.fila-dif > td { background: rgba(244, 63, 94, .05); }
.table-auditoria .js-fisico { font-weight: 600; text-align: right; }
.table-auditoria td { vertical-align: middle; }
