/**
 * Live Analytics Report Styles
 *
 * @package SlimStat
 * @since 5.4.0
 */

/* ═══════════════════════════════════════════════════════════════
   Live Analytics Container
   ═══════════════════════════════════════════════════════════════ */

.live-analytics-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
    width: 100%;
    height: 321px;
    background: #ffffff;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   Main Grid Layout
   ═══════════════════════════════════════════════════════════════ */

.live-analytics-grid {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 0px;
    gap: 24px;
    width: 100%;
    height: 289px;
    flex: none;
    order: 0;
    align-self: stretch;
    flex-grow: 1;
}

/* ═══════════════════════════════════════════════════════════════
   Metrics Panel (Left)
   ═══════════════════════════════════════════════════════════════ */

.live-analytics-metrics {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    padding: 0px;
    width: 249px;
    min-width: 249px;
    height: 289px;
    border-right: 1px dashed #ebebeb;
    border-radius: 0px;
    flex: none;
    order: 0;
    align-self: stretch;
    flex-grow: 0;
    flex-shrink: 0;
    position: relative;
}

.live-metric-item {
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 20px 0px 20px 12px;
    gap: 12px;
    width: 249px;
    height: 99px;
    border-bottom: 1px dashed #ebebeb;
    flex: none;
    flex-grow: 0;
    position: relative;
    isolation: isolate;
}

/* Active state is now handled by .clickable-metric.active class */

.live-metric-item:last-child {
    border-bottom: none;
    padding-bottom: 12px;
    height: 91px;
}

/* Hover state is now handled by .clickable-metric:hover */

/* Metric Icons */
.metric-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    flex-shrink: 0;
    flex: none;
    order: 0;
    flex-grow: 0;
}

.metric-icon svg {
    width: 18px;
    height: 18px;
}

.countries-icon,
.users-icon,
.pages-icon {
    background: transparent;
    color: #9ba1a6;
}

/* Metric Content */
.metric-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0px;
    gap: 12px;
    width: auto;
    height: 59px;
    flex: none;
    order: 0;
    flex-grow: 0;
    z-index: 0;
}

.metric-label {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 0px;
    gap: 4px;
    height: 18px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 14px;
    line-height: 17px;
    color: #676e74;
    mix-blend-mode: normal;
    flex: none;
    order: 0;
    flex-grow: 0;
}

.users-label {
    color: #676e74;
}

.pages-label {
    text-decoration: underline;
}

.metric-label .metric-icon {
    margin-right: 0;
}

.metric-value {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 0px 0px 0px 22px;
    gap: 8px;
    height: 29px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 24px;
    line-height: 29px;
    letter-spacing: 1px;
    color: #202224;
    flex: none;
    order: 1;
    flex-grow: 0;
    transition: transform 0.3s ease-out, color 0.3s ease-out;
    will-change: transform, color;
}

.users-value {
    color: #202224;
}

/* ═══════════════════════════════════════════════════════════════
   Chart Panel (Right)
   ═══════════════════════════════════════════════════════════════ */

.live-analytics-chart {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 0px;
    gap: 8px;
    width: 100%;
    height: 289px;
    background: transparent;
    border-radius: 0;
    border: none;
    flex: 1;
    flex-grow: 1;
    order: 1;
    align-self: stretch;
    min-width: 0;
}

.live-analytics-chart--locked {
    justify-content: center;
    align-items: center;
}

.live-analytics-promo {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
    overflow: hidden;
}

.live-analytics-promo-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Mock chart wrapper with blur effect for non-premium users */
.live-analytics-mock-chart-wrapper {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 5px;
    gap: 8px;
    filter: blur(6px);
    -webkit-filter: blur(6px);
    pointer-events: none;
    user-select: none;
}

.live-analytics-mock-chart-wrapper .chart-container {
    flex: 1;
    width: 100%;
    min-height: 0;
}

.live-analytics-mock-chart-wrapper .chart-header {
    flex-shrink: 0;
}

.live-analytics-promo-overlay {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 24px;
}

.live-analytics-promo-heading {
    margin: 0;
}

.live-analytics-promo-title {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 600;
    font-size: 18px;
    color: #111827;
}

.live-analytics-promo-button {
    color: #e8294c;
    background: transparent;
    text-decoration: underline !important;
    margin-top: 0;
    padding: 0;
    width: auto;
    font-size: 16px;
    font-weight: 500;
}

.chart-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 0px;
    gap: 8px;
    width: 100%;
    min-height: 20px;
    flex: none;
    order: 0;
    flex-shrink: 0;
}

