﻿/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Fuentes ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

/* ── Root ── */
html, body {
    height: 100%;
    font-family: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(165deg, #06060f 0%, #0c0c24 40%, #0f0f1e 100%);
    color: #e2e8f0;
}

/* ── Layout principal ── */
.dashboard {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* ── Header ── */
.dash-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 28px;
    border-bottom: 1px solid rgba(99,102,241,0.12);
    background: rgba(6,6,15,0.7);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
    z-index: 10;
}

.dash-header-logout {
    margin-left: auto;
}

.btn-logout {
    background: transparent;
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 8px;
    padding: 7px 14px;
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    white-space: nowrap;
}

.btn-logout:hover {
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.06);
}

.dash-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #22d3ee);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    letter-spacing: -1px;
    box-shadow: 0 0 20px rgba(99,102,241,0.3);
    flex-shrink: 0;
}

.dash-title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #f1f5f9;
}

.dash-subtitle {
    font-size: 11px;
    color: #64748b;
    letter-spacing: 1.2px;
    text-transform: uppercase;
}

/* ── Main ── */
.dash-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 24px 32px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    min-height: 0; /* ← este es clave en flexbox */
}
    /* Fondo de puntos */
    .dash-main::before {
        content: '';
        position: absolute;
        inset: 0;
        opacity: 0.03;
        background-image: radial-gradient(circle, #6366f1 1px, transparent 1px);
        background-size: 32px 32px;
        pointer-events: none;
    }

/* ── Estado vacío ── */
.dash-empty {
    text-align: center;
    max-width: 520px;
    opacity: 0.85;
    animation: fadeUp 0.6s ease-out;
    margin: auto;
}

.dash-empty-icon {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    margin: 0 auto 24px;
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.dash-empty h2 {
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 10px;
    color: #cbd5e1;
}

.dash-empty p {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
}

.dash-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 24px;
    justify-content: center;
}

.dash-example-btn {
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: 10px;
    padding: 8px 16px;
    color: #94a3b8;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

    .dash-example-btn:hover {
        background: rgba(99,102,241,0.12);
        color: #c7d2fe;
    }

/* ── Loading ── */
.dash-loading {
    text-align: center;
    margin: auto;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(99,102,241,0.15);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.dash-loading p {
    color: #94a3b8;
    font-size: 14px;
}

/* ── Error ── */
.dash-error {
    background: rgba(244,63,94,0.08);
    border: 1px solid rgba(244,63,94,0.2);
    border-radius: 12px;
    padding: 16px 24px;
    max-width: 520px;
    text-align: center;
    color: #fda4af;
    font-size: 14px;
    margin: auto;
}

/* ── Resultado ── */
.dash-result {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 16px;
    animation: fadeUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

    .result-header h2 {
        font-size: 20px;
        font-weight: 700;
        margin: 0 0 4px;
        color: #f1f5f9;
    }

.result-subtitle {
    font-size: 13px;
    color: #64748b;
    margin: 0;
}

.result-miles {
    font-size: 11px;
    color: #22d3ee;
    margin: 4px 0 0;
    opacity: 0.8;
}

.result-registros {
    font-size: 11px;
    color: #475569;
    margin: 4px 0 0;
    font-family: 'Space Mono', monospace;
}

/* ── Acciones del result header ── */
.result-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ── Botón Ver SQL ── */
.btn-sql {
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 8px;
    padding: 6px 14px;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
    font-family: 'Space Mono', monospace;
    transition: all 0.2s;
    white-space: nowrap;
}

    .btn-sql.active {
        background: rgba(99,102,241,0.15);
    }

/* ── Panel SQL ── */
.sql-panel {
    background: rgba(6,6,15,0.6);
    border: 1px solid rgba(99,102,241,0.12);
    border-radius: 10px;
    padding: 14px 18px;
    font-family: 'Space Mono', monospace;
    font-size: 12.5px;
    color: #a5b4fc;
    line-height: 1.7;
    overflow-x: auto;
    white-space: pre-wrap;
}

/* ── Contenedor del gráfico ── */
.chart-container {
    width: 100%;
    min-height: 380px;
    height: auto;
    flex-shrink: 0;
    overflow: hidden;
    background: rgba(15,15,40,0.35);
    border: 1px solid rgba(99,102,241,0.1);
    border-radius: 16px;
    padding: 20px 16px;
    box-shadow: 0 4px 40px rgba(0,0,0,0.2);
}

    /* ApexCharts necesita que su contenedor interno sea 100% del ancho */
    .chart-container .apexcharts-canvas,
    .chart-container > div {
        width: 100% !important;
    }

/* ── Insight ── */
.dash-insight {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(99,102,241,0.04);
    border: 1px solid rgba(99,102,241,0.1);
    border-radius: 10px;
    padding: 12px 16px;
}

    .dash-insight p {
        margin: 0;
        font-size: 13px;
        color: #94a3b8;
        line-height: 1.6;
    }

/* ── Filtros ── */
.dash-filters {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: rgba(34,211,238,0.03);
    border: 1px solid rgba(34,211,238,0.1);
    border-radius: 10px;
    padding: 12px 16px;
}

.filters-label {
    font-size: 11px;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 0 0 8px;
}

.filters-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    font-size: 12px;
    color: #67e8f9;
    background: rgba(34,211,238,0.07);
    border: 1px solid rgba(34,211,238,0.15);
    border-radius: 6px;
    padding: 3px 10px;
}

/* ── Footer ── */
.dash-footer {
    padding: 16px 28px 20px;
    border-top: 1px solid rgba(99,102,241,0.1);
    background: rgba(6,6,15,0.5);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
    /* Garantiza visibilidad en mobile cuando aparece el teclado */
    position: sticky;
    bottom: 0;
    z-index: 20;
}

.dash-input-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15,15,40,0.5);
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: 14px;
    padding: 6px 6px 6px 20px;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 2px 20px rgba(0,0,0,0.15);
}

    .dash-input-bar input {
        flex: 1;
        background: transparent;
        border: none;
        outline: none;
        color: #e2e8f0;
        font-size: 14.5px;
        font-family: inherit;
        padding: 10px 0;
    }

        .dash-input-bar input::placeholder {
            color: #475569;
        }

        .dash-input-bar input:disabled {
            opacity: 0.5;
        }

.btn-consultar {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 2px 12px rgba(99,102,241,0.3);
    white-space: nowrap;
}

    .btn-consultar:disabled {
        background: rgba(99,102,241,0.15);
        color: #4b5563;
        box-shadow: none;
        cursor: default;
    }

.dash-footer-note {
    text-align: center;
    font-size: 11px;
    color: #475569;
    margin: 10px 0 0;
    letter-spacing: 0.3px;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(99,102,241,0.2);
    border-radius: 3px;
}

/* ── Animaciones ── */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Mobile ── */
@media (max-width: 600px) {
    .dash-header {
        padding: 10px 16px;
        gap: 10px;
    }

    .dash-logo {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }

    .dash-title {
        font-size: 15px;
    }

    .dash-subtitle {
        font-size: 11px;
    }

    .dash-footer {
        padding: 10px 12px 14px;
    }

    .dash-input-bar {
        padding: 4px 4px 4px 14px;
        border-radius: 12px;
        gap: 8px;
    }

    .dash-input-bar input {
        font-size: 14px;
        padding: 8px 0;
    }

    .btn-consultar {
        padding: 9px 14px;
        font-size: 13px;
        border-radius: 9px;
    }

    .dash-main {
        padding: 0 12px;
    }

    .result-header {
        flex-direction: column;
        gap: 10px;
    }

    .result-header-actions {
        display: flex;
        gap: 8px;
    }

    .chart-container {
        padding: 12px 8px;
        border-radius: 12px;
        min-height: 340px;
    }
}

/* ── Estilos de impresión ── */
@media print {

    body {
        background: #fff !important;
        color: #1e293b !important;
        overflow: visible !important;
    }

    .dashboard {
        height: auto !important;
        overflow: visible !important;
    }

    .dash-main {
        overflow: visible !important;
        height: auto !important;
    }

    /* Ocultar lo que no queremos imprimir */
    .dash-header,
    .dash-footer,
    footer.dash-footer,
    .dash-empty,
    .dash-loading,
    .dash-error,
    .result-header-actions,
    .sql-panel {
        display: none !important;
        visibility: hidden !important;
    }

    .dash-result {
        background: #fff !important;
        color: #1e293b !important;
        padding: 16px !important;
        animation: none !important;
    }

    .result-subtitle,
    .result-miles,
    .result-registros {
        color: #475569 !important;
    }

    .dash-insight {
        border: 1px solid #e2e8f0 !important;
        background: #f8fafc !important;
        color: #1e293b !important;
    }

    .dash-filters {
        background: #f8fafc !important;
        color: #1e293b !important;
    }

    .chip {
        background: #e2e8f0 !important;
        color: #1e293b !important;
    }
}

/* == Login == */
.login-page {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
}

.login-card {
    background: rgba(12, 12, 28, 0.92);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 24px;
    padding: 40px 40px 36px;
    width: 100%;
    max-width: 420px;
    backdrop-filter: blur(20px);
    box-shadow:
        0 0 0 1px rgba(99, 102, 241, 0.08),
        0 8px 32px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(99, 102, 241, 0.06);
}

/* — Brand header — */
.login-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.login-logo {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, #6366f1, #22d3ee);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 22px;
    color: #fff;
    letter-spacing: -1px;
    box-shadow: 0 0 28px rgba(99, 102, 241, 0.4);
    flex-shrink: 0;
}

.login-brand-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.4px;
    color: #f1f5f9;
}

