/* ==========================================================
   RACETRUCK · Tema oscuro profesional
   Variables y selectores compatibles con templates existentes
   ========================================================== */
:root {
    --bg: #0a0a0a;
    --bg-2: #0f1318;
    --panel: #14171c;
    --panel-soft: #1c2027;
    --panel-2: #1c2027;
    --border: #262b34;
    --border-soft: #1f242c;
    --line: #262b34;
    --text: #f5f6f8;
    --text-soft: #cfd5e0;
    --muted: #8a93a3;
    --primary: #ff5a1f;
    --primary-2: #ef3b3b;
    --primary-soft: rgba(255, 90, 31, 0.12);
    --primary-border: rgba(255, 90, 31, 0.3);
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.12);
    --danger: #ef3b3b;
    --danger-soft: rgba(239, 59, 59, 0.12);
    --warning: #facc15;
    --warning-soft: rgba(250, 204, 21, 0.12);
    --info: #38bdf8;
    --info-soft: rgba(56, 189, 248, 0.12);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(255, 90, 31, 0.08);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', Tahoma, Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color .15s ease;
}
a:hover { color: var(--primary-2); text-decoration: none; }

/* ============== LAYOUT ============== */
.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, #0a0a0a 0%, #0f1318 100%);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.sidebar::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.brand-logo {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800; color: #fff;
    box-shadow: 0 6px 16px rgba(255, 90, 31, 0.35);
    letter-spacing: -0.5px;
}
.brand-title { font-size: 16px; font-weight: 800; letter-spacing: -0.3px; }
.brand-subtitle { font-size: 11px; color: var(--muted); margin-top: 2px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-section {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--muted);
    font-weight: 700;
    padding: 10px 12px 4px;
    margin-top: 6px;
}

.nav-link {
    color: var(--text-soft);
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.15s ease;
    font-weight: 500;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}
.nav-link:hover {
    background: var(--primary-soft);
    color: var(--primary);
    text-decoration: none;
}
.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-left: 2px solid var(--primary);
    padding-left: 10px;
}
.nav-link-danger {
    margin-top: 12px;
    background: rgba(239, 59, 59, 0.08);
    color: #fca5a5;
}
.nav-link-danger:hover { background: rgba(239, 59, 59, 0.15); color: var(--danger); }

.main-content {
    flex: 1;
    padding: 24px 28px;
    min-width: 0;
}

/* Botón hamburguesa + backdrop del sidebar off-canvas (ocultos en desktop; ver RESPONSIVE) */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 1001;
    width: 42px; height: 42px;
    align-items: center; justify-content: center;
    background: #0f1318; color: #fff;
    border: 1px solid var(--border); border-radius: 10px;
    font-size: 20px; cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.topbar {
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-soft);
}
.page-title {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.3px;
}
.page-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}
.page-body { display: block; }

/* ============== CARDS ============== */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.hero {
    background: linear-gradient(135deg, #14171c 0%, #1c2027 60%, #2a1810 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 26px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}
.hero::after {
    content: "";
    position: absolute;
    right: -60px; top: -60px;
    width: 200px; height: 200px;
    background: radial-gradient(circle, var(--primary-soft) 0%, transparent 70%);
    pointer-events: none;
}
.hero-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 10px;
    border: 1px solid var(--primary-border);
}
.hero-title {
    margin: 0 0 6px 0;
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
}
.hero-text {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    max-width: 760px;
    line-height: 1.5;
}

/* ============== GRIDS ============== */
.grid,
.grid-formularios,
.resumen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
}

.grid-filtros {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.resumen-box {
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    position: relative;
}
.resumen-box::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--primary);
    border-radius: 2px 0 0 2px;
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.module-card {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    min-height: 92px;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}
.module-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--primary);
    transform: scaleY(0);
    transform-origin: bottom;
    transition: transform 0.2s ease;
}
.module-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary-border);
    text-decoration: none;
}
.module-card:hover::before { transform: scaleY(1); }

.module-name {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    letter-spacing: -0.2px;
}
.module-desc {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

/* ============== HEADINGS ============== */
h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    color: var(--text);
    letter-spacing: -0.2px;
}
h1 { font-size: 22px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text); }
h4 { font-size: 13px; font-weight: 700; }

.section-title { margin-bottom: 12px; }