.chart-header h4 {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 500;
    font-size: 14px;
    line-height: 17px;
    display: flex;
    align-items: center;
    color: #676e74;
    flex: none;
    order: 0;
    flex-grow: 0;
    padding-left: 4px;
}

/* Chart Title with LIVE Indicator */
.chart-title-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(239, 68, 68, 0.08);
    border-radius: 4px;
    flex-shrink: 0;
    cursor: pointer;
}

.live-dot {
    width: 6px;
    height: 6px;
    background: #ef4444;
    border-radius: 50%;
    position: relative;
    animation: livePulse 2s ease-in-out infinite;
}

.live-dot::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: #ef4444;
    border-radius: 50%;
    opacity: 0;
    animation: liveRipple 2s ease-in-out infinite;
}

.live-text {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 10px;
    line-height: 14px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ef4444;
}

/* LIVE Indicator Animations */
@keyframes livePulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.95);
    }
}

@keyframes liveRipple {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(2.5);
    }
}

/* Fast pulse animation during updates */
@keyframes livePulseFast {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.85);
    }
}

@keyframes liveRippleFast {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(2.8);
    }
}

/* Updating state for live indicator */
.live-indicator.updating {
    background: rgba(239, 68, 68, 0.12);
    transition: background 0.3s ease;
}

.live-indicator.updating .live-dot {
    animation: livePulseFast 0.8s ease-in-out infinite;
}

.live-indicator.updating .live-dot::before {
    animation: liveRippleFast 0.8s ease-in-out infinite;
}

.live-indicator.updating .live-text {
    color: #dc2626;
}

/* Clickable Metric Items */
.clickable-metric {
    cursor: pointer;
    transition: all 0.2s ease;
}

.clickable-metric:hover .metric-label {
    text-decoration: underline;
    text-decoration-style: dashed;
}

.clickable-metric.disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}

.clickable-metric.active {
    background: linear-gradient(90deg, rgba(231, 41, 75, 0) 0%, rgba(231, 41, 75, 0.03) 100%);
}

.clickable-metric.active::after {
    content: "";
    position: absolute;
    width: 2px;
    height: 98px;
    right: 0;
    top: 0;
    background: #e7294b;
    flex: none;
    order: 1;
    flex-grow: 0;
    z-index: 1;
}

.clickable-metric.active .metric-label,
.clickable-metric.active .users-label,
.clickable-metric.active .pages-label,
.clickable-metric.active .countries-label {
    color: #e7294b !important;
}

.clickable-metric.active .metric-icon svg,
.clickable-metric.active .metric-icon svg path,
.clickable-metric.active .metric-icon svg circle,
.clickable-metric.active .metric-icon svg ellipse {
    fill: #e7294b !important;
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #9ba1a6;
    font-size: 14px;
    font-weight: 500;
}

.empty-state p {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chart-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0px;
    gap: 4px;
    width: 100%;
    height: 246px;
    position: relative;
    flex: 1;
    flex-grow: 1;
    order: 1;
    align-self: stretch;
    min-width: 0;
}

.chart-container canvas {
    transition: opacity 0.2s ease-out;
}

/* ═══════════════════════════════════════════════════════════════
   Chart Frame & Grid Lines
   ═══════════════════════════════════════════════════════════════ */

.chart-frame {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0px;
    gap: 4px;
    isolation: isolate;
    width: 927px;
    height: 227px;
    flex: none;
    order: 0;
    align-self: stretch;
    flex-grow: 0;
    position: relative;
}

.chart-grid-line {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0px;
    gap: 2px;
    width: 927px;
    height: 18px;
}

.chart-grid-line .grid-value {
    width: 22px;
    height: 15px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 12px;
    line-height: 15px;
    color: #9ba1a6;
    mix-blend-mode: normal;
    flex: none;
    order: 0;
    flex-grow: 0;
}

.chart-grid-line .grid-dashed {
    box-sizing: border-box;
    width: 927px;
    height: 1px;
    border: 1px dashed #ebebeb;
    flex: none;
    order: 1;
    flex-grow: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Chart Bars Container
   ═══════════════════════════════════════════════════════════════ */

.chart-bars-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0px;
    gap: 8px;
    width: 880px;
    height: 200px;
    flex: none;
    order: 2;
    flex-grow: 0;
    z-index: 2;
}

