/* ==================== Brand Colors (softwareeconomico.com) ==================== */
:root {
    --se-blue-900: #1e3a8a;
    --se-blue-800: #1e40af;
    --se-blue-600: #2563eb;
    --se-gray-900: #111827;
    --se-gray-800: #1f2937;
    --se-gray-700: #374151;
    --se-gray-100: #f3f4f6;
    --se-amber-500: #f59e0b;
    --se-amber-600: #d97706;
}

/* ==================== Bootstrap overrides ==================== */
.btn-primary {
    background-color: var(--se-blue-600);
    border-color: var(--se-blue-600);
}
.btn-primary:hover {
    background-color: var(--se-blue-800);
    border-color: var(--se-blue-800);
}

.btn-dark {
    background-color: var(--se-gray-900);
    border-color: var(--se-gray-900);
}
.btn-dark:hover {
    background-color: var(--se-gray-800);
    border-color: var(--se-gray-800);
}

.btn-warning {
    background-color: var(--se-amber-500);
    border-color: var(--se-amber-500);
}
.btn-warning:hover {
    background-color: var(--se-amber-600);
    border-color: var(--se-amber-600);
}

.bg-light {
    background-color: var(--se-gray-100) !important;
}

.bg-dark {
    background-color: var(--se-gray-900) !important;
}

.text-primary {
    color: var(--se-gray-900) !important;
}

.border-dark {
    border-color: var(--se-gray-900) !important;
}

/* ==================== Form styles ==================== */
.form-control:focus {
    border-color: var(--se-blue-600);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-control, .input-group-text {
    border-radius: 0.375rem;
    border: 1px solid #ced4da;
    background: #fff;
    color: #2a3b4d;
}

.input-group-text {
    background: #f0f4ff;
    border-left: 2px solid var(--se-blue-600);
    color: var(--se-blue-600);
}

.form-select {
    border-radius: 0.375rem;
    border: 1px solid #ced4da;
    background-color: #fff;
    color: #2a3b4d;
}

.form-control-sm,
.form-select-sm {
    height: 31px !important;
    padding: 0.25rem 0.5rem !important;
    font-size: 0.8125rem !important;
    line-height: 1.5 !important;
}

.form-select-sm {
    padding-right: 2rem !important;
}

.chart-card .form-label,
.sidebar .form-label {
    font-size: 0.8rem;
    color: var(--se-gray-700);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-weight: 600;
}

.chart-card .btn-sm {
    border-radius: 0.375rem;
    padding: 0.35rem 1rem;
    font-weight: 600;
    font-size: 0.8125rem;
}

/* ==================== Dialog ==================== */
dialog {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    padding: 1.25rem;
    max-width: 400px;
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5);
}

/* ==================== Login Logo & Title ==================== */
.logo-img {
    max-width: 90%;
    width: auto;
    max-height: 210px;
}

.logo-img + h1#auth_title {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.body-login {
    height: 100vh;
}

/* ==================== Cards ==================== */
.border-left-accent {
    border-left-width: 4px !important;
}

.hidden {
    display: none;
}

.card-main {
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    background: #fff;
}

/* ==================== Sidebar ==================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    background-color: var(--se-gray-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--se-gray-700);
    background: linear-gradient(180deg, var(--se-gray-800) 0%, var(--se-gray-900) 100%);
}

.sidebar-header h5 {
    margin: 0;
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
}

.sidebar-company {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.25rem;
    line-height: 1.3;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background-color 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
    background-color: var(--se-gray-700);
    color: #fff;
}

.sidebar-nav a.active {
    background-color: var(--se-blue-600);
    color: #fff;
}

.sidebar-nav a svg {
    flex-shrink: 0;
}

/* ===== Sidebar collapsible groups ===== */
.sidebar-nav details {
    border: none;
}

.sidebar-nav details summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    list-style: none;
    transition: color 0.15s;
}

.sidebar-nav details summary::-webkit-details-marker {
    display: none;
}

.sidebar-nav details summary::before {
    content: '\25B8';
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    width: 0.75rem;
}

.sidebar-nav details[open] summary::before {
    transform: rotate(90deg);
}

.sidebar-nav details summary:hover {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-nav details a {
    padding-left: 2.75rem;
    font-size: 0.8rem;
}

.sidebar-nav details a svg {
    width: 15px;
    height: 15px;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--se-gray-700);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.15s;
}