.login-brand-sub {
    font-size: 11px;
    color: #64748b;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* — Divider — */
.login-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.3), transparent);
    margin-bottom: 28px;
}

/* — Campos — */
.login-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 20px;
}

.login-field label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #94a3b8;
}

.login-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.login-input-icon {
    position: absolute;
    left: 14px;
    font-size: 15px;
    pointer-events: none;
    opacity: 0.6;
}

.login-input-wrap input {
    width: 100%;
    background: rgba(99, 102, 241, 0.07);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 11px;
    padding: 13px 16px 13px 42px;
    font-size: 15px;
    color: #e2e8f0;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.login-input-wrap input:focus {
    border-color: rgba(99, 102, 241, 0.55);
    background: rgba(99, 102, 241, 0.11);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.13);
}

.login-input-wrap input::placeholder {
    color: #3d4f66;
}

/* — Botones — */
.login-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
}

.login-btn-cancel {
    flex: 1;
    padding: 13px;
    border-radius: 11px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    background: transparent;
    color: #64748b;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.login-btn-cancel:hover {
    border-color: rgba(99, 102, 241, 0.4);
    color: #94a3b8;
    background: rgba(99, 102, 241, 0.05);
}

.login-btn-submit {
    flex: 2;
    padding: 13px;
    border-radius: 11px;
    border: none;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 18px rgba(99, 102, 241, 0.35);
    letter-spacing: 0.2px;
}

.login-btn-submit:hover {
    opacity: 0.9;
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

/* — Error — */
.login-error {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 13px;
    color: #fca5a5;
    margin-bottom: 20px;
}

.login-error-icon {
    font-style: normal;
    font-size: 15px;
    flex-shrink: 0;
}

.login-validation {
    font-size: 12px;
    color: #fca5a5;
    padding-left: 2px;
}