/* ============== FORMS ============== */
input, select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    margin-top: 4px;
    margin-bottom: 8px;
    font-family: inherit;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type="checkbox"], input[type="radio"] {
    width: auto;
    margin: 0;
    accent-color: var(--primary);
}
input[type="date"], input[type="month"] {
    color-scheme: dark;
}

label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 2px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

button {
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    font-family: inherit;
    transition: all 0.15s ease;
    box-shadow: 0 6px 16px rgba(255, 90, 31, 0.18);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
button:hover { transform: translateY(-1px); filter: brightness(1.08); }
button:active { transform: translateY(0); }

.btn-mini, .small-btn {
    width: auto;
    padding: 6px 10px;
    font-size: 11px;
    border-radius: 8px;
    box-shadow: none;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: inherit;
    padding: 0;
    text-decoration: underline;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 600;
    box-shadow: none;
}
.btn-link:hover { color: var(--primary-2); transform: none; }

.link-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 7px 12px;
    background: var(--panel-soft);
    color: var(--primary);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 12px;
    border: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.15s ease;
}
.link-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.actions-filtro,
.acciones-filtro {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* ============== TABLES ============== */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    font-size: 13px;
}
th {
    background: var(--bg-2);
    color: var(--muted);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
th, td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: middle;
    color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 90, 31, 0.04); }

.tabla-wrapper {
    overflow-x: auto;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    box-sizing: border-box;
    background: var(--panel);
}
.tabla-wrapper table {
    min-width: 1100px;
    margin-top: 0;
    border: none;
    box-shadow: none;
}

.acciones-col { min-width: 140px; }
.acciones-box {
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-items: flex-start;
}

/* ============== AMOUNTS / STATES ============== */
.monto-pos { color: var(--success); font-weight: 700; }
.monto-neg { color: var(--danger); font-weight: 700; }

.verde { color: var(--success); }
.rojo  { color: var(--danger); }
.azul  { color: var(--info); }
.gris  { color: var(--muted); }

.resaltado {
    background: linear-gradient(135deg, rgba(255,90,31,0.08), rgba(239,59,59,0.05));
    border: 1px solid var(--primary-border);
}

/* ============== BADGES ============== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    background: var(--primary-soft);
    color: var(--primary);
    border: 1px solid var(--primary-border);
}
.badge-ok       { background: var(--success-soft); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.badge-baja     { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(239,59,59,0.3); }
.badge-pendiente{ background: var(--warning-soft); color: var(--warning); border: 1px solid rgba(250,204,21,0.3); }

/* ============== KPIs (legacy) ============== */
.kpi-titulo {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}
.kpi-valor {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* ============== MISC ============== */
.menu { display: none; }

.paginacion {
    margin: 14px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13px;
}
.paginacion a {
    font-weight: 700;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-soft);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}
.paginacion a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

.periodo {
    font-size: 14px;
    color: var(--muted);
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 18px 0;
}

.note {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    line-height: 1.5;
}

.hidden { display: none; }

/* ============== ACCIONES (legacy) ============== */
.acciones {
    min-width: 160px;
}
.acciones form { display: block; margin: 4px 0; }
.acciones details { display: block; margin: 4px 0; }
.acciones summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--primary);
    list-style: none;
    margin: 0;
    padding: 4px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.acciones summary::-webkit-details-marker { display: none; }
.acciones summary::before { content: "▸ "; }
.acciones details[open] summary::before { content: "▾ "; }
.acciones details form {
    margin-top: 6px;
    padding: 10px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.acciones .btn-mini { white-space: nowrap; }

.inline-form { display: inline; margin: 0; }

/* ============== COLUMNAS VENTA ============== */
.columnas-venta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 16px 0;
    align-items: start;
}
.bloque-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--panel-soft);
}
.bloque-item h3 {
    margin-top: 0;
    margin-bottom: 8px;
}
.bloque-abajo {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--panel-soft);
    margin-top: 16px;
}
.total-box {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

/* ============== CHECKBOX LIST ============== */
.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    margin: 0;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
    cursor: pointer;
    font-size: 13px;
}
.checkbox-item:hover { border-color: var(--primary-border); }
.checkbox-item input[type="checkbox"] {
    width: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    flex: 0 0 auto;
}
.checkbox-item span {
    flex: 1;
    line-height: 1.2;
}