.sidebar-footer a:hover {
    color: #fff;
}

.sidebar-footer .user-info {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 0.75rem;
    word-break: break-all;
}

/* ==================== Main content (with sidebar) ==================== */
.main-content {
    margin-left: 250px;
    padding: 1.25rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#footer-placeholder {
    margin-top: auto;
}

/* ==================== Page header ==================== */
.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #2a3b4d;
    margin: 0 0 1.25rem 0;
    padding-bottom: 0.75rem;
    border-bottom: 3px solid var(--se-blue-600);
}

/* ==================== Mobile header bar ==================== */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 3px solid var(--se-blue-600);
}

.mobile-header .mobile-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2a3b4d;
    margin: 0;
}

/* ==================== Mobile toggle button ==================== */
.sidebar-toggle {
    display: none;
    background-color: var(--se-gray-900);
    color: #fff;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* ==================== KPI Cards ==================== */
.kpi-card {
    border-left-width: 5px !important;
    border-radius: 0.5rem !important;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: transform 0.15s;
}

.kpi-card:hover {
    transform: translateY(-2px);
}

.kpi-card .kpi-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-card .kpi-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #2a3b4d;
}

.kpi-card .kpi-detail {
    font-size: 0.78rem;
    color: #6c757d;
}

/* ==================== Chart Container ==================== */
.chart-container {
    border-radius: 0.5rem;
}

.chart-container canvas {
    max-height: 300px;
}

/* ==================== Modern Table ==================== */
.modern-table {
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    background: #fff;
    border: 1px solid #e5e7eb;
}

table.modern-table thead th {
    color: #fff;
    font-weight: 600;
    border: none;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}

.modern-table tbody tr {
    background: #fff;
}

.modern-table tbody tr:last-child {
    border-bottom: none;
}

.modern-table td {
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #2a3b4d;
}

.modern-table th, .modern-table td {
    vertical-align: middle;
}

/* ==================== Alert range (date range display) ==================== */
.alert-range {
    background: #e0f2fe;
    color: var(--se-blue-600);
    border: none;
}

/* ==================== Analytics Dashboard ==================== */
.analytics-section {
    margin-bottom: 1.75rem;
}

.chart-card {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
    padding: 1.25rem;
    min-height: 280px;
    overflow: visible;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease;
}

.chart-card:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1), 0 8px 24px rgba(0, 0, 0, 0.08);
}

.chart-card h6 {
    font-weight: 700;
    color: var(--se-gray-900);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
}

.chart-card canvas {
    flex: 1;
    max-height: 260px;
}

.reorder-table {
    width: 100%;
    font-size: 0.88rem;
}

.reorder-table th {
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    padding: 0.5rem 0.4rem;
    border-bottom: 2px solid #e5e7eb;
}

.reorder-table td {
    padding: 0.5rem 0.4rem;
    border-bottom: 1px solid #f3f4f6;
    color: #2a3b4d;
    vertical-align: middle;
}

.reorder-table tr:last-child td {
    border-bottom: none;
}

.badge-priority {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.25em 0.6em;
    border-radius: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-critica { background: #fde8e8; color: #dc2626; }
.badge-urgente { background: #fff3e0; color: #e65100; }
.badge-alta { background: #fef9c3; color: #92400e; }
.badge-normal { background: #dcfce7; color: #166534; }

.loading-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    color: #9ca3af;
    font-size: 0.9rem;
}

.loading-placeholder .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.5rem;
}

.no-data-message {
    text-align: center;
    color: #9ca3af;
    padding: 2rem 1rem;
    font-size: 0.9rem;
}

.see-more-link {
    display: inline-block;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--se-blue-600);
    text-decoration: none;
}

.see-more-link:hover {
    text-decoration: underline;
}

.mini-kpi {
    text-align: center;
    padding: 1rem 0.5rem;
}

.mini-kpi .mini-kpi-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2a3b4d;
}

.mini-kpi .mini-kpi-label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.25rem;
}

/* ==================== Product Autocomplete Dropdown ==================== */
.list-group.position-absolute {
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 0.375rem;
}

.list-group.position-absolute .list-group-item:nth-child(odd) {
    background-color: #f8f9fa;
}

.list-group.position-absolute .list-group-item:nth-child(even) {
    background-color: #fff;
}

