/* ============================================================
   Analytics Dashboard — Modern Glass (Light Theme)
   ============================================================ */

.analytics-main {
    padding: 2rem 0;
    min-height: calc(100vh - 80px);
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.analytics-header h2 {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.analytics-header p {
    color: var(--gray-600);
    margin: 0;
    font-size: 0.9rem;
}

.period-selector select {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-primary);
    border: 1.5px solid var(--gray-300);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    outline: none;
}

.period-selector select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Stat Cards */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    transition: all var(--duration-normal) var(--ease-out);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-card:nth-child(2)::before {
    background: linear-gradient(135deg, #10B981, #34D399);
}

.stat-card:nth-child(3)::before {
    background: linear-gradient(135deg, #F59E0B, #FBBF24);
}

.stat-card:nth-child(4)::before {
    background: linear-gradient(135deg, #3B82F6, #60A5FA);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1;
    margin-bottom: 6px;
    letter-spacing: -0.03em;
}

.stat-card:nth-child(1) .stat-value { color: var(--primary-dark); }
.stat-card:nth-child(2) .stat-value { color: #059669; }
.stat-card:nth-child(3) .stat-value { color: #D97706; }
.stat-card:nth-child(4) .stat-value { color: #2563EB; }

.stat-label {
    font-size: 0.8rem;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* Chart */
.chart-section {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.chart-section h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.chart-container {
    min-height: 220px;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 220px;
    padding-bottom: 36px;
    position: relative;
    overflow-x: auto;
}

.chart-bar-col {
    flex: 1;
    min-width: 32px;
    max-width: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    cursor: pointer;
}

.chart-bar {
    width: 100%;
    max-width: 40px;
    background: var(--primary-gradient);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    transition: all 0.3s var(--ease-out);
    min-height: 2px;
    position: relative;
}

.chart-bar-col:hover .chart-bar {
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
    transform: scaleX(1.08);
}

.chart-bar-value {
    font-size: 0.75rem;
    color: var(--gray-700);
    margin-bottom: 4px;
    font-weight: 700;
}

.chart-bar-label {
    font-size: 0.7rem;
    color: var(--gray-600);
    margin-top: 6px;
    white-space: nowrap;
    font-weight: 500;
}

/* Top Pages */
.top-pages-section {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.top-pages-section h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.top-page-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
    transition: background var(--duration-fast);
}

.top-page-row:last-child {
    border-bottom: none;
}

.top-page-row:hover {
    background: rgba(99, 102, 241, 0.04);
    border-radius: var(--radius-sm);
    padding-left: 8px;
    padding-right: 8px;
    margin: 0 -8px;
}

.top-page-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    color: var(--gray-700);
    font-weight: 700;
    flex-shrink: 0;
}

.top-page-type {
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.top-page-type.menu {
    background: var(--success-light);
    color: #065F46;
}

.top-page-type.board {
    background: var(--info-light);
    color: #1E40AF;
}

.top-page-id {
    flex: 1;
    color: var(--gray-800);
    font-size: 0.9rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-weight: 500;
}

.top-page-views {
    color: var(--gray-700);
    font-size: 0.88rem;
    white-space: nowrap;
    font-weight: 700;
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--gray-600);
}

/* ============================================================
   Tabs
   ============================================================ */
.analytics-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-md);
    padding: 4px;
    width: fit-content;
    border: 1px solid var(--gray-200);
}

.analytics-tab {
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--gray-600);
    transition: all 0.2s;
    font-family: inherit;
}

.analytics-tab:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.06);
}

.analytics-tab.active {
    background: var(--primary-color);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

/* ============================================================
   Interactions Grid (two-column layouts)
   ============================================================ */
.interactions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Interaction list name column */
.interaction-name-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.interaction-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.interaction-subtitle {
    font-size: 0.75rem;
    color: var(--gray-500);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   Taps by Type bars
   ============================================================ */
.taps-by-type {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.type-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.type-label {
    width: 100px;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.type-bar-track {
    flex: 1;
    height: 10px;
    background: var(--gray-200);
    border-radius: 5px;
    overflow: hidden;
}

.type-bar-fill {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease-out;
}

.type-count {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--gray-800);
    width: 60px;
    text-align: right;
}

.type-pct {
    font-size: 0.8rem;
    color: var(--gray-500);
    width: 36px;
    text-align: right;
}

/* ============================================================
   Hourly Heatmap
   ============================================================ */
.hourly-heatmap {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 3px;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    min-height: 48px;
    transition: transform 0.15s;
}

.heatmap-cell:hover {
    transform: scale(1.12);
    z-index: 1;
}

.heatmap-count {
    font-size: 0.78rem;
    line-height: 1;
}

.heatmap-label {
    font-size: 0.6rem;
    opacity: 0.8;
    margin-top: 2px;
}

/* ============================================================
   Device Breakdown
   ============================================================ */
.device-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.device-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.device-name {
    width: 70px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-800);
    flex-shrink: 0;
}

.device-bar-track {
    flex: 1;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.device-bar-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 4px;
    transition: width 0.5s ease-out;
}

.device-pct {
    font-weight: 700;
    font-size: 0.85rem;
    width: 40px;
    text-align: right;
    color: var(--gray-800);
}

.device-count {
    color: var(--gray-600);
    font-size: 0.8rem;
    width: 60px;
    text-align: right;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .analytics-header {
        flex-direction: column;
        gap: 12px;
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .chart-bar-col {
        min-width: 22px;
    }

    .chart-section,
    .top-pages-section {
        padding: 1.25rem;
    }

    .interactions-grid {
        grid-template-columns: 1fr;
    }

    .hourly-heatmap {
        grid-template-columns: repeat(12, 1fr);
    }

    .heatmap-cell {
        min-height: 40px;
    }

    .heatmap-count {
        font-size: 0.65rem;
    }

    .heatmap-label {
        font-size: 0.5rem;
    }

    .type-label {
        width: 80px;
        font-size: 0.78rem;
    }

    .analytics-tabs {
        width: 100%;
    }

    .analytics-tab {
        flex: 1;
        text-align: center;
        font-size: 0.82rem;
        padding: 0.5rem 0.75rem;
    }
}
