/* ============================================
   EDUTOPIA ANALYTICS DASHBOARD
   Brand Style Guide Implementation
   ============================================ */

/* ===== ROOT VARIABLES ===== */
:root {
    /* Edutopia Brand Colors */
    --edutopia-orange: #FF4C00;
    --dark-orange: #FF780D;
    --tangerine: #FF9B0D;
    --sunshine: #FFBC0D;
    --midnight-blue: #1D2A44;
    --space-blue: #004861;
    --pacific-blue: #0094C7;
    
    /* Supporting Colors */
    --white: #FFFFFF;
    --gray-50: #F8FAFC;
    --gray-100: #F1F5F9;
    --gray-200: #E2E8F0;
    --gray-300: #CBD5E1;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1E293B;
    --gray-900: #0F172A;
    
    /* Shadows - Modern & Soft */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.03), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.04), 0 4px 8px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.06), 0 8px 16px rgba(0, 0, 0, 0.08);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--gray-50);
    color: var(--midnight-blue);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ===== HEADER ===== */
.header {
    background: linear-gradient(135deg, var(--midnight-blue) 0%, var(--space-blue) 100%);
    padding: 40px 48px;
    margin-bottom: 40px;
    color: var(--white);
}

.header-content h1 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 2.75rem;
    font-weight: 800;
    color: var(--white);
    margin-bottom: 8px;
    letter-spacing: -0.8px;
}

.subtitle {
    font-size: 1.15rem;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 400;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    margin-top: 32px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group label {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
}

.quarter-select {
    padding: 10px 18px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--white);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    backdrop-filter: blur(8px);
}

.quarter-select:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.quarter-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.2);
}

.quarter-select option {
    background: var(--midnight-blue);
    color: var(--white);
}

.last-updated {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

/* ===== NAVIGATION BAR ===== */
.nav-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

.nav-btn {
    padding: 10px 20px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    border-color: rgba(255, 255, 255, 0.3);
}

.nav-btn.active {
    background: var(--edutopia-orange);
    border-color: var(--edutopia-orange);
    color: var(--white);
    box-shadow: none;
}

.nav-btn:disabled,
.nav-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: transparent;
    border-color: transparent;
    transform: none;
    pointer-events: none;
    box-shadow: none;
}

/* ===== SECTIONS ===== */
.section {
    margin-bottom: 40px;
}

.section-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--gray-200);
}

.subsection-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 16px;
}

/* ===== KPI GRID ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--white);
    padding: 32px 28px;
    border: 1px solid var(--gray-200);
}

.kpi-traffic {}
.kpi-engagement {}
.kpi-conversion {}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.kpi-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.75px;
}

.kpi-value {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 2.75rem;
    font-weight: 800;
    color: var(--midnight-blue);
    line-height: 1.1;
    letter-spacing: -1.2px;
    margin-bottom: 8px;
}

.kpi-sublabel {
    font-size: 0.9rem;
    color: var(--gray-600);
    font-weight: 500;
}

/* ===== METRICS GRID ===== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.metric-card {
    background: var(--white);
    padding: 32px 28px;
    border: 1px solid var(--gray-200);
}

.metric-conversion {}
.metric-engagement {}
.metric-retention {}

.metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.metric-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--midnight-blue);
    line-height: 1.1;
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.metric-sublabel {
    font-size: 0.85rem;
    color: var(--gray-600);
}

.benchmark {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-200);
}

/* ===== VERIFICATION STATUS ===== */
.status-verified {}
.status-unverified {}

/* ===== INFO ICONS ===== */
.info-icon {
    background: none;
    border: none;
    color: var(--edutopia-orange);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    margin-left: 4px;
    transition: all 0.2s ease;
    opacity: 0.8;
    line-height: 1;
    font-weight: bold;
}

.info-icon:hover {
    opacity: 1;
    transform: scale(1.15);
    color: var(--dark-orange);
}