.list-group.position-absolute .list-group-item:hover {
    background-color: #e9ecef;
}

/* ==================== Corporate Footer ==================== */
.main-content > .text-center.text-muted {
    border-top: 1px solid #e5e7eb;
    padding-top: 1rem;
    margin-top: 2rem;
}

/* ==================== Misc ==================== */
html, body {
    overflow-x: hidden !important;
}

.table-striped > tbody > tr:nth-of-type(odd) {
    background-color: #f8f9fa;
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .sidebar-toggle {
        display: flex;
    }

    .page-title {
        display: none;
    }

    .main-content {
        margin-left: 0;
        padding: 0.75rem;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.show {
        display: block;
    }

    /* KPI cards mobile */
    .kpi-card .kpi-value {
        font-size: 1.1rem;
    }

    .kpi-card .kpi-label {
        font-size: 0.7rem;
    }

    .kpi-card .card-body {
        padding: 0.5rem 0.6rem !important;
    }

    /* Chart cards mobile */
    .chart-card {
        padding: 1rem;
        min-height: 200px;
    }

    .chart-card canvas {
        max-height: 220px;
    }

    .chart-container canvas {
        max-height: 220px;
    }

    /* Reorder table — stack on mobile */
    .reorder-table thead {
        display: none;
    }

    .reorder-table,
    .reorder-table tbody,
    .reorder-table tr,
    .reorder-table td {
        display: block;
        width: 100%;
    }

    .reorder-table tr {
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        background: #f8f9fa;
        border-radius: 0.75rem;
        border: 1px solid #e5e7eb;
    }

    .reorder-table td {
        padding: 0.25rem 0;
        border-bottom: none;
        font-size: 0.85rem;
    }

    .reorder-table td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 0.7rem;
        color: #6c757d;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        margin-bottom: 0.15rem;
    }

    /* Mini KPI mobile */
    .mini-kpi .mini-kpi-value {
        font-size: 1.1rem;
    }

    .mini-kpi .mini-kpi-label {
        font-size: 0.65rem;
    }

    /* Non-moving products: 3 mini-KPIs stack to 1 per row on mobile */
    #noMovementContainer .col-4 {
        width: 100%;
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Autocomplete dropdown mobile */
    .list-group.position-absolute {
        max-height: 200px;
        overflow-y: auto;
    }

    /* Filter form labels */
    .chart-card .form-label {
        font-size: 0.75rem;
    }

    /* Analytics section spacing */
    .analytics-section {
        margin-bottom: 0.75rem;
    }

    /* Filters in chart-card mobile */
    .chart-card .d-flex.flex-wrap {
        gap: 0.4rem !important;
    }

    /* Table responsive stack */
    .table-responsive-stack {
        display: block;
        width: 100%;
    }

    .table-responsive-stack thead {
        display: none;
    }

    .table-responsive-stack tr {
        display: block;
        margin-bottom: 1rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
        border-radius: 10px;
        background: #fff;
        border: 1px solid #e0e6ed;
        border-bottom: 3px solid var(--se-gray-700);
        color: #2a3b4d;
        padding: 1rem 0.8rem;
    }

    .table-responsive-stack td {
        display: block;
        width: 100% !important;
        text-align: left !important;
        padding: 0.5rem 0.2rem 0.8rem 0.2rem;
        border: none;
        min-height: 36px;
        word-break: break-word;
        white-space: pre-line;
        font-size: 1.05rem;
    }

    .table-responsive-stack td::before {
        content: attr(data-label);
        display: block;
        font-weight: bold;
        margin-bottom: 0.3rem;
        color: var(--se-gray-700);
        font-size: 0.85rem;
    }

    .table-responsive-stack td:not(:last-child) {
        margin-bottom: 0.5rem;
    }

    .paginacion-responsive {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        overflow-x: auto !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    .paginacion-responsive button,
    .paginacion-responsive input[type="number"] {
        min-width: 40px;
        max-width: 60px;
        width: auto !important;
        flex: 0 0 auto !important;
        box-sizing: border-box;
    }

    .card-main, .table-responsive-stack {
        width: 100%;
        box-sizing: border-box;
    }

    .main-content > .container {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.5rem;
    }

    /* KPI cards extra small */
    .kpi-card .kpi-value {
        font-size: 0.95rem;
    }

    .kpi-card .kpi-label {
        font-size: 0.65rem;
    }

    .kpi-card .kpi-detail {
        font-size: 0.65rem;
    }

    .kpi-card .card-body {
        padding: 0.4rem 0.5rem !important;
    }

    /* Chart card extra small */
    .chart-card {
        padding: 0.75rem;
        min-height: 180px;
    }

    .chart-card h6 {
        font-size: 0.85rem;
    }

    .chart-card canvas {
        max-height: 200px;
    }

    /* Filters compact */
    .chart-card .form-label {
        font-size: 0.7rem;
        margin-bottom: 0.2rem;
    }

    .chart-card .btn-sm {
        font-size: 0.75rem;
        padding: 0.3rem 0.75rem;
    }

    /* Mini KPI extra small */
    .mini-kpi .mini-kpi-value {
        font-size: 0.95rem;
    }

    .mini-kpi .mini-kpi-label {
        font-size: 0.6rem;
    }

    .mini-kpi {
        padding: 0.5rem 0.25rem;
    }

    /* Reorder table extra small */
    .reorder-table td {
        font-size: 0.8rem;
    }

    /* Non-moving products: keep stacked on extra small */
    #noMovementContainer .col-4 {
        width: 100%;
        flex: 0 0 100%;
        max-width: 100%;
    }

    .paginacion-responsive {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px !important;
        width: 100% !important;
        overflow-x: auto !important;
        align-items: center;
    }

    .paginacion-responsive button {
        min-width: 60px;
        max-width: 80px;
        width: auto;
        flex: 0 0 auto;
        font-size: 1rem;
        padding: 4px 10px;
    }

    .paginacion-responsive input[type="number"] {
        max-width: 50px;
        padding: 2px 2px;
    }

    .paginacion-responsive span {
        font-size: 0.95rem;
        padding: 0 2px;
        white-space: nowrap;
    }
}