.chart-bar {
    margin: 0 auto;
    width: 20px;
    min-height: 2px;
    background: #e6e6e6;
    border-radius: 100px 100px 0px 0px;
    flex: none;
    flex-grow: 0;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.chart-bar:hover {
    background: #d0d0d0;
    transform: translateY(-2px);
}

.chart-bar.active,
.chart-bar.peak {
    background: #e7294b;
}

.chart-bar.active:hover,
.chart-bar.peak:hover {
    background: #c91f3d;
}

/* ═══════════════════════════════════════════════════════════════
   Chart Bottom Border & Labels
   ═══════════════════════════════════════════════════════════════ */

.chart-bottom-border {
    box-sizing: border-box;
    width: 927px;
    height: 1px;
    border: 1px dashed #ebebeb;
    flex: none;
    order: 3;
    align-self: stretch;
    flex-grow: 0;
    z-index: 3;
}

.chart-labels-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0px;
    gap: 4px;
    width: 880px;
    height: 15px;
    flex: none;
    order: 1;
    flex-grow: 0;
}

.chart-label {
    margin: 0 auto;
    height: 15px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-style: normal;
    font-weight: 600;
    font-size: 12px;
    line-height: 15px;
    color: #9ba1a6;
    mix-blend-mode: normal;
    flex: none;
    flex-grow: 0;
    text-align: center;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   Loading States
   ═══════════════════════════════════════════════════════════════ */

.chart-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10;
    border-radius: 4px;
}

.chart-loading-overlay .loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #e7294b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.chart-loading-overlay span {
    font-size: 13px;
    color: #676e74;
    font-weight: 500;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ═══════════════════════════════════════════════════════════════
   Animations
   ═══════════════════════════════════════════════════════════════ */

@keyframes livePulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Smooth chart bar animations */
@keyframes barSlideUp {
    from {
        transform: scaleY(0);
        opacity: 0;
    }
    to {
        transform: scaleY(1);
        opacity: 1;
    }
}

@keyframes barPulse {
    0%,
    100% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(1.05);
    }
}

/* Number update highlight animation */
@keyframes numberHighlight {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.02);
        opacity: 0.95;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Responsive Design
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1280px) {
    .live-analytics-container {
        max-width: 100%;
        height: 321px; /* Match desktop height */
    }

    .live-analytics-grid {
        flex-direction: row; /* Keep horizontal */
        height: 100%;
        gap: 16px; /* Reduce gap */
    }

    .live-analytics-metrics {
        width: 180px; /* Smaller metrics panel */
        min-width: 180px;
        height: 100%;
        border-right: 1px dashed #ebebeb;
        border-bottom: none;
        padding-bottom: 0;
        order: 0;
        flex-shrink: 0;
    }

    .live-metric-item {
        width: 100%;
        height: 96px;
        padding: 12px 0px 12px 8px;
    }

    .live-analytics-chart {
        width: 100%;
        height: 100%;
        order: 1;
        flex-grow: 1;
        min-width: 0;
    }

    .chart-header {
        width: 100%;
    }

    .chart-container {
        width: 100%;
        height: calc(100% - 30px);
    }
}