.info-icon:focus {
    outline: 2px solid var(--edutopia-orange);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ===== TOOLTIPS ===== */
.tooltip-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(29, 42, 68, 0.7);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tooltip-content {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-width: 650px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.tooltip-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--gray-200);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.tooltip-close:hover {
    background: var(--edutopia-orange);
    color: var(--white);
    transform: rotate(90deg);
}

.tooltip-body {
    padding: 36px;
}

.tooltip-body h3 {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--edutopia-orange);
}

.tooltip-section {
    margin-bottom: 24px;
}

.tooltip-section:last-child {
    margin-bottom: 0;
}

.tooltip-section h4 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-section p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--gray-700);
    margin: 0;
}

/* ===== TABLES ===== */
.table-container {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow);
    margin-bottom: 40px;
    overflow-x: auto;
    border: 1px solid var(--gray-200);
}

.conversion-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.95rem;
}

.conversion-table thead th {
    background: var(--gray-50);
    color: var(--gray-700);
    padding: 16px 20px;
    text-align: left;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.75px;
    border-bottom: 2px solid var(--gray-200);
}

.conversion-table thead th:first-child { border-top-left-radius: var(--radius-sm); }
.conversion-table thead th:last-child { border-top-right-radius: var(--radius-sm); }

.conversion-table tbody td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
}

.conversion-table tbody tr {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.conversion-table tbody tr:hover {
    background: var(--gray-50);
}

.conversion-table tbody tr:last-child td {
    border-bottom: none;
}

.rate {
    font-weight: 700;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.rate.high {
    color: var(--edutopia-orange);
}

.rate.medium {
    color: var(--tangerine);
}

.rate.low {
    color: var(--gray-600);
}

/* ===== CHARTS ===== */
.chart-container {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow);
    margin-bottom: 40px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--gray-200);
    will-change: transform, box-shadow;
}

.chart-container:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--gray-300);
}

.chart-container canvas {
    max-height: 400px;
}

/* ===== ANIMATIONS ===== */
/* Minimal animations removed for cleaner aesthetic */

/* Loading spinner */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px;
    flex-direction: column;
}

.report-load-error {
    gap: 16px;
    text-align: center;
}

.report-load-error p {
    margin: 0;
    max-width: 440px;
}

.report-load-retry {
    min-height: 44px;
    padding: 8px 20px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: white;
    color: var(--midnight-blue);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.report-load-retry:hover {
    background: var(--gray-100);
}

.report-load-retry:focus-visible {
    outline: 2px solid var(--pacific-blue);
    outline-offset: 3px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--edutopia-orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }
    
    .header {
        padding: 28px 24px;
    }
    
    .header-content h1 {
        font-size: 2rem;
    }
    
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .kpi-value {
        font-size: 2.25rem;
    }
    
    .metric-value {
        font-size: 1.75rem;
    }
    
    .tooltip-content {
        width: 95%;
    }
    
    .tooltip-body {
        padding: 28px 20px;
    }
    
    .conversion-table {
        font-size: 0.85rem;
    }
    
    .conversion-table th,
    .conversion-table td {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 1.75rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
    
    .kpi-value {
        font-size: 2rem;
    }
    
    .quarter-select {
        width: 100%;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .header-controls,
    .info-icon,
    .tooltip-container {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .kpi-card,
    .metric-card,
    .table-container,
    .chart-container {
        break-inside: avoid;
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid var(--gray-300);
    }
}

/* ===== UTILITY CLASSES ===== */
.text-center {
    text-align: center;
}

.text-muted {
    color: var(--gray-600);
}

.mb-0 {
    margin-bottom: 0;
}

.mt-2 {
    margin-top: 16px;
}

/* ===== CHANGELOG BUTTON ===== */
.changelog-btn {
    padding: 0.6rem;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.changelog-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--edutopia-orange);
    transform: scale(1.05);
}

/* ===== CHANGELOG MODAL ===== */
.changelog-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.changelog-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.changelog-content {
    background: var(--white);
    border-radius: 16px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.changelog-header {
    padding: 1.5rem 2rem;
    border-bottom: 2px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--midnight-blue) 0%, var(--space-blue) 100%);
    color: var(--white);
    border-radius: 16px 16px 0 0;
}

.changelog-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--white);
    font-size: 2rem;
    line-height: 1;
    padding: 0.25rem 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.changelog-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.commit-entry {
    padding: 1rem;
    border-left: none;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    border-radius: 0 8px 8px 0;
}

