/* ==========================================================================
   SACOM Analytics Dashboard
   Camino A: clonado fiel del referente visual (WattVision dashboard)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg-app:         #F5F7FA;
    --bg-sidebar:     #FFFFFF;
    --bg-card:        #FFFFFF;
    --bg-hover:       #F5F7FA;

    --brand:          #2D5BA7;
    --brand-hover:    #234A8A;
    --brand-soft:     #EEF3FC;
    --brand-softer:   #F7FAFE;

    --positive:       #16A34A;
    --positive-soft:  #DCFCE7;
    --negative:       #DC2626;
    --negative-soft:  #FEE2E2;
    --neutral:        #64748B;
    --neutral-soft:   #F1F5F9;

    --text-primary:   #0F172A;
    --text-secondary: #475569;
    --text-tertiary:  #94A3B8;

    --border:         #E2E8F0;
    --border-soft:    #EEF2F7;

    --font-body: 'Inter', system-ui, -apple-system, sans-serif;

    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;

    --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04);

    --sidebar-w: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    font-family: var(--font-body);
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* LAYOUT */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 12px 24px 12px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-soft);
}

.sidebar__logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar__name {
    font-size: 20px;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: -0.02em;
    line-height: 1;
}

.sidebar__tagline {
    font-size: 9.5px;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 4px;
}

.sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

.nav-item.active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; stroke-width: 2; }

.sidebar__footer { margin-top: auto; padding-top: 16px; }

.sidebar__user {
    background: var(--brand-softer);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar__user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar__user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sidebar__user-role { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

.sidebar__logout {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-tertiary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.sidebar__logout:hover {
    background: var(--negative-soft);
    color: var(--negative);
}

.sidebar__logout svg {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px;
    min-height: 16px;
    max-width: 16px;
    max-height: 16px;
    flex-shrink: 0;
}

/* MAIN */
.main { padding: 32px 40px; max-width: 1500px; }

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    gap: 24px;
    flex-wrap: wrap;
}

.header-row__title h1 {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    line-height: 1.1;
}

.header-row__title p {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 14px;
}

.header-row__actions { display: flex; gap: 10px; align-items: center; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}

.btn svg { width: 16px; height: 16px; stroke-width: 2; }

.btn--secondary {
    background: var(--neutral-soft);
    color: var(--text-primary);
}

.btn--secondary:hover { background: #E8EDF3; }

.btn--primary { background: var(--brand); color: white; }
.btn--primary:hover { background: var(--brand-hover); }

.range-selector { position: relative; }

.range-selector__dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    min-width: 100%;
    overflow: hidden;
    z-index: 10;
    display: none;
}

.range-selector.open .range-selector__dropdown { display: block; }

.range-selector__option {
    padding: 10px 16px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
}

.range-selector__option:hover { background: var(--bg-hover); color: var(--text-primary); }

.range-selector__option.active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}

/* KPI GRID */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-soft);
}

.kpi-card__top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 22px;
}

.kpi-card__icon {
    width: 42px;
    height: 42px;
    background: var(--brand-soft);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--brand);
}

.kpi-card__icon svg { width: 20px; height: 20px; stroke-width: 2; }

.kpi-card__delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: var(--radius-pill);
}

.kpi-card__delta.positive { background: var(--positive-soft); color: var(--positive); }
.kpi-card__delta.negative { background: var(--negative-soft); color: var(--negative); }
.kpi-card__delta.neutral { background: var(--neutral-soft); color: var(--neutral); }

.kpi-card__label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }

.kpi-card__value {
    font-size: 30px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.kpi-card__value .unit {
    font-size: 14px;
    color: var(--text-tertiary);
    font-weight: 500;
    margin-left: 4px;
}

/* MAIN GRID */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 16px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-soft);
}

.card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}

.card__title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.card__subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    margin-top: 4px;
}

.chart-legend {
    display: flex;
    gap: 18px;
    font-size: 13px;
    color: var(--text-secondary);
}

.chart-legend__item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s;
}

.chart-legend__item.inactive { opacity: 0.4; }

.chart-legend__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--brand);
}

.chart-legend__dot--soft { background: #C7D6EE; }

.chart-wrapper { position: relative; height: 340px; }

/* SIDE PANEL barras */
.side-panel__list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.side-panel__item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
    gap: 12px;
}

.side-panel__item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.side-panel__item-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--brand);
    white-space: nowrap;
}

.side-panel__bar {
    height: 6px;
    background: var(--neutral-soft);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.side-panel__bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand) 0%, #5C8BD6 100%);
    border-radius: var(--radius-pill);
    transition: width 0.6s ease;
}

/* TABLA */
.data-table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
    text-align: left;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    padding: 0 16px 16px 0;
    border-bottom: 1px solid var(--border);
}

.data-table th.numeric { text-align: right; }
.data-table th:last-child { padding-right: 0; }