@media (max-width: 600px) {
    .body-login {
        min-height: 100vh;
    }

    img.logo-img.img-fluid {
        max-height: 130px;
        width: auto;
    }

    .logo-img + h1#auth_title {
        margin-top: 0.5rem;
        margin-bottom: 1rem;
    }

    .card .card-body.p-4 {
        padding: 1rem;
    }
}

/* ==================== Print ==================== */
@page {
    size: landscape;
    margin: 10mm;
}

@media print {
    /* Hide non-data UI elements */
    .sidebar,
    .sidebar-overlay,
    .sidebar-toggle,
    .mobile-header,
    .no-print,
    #noDataMessage,
    #footer-placeholder,
    dialog {
        display: none !important;
    }

    html, body {
        width: 100% !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .container, .container-fluid {
        max-width: 100% !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .page-title {
        display: block !important;
        border-bottom: 2px solid #000;
        margin-bottom: 0.5rem;
    }

    /* Hide filter controls (inputs, selects, labels, buttons, forms) */
    .chart-card .form-label,
    .chart-card .input-group,
    .chart-card select,
    .chart-card input,
    .chart-card .btn,
    .chart-card #formParametros,
    .chart-card > .row.g-2,
    .list-group.position-absolute {
        display: none !important;
    }

    /* Keep data elements visible */
    .chart-card #chartSection,
    .chart-card #rangoFechasCard,
    .chart-card .alert-range,
    .chart-card canvas,
    .chart-card table {
        display: block !important;
    }

    .chart-card #rangoFechasCard {
        display: flex !important;
    }

    /* Purchase costs: show desktop table, hide mobile cards */
    .d-none.d-md-block {
        display: block !important;
    }

    .d-md-none {
        display: none !important;
    }

    .chart-card {
        box-shadow: none !important;
        border: 1px solid #ccc;
        break-inside: avoid;
        page-break-inside: avoid;
        width: 100% !important;
        min-height: auto !important;
        padding: 0.5rem !important;
    }

    /* Hide chart-cards that only contain filters (no data sections) */
    .chart-card:not(:has(#chartSection)):not(:has(table)):not(:has(canvas)) {
        display: none !important;
    }

    .kpi-card {
        box-shadow: none !important;
        border: 1px solid #ccc;
    }

    .kpi-card:hover,
    .chart-card:hover {
        transform: none !important;
        box-shadow: none !important;
    }

    .row {
        width: 100% !important;
    }

    table {
        width: 100% !important;
        font-size: 0.8rem;
    }
}