.commit-entry:hover {
    background: var(--gray-50);
}

.commit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.commit-type {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.commit-type.fix { background: #fee; color: #c00; }
.commit-type.feature { background: #efe; color: #060; }
.commit-type.documentation { background: #eef; color: #006; }
.commit-type.maintenance { background: #ffe; color: #880; }
.commit-type.refactor { background: #fef; color: #808; }
.commit-type.removal { background: #fee; color: #800; }
.commit-type.revert { background: #eee; color: #444; }
.commit-type.other { background: #f5f5f5; color: #666; }

.commit-date {
    color: var(--gray-600);
    font-size: 0.85rem;
    font-weight: 500;
}

.commit-message {
    color: var(--midnight-blue);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.commit-meta {
    display: flex;
    gap: 1rem;
    align-items: center;
    font-size: 0.85rem;
    color: var(--gray-600);
}

.commit-hash {
    font-family: 'Monaco', 'Courier New', monospace;
    background: var(--gray-100);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.commit-link {
    color: var(--pacific-blue);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
}

.commit-link:hover {
    color: var(--space-blue);
    text-decoration: underline;
}

.changelog-pagination {
    padding: 1rem 2rem;
    border-top: 2px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--gray-50);
    border-radius: 0 0 16px 16px;
}

.page-btn {
    padding: 8px 16px;
    border: 1px solid var(--gray-300);
    background: var(--white);
    color: var(--midnight-blue);
    border-radius: 100px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-btn:hover:not(:disabled) {
    background: var(--gray-100);
    border-color: var(--gray-400);
    transform: translateY(-1px);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: var(--gray-300);
    color: var(--gray-400);
}

#page-info {
    font-weight: 600;
    color: var(--midnight-blue);
}

/* ===== SITE-WIDE DASHBOARD STYLES ===== */

/* Map Container */
#geo-map {
    width: 100%;
    z-index: 1;
}

/* Leaflet Info Control */
.info-control {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--midnight-blue);
    border: 1px solid var(--gray-200);
}

.legend {
    line-height: 18px;
    color: #555;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.legend i {
    width: 18px;
    height: 18px;
    float: left;
    margin-right: 8px;
    opacity: 0.8;
}

/* Trend Indicators */
.kpi-trend {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-top: 8px;
    color: var(--gray-600);
    background: var(--gray-100);
}

.kpi-trend.trend-up {
    color: #059669;
    background: #D1FAE5;
}

.kpi-trend.trend-down {
    color: #DC2626;
    background: #FEE2E2;
}

/* Chart Controls */
.chart-controls {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--gray-100);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.chart-btn {
    padding: 6px 16px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-600);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chart-btn:hover:not(.active) {
    color: var(--gray-800);
}

.chart-btn.active {
    background: var(--white);
    color: var(--midnight-blue);
    box-shadow: var(--shadow-sm);
}

/* Chart Wrappers */
.chart-wrapper-donut {
    position: relative;
    height: 350px;
    width: 100%;
}

/* Device Breakdown Grid */
.device-breakdown-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 32px;
    align-items: center;
    height: 100%;
}

.device-chart-wrapper {
    width: 220px;
    height: 220px;
    position: relative;
    margin: 0 auto;
}

.device-table-container {
    width: 100%;
    overflow-x: auto;
}

/* Simple Table */
.simple-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.simple-table th {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-600);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--gray-50);
}

.simple-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-800);
    font-weight: 500;
}

.simple-table tbody tr {
    transition: background-color 0.2s;
}

.simple-table tbody tr:hover {
    background: var(--gray-50);
}

/* Grid Layouts */
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Metrics grid with custom columns */
.metrics-grid[style*="grid-template-columns"] {
    margin-bottom: 0;
}

.metrics-grid .chart-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 420px; /* Standardized height */
}

.metrics-grid .chart-container canvas {
    flex: 1;
    width: 100% !important;
}

/* Commit author styling */
.commit-author {
    color: var(--gray-600);
    font-style: italic;
}

@media (max-width: 1024px) {
    .grid-2-col {
        grid-template-columns: 1fr;
    }
    
    .device-breakdown-grid {
        grid-template-columns: 1fr;
        gap: 24px;
        justify-items: center;
    }
    
    .metrics-grid[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    .chart-container {
        min-height: auto;
    }
}

/* ===== ARTICLE DETAILS MODAL ===== */
.article-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(29, 42, 68, 0.75);
    backdrop-filter: blur(4px);
}

.article-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.article-modal-content {
    background: var(--white);
    border-radius: 16px;
    width: 95%;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
    animation: articleModalFadeIn 0.3s ease;
    overflow: hidden;
}

@keyframes articleModalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-30px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.article-modal-header {
    padding: 24px 32px;
    background: linear-gradient(135deg, var(--midnight-blue) 0%, var(--space-blue) 100%);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.article-modal-title-wrap {
    flex: 1;
    min-width: 0;
}

.article-modal-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 8px 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.article-modal-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    flex-wrap: wrap;
}

.meta-sep {
    color: rgba(255, 255, 255, 0.4);
}

.article-external-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    text-decoration: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.article-external-link:hover {
    background: rgba(255, 255, 255, 0.25);
}

.article-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px 32px;
}

/* Loading State */
.article-modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--gray-600);
}

