// Analytics dashboard: visual refresh.
//
// Imported last from style.scss, so it overrides the rules above it without
// changing any markup or component. It uses the same tokens as the main
// dashboard refresh (static/css/settings-refresh.css), so both pages match.

.ep-analytics-dashboard {
    --ep-primary: #5b4e96;
    --ep-primary-hover: #4a3e82;
    --ep-primary-soft: #f1effa;
    --ep-primary-ring: rgba(91, 78, 150, 0.18);
    --ep-text: #1d2236;
    --ep-text-2: #464c63;
    --ep-muted: #6b7189;
    --ep-border: #e5e7ef;
    --ep-border-strong: #d5d8e4;
    --ep-bg: #f6f7fb;
    --ep-surface: #ffffff;
    --ep-surface-2: #fafbfd;
    --ep-radius: 12px;
    --ep-radius-sm: 8px;
    --ep-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);

    padding: 24px;
    background: var(--ep-bg);
    color: var(--ep-text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;

    @media screen and (max-width: 1400px) {
        padding: 20px;
    }

    @media screen and (max-width: 767px) {
        padding: 12px;
    }

    // Shared card surface for every panel.
    .ep-header-wrapper,
    .ep-geolocation-setting,
    .ep-card-wrapper {
        background: var(--ep-surface);
        border: 1px solid var(--ep-border);
        border-radius: var(--ep-radius);
        box-shadow: var(--ep-shadow);
    }

    // ---------- Header ----------

    .ep-header-wrapper {
        padding: 18px 24px;
        margin-bottom: 16px;
        gap: 24px;

        .dashboard-title {
            font-size: 20px;
            font-weight: 600;
            line-height: 1.3;
            letter-spacing: -0.01em;
            color: var(--ep-text);
            padding-bottom: 4px;
        }

        p {
            font-size: 13px;
            line-height: 1.5;
            color: var(--ep-muted);
        }

        .button-wrapper {
            gap: 12px;
        }
    }

    // ---------- Geolocation notice ----------

    .ep-geolocation-setting {
        align-items: flex-start;
        gap: 20px;
        padding: 14px 24px;
        margin: 0 0 20px;

        .ep-tracking-toggle-wrapper {
            flex: 0 0 auto;
            padding-top: 2px;
        }

        &__note {
            flex: 1 1 auto;
            min-width: 0;
            max-width: none;
            margin: 0;
            font-size: 12.5px;
            line-height: 1.6;
            color: var(--ep-muted);
        }
    }

    .ep-tracking-toggle-text {
        font-size: 14px;
        font-weight: 500;
        color: var(--ep-text);
    }

    // ---------- Buttons and inputs ----------

    .ep-btn {
        min-height: 38px;
        padding: 0 14px;
        border: 1px solid var(--ep-border-strong);
        border-radius: var(--ep-radius-sm);
        background: var(--ep-surface);
        color: var(--ep-text-2);
        font-size: 14px;
        font-weight: 500;
        transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;

        svg path {
            transition: stroke 0.15s ease;
        }

        &:hover {
            background: var(--ep-primary-soft);
            border-color: var(--ep-primary);
            color: var(--ep-primary);

            svg path {
                stroke: var(--ep-primary) !important;
            }
        }

        &.primary,
        &.active {
            background: var(--ep-primary);
            border-color: var(--ep-primary);
            color: #fff;
            box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);

            svg path {
                stroke: #fff !important;
            }

            &:hover {
                background: var(--ep-primary-hover);
                border-color: var(--ep-primary-hover);
                color: #fff;
            }
        }

        &:focus-visible {
            outline: none;
            box-shadow: 0 0 0 3px var(--ep-primary-ring);
        }
    }

    .ep-date-range-trigger {
        height: 38px;
        min-width: 0;
        padding: 0 12px;
        border: 1px solid var(--ep-border-strong);
        border-radius: var(--ep-radius-sm);
        box-shadow: none;
        font-family: inherit;
        font-size: 14px;
        font-weight: 500;
        color: var(--ep-text-2);

        &:hover {
            border-color: var(--ep-primary);
            background: var(--ep-surface);
        }
    }

    .ep-date-range-picker {
        font-family: inherit;
    }

    .ep-card-wrapper .ep-card-header select {
        min-height: 34px;
        border: 1px solid var(--ep-border-strong);
        border-radius: var(--ep-radius-sm);
        font-size: 13px;
        font-weight: 500;
        color: var(--ep-text-2);

        &:hover {
            border-color: var(--ep-primary);
        }

        &:focus {
            border-color: var(--ep-primary);
            box-shadow: 0 0 0 3px var(--ep-primary-ring);
        }
    }

    // ---------- Cards and tabs ----------

    .ep-card-wrapper {
        padding: 20px 24px;
        margin-bottom: 20px;

        .ep-card-header {
            h4 {
                font-size: 15px;
                font-weight: 600;
                color: var(--ep-text);
            }

            .tabs {
                gap: 20px;

                .tab {
                    padding-bottom: 12px;
                    border-bottom-width: 2px;
                    font-size: 14px;
                    font-weight: 500;
                    color: var(--ep-muted);
                    transition: color 0.15s ease, border-color 0.15s ease;

                    &:hover {
                        color: var(--ep-text);
                    }

                    &.active {
                        font-weight: 600;
                        color: var(--ep-primary);
                        border-color: var(--ep-primary);
                        border-width: 2px;
                    }
                }
            }
        }
    }

    // Tabbed panels: one divider line under the tab row.
    .views-chart .ep-card-header,
    .device-analytics .ep-card-header,
    .analytics-wrapper-table .ep-card-header {
        border-bottom: 1px solid var(--ep-border);
    }

    // ---------- Overview stat cards ----------

    .ep-card-wrapper .ep-overview-cards {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 16px;

        @media screen and (max-width: 1400px) {
            grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
            gap: 12px;
        }

        .ep-card {
            --ep-accent: var(--ep-primary);
            --ep-accent-soft: var(--ep-primary-soft);

            position: relative;
            display: flex;
            flex-direction: column;
            min-width: 0;
            padding: 18px 18px 16px;
            overflow: hidden;
            background: var(--ep-surface);
            border: 1px solid var(--ep-border);
            border-radius: 12px;
            transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;

            &:hover {
                border-color: var(--ep-border-strong);
                box-shadow: 0 6px 16px -8px rgba(16, 24, 40, 0.16);
                transform: translateY(-1px);
            }

            &--embeds      { --ep-accent: #5b4e96; --ep-accent-soft: #f1effa; }
            &--views       { --ep-accent: #e8603f; --ep-accent-soft: #fff1ec; }
            &--unique      { --ep-accent: #d98a0b; --ep-accent-soft: #fff6e6; }
            &--clicks      { --ep-accent: #2f6bf0; --ep-accent-soft: #edf3ff; }
            &--impressions { --ep-accent: #6136fe; --ep-accent-soft: #f2edff; }

            .card-top {
                display: flex;
                align-items: center;
                gap: 10px;
                margin-bottom: 16px;
                min-height: 36px;
            }

            // The icons ship as a solid tile; recolour them as a soft chip.
            .ep-card-icon {
                display: inline-flex;
                flex: 0 0 auto;

                > svg {
                    width: 36px;
                    height: 36px;

                    > rect {
                        fill: var(--ep-accent-soft);
                    }

                    path {
                        stroke: var(--ep-accent);
                    }
                }
            }

            h5 {
                flex: 1 1 auto;
                min-width: 0;
                margin: 0;
                overflow: hidden;
                font-size: 13px;
                font-weight: 500;
                line-height: 1.3;
                color: var(--ep-muted);
                white-space: nowrap;
                text-overflow: ellipsis;
            }

            h2 {
                margin: 0;
                padding: 0 0 10px;
                font-size: 30px;
                font-weight: 700;
                line-height: 1.1;
                letter-spacing: -0.02em;
                color: var(--ep-text);
                font-variant-numeric: tabular-nums;
                cursor: default;

                @media screen and (max-width: 1400px) {
                    font-size: 26px;
                }
            }

            .card-sub {
                display: flex;
                flex-wrap: wrap;
                align-items: center;
                gap: 6px;
                margin: auto 0 0;
                font-size: 12px;
                line-height: 1.3;
                color: var(--ep-muted);
            }

            .ep-trend {
                display: inline-flex;
                align-items: center;
                gap: 3px;
                padding: 2px 8px 2px 6px;
                border-radius: 999px;
                font-size: 12px;
                font-weight: 600;
                font-variant-numeric: tabular-nums;

                svg {
                    flex: 0 0 auto;
                }

                &--up   { background: #e7f6ef; color: #057a55; }
                &--down { background: #fdecec; color: #c81e1e; }
                &--flat { background: #f1f2f6; color: var(--ep-muted); }
            }

            .ep-eye-icon-btn {
                flex: 0 0 auto;
                width: 30px;
                height: 30px;
                margin-left: auto;
                padding: 0;
                border: 1px solid var(--ep-border);
                border-radius: 8px;
                background: var(--ep-surface);
                color: var(--ep-muted);
                opacity: 1;

                svg {
                    width: 16px;
                    height: 16px;
                }

                &:hover {
                    background: var(--ep-primary-soft);
                    border-color: var(--ep-primary);
                    color: var(--ep-primary);
                    transform: none;
                }

                &:focus-visible {
                    outline: none;
                    box-shadow: 0 0 0 3px var(--ep-primary-ring);
                }
            }
        }
    }

    // ---------- Charts row ----------

    .ep-main-graphs {
        gap: 20px;

        @media screen and (max-width: 1400px) {
            gap: 16px;
        }
    }

    .zoom-controls button {
        border: 1px solid var(--ep-border);
        border-radius: var(--ep-radius-sm);
        background: var(--ep-surface);
        color: var(--ep-text-2);
        box-shadow: var(--ep-shadow);

        &:hover {
            border-color: var(--ep-primary);
            color: var(--ep-primary);
        }
    }

    // ---------- Tables ----------

    .ep-table-wrapper {
        gap: 20px;

        // The referrer card used an invalid `flex-basis: 0 0 400`, so the
        // two cards did not fill the row. Split it 1 : 2 instead.
        .refallal-wrapper-table {
            flex: 1 1 0;
            min-width: 0;
        }

        .analytics-wrapper-table {
            flex: 2 1 0;
            min-width: 0;
        }

        @media screen and (max-width: 1024px) {
            .refallal-wrapper-table,
            .analytics-wrapper-table {
                flex: 1 1 auto;
            }
        }

        .tab-table-content {
            border: 1px solid var(--ep-border);
            border-radius: 10px;
        }

        table {
            th {
                padding: 10px 14px;
                border-bottom: 1px solid var(--ep-border);
                background: var(--ep-surface-2);
                font-size: 12px;
                font-weight: 600;
                letter-spacing: 0.02em;
                text-transform: uppercase;
                color: var(--ep-muted);
            }

            td {
                padding: 12px 14px;
                border-bottom: 1px solid var(--ep-border);
                font-size: 13px;
                color: var(--ep-text);
            }

            tbody tr:nth-child(even) {
                background: transparent;
            }

            tbody tr:hover td {
                background: var(--ep-surface-2);
            }

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

        td.no-data-message {
            padding: 32px 16px;
            border-bottom: 0;
            text-align: center;
            font-size: 13px;
            color: var(--ep-muted);
            white-space: normal;
        }
    }

    // The referrer card heading is an h4 outside the tab row.
    .refallal-wrapper-table h4 {
        font-size: 15px;
        font-weight: 600;
        color: var(--ep-text);
    }
}

// UTM table: keep all four columns inside the card instead of scrolling
// the CTR column out of view.
.ep-analytics-dashboard .ep-table-wrapper .refallal-wrapper-table table {
    table-layout: fixed;

    th,
    td {
        padding-left: 12px;
        padding-right: 12px;
        white-space: nowrap;
    }

    th:first-child,
    td:first-child {
        width: 44%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    th:not(:first-child),
    td:not(:first-child) {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }
}

// Overview skeleton: same shape as the loaded cards (icon + label row,
// number, trend pill) so nothing jumps when the data arrives.
.ep-analytics-dashboard .ep-card-wrapper .ep-overview-cards .skeleton-card {
    &:hover {
        border-color: var(--ep-border);
        box-shadow: none;
        transform: none;
    }

    .skeleton-icon {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    .skeleton-label {
        width: 55%;
        max-width: 120px;
        height: 12px;
    }

    .skeleton-number {
        width: 72px;
        height: 30px;
        margin-bottom: 12px;
        border-radius: 6px;
    }

    .skeleton-sub {
        width: 70%;
        max-width: 150px;
        height: 20px;
        border-radius: 999px;
    }
}

// Viewer Locations / Views Over Time: the filter select (34px) is taller
// than the tabs (31px), so the active tab underline ended 3px above the
// header divider. Pin the tabs to the bottom of the row and lift the
// select so the row is as tall as the tabs, like the Device card.
.ep-analytics-dashboard .views-chart .ep-card-header .tab-header-wrapper {
    display: flex;
    align-items: flex-end;

    select {
        margin: -9px 0 6px;
    }
}

// .graph-placeholder clips its overflow (for the map), which cut off the
// top of the lifted select. Grow its box upward by the same amount
// without moving the content.
.ep-analytics-dashboard .views-chart .graph-placeholder {
    margin-top: -10px;
    padding-top: 10px;
}

// ---------- Pro teaser (free plan) ----------
// A blurred preview of the locked section, built from made-up figures,
// with the upgrade button on top, like the embed details modal teaser.

.ep-analytics-dashboard .ep-pro-section-wrapper {
    .ep-pro-teaser {
        position: relative;
        min-height: 300px;
        overflow: hidden;
        border-radius: 10px;
    }

    .ep-pro-teaser-preview {
        filter: blur(4px);
        opacity: 0.85;
        pointer-events: none;
        user-select: none;
    }

    .ep-pro-teaser-cta {
        position: absolute;
        inset: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 20px;
        text-align: center;
        background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0.35) 70%);
    }

    .ep-pro-teaser-badge {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        padding: 3px 10px;
        border-radius: 999px;
        background: var(--ep-primary-soft);
        color: var(--ep-primary);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
    }

    .ep-pro-teaser-title {
        max-width: 320px;
        margin: 0;
        font-size: 14px;
        font-weight: 600;
        line-height: 1.4;
        color: var(--ep-text);
    }

    .ep-unlock-btn {
        min-width: 0;
        padding: 11px 22px;
        font-size: 14px;
    }

    .ep-pro-teaser-more {
        padding: 2px 4px;
        border: 0;
        background: none;
        color: var(--ep-primary);
        font-size: 12.5px;
        font-weight: 500;
        text-decoration: underline;
        text-underline-offset: 2px;
        cursor: pointer;

        &:hover {
            color: var(--ep-primary-hover);
        }
    }

    // Preview pieces.
    .ep-pro-teaser-table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid var(--ep-border);

        th {
            padding: 10px 14px;
            background: var(--ep-surface-2);
            border-bottom: 1px solid var(--ep-border);
            font-size: 12px;
            font-weight: 600;
            text-align: left;
            text-transform: uppercase;
            color: var(--ep-muted);
        }

        td {
            padding: 12px 14px;
            border-bottom: 1px solid var(--ep-border);
            font-size: 13px;
            color: var(--ep-text);
        }
    }

    .ep-pro-teaser-donut {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 18px;
        padding: 24px 0;
    }

    .ep-pro-teaser-legend {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 16px;
        font-size: 13px;
        color: var(--ep-text-2);

        span {
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }

        i {
            width: 10px;
            height: 10px;
            border-radius: 50%;
        }
    }

    .ep-pro-teaser-chart {
        padding: 16px 0;
    }

    .ep-pro-teaser-bars {
        display: flex;
        flex-direction: column;
        gap: 18px;
        padding: 28px 8px;
    }

    .ep-pro-teaser-bar-row {
        display: grid;
        grid-template-columns: 130px 1fr 60px;
        align-items: center;
        gap: 14px;
        font-size: 13px;
        color: var(--ep-text);
    }

    .ep-pro-teaser-bar {
        height: 10px;
        border-radius: 5px;
        background: #eceef4;

        span {
            display: block;
            height: 100%;
            border-radius: 5px;
            background: var(--ep-primary);
        }
    }

    .ep-pro-teaser-bar-value {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }
}

// ---------- Unlock to Pro buttons ----------
// Same button as the Hub upgrade card, see Shared/styles.
@import "../../Shared/styles/unlock-premium-button";

body .ep-unlock-btn.ep-unlock-btn-primary,
body .ep-pro-actions .ep-unlock-pro-btn,
body .ep-analytics-pro-modal .ep-modal-body .ep-pro-actions .ep-unlock-pro-btn,
body .ep-analytics-dashboard .ep-pro-section-wrapper .ep-unlock-btn {
    @include ep-unlock-premium-button;
}
