:root {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --border-color: #333333;
    --text-muted: #8e8e93;
    --text-light: #f5f5f7;
    --primary-color: #2563eb;
    --secondary-color: #3b82f6;
    --primary-gradient: linear-gradient(135deg, #2563eb, #3b82f6);

    /* Tokens Semánticos Financieros y Estados WCAG */
    --success-color: #10b981;
    --teal-color: #059669;
    --warning-color: #f59e0b;
    --danger-color: #dc2626;
    --info-color: #3b82f6;
}

/* Badges de Estado Pro (Baja opacidad + Texto e Ícono brilloso + Borde sutil) */
.badge-status {
    padding: 0.35em 0.75em;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
}

.badge-emitida {
    background-color: rgba(16, 185, 129, 0.12) !important;
    color: #10b981 !important;
    border: 1px solid rgba(16, 185, 129, 0.25) !important;
}

.badge-borrador {
    background-color: rgba(245, 158, 11, 0.12) !important;
    color: #f59e0b !important;
    border: 1px solid rgba(245, 158, 11, 0.25) !important;
}

.badge-anulada {
    background-color: rgba(220, 38, 38, 0.12) !important;
    color: #dc2626 !important;
    border: 1px solid rgba(220, 38, 38, 0.25) !important;
}

body {
    background-color: var(--bg-primary) !important;
    color: var(--text-light) !important;
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
}

body > div.d-flex,
main {
    min-width: 0;
}

/* Sidebar Estilizada */
.sidebar {
    width: 250px;
    min-height: 100vh;
    background-color: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-color) !important;
    padding: 1.5rem 1.25rem !important;
}

.sidebar-toggle {
    width: 44px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-light);
    font-size: 1.6rem;
    line-height: 1;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus {
    color: #fff;
    border-color: #5b6470;
    background: rgba(255, 255, 255, 0.05);
}

/* Marca / Logo */
.brand-logo {
    padding: 0.5rem 0.25rem;
}

.brand-icon-wrapper {
    background: var(--primary-gradient);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.brand-icon-wrapper i {
    color: #fff !important;
    font-size: 1.2rem;
}

.brand-name {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff !important;
    letter-spacing: 0.5px;
}

.brand-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
}

/* Navegación */
.sidebar .nav-link {
    color: var(--text-muted);
    border-radius: 10px;
    font-size: 0.925rem;
    padding: 0.75rem 1rem;
    font-weight: 500;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
}

.sidebar .nav-link i {
    font-size: 1.1rem;
    transition: transform 0.25s ease;
}

.sidebar .nav-link:hover {
    color: var(--text-light);
    background-color: rgba(255, 255, 255, 0.03);
}

.sidebar .nav-link:hover i {
    transform: translateX(3px);
}

.sidebar .nav-link.active {
    background: var(--primary-gradient) !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* Tarjetas y Contenedores */
.card-bloque {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
}

.card-metrica {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    height: 100%;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.1);
}

.card-metrica:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px 0 rgba(37, 99, 235, 0.1);
    border-color: rgba(37, 99, 235, 0.3);
}

/* Tablas */
.table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.02);
    border-color: var(--border-color);
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom-width: 2px;
}

.table td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
}

/* Formularios */
.form-control, .form-select {
    background-color: var(--bg-primary);
    border-color: var(--border-color);
    color: var(--text-light);
    border-radius: 10px;
    padding: 0.625rem 1rem;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-primary);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.15);
    color: var(--text-light);
}

/* Panel Resumen Lateral */
.panel-resumen {
    position: sticky;
    top: 1.5rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
}

/* Botones Premium */
.btn-primary {
    background: var(--primary-gradient);
    border: none;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
    font-weight: 500;
    border-radius: 10px;
    padding: 0.625rem 1.25rem;
    transition: all 0.25s ease;
    color: #fff !important;
}

.btn-primary:hover, .btn-primary:focus {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
}

.btn-warning {
    font-weight: 500;
    border-radius: 10px;
    padding: 0.625rem 1.25rem;
}

