/* Ujjina Player Studio - Analytics Dashboard */

/* Toggle Editor/Analytics */
.view-toggle {
    display: inline-flex;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    overflow: hidden;
    margin-left: 10px;
}

.view-toggle-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.view-toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

.view-toggle-btn:not(.active):hover {
    color: var(--text);
    background: var(--surface-hover);
}

/* Analytics panel */
.analytics-panel {
    background: var(--bg);
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

.analytics-panel .analytics-inner {
    max-width: 1240px;
    margin: 0 auto;
    width: 100%;
}

/* Header row: title + time range */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.analytics-header h2 {
    font-size: 11px;
    font-weight: 800;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.time-range-group {
    display: flex;
    gap: 4px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    padding: 3px;
}

.time-range-btn {
    padding: 6px 14px;
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.time-range-btn.active {
    background: var(--accent);
    color: #fff;
}

.time-range-btn:not(.active):hover {
    color: var(--text);
    background: var(--surface-hover);
}

.stats-retention-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: -4px 0 18px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 193, 69, 0.38);
    border-radius: 10px;
    background: rgba(255, 193, 69, 0.10);
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.5;
}

.stats-retention-notice svg {
    flex: 0 0 auto;
    margin-top: 1px;
    color: #ffc145;
}

.stats-retention-notice strong {
    color: var(--text);
}

.stats-retention-notice-compact {
    margin: 0 0 18px;
    padding: 10px 12px;
    font-size: 11px;
}

/* Stat cards row */
.analytics-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.analytics-stats-6 {
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.25s, border-color 0.25s;
}

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

.stat-card:hover {
    box-shadow: var(--shadow), var(--shadow-glow);
    border-color: var(--border-accent);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-card-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.stat-card-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
}

/* Realtime pulse animation */
.stat-card-value .live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    animation: pulse-live 1.5s ease infinite;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* Chart grid */
.analytics-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 22px;
    position: relative;
    overflow: hidden;
}

.chart-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-border-top);
    opacity: 0.4;
}

.chart-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 16px;
}

.chart-card canvas {
    width: 100% !important;
    max-height: 220px;
}

.chart-card.wide {
    grid-column: 1 / -1;
}

/* Sessions table */
.sessions-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 22px;
    overflow: hidden;
    position: relative;
}

.sessions-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-border-top);
    opacity: 0.4;
}

.sessions-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 16px;
}

.sessions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.sessions-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
    background: var(--input-bg);
    position: sticky;
    top: 0;
    z-index: 1;
}

.sessions-table td {
    padding: 9px 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    vertical-align: middle;
}

.sessions-table tbody tr:nth-child(even) td {
    background: var(--surface-hover);
}

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

.sessions-table tr:hover td {
    color: var(--text);
    background: var(--surface-hover);
}

/* Empty state */
.analytics-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.analytics-empty svg {
    opacity: 0.3;
}

.analytics-empty p {
    font-size: 14px;
    font-weight: 500;
}

/* Detail table below charts */
.chart-detail {
    margin-top: 14px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    max-height: 220px;
    overflow-y: auto;
}

.chart-detail-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 4px;
    border-radius: 6px;
    transition: background 0.15s;
}

.chart-detail-row:hover {
    background: var(--surface-hover);
}

