/*
 * Dashboard conversacional responsivo.
 *
 * Usa 100dvh cuando está disponible para respetar la altura
 * realmente visible en navegadores móviles.
 */

html.erp-dashboard-open,
body.erp-dashboard-open {
    overflow: hidden !important;
    overscroll-behavior: none;
}

body.erp-dashboard-open {
    position: fixed;
    right: 0;
    left: 0;
    width: 100%;
}

.erp-dashboard-preview,
.erp-dashboard-preview *,
.erp-dashboard-modal,
.erp-dashboard-modal * {
    box-sizing: border-box;
}

.erp-dashboard-preview {
    width: min(100%, 355px);
    max-width: 100%;
    margin-top: 8px;
    border: 1px solid #dfe4ec;
    border-radius: 16px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.09);
}

.erp-dashboard-preview__header {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #edf0f5;
    background: linear-gradient(135deg, #f8faff, #eef3ff);
}

.erp-dashboard-preview__heading {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.erp-dashboard-preview__heading strong,
.erp-dashboard-preview__heading span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-dashboard-preview__heading strong {
    font-size: 13px;
    color: #172033;
}

.erp-dashboard-preview__heading span {
    font-size: 10px;
    color: #667085;
}

.erp-dashboard-preview__button {
    flex: 0 0 auto;
    padding: 7px 10px;
    border: 0;
    border-radius: 9px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    color: #ffffff;
    background: #2f5bea;
}

.erp-dashboard-preview__button:hover {
    background: #2043bd;
}

.erp-dashboard-preview__button:focus-visible,
.erp-dashboard-modal__close:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

.erp-dashboard-preview__content {
    min-width: 0;
    padding: 11px;
    overflow: hidden;
    background: #f8fafc;
}

.erp-dashboard__kpis {
    min-width: 0;
    display: grid;
    grid-template-columns:
        repeat(
            auto-fit,
            minmax(min(100%, 160px), 1fr)
        );
    gap: 12px;
}

.erp-dashboard__kpis--compact {
    grid-template-columns:
        repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.erp-dashboard__kpi {
    min-width: 0;
    padding: 14px;
    border: 1px solid #e4e7ec;
    border-radius: 14px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.erp-dashboard__kpis--compact
.erp-dashboard__kpi {
    padding: 9px;
    border-radius: 11px;
}

.erp-dashboard__kpi-name {
    overflow: hidden;
    font-size: 12px;
    color: #667085;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-dashboard__kpi-value {
    display: block;
    max-width: 100%;
    margin-top: 6px;
    overflow: hidden;
    font-size: clamp(18px, 2.2vw, 28px);
    line-height: 1.15;
    color: #101828;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-dashboard__kpis--compact
.erp-dashboard__kpi-value {
    font-size: 16px;
}

.erp-dashboard__variation {
    margin-top: 7px;
    font-size: 11px;
    font-weight: 700;
}

.erp-dashboard__variation.is-positive {
    color: #067647;
}

.erp-dashboard__variation.is-negative {
    color: #b42318;
}

.erp-dashboard__variation.is-neutral {
    color: #667085;
}

.erp-dashboard__kpi-detail {
    display: block;
    margin-top: 7px;
    overflow-wrap: anywhere;
    line-height: 1.35;
    color: #667085;
}

.erp-dashboard__charts {
    min-width: 0;
    margin-top: 16px;
    display: grid;
    grid-template-columns:
        repeat(
            auto-fit,
            minmax(min(100%, 320px), 1fr)
        );
    gap: 14px;
}

.erp-dashboard__charts--compact {
    grid-template-columns: minmax(0, 1fr);
    margin-top: 10px;
}

.erp-dashboard__chart-card,
.erp-dashboard__table-section {
    min-width: 0;
    max-width: 100%;
    padding: 15px;
    border: 1px solid #e4e7ec;
    border-radius: 14px;
    overflow: hidden;
    background: #ffffff;
}

.erp-dashboard__charts--compact
.erp-dashboard__chart-card {
    padding: 10px;
}

.erp-dashboard__section-title {
    margin: 0 0 12px;
    overflow-wrap: anywhere;
    font-size: 14px;
    color: #172033;
}

.erp-dashboard__charts--compact
.erp-dashboard__section-title {
    margin-bottom: 7px;
    font-size: 11px;
}

.erp-dashboard__canvas {
    position: relative;
    width: 100%;
    min-width: 0;
    height: clamp(230px, 34vh, 330px);
}

.erp-dashboard__canvas canvas {
    width: 100% !important;
    max-width: 100%;
    height: 100% !important;
}

.erp-dashboard__canvas--compact {
    height: 150px;
}

.erp-dashboard__warning {
    margin: 0;
    padding: 16px;
    border-radius: 10px;
    overflow-wrap: anywhere;
    font-size: 12px;
    color: #7a2e0e;
    background: #fff4e5;
}

.erp-dashboard__table-section {
    margin-top: 16px;
}

.erp-dashboard__table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid #eaecf0;
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
}

.erp-dashboard__table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    color: #344054;
}

.erp-dashboard__table th,
.erp-dashboard__table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eaecf0;
    text-align: left;
    white-space: nowrap;
}

.erp-dashboard__table th {
    position: sticky;
    top: 0;
    z-index: 1;
    font-weight: 700;
    color: #344054;
    background: #f9fafb;
}

.erp-dashboard__table tbody tr:last-child td {
    border-bottom: 0;
}

.erp-dashboard__table tbody tr:hover {
    background: #f8faff;
}

/* Modal */

.erp-dashboard-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483500;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    overflow: hidden;
    display: grid;
    place-items: center;
}

.erp-dashboard-modal[hidden] {
    display: none;
}

.erp-dashboard-modal__backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    cursor: default;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(3px);
}