.data-table td {
    padding: 16px 16px 16px 0;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13.5px;
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table td:last-child { padding-right: 0; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr { transition: background 0.15s; }
.data-table tbody tr:hover { background: var(--bg-hover); }

.data-table td.numeric {
    text-align: right;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.data-table .rank {
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 600;
    width: 40px;
}

.data-table .primary-text {
    font-weight: 500;
    max-width: 480px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table .primary-text a {
    color: inherit;
    text-decoration: none;
    transition: color 0.15s;
}

.data-table .primary-text a:hover { color: var(--brand); }

/* STATES */
.loading-skeleton {
    background: linear-gradient(90deg, #EEF2F7 0%, #F8FAFD 50%, #EEF2F7 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    color: transparent !important;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.error-banner {
    background: var(--negative-soft);
    border-left: 4px solid var(--negative);
    color: var(--negative);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
    font-size: 13.5px;
}

.error-banner strong {
    display: block;
    margin-bottom: 4px;
    font-weight: 700;
}

.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}

.footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 16px 4px 0;
    color: var(--text-tertiary);
    font-size: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

/* ==========================================================================
   COMPONENTES COMUNES NUEVAS VISTAS
   ========================================================================== */

.view { animation: fadeIn 0.25s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.muted-text {
    color: var(--text-secondary);
    font-size: 13.5px;
    margin: -8px 0 20px;
    line-height: 1.55;
}

/* Badge en sidebar */
.nav-badge {
    margin-left: auto;
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    font-size: 9.5px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ==========================================================================
   OPORTUNIDADES
   ========================================================================== */

.opportunities-hero {
    display: flex;
    gap: 20px;
    align-items: center;
    background: linear-gradient(135deg, #2D5BA7 0%, #5C8BD6 100%);
    color: white;
    padding: 28px 32px;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(45, 91, 167, 0.18);
    position: relative;
    overflow: hidden;
}

.opportunities-hero::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

.opportunities-hero::after {
    content: '';
    position: absolute;
    bottom: -60px;
    right: 30px;
    width: 140px;
    height: 140px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
    pointer-events: none;
}

.opportunities-hero__icon {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    backdrop-filter: blur(4px);
    z-index: 1;
}

.opportunities-hero__icon svg { width: 32px; height: 32px; }

.opportunities-hero__content {
    flex: 1;
    z-index: 1;
    position: relative;
}

.opportunities-hero__title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 8px;
}

.opportunities-hero__title span {
    color: #FFE08A;
    font-weight: 800;
}

.opportunities-hero__sub {
    font-size: 13.5px;
    opacity: 0.92;
    line-height: 1.55;
    max-width: 720px;
}

.opportunities-hero__sub span {
    font-weight: 700;
    color: #FFE08A;
}

/* Lista de tarjetas */
.opportunities-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.opportunity-card {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 18px;
    align-items: center;
    background: var(--bg-app);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 18px 22px;
    transition: all 0.2s ease;
}

.opportunity-card:hover {
    border-color: var(--brand);
    transform: translateX(2px);
    box-shadow: 0 4px 14px rgba(45, 91, 167, 0.08);
}

.opportunity-card__rank {
    width: 32px;
    height: 32px;
    background: var(--brand-soft);
    color: var(--brand);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.opportunity-card__main {
    min-width: 0;
}

.opportunity-card__title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.opportunity-card__query {
    font-size: 15.5px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.3;
}

.difficulty-pill {
    font-size: 10.5px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: var(--radius-pill);
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
}

.difficulty-pill.difficulty--easy {
    background: #DCFCE7;
    color: #15803D;
}

.difficulty-pill.difficulty--medium {
    background: #FEF3C7;
    color: #B45309;
}

.difficulty-pill.difficulty--hard {
    background: #FEE2E2;
    color: #B91C1C;
}

.opportunity-card__page {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 14px;
    overflow: hidden;
}

.opportunity-card__page svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.opportunity-card__page a {
    color: var(--text-secondary);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.15s;
}

.opportunity-card__page a:hover {
    color: var(--brand);
}

.opportunity-card__stats {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.opp-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 60px;
}

.opp-stat__label {
    font-size: 10.5px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    white-space: nowrap;
}

.opp-stat__value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.opp-stat--highlight .opp-stat__value {
    color: var(--brand);
}

.opp-stat-arrow {
    color: var(--text-tertiary);
    font-size: 16px;
    margin: 0 -4px;
}

.opp-stat__divider {
    width: 1px;
    height: 32px;
    background: var(--border);
    margin: 0 4px;
}

.opportunity-card__gain {
    text-align: right;
    padding-left: 18px;
    border-left: 1px solid var(--border);
    flex-shrink: 0;
    min-width: 130px;
}

.gain-label {
    font-size: 10.5px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 4px;
}

.gain-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--positive);
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.gain-unit {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

@media (max-width: 900px) {
    .opportunity-card {
        grid-template-columns: 32px 1fr;
        gap: 14px;
    }
    .opportunity-card__gain {
        grid-column: 1 / -1;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-top: 14px;
        margin-top: 4px;
        text-align: left;
        display: flex;
        align-items: baseline;
        gap: 8px;
    }
    .gain-value { font-size: 22px; }
    .opportunities-hero { padding: 22px; }
    .opportunities-hero__title { font-size: 19px; }
}

/* ==========================================================================
   LOCALIDADES
   ========================================================================== */

.locations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.location-card {
    background: var(--bg-app);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    padding: 18px;
    transition: all 0.2s ease;
}

.location-card:hover {
    border-color: var(--brand);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(45, 91, 167, 0.08);
}

.location-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.location-card__name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.location-card__name svg {
    width: 16px;
    height: 16px;
    color: var(--brand);
    stroke-width: 2;
    flex-shrink: 0;
}

.location-card__clicks {
    font-size: 22px;
    font-weight: 700;
    color: var(--brand);
    line-height: 1;
    letter-spacing: -0.02em;
}

.location-card__clicks .label {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.location-card__stats {
    display: flex;
    gap: 16px;
    font-size: 11.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-soft);
}

.location-card__stats strong {
    color: var(--text-primary);
    font-weight: 600;
}

.location-card__queries {
    list-style: none;
    padding: 0;
    margin: 0;
}

.location-card__queries li {
    font-size: 12.5px;
    color: var(--text-secondary);
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.location-card__queries li .q {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.location-card__queries li .c {
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* ==========================================================================
   DISPOSITIVOS
   ========================================================================== */

.devices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 1100px) { .devices-grid { grid-template-columns: 1fr; } }

.device-donut-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 24px;
    padding: 8px 0;
}

.donut-container {
    position: relative;
    width: 220px;
    height: 220px;
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-center__value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.donut-center__label {
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    margin-top: 4px;
}

.device-legend {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.device-legend__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-app);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.device-legend__left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.device-legend__dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

.device-legend__name {
    font-weight: 500;
    color: var(--text-primary);
}

.device-legend__right {
    text-align: right;
}

.device-legend__pct {
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.device-legend__count {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* ==========================================================================
   HEATMAP
   ========================================================================== */

.heatmap-wrapper {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0 4px;
    margin-top: 8px;
}

.heatmap-rows {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    padding-top: 34px; /* deja espacio para labels superiores de las columnas */
}

.heatmap-row-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    height: 52px;
    display: flex;
    align-items: center;
    width: 44px;
}

.heatmap-columns {
    display: flex;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.heatmap-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 52px;
}

.heatmap-column__label {
    font-size: 11.5px;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: center;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.heatmap-cell {
    width: 100%;
    height: 52px;
    border-radius: 7px;
    background: var(--border-soft);
    cursor: default;
    position: relative;
    transition: transform 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.heatmap-cell--null {
    background: transparent;
    border: 1px dashed var(--border);
}

.heatmap-cell--has-value {
    color: var(--text-primary);
}

.heatmap-cell--dark {
    color: white;
}

.heatmap-cell:hover {
    transform: scale(1.06);
    z-index: 2;
    box-shadow: 0 4px 12px rgba(45, 91, 167, 0.18);
}

.heatmap-cell__tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    z-index: 5;
}

.heatmap-cell__tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text-primary);
}

.heatmap-cell:hover .heatmap-cell__tooltip { opacity: 1; }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.heatmap-legend__scale {
    display: flex;
    gap: 3px;
}

.heatmap-legend__cell {
    width: 22px;
    height: 22px;
    border-radius: 4px;
}

/* Resumen por día de la semana */
.dow-summary {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
}

.dow-summary__item {
    background: var(--bg-app);
    border-radius: var(--radius-md);
    padding: 18px 12px;
    text-align: center;
}

.dow-summary__name {
    font-size: 11.5px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 10px;
}

.dow-summary__value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.dow-summary__bar {
    height: 5px;
    background: var(--neutral-soft);
    border-radius: var(--radius-pill);
    margin-top: 14px;
    overflow: hidden;
}

.dow-summary__bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand) 0%, #5C8BD6 100%);
    border-radius: var(--radius-pill);
}

@media (max-width: 900px) {
    .dow-summary { grid-template-columns: repeat(4, 1fr); }
    .heatmap-cell { height: 40px; }
    .heatmap-row-label { height: 40px; }
}

@media (max-width: 640px) {
    .dow-summary { grid-template-columns: repeat(2, 1fr); }
    .heatmap-cell { height: 32px; }
    .heatmap-row-label { height: 32px; font-size: 11px; width: 36px; }
}

/* RESPONSIVE */
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .main { padding: 24px 20px; }
    .header-row__title h1 { font-size: 24px; }
    .kpi-grid { grid-template-columns: 1fr; }
}