.btn-outline-danger {
    border-radius: 10px;
    padding: 0.625rem 1.25rem;
}

/* Botones de Acción en Tablas (Ghost / Subtle Icons) */
.btn-action-ghost {
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-muted) !important;
    border-radius: 8px !important;
    padding: 0.35rem 0.65rem !important;
    font-size: 0.85rem !important;
    transition: all 0.2s ease-in-out !important;
}

.btn-action-ghost:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: var(--text-light) !important;
    border-color: var(--text-muted) !important;
}

.btn-action-ghost.btn-edit:hover {
    background: rgba(37, 99, 235, 0.15) !important;
    color: #60a5fa !important;
    border-color: rgba(37, 99, 235, 0.4) !important;
}

.btn-action-ghost.btn-restock:hover {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
    border-color: rgba(16, 185, 129, 0.4) !important;
}

.btn-action-ghost.btn-delete:hover {
    background: rgba(220, 38, 38, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(220, 38, 38, 0.4) !important;
}

/* Responsividad Móvil y Tablets (Media Queries) */
@media (max-width: 991.98px) {
    body > div.d-flex {
        flex-direction: column !important;
    }
    
    .sidebar {
        width: 100% !important;
        min-height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding: 1rem !important;
    }

    .sidebar .brand-logo {
        margin-bottom: 0 !important;
        padding: 0;
        min-height: 44px;
    }

    .sidebar .brand-name {
        max-width: calc(100vw - 145px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .sidebar-collapse {
        padding-top: 1rem;
    }

    .sidebar ul.nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.35rem !important;
    }

    .sidebar ul.nav .nav-item {
        min-width: 0;
    }

    .sidebar ul.nav .nav-link {
        min-height: 44px;
        font-size: 0.825rem;
        line-height: 1.2;
        padding: 0.55rem 0.65rem;
        white-space: normal;
    }

    .sidebar .sidebar-footer {
        margin-top: 0.75rem !important;
        padding-top: 0.75rem !important;
    }

    .sidebar .sidebar-footer .btn {
        min-height: 44px;
    }

    main.p-4 {
        padding: 1rem !important;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
        margin-bottom: 1.25rem !important;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 > * {
        min-width: 0;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 h1 {
        font-size: 1.65rem;
        line-height: 1.15;
        margin-bottom: 0.5rem !important;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 p {
        line-height: 1.45;
    }

    main .d-flex.justify-content-between.align-items-center.mb-4 .btn {
        width: 100%;
        min-height: 48px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        white-space: normal;
        text-align: center;
    }

    main:not(.p-0) .card-bloque.p-4 {
        padding: 1.25rem !important;
    }

    main .row.g-3,
    main .row.g-4 {
        --bs-gutter-y: 1rem;
    }

    main .card-bloque > .d-flex.justify-content-between.align-items-center {
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    main .card-bloque > .d-flex.justify-content-between.align-items-center .btn-link {
        padding-inline: 0;
        text-align: right;
    }

    main .card-bloque .brand-icon-wrapper {
        flex: 0 0 auto;
    }

    .table-responsive {
        width: 100%;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .table-responsive table:not(:has(td[colspan])) {
        min-width: 680px;
    }

    .table-responsive table:has(td[colspan]) {
        min-width: 0;
        width: 100%;
    }

    .table-responsive table:has(td[colspan]) thead {
        display: none;
    }

    .table-responsive td[colspan] {
        display: table-cell;
        width: 100%;
        padding: 2rem 0.25rem !important;
        white-space: normal;
    }

    .table-responsive td[colspan] h5 {
        font-size: 1.1rem;
        line-height: 1.35;
    }

    .table-responsive td[colspan] p {
        line-height: 1.45;
    }

    .table-responsive td[colspan] .btn {
        width: 100%;
        max-width: 280px;
        min-height: 46px;
        white-space: normal;
    }

    .panel-resumen,
    .sticky-top {
        position: static !important;
    }

    .form-control,
    .form-select {
        font-size: 1rem;
    }
}

@media (min-width: 992px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
    }
}