.erp-dashboard-modal__dialog {
    position: relative;
    z-index: 1;
    width: min(1440px, 100%);
    height: min(920px, 100%);
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    border-radius: clamp(12px, 2vw, 20px);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: #f5f7fb;
    box-shadow: 0 30px 90px rgba(15, 23, 42, 0.35);
}

.erp-dashboard-modal__header {
    min-width: 0;
    padding: clamp(12px, 2vw, 18px)
        clamp(12px, 2.2vw, 22px);
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ffffff;
    background: linear-gradient(135deg, #2f5bea, #2043bd);
}

.erp-dashboard-modal__heading {
    min-width: 0;
    flex: 1;
}

.erp-dashboard-modal__heading h2 {
    margin: 0;
    overflow: hidden;
    display: -webkit-box;
    font-size: clamp(16px, 2vw, 20px);
    line-height: 1.25;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.erp-dashboard-modal__heading p {
    margin: 5px 0 0;
    overflow: hidden;
    display: -webkit-box;
    font-size: 12px;
    line-height: 1.3;
    color: rgba(255, 255, 255, 0.82);
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.erp-dashboard-modal__close {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 25px;
    line-height: 1;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
}

.erp-dashboard-modal__close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.erp-dashboard-modal__body {
    min-width: 0;
    min-height: 0;
    padding: clamp(10px, 2vw, 20px);
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Tablet y móvil */

@media (max-width: 760px) {
    .erp-dashboard-modal {
        padding: 0;
    }

    .erp-dashboard-modal__dialog {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .erp-dashboard-modal__header {
        padding-top:
            max(
                12px,
                env(safe-area-inset-top)
            );
        padding-right:
            max(
                12px,
                env(safe-area-inset-right)
            );
        padding-left:
            max(
                12px,
                env(safe-area-inset-left)
            );
    }

    .erp-dashboard-modal__body {
        padding-right:
            max(
                10px,
                env(safe-area-inset-right)
            );
        padding-bottom:
            max(
                14px,
                env(safe-area-inset-bottom)
            );
        padding-left:
            max(
                10px,
                env(safe-area-inset-left)
            );
    }

    .erp-dashboard__charts {
        grid-template-columns: minmax(0, 1fr);
    }

    .erp-dashboard__canvas {
        height: clamp(220px, 40vh, 300px);
    }
}

/* Teléfonos angostos */

@media (max-width: 480px) {
    .erp-dashboard-modal__header {
        gap: 9px;
    }

    .erp-dashboard-modal__close {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }

    .erp-dashboard-modal__body {
        padding-top: 10px;
    }

    .erp-dashboard-modal__body
    .erp-dashboard__kpis {
        grid-template-columns:
            repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .erp-dashboard-modal__body
    .erp-dashboard__kpi {
        padding: 10px;
    }

    .erp-dashboard-modal__body
    .erp-dashboard__kpi-value {
        font-size: 17px;
    }

    .erp-dashboard__chart-card,
    .erp-dashboard__table-section {
        padding: 10px;
        border-radius: 11px;
    }

    .erp-dashboard__canvas {
        height: 235px;
    }

    .erp-dashboard__table th,
    .erp-dashboard__table td {
        padding: 9px 10px;
    }
}

@media (max-width: 350px) {
    .erp-dashboard-modal__body
    .erp-dashboard__kpis {
        grid-template-columns: minmax(0, 1fr);
    }

    .erp-dashboard-preview__header {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .erp-dashboard-preview__button {
        width: 100%;
    }
}

/* Pantallas bajas o modo horizontal */

@media (max-height: 600px) and (orientation: landscape) {
    .erp-dashboard-modal {
        padding: 0;
    }

    .erp-dashboard-modal__dialog {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .erp-dashboard-modal__header {
        padding-top:
            max(
                8px,
                env(safe-area-inset-top)
            );
        padding-bottom: 8px;
    }

    .erp-dashboard-modal__heading p {
        margin-top: 2px;
        -webkit-line-clamp: 1;
    }

    .erp-dashboard-modal__close {
        width: 34px;
        height: 34px;
    }

    .erp-dashboard-modal__body {
        padding-top: 8px;
    }

    .erp-dashboard__canvas {
        height: 210px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .erp-dashboard-modal *,
    .erp-dashboard-preview * {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