.chart-detail-row .detail-rank {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.chart-detail-row .detail-flag {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
}

.chart-detail-row .detail-flag img {
    vertical-align: middle;
    border-radius: 1px;
}

.chart-detail-row .detail-label {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-detail-row .detail-value {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    min-width: 50px;
    text-align: right;
}

.chart-detail-row .detail-bar {
    width: 60px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-left: 8px;
    flex-shrink: 0;
    overflow: hidden;
}

.chart-detail-row .detail-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}

/* Suspicious legend */
.suspicious-legend {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.suspicious-legend svg {
    flex-shrink: 0;
    margin-top: 1px;
}

/* Country flag inline */
.conn-country {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Suspicious row highlight */
.sessions-table tr.suspicious td {
    color: #ff6b81;
    font-weight: 600;
}

/* Connections card margin */
.sessions-card {
    margin-bottom: 24px;
}

/* Primary KPI card — visual hierarchy */
.analytics-stats .stat-card:first-child .stat-card-value {
    font-size: 36px;
    color: var(--accent);
}

.analytics-stats .stat-card:first-child .stat-card-label {
    color: var(--accent);
    opacity: 0.8;
}

.analytics-stats .stat-card:first-child {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-glow);
}

/* Live button active state — pulse dot */
.time-range-btn[data-range="live"].active {
    background: #ef4444;
    color: #fff;
}

.time-range-btn[data-range="live"].active::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: middle;
    animation: pulse-live 1.5s ease infinite;
}

/* Export buttons */
.btn-export-pdf,
.btn-export-csv {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s, box-shadow 0.2s;
    border: none;
    font-family: inherit;
}

.btn-export-pdf {
    background: var(--accent);
    color: #fff;
}

.btn-export-pdf:hover {
    opacity: 0.88;
    box-shadow: 0 0 12px var(--accent-glow, rgba(139,111,255,0.3));
}

.btn-export-csv {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-export-csv:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Monthly report button */
.btn-monthly-report {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 8px;
    background: linear-gradient(135deg, #8b6fff, #5ca0ff);
    color: #fff;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: opacity 0.2s;
}

.btn-monthly-report:hover {
    opacity: 0.88;
}

/* GDPR notice */
.sessions-gdpr-note {
    margin-top: 12px;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    padding: 10px 4px 0;
    line-height: 1.5;
    border-top: 1px solid var(--border);
}

.analytics-geo-attribution {
    margin-top: 8px;
    font-size: 10px;
    line-height: 1.4;
    text-align: right;
}

.analytics-geo-attribution a {
    color: var(--text-muted);
    text-decoration: none;
}

.analytics-geo-attribution a:hover,
.analytics-geo-attribution a:focus-visible {
    color: var(--accent);
    text-decoration: underline;
}

/* Print/PDF — hide interactive elements */
@media print {
    .btn-export-pdf,
    .btn-export-csv,
    .btn-monthly-report,
    .time-range-group,
    #custom-range-picker { display: none !important; }
}

/* Responsive */
@media (max-width: 768px) {
    .analytics-panel {
        padding: 16px;
    }

    .analytics-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .analytics-header > div {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .stats-retention-notice {
        margin-top: 0;
    }

    .time-range-group {
        flex-wrap: wrap;
    }

    .btn-export-pdf,
    .btn-export-csv,
    .btn-monthly-report {
        flex: 1;
        justify-content: center;
        min-width: 120px;
    }

    .stat-card-value {
        font-size: 22px;
    }

    .analytics-stats .stat-card:first-child .stat-card-value {
        font-size: 28px;
    }

    .sessions-card {
        padding: 16px;
        overflow-x: auto;
    }

    .sessions-table {
        font-size: 11px;
        min-width: 500px;
    }
}

@media (max-width: 480px) {
    .analytics-panel {
        padding: 10px;
    }

    .analytics-header > div {
        flex-direction: column;
        align-items: stretch;
    }

    .time-range-group {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .time-range-btn {
        padding: 5px 10px;
        font-size: 10px;
        text-align: center;
    }

    .stat-card {
        padding: 14px;
        border-radius: 10px;
    }

    .stat-card-value {
        font-size: 20px;
    }

    .stat-card-label {
        font-size: 9px;
    }

    .stat-card-sub {
        font-size: 10px;
    }

    .chart-card {
        padding: 14px;
        border-radius: 10px;
    }

    .view-toggle {
        margin-left: 0;
    }

    .sessions-card {
        padding: 12px;
        border-radius: 10px;
    }
}