/* ============== SCROLLBAR ============== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
    border: 2px solid var(--bg-2);
}
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============== RESPONSIVE ============== */
@media (max-width: 1100px) {
    .grid, .grid-formularios, .resumen-grid, .grid-filtros {
        grid-template-columns: 1fr;
    }
    .columnas-venta { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    /* Sidebar off-canvas: oculto por defecto, se despliega con la hamburguesa (C-05) */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 260px; height: 100dvh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .sidebar-backdrop { display: block; }
    .menu-toggle { display: flex; }
    .main-content { padding: 64px 16px 16px; }  /* deja lugar para la hamburguesa fija */
    .page-title { font-size: 20px; }
    .hero-title { font-size: 22px; }
    /* Tablas: scroll horizontal en móvil en vez de romper el layout */
    .main-content table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
}

/* ============== UTILITIES ============== */
.text-muted { color: var(--muted); }
.text-pos   { color: var(--success); }
.text-neg   { color: var(--danger); }
.text-warn  { color: var(--warning); }
.text-info  { color: var(--info); }
.text-primary { color: var(--primary); }
.font-mono  { font-family: ui-monospace, 'Cascadia Code', Menlo, monospace; font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }

/* ==========================================================
   TASTE-SKILL UPGRADES — Premium interaction & typography
   ========================================================== */

/* Scroll suave global */
html { scroll-behavior: smooth; }

/* min-height seguro en móvil (evita el bug de 100vh en iOS) */
.app-shell { min-height: 100dvh; }

/* Headings: sin palabras huérfanas */
h1, h2, h3, h4, .page-title, .hero-title {
    text-wrap: balance;
}

/* Números tabulares en contextos de datos */
td, .kpi-valor, .total-box, .monto-pos, .monto-neg,
[class*="val"], [class*="amount"], [class*="price"] {
    font-variant-numeric: tabular-nums;
}

/* Transición premium en todos los elementos interactivos */
button, .nav-link, .link-btn, .paginacion a, .module-card,
.badge, input, select, textarea {
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* Active/press feedback en botones — sensación física */
button:active:not(.btn-link):not([disabled]) {
    transform: scale(0.97) translateY(1px) !important;
    filter: brightness(0.95) !important;
}

/* Focus visible — accesibilidad y navegación por teclado */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 4px;
}
button:focus-visible, a:focus-visible { outline-offset: 3px; }

/* Nav link active: borde izquierdo + glow sutil */
.nav-link.active {
    box-shadow: inset 3px 0 0 var(--primary);
    background: var(--primary-soft);
}

/* Filas de tabla: transición suave */
tr { transition: background 0.15s cubic-bezier(0.16, 1, 0.3, 1); }
tr:hover td { transition: background 0.15s cubic-bezier(0.16, 1, 0.3, 1); }

/* ==========================================================
   SKELETON SHIMMER — Loading states premium
   ========================================================== */
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--panel-soft) 25%,
        var(--border) 50%,
        var(--panel-soft) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.6s ease-in-out infinite;
    border-radius: 4px;
    color: transparent !important;
    pointer-events: none;
}
.skeleton-text  { height: 14px; border-radius: 3px; }
.skeleton-title { height: 22px; width: 60%; border-radius: 4px; }
.skeleton-block { height: 80px; border-radius: var(--radius-sm); }

/* ==========================================================
   EMPTY STATE — Siempre diseñado, nunca vacío
   ========================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 56px 32px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}
.empty-state-icon  { font-size: 40px; margin-bottom: 16px; opacity: 0.7; }
.empty-state-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-state-desc  { font-size: 13px; color: var(--muted); max-width: 320px; line-height: 1.55; margin-bottom: 20px; }

/* ==========================================================
   INLINE ALERTS — Error / Success / Warning sin alert()
   ========================================================== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success {
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.25);
    color: #10b981;
}
.alert-error {
    background: rgba(239,68,68,0.08);
    border: 1px solid rgba(239,68,68,0.25);
    color: #f87171;
}
.alert-warning {
    background: rgba(245,158,11,0.08);
    border: 1px solid rgba(245,158,11,0.25);
    color: #f59e0b;
}
.alert-info {
    background: rgba(56,189,248,0.08);
    border: 1px solid rgba(56,189,248,0.25);
    color: #38bdf8;
}

/* ==========================================================
   UTILITIES EXTRA
   ========================================================== */
.tabular    { font-variant-numeric: tabular-nums; }
.text-balance { text-wrap: balance; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only    { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.divide-y > * + * { border-top: 1px solid var(--border); }
.gap-stack  { display: flex; flex-direction: column; gap: 8px; }
.mt-auto    { margin-top: auto; }
