/* ============================================================
   STOCKLATAM — CSS de la app (reemplaza Tailwind CDN)
   Capas: reset -> utilidades -> componentes.
   Las utilidades reproducen a mano exactamente las clases que ya
   usan las vistas (mismo nombre, mismo valor) — cero cambios de
   marcado al migrar. Ver tokens.css para los custom properties.
   ============================================================ */

/* ---------- Reset minimo (equivalente al preflight de Tailwind) ---------- */
*, *::before, *::after { box-sizing: border-box; border-width: 0; border-style: solid; border-color: var(--color-border); }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
input, textarea, select { font: inherit; color: inherit; }
table { border-collapse: collapse; }
ul { margin: 0; padding: 0; }
/* El color base del texto DEBE definirse aqui: sin esto, todo elemento que no
   traiga un color explicito hereda el negro por defecto del navegador, y en tema
   oscuro quedaba texto negro sobre fondo oscuro (ilegible). */
html, body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
}

/* ---------- Layout / display ---------- */
.block { display: block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.inline { display: inline; }
.grid { display: grid; }
/* !important como en Tailwind: sin esto, cualquier regla de componente posterior
   (p. ej. .btn-primary { display: inline-flex }) gana por orden y el elemento
   marcado como oculto se sigue viendo. Las variantes lg: de abajo tambien lo llevan
   para poder sobrescribirla en escritorio. */
.hidden { display: none !important; }
.sticky { position: sticky; }
.fixed { position: fixed; }
/* min-width:0 es imprescindible: un flex item usa min-width:auto por defecto y no
   encoge por debajo de su contenido, asi que una tabla ancha empujaba TODA la pagina
   a hacer scroll horizontal en vez de dejar que .table-container scrollee dentro. */
.flex-1 { flex: 1 1 0%; min-width: 0; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-shrink-0, .shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-span-2 { grid-column: span 2 / span 2; }
.overflow-hidden { overflow: hidden; }
.overflow-y-auto { overflow-y: auto; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.top-0 { top: 0; }
.z-30 { z-index: 30; }
.z-40 { z-index: 40; }
.cursor-pointer { cursor: pointer; }
.object-cover { object-fit: cover; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-disc { list-style-type: disc; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Espaciado (escala Tailwind: 1=.25rem) ---------- */
.gap-1 { gap: .25rem; }
.gap-1\.5 { gap: .375rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.p-1 { padding: .25rem; }
.p-2 { padding: .5rem; }
.p-3 { padding: .75rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-8 { padding-left: 2rem; padding-right: 2rem; }
.py-1 { padding-top: .25rem; padding-bottom: .25rem; }
.py-3 { padding-top: .75rem; padding-bottom: .75rem; }
.py-6 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.pb-1 { padding-bottom: .25rem; }
.pb-6 { padding-bottom: 1.5rem; }
.pl-4 { padding-left: 1rem; }
.pt-2 { padding-top: .5rem; }
.pt-4 { padding-top: 1rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-1\.5 { margin-bottom: .375rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.-mt-0\.5 { margin-top: -.125rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.ml-auto { margin-left: auto; }
.space-y-1 > * + * { margin-top: .25rem; }
.space-y-2 > * + * { margin-top: .5rem; }
.space-y-3 > * + * { margin-top: .75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-5 > * + * { margin-top: 1.25rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* ---------- Tamanos ---------- */
.h-4 { height: 1rem; } .w-4 { width: 1rem; }
.h-5 { height: 1.25rem; } .w-5 { width: 1.25rem; }
.h-6 { height: 1.5rem; } .w-6 { width: 1.5rem; }
.h-7 { height: 1.75rem; } .w-7 { width: 1.75rem; }
.h-9 { height: 2.25rem; } .w-9 { width: 2.25rem; }
.h-11 { height: 2.75rem; } .w-11 { width: 2.75rem; }
.h-16 { height: 4rem; } .w-16 { width: 4rem; }
.h-20 { height: 5rem; } .w-20 { width: 5rem; }
.h-24 { height: 6rem; } .w-24 { width: 6rem; }
.h-full { height: 100%; }
.w-64 { width: 16rem; }
/* Utilidades de ancho con !important, por el mismo motivo que .hidden: si no,
   .input-field { width: 100% } (definida despues) ganaba y los filtros "w-auto"
   se estiraban a todo el ancho desbordando la pantalla en movil. */
.w-full { width: 100% !important; }
.w-auto { width: auto !important; }
.min-w-0 { min-width: 0; }
.min-w-\[200px\] { min-width: 200px; }
.max-w-2xl { max-width: 42rem; }
.max-w-md { max-width: 28rem; }
.max-h-48 { max-height: 12rem; }
.\!h-auto { height: auto !important; }
.\!justify-start { justify-content: flex-start !important; }

/* ---------- Tipografia ---------- */
.font-mono { font-family: var(--font-mono, ui-monospace, SFMono-Regular, Consolas, monospace); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-xs { font-size: .75rem; line-height: 1rem; }
.text-sm { font-size: .875rem; line-height: 1.25rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.uppercase { text-transform: uppercase; }
.tracking-wider { letter-spacing: .05em; }

/* ---------- Color (paleta Tailwind por defecto, valores fijos) ---------- */
.bg-black\/40 { background-color: rgba(0, 0, 0, .4); }
.bg-white\/20 { background-color: rgba(255, 255, 255, .2); }
.bg-red-50 { background-color: #fef2f2; }
.border-red-200 { border-color: #fecaca; }
.text-red-700 { color: #b91c1c; }
.text-amber-100 { color: #fef3c7; }
.text-slate-400 { color: var(--slate-400); }
.text-white { color: #fff; }
.border { border-width: 1px; }
.border-b { border-bottom-width: 1px; }
.border-t { border-top-width: 1px; }
.border-white\/10 { border-color: rgba(255, 255, 255, .1); }
.rounded-2xl { border-radius: 1rem; }
.rounded-full { border-radius: 9999px; }
.rounded-lg { border-radius: .5rem; }
.rounded-xl { border-radius: .75rem; }
.shadow-2xl { box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25); }
.backdrop-blur-md { backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.transition-all { transition-property: all; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: .15s; }
.transition-colors { transition-property: color, background-color, border-color; transition-timing-function: cubic-bezier(.4,0,.2,1); transition-duration: .15s; }
.duration-200 { transition-duration: .2s; }
.-translate-x-full { transform: translateX(-100%); }

.hover\:bg-slate-100:hover { background-color: var(--slate-100); }
.hover\:bg-surface-alt:hover { background-color: var(--color-surface-alt); }
.hover\:text-red-400:hover { color: #f87171; }

/* ---------- Responsive: sm (>=640px) / lg (>=1024px) ---------- */
@media (min-width: 640px) {
    .sm\:flex-row { flex-direction: row; }
    .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sm\:w-fit { width: fit-content; }
}
@media (min-width: 1024px) {
    .lg\:col-span-2 { grid-column: span 2 / span 2; }
    .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .lg\:hidden { display: none !important; }
    .lg\:flex { display: flex !important; }
    .lg\:inline-flex { display: inline-flex !important; }
    .lg\:ml-64 { margin-left: 16rem; }
    .lg\:p-6 { padding: 1.5rem; }
    .lg\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
    .lg\:translate-x-0 { transform: translateX(0); }
}

/* ---------- Componentes (antes @apply de Tailwind, ahora CSS plano) ---------- */
.sidebar-link { display: flex; align-items: center; gap: .75rem; padding: .625rem 1rem; border-radius: .5rem; font-size: .875rem; font-weight: 500; transition: background-color .15s, color .15s; color: var(--color-nav-text); }
.sidebar-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-link.active { background: var(--color-primary); color: #fff; font-weight: 600; }

.stat-card { border-radius: .75rem; border: 1px solid var(--color-border); padding: 1.25rem; transition: box-shadow .15s; background: var(--color-surface); box-shadow: var(--shadow-card); }
.stat-card:hover { box-shadow: 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1); }

.btn-primary, .btn-secondary, .btn-danger {
    font-weight: 500; font-size: .875rem; transition: background-color .15s, color .15s;
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding-left: 1.25rem; padding-right: 1.25rem; border-radius: var(--radius-btn); min-height: var(--btn-touch-min);
}
/* El color del texto viene del token: en claro es blanco sobre ambar oscuro,
   en oscuro es texto oscuro sobre ambar luminoso. Ambos >= 4.8:1. */
.btn-primary { color: var(--color-primary-fg); box-shadow: 0 1px 2px rgba(0,0,0,.05); background: var(--color-primary); }
.btn-primary .subtitulo { color: var(--color-primary-fg-soft); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: color-mix(in srgb, var(--color-text) 8%, var(--color-surface)); color: var(--color-text); }
.btn-secondary:hover { background: color-mix(in srgb, var(--color-text) 14%, var(--color-surface)); }
.btn-danger { background: var(--color-status-cancelado); color: var(--color-danger-fg); }
.btn-danger:hover { background: color-mix(in srgb, var(--color-status-cancelado) 85%, #000); }
.btn-sm { padding-left: .75rem; padding-right: .75rem; font-size: .875rem; font-weight: 500; min-height: 2.25rem; border-radius: var(--radius-btn); }

/* Fondo y color explicitos: los controles de formulario no heredan el tema solos
   y quedaban con el blanco/negro por defecto del navegador. */
.input-field {
    width: 100%; border: 1px solid var(--color-border); padding: .625rem .75rem; font-size: .875rem;
    outline: none; transition: box-shadow .15s, border-color .15s; border-radius: var(--radius-btn);
    background: var(--color-surface); color: var(--color-text);
}
.input-field::placeholder { color: var(--color-text-muted); opacity: 1; }
.input-field option { background: var(--color-surface); color: var(--color-text); }
.input-field:focus { box-shadow: 0 0 0 2px var(--color-primary); border-color: var(--color-primary); }

/* Foco visible en todo lo interactivo, no solo en los inputs: sin esto no se puede
   navegar la app con teclado. :focus-visible evita el anillo al hacer clic con ratón. */
button:focus-visible, a:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-btn);
}

/* Estado deshabilitado — los botones se bloquean mientras hay una petición en vuelo. */
button:disabled, .btn-primary:disabled, .btn-secondary:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* Contenedor de graficos Chart.js — el canvas se estira al alto del padre. */
.chart-box { position: relative; height: 260px; }
@media (min-width: 1024px) { .chart-box { height: 300px; } }

.badge { display: inline-flex; align-items: center; padding: .25rem .625rem; font-size: .75rem; font-weight: 600; border-radius: var(--radius-badge); }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }

.table-container { overflow-x: auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.table-container table { width: 100%; font-size: .875rem; }
.table-container thead { border-bottom: 1px solid var(--color-border); background: var(--color-surface-alt); }
.table-container th { padding: .75rem 1rem; text-align: left; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted); }
/* Antes: var(--slate-100) fijo — una linea casi blanca sobre superficie oscura. */
.table-container td { padding: .75rem 1rem; border-bottom: 1px solid var(--color-border); color: var(--color-text); }
.table-container tbody tr:hover { background: var(--color-surface-alt); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.hidden { display: none; }
.modal-content { width: 100%; max-width: 32rem; max-height: 90vh; overflow-y: auto; background: var(--color-surface); border-radius: 1rem; box-shadow: var(--shadow-float); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn .25s ease-out; }

/* ---------- Conmutador de tema ---------- */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.5rem; height: 2.5rem; border-radius: var(--radius-btn);
    color: var(--color-text-muted); background: transparent; transition: background-color .15s, color .15s;
}
.theme-toggle:hover { background: var(--color-surface-alt); color: var(--color-text); }
/* Solo se ve el icono del tema al que se va a cambiar:
   en oscuro se ve el sol (clic -> claro), en claro se ve la luna (clic -> oscuro). */
.theme-toggle .icono-sol { display: none; }
.theme-toggle .icono-luna { display: block; }
:root[data-theme="dark"] .theme-toggle .icono-sol { display: block; }
:root[data-theme="dark"] .theme-toggle .icono-luna { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icono-sol { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icono-luna { display: none; }
}

/* Hueco para que el boton flotante de escaneo no tape la ultima fila/boton. */
@media (max-width: 1023px) { main { padding-bottom: 6rem; } }

.scan-fab { position: fixed; bottom: 1.25rem; right: 1.25rem; width: 4rem; height: 4rem; border-radius: 9999px; display: flex; align-items: center; justify-content: center; color: var(--color-primary-fg); box-shadow: var(--shadow-float); background: var(--color-primary); }
@media (min-width: 1024px) { .scan-fab { display: none; } }

/* ---------- Sidebar colapsable a riel de iconos (solo escritorio, >=1024px) ---------- */
#sidebar-collapse-btn {
    position: absolute; top: 1.1rem; right: -13px; width: 26px; height: 26px;
    border-radius: 50%; align-items: center; justify-content: center;
    background: var(--color-surface); border: 1px solid var(--color-border);
    color: var(--color-primary); cursor: pointer; z-index: 41; box-shadow: var(--shadow-card);
}
#sidebar-collapse-btn svg { width: 13px; height: 13px; transition: transform .2s ease; }
#sidebar-collapse-btn:hover { background: color-mix(in srgb, var(--color-text) 8%, var(--color-surface)); }
#content-shift { transition: margin-left .2s ease; }
@media (min-width: 1024px) {
    body.sidebar-collapsed #sidebar { width: var(--sidebar-width-collapsed); }
    body.sidebar-collapsed #content-shift { margin-left: var(--sidebar-width-collapsed); }
    body.sidebar-collapsed #sidebar-collapse-btn svg { transform: rotate(180deg); }
    body.sidebar-collapsed #sidebar .label-text,
    body.sidebar-collapsed #sidebar .nav-section-label { display: none; }
    body.sidebar-collapsed #sidebar .sidebar-link { justify-content: center; padding-left: .5rem; padding-right: .5rem; }
    body.sidebar-collapsed #sidebar .sidebar-footer-row { flex-direction: column; gap: .6rem; }
}