@media (max-width: 768px) {
    .live-analytics-container {
        padding: 10px;
        height: 260px; /* Adjusted height */
    }

    .live-analytics-grid {
        gap: 12px;
    }

    .live-analytics-metrics {
        width: 130px; /* Narrower metrics */
        min-width: 130px;
    }

    .live-metric-item {
        padding: 8px 0px 8px 8px;
        height: 80px;
        gap: 8px;
    }

    .metric-icon {
        width: 14px;
        height: 14px;
    }

    .metric-icon svg {
        width: 14px;
        height: 14px;
    }

    .metric-value {
        font-size: 18px;
        padding-left: 14px;
        line-height: 22px;
    }

    .metric-label {
        font-size: 11px;
        gap: 4px;
    }

    .live-analytics-chart {
        height: 100%;
    }

    .chart-container {
        width: 100%;
        height: calc(100% - 25px);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .chart-container canvas {
        min-width: 400px; /* Prevent bars from sticking together */
        width: 100%;
        /* Removed height: 100% !important to prevent stretching */
    }

    /* Style the scrollbar for mobile */
    .chart-container::-webkit-scrollbar {
        height: 3px;
    }
    .chart-container::-webkit-scrollbar-track {
        background: transparent;
    }
    .chart-container::-webkit-scrollbar-thumb {
        background: #ebebeb;
        border-radius: 10px;
    }

    .empty-state {
        position: sticky;
        left: 0;
        width: 100%;
        transform: translateY(-50%);
        top: 50%;
    }

    .live-indicator {
        padding: 1px 6px;
    }

    .live-text {
        font-size: 9px;
    }
}

@media (max-width: 480px) {
    .live-analytics-container {
        padding: 6px;
        height: 200px; /* Scaled down */
    }

    .live-analytics-grid {
        gap: 8px;
    }

    .live-analytics-metrics {
        width: 100px;
        min-width: 100px;
    }

    .live-metric-item {
        padding: 6px 0px 6px 4px;
        height: 62px;
        gap: 4px;
    }

    .metric-content {
        gap: 4px;
    }

    .metric-value {
        font-size: 14px;
        padding-left: 10px;
        line-height: 18px;
        letter-spacing: 0.5px;
    }

    .metric-label {
        font-size: 10px;
        height: 14px;
    }

    .metric-icon {
        width: 12px;
        height: 12px;
    }

    .metric-icon svg {
        width: 12px;
        height: 12px;
    }

    .live-text {
        font-size: 8px;
    }

    .chart-container canvas {
        min-width: 350px; /* Compact width for small screens */
    }
}

/* ═══════════════════════════════════════════════════════════════
   Light Theme Only - Dark mode disabled for Live Analytics
   ═══════════════════════════════════════════════════════════════ */

/* Live Analytics always uses light theme regardless of system preference */
.live-analytics-light-theme,
.live-analytics-container {
    background: #ffffff !important;
    color: #202224 !important;
}

/* ========================================
   Postbox Configuration Classes
   ======================================== */

/* Hide postbox header completely */
.postbox.slimstat-hide-header .postbox-header,
.postbox.slimstat-hide-header .slimstat-header-buttons,
.postbox.slimstat-hide-header h3 {
    display: none !important;
}

/* Remove postbox padding */
.postbox.slimstat-hide-padding .inside {
    padding: 0 !important;
    margin: 0 !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Full width postbox */
.postbox.slimstat-full-width {
    width: 100% !important;
    max-width: none !important;
}

/* Remove postbox border */
.postbox.slimstat-no-border {
    border: none !important;
    box-shadow: none !important;
}

/* Remove postbox background */
.postbox.slimstat-no-background {
    background: transparent !important;
}

/* Live Analytics specific styles are now handled by postbox_config classes above */

.live-analytics-light-theme .live-analytics-title h3,
.live-analytics-container .live-analytics-title h3 {
    color: #1f2937 !important;
}

/* Active state handled by .clickable-metric.active */

.live-analytics-light-theme .metric-value,
.live-analytics-container .metric-value {
    color: #202224 !important;
}

.live-analytics-light-theme .metric-label,
.live-analytics-container .metric-label {
    color: #676e74 !important;
}

.live-analytics-light-theme .live-analytics-chart,
.live-analytics-container .live-analytics-chart {
    background: transparent !important;
    border-color: transparent !important;
}

.live-analytics-light-theme .chart-header h4,
.live-analytics-container .chart-header h4 {
    color: #676e74 !important;
}

/* ═══════════════════════════════════════════════════════════════
   WordPress Admin Specific
   ═══════════════════════════════════════════════════════════════ */

/* Postbox styling is now handled by postbox_config classes */

/* Active state handled by .clickable-metric.active */

.postbox .live-analytics-container .live-analytics-chart {
    background: transparent !important;
}

.postbox .live-analytics-container .live-analytics-header {
    border-bottom: none;
}

/* ═══════════════════════════════════════════════════════════════
   Customization Classes
   ═══════════════════════════════════════════════════════════════ */

/* Full-width variant */
.live-analytics-fullwidth {
    width: 100%;
    max-width: none;
}

.live-analytics-fullwidth .live-analytics-grid {
    grid-template-columns: 320px 1fr;
}

/* Ensure Live Analytics report takes full width */
.wrap.slimstat .postbox.live-analytics {
    width: 98.7% !important;
}

.wrap.slimstat .postbox.live-analytics.full-width {
    width: 98.7% !important;
}

/* Compact variant */
.live-analytics-compact .live-analytics-container {
    padding: 0;
}

.live-analytics-compact .live-analytics-metrics {
    gap: 12px;
}

.live-analytics-compact .live-metric-item {
    padding: 12px;
}

/* Minimal variant */
.live-analytics-minimal .live-analytics-container {
    box-shadow: none;
    border: none;
    background: transparent;
}

.live-analytics-minimal .live-analytics-header {
    border-bottom: none;
    padding-bottom: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Accessibility
   ═══════════════════════════════════════════════════════════════ */

.live-analytics-container:focus-within {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.metric-icon svg {
    display: block;
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