.spinner-small {
    width: 36px;
    height: 36px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--edutopia-orange);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

/* No Data State */
.article-modal-nodata {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-600);
}

.nodata-hint {
    font-size: 0.9rem;
    color: var(--gray-500);
    margin-top: 8px;
}

/* KPI Row */
.article-kpi-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.article-kpi {
    background: var(--gray-50);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    border-left: none;
}

.article-kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--midnight-blue);
    line-height: 1.2;
    margin-bottom: 4px;
}

.article-kpi-label {
    font-size: 0.85rem;
    color: var(--gray-600);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Charts Grid */
.article-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 28px;
}

.article-chart-card {
    background: var(--gray-50);
    border-radius: 10px;
    padding: 20px;
}

.article-chart-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--gray-200);
}

.article-chart-wrap {
    height: 200px;
    position: relative;
}

.article-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    justify-content: center;
}

.article-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--gray-700);
}

.article-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* Geography Table */
.article-geo-section {
    background: var(--gray-50);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 28px;
}

.article-geo-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--gray-200);
}

.article-geo-table {
    width: 100%;
    border-collapse: collapse;
}

.article-geo-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    border-bottom: 2px solid var(--gray-200);
}

.article-geo-table td {
    padding: 10px 12px;
    font-size: 0.9rem;
    color: var(--midnight-blue);
    border-bottom: 1px solid var(--gray-200);
}

.article-geo-table tr:last-child td {
    border-bottom: none;
}

.geo-bar-container {
    width: 100%;
    background: var(--gray-200);
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
}

.geo-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--pacific-blue), var(--space-blue));
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Trend Chart */
.article-trend-section {
    background: var(--gray-50);
    border-radius: 10px;
    padding: 20px;
}

.article-trend-section h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--midnight-blue);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--gray-200);
}

.article-trend-wrap {
    height: 220px;
    position: relative;
}

/* Clickable Article Row */
.articles-table tbody tr {
    cursor: pointer;
    transition: all 0.2s ease;
}

.articles-table tbody tr:hover {
    background: rgba(0, 148, 199, 0.08);
}

.articles-table tbody tr .article-title {
    position: relative;
}

.article-detail-indicator {
    display: inline-block;
    margin-left: 8px;
    color: var(--pacific-blue);
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 0.85rem;
}

.articles-table tbody tr:hover .article-detail-indicator {
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .article-modal-content {
        width: 98%;
        max-height: 95vh;
        border-radius: 12px;
    }
    
    .article-modal-header {
        padding: 20px;
    }
    
    .article-modal-header h2 {
        font-size: 1.25rem;
    }
    
    .article-modal-body {
        padding: 20px;
    }
    
    .article-kpi-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .article-kpi-value {
        font-size: 1.75rem;
    }
    
    .article-charts-grid {
        grid-template-columns: 1fr;
    }
    
    .article-modal-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .meta-sep {
        display: none;
    }
}

/* ===== LOGIN OVERLAY ===== */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--midnight-blue);
    background-image: linear-gradient(135deg, var(--midnight-blue) 0%, #0d1626 100%);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.login-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.login-box {
    background: var(--white);
    padding: 48px;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 440px;
    text-align: center;
    border-top: none;
    animation: slideUp 0.4s ease-out;
}

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

.login-header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--midnight-blue);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.login-header p {
    color: var(--gray-600);
    margin-bottom: 32px;
    font-size: 1rem;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-300);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    outline: none;
}

.input-group input:focus {
    border-color: var(--pacific-blue);
    box-shadow: 0 0 0 3px rgba(0, 148, 199, 0.1);
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: var(--edutopia-orange);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 20px;
}

.login-btn:hover {
    background: var(--dark-orange);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(255, 76, 0, 0.2);
}

.login-btn:active {
    transform: translateY(0);
}

.login-error {
    color: #DC2626;
    background: #FEF2F2;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 10px;
    border: 1px solid #FECACA;
}

.login-footer {
    border-top: 1px solid var(--gray-200);
    padding-top: 20px;
    margin-top: 10px;
}

.login-footer p {
    font-size: 0.85rem;
    color: var(--gray-500);
}

/* Shake animation for error */
@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
    border-color: #DC2626 !important;
}

/* Responsive adjustments for login */
@media (max-width: 480px) {
    .login-box {
        padding: 32px 24px;
        width: 90%;
    }
    
    .login-header h1 {
        font-size: 1.5rem;
    }
}
/* Send tables use one compact title; full variants remain keyboard accessible. */
.email-subject { width: 300px; max-width: 100%; min-width: 220px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.email-subject .email-subject-title { display: block; font-size: inherit; font-weight: 600; line-height: 1.45; }
.email-subject summary .email-subject-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.email-subject small { display: block; margin-top: 5px; color: #64748b; font-size: 12px; font-weight: 400; line-height: 1.5; }
.email-subject summary { cursor: pointer; list-style: none; border-radius: 3px; }
.email-subject summary::-webkit-details-marker { display: none; }
.email-subject summary:focus-visible { outline: 2px solid #087f8c; outline-offset: 4px; }
.email-subject-toggle { display: inline-block; margin-top: 5px; color: #087f8c; font-size: 12px; font-weight: 500; }
.email-subject-toggle::before { content: '+ '; }
.email-subject[open] .email-subject-toggle::before { content: '- '; }
.email-subject-detail { margin-top: 10px; padding-top: 10px; border-top: 1px solid #dce2e6; }
.email-subject-detail ol { margin: 0; padding-left: 18px; }
.email-subject-detail li { margin-bottom: 8px; line-height: 1.5; }
/* Community summary keeps the three quarterly measures together. */
.community-kpi-row, .community-annual-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.community-kpi-row .kpi-trend { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; background: transparent; padding: 0; border-radius: 0; white-space: normal; }
.community-annual-grid .chart-container { min-width: 0; height: 300px; position: relative; padding-bottom: 56px; }
.community-annual-grid canvas { max-height: 230px; }
.community-section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.community-note { font-size: 14px; color: var(--gray-600); margin: 16px 0 0; }
.kpi-trend .is-good { color: #13804d; }
.kpi-trend .is-bad { color: #bb3434; }
@media (max-width: 800px) { .community-kpi-row, .community-annual-grid { grid-template-columns: 1fr; } }

/* Keep the whole header together, including tables with multiple header rows. */
@media screen {
    :where(table > thead) {
        position: sticky;
        top: 0;
        z-index: 2;
        background-color: var(--gray-50, white);
    }

    :where(div:has(> table:only-child)) {
        overflow: auto;
        max-height: 70vh;
    }
}
