/* ═══════════════════════════════════════════════════════════════
   Cloudflare Analytics Panel Styles
   ═══════════════════════════════════════════════════════════════ */

/* Traffic Network Button - matches fm-upgrade-btn style */
.fm-traffic-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1d78ed 0%, #0c49c2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
    margin-top: 8px;
}

.fm-traffic-btn:hover {
    box-shadow: 0 6px 12px rgba(102, 126, 234, 0.4);
}

.fm-traffic-btn svg {
    width: 16px;
    height: 16px;
}

/* Analytics Panel - same base as upload-panel */
.analytics-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 620px;
    height: 480px;
    background: white;
    box-shadow: 0 4px 11px rgb(0 0 0 / 28%);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 360px;
    min-height: 280px;
    border: 1px solid #0078d7;
}

.analytics-panel.dragging {
    user-select: none;
    cursor: move;
}

.analytics-panel.resizing {
    user-select: none;
}

.analytics-panel.minimized {
    height: auto !important;
    max-height: none !important;
    resize: none;
    overflow: hidden;
    bottom: -138px !important;
}

.analytics-panel.minimized .analytics-panel-body,
.analytics-panel.minimized .analytics-panel-footer {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
}

.analytics-panel.maximized {
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    max-width: 100vw !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0;
}

.analytics-panel-header {
    cursor: move;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 12px 16px;
    background: #0078d7;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.analytics-panel-header:active {
    cursor: grabbing;
}

.analytics-panel.minimized .analytics-panel-header:hover {
    background: #0078d7;
}

.analytics-panel-title {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
}

.analytics-panel-actions {
    display: flex;
    gap: 4px;
}

.analytics-action-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.analytics-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.analytics-action-btn svg {
    width: 16px;
    height: 16px;
}

/* Resize handles */
.analytics-panel {
    --resize-handle-size: 6px;
}

.analytics-panel:not(.minimized):not(.maximized) .resize-handle {
    position: absolute;
    z-index: 10;
    background: transparent;
}

.analytics-panel:not(.minimized):not(.maximized) .resize-handle-n {
    top: -3px; left: 0; right: 0; height: 6px; cursor: n-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-s {
    bottom: -3px; left: 0; right: 0; height: 6px; cursor: s-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-e {
    right: -3px; top: 0; bottom: 0; width: 6px; cursor: e-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-w {
    left: -3px; top: 0; bottom: 0; width: 6px; cursor: w-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-ne {
    top: -3px; right: -3px; width: 12px; height: 12px; cursor: ne-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-nw {
    top: -3px; left: -3px; width: 12px; height: 12px; cursor: nw-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-se {
    bottom: -3px; right: -3px; width: 12px; height: 12px; cursor: se-resize;
}
.analytics-panel:not(.minimized):not(.maximized) .resize-handle-sw {
    bottom: -3px; left: -3px; width: 12px; height: 12px; cursor: sw-resize;
}

/* Panel Body */
.analytics-panel-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: #f8f9fa;
}

/* Panel Footer */
.analytics-panel-footer {
    flex-shrink: 0;
    padding: 8px 16px;
    background: #e8e8e8;
    font-size: 12px;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ═══ Stats Cards ═══ */
.analytics-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.analytics-stat-card {
    background: white;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    text-align: center;
}

.analytics-stat-label {
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
}

.analytics-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: #0078d7;
    margin-bottom: 4px;
    word-break: break-all;
}

.analytics-stat-change {
    font-size: 11px;
    font-weight: 500;
}

.analytics-stat-change.positive {
    color: #52c41a;
}

.analytics-stat-change.negative {
    color: #f5222d;
}

/* ═══ Chart Section ═══ */
.analytics-chart-section {
    background: white;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 16px;
}

.analytics-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.analytics-chart-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.analytics-chart-controls {
    display: flex;
    gap: 6px;
}

.analytics-chart-btn {
    background: transparent;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
}

.analytics-chart-btn:hover {
    border-color: #0078d7;
    color: #0078d7;
}

.analytics-chart-btn.active {
    background: #0078d7;
    color: white;
    border-color: #0078d7;
}

/* SVG Chart */
.analytics-chart-svg {
    width: 100%;
    height: 200px;
}

.analytics-chart-svg .grid-line {
    stroke: #f0f0f0;
    stroke-width: 1;
}

.analytics-chart-svg .data-line {
    fill: none;
    stroke: #0078d7;
    stroke-width: 2;
    stroke-linejoin: round;
}

.analytics-chart-svg .data-area {
    fill: rgba(0, 120, 215, 0.1);
    stroke: none;
}

.analytics-chart-svg .data-dot {
    fill: #0078d7;
    stroke: white;
    stroke-width: 2;
}

.analytics-chart-svg .axis-label {
    font-size: 10px;
    fill: #999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.analytics-chart-svg .axis-label-y {
    text-anchor: end;
}

.analytics-chart-svg .axis-label-x {
    text-anchor: middle;
}

/* Chart tooltip */
.analytics-chart-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
    display: none;
}

/* ═══ Period Selector ═══ */
.analytics-period-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}

.analytics-period-btn {
    background: white;
    border: 1px solid #d9d9d9;
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: #666;
}

.analytics-period-btn:hover {
    border-color: #0078d7;
    color: #0078d7;
}

.analytics-period-btn.active {
    background: #0078d7;
    color: white;
    border-color: #0078d7;
}

/* ═══ Status Codes Section ═══ */
.analytics-status-section {
    background: white;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 16px;
}

.analytics-status-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
}

.analytics-status-bar {
    display: flex;
    height: 24px;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.analytics-status-segment {
    height: 100%;
    transition: width 0.3s;
    position: relative;
    min-width: 2px;
}

.analytics-status-segment:hover {
    opacity: 0.8;
}

.analytics-status-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
}

.analytics-status-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.analytics-status-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ═══ Status Pie Chart ═══ */
.analytics-status-chart-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.analytics-pie-chart-wrap {
    flex-shrink: 0;
    width: 140px;
    height: 140px;
    position: relative;
}

.analytics-pie-chart-svg {
    width: 100%;
    height: 100%;
}

.analytics-pie-center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.analytics-pie-center-value {
    font-size: 18px;
    font-weight: 700;
    color: #333;
    display: block;
}

.analytics-pie-center-label {
    font-size: 10px;
    color: #999;
    display: block;
}

.analytics-status-bar-wrap {
    flex: 1;
    min-width: 0;
}

/* ═══ Region Section ═══ */
.analytics-region-section {
    background: white;
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 16px;
}

.analytics-region-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
}

.analytics-region-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.analytics-region-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.analytics-region-name {
    width: 100px;
    flex-shrink: 0;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.analytics-region-bar-bg {
    flex: 1;
    height: 16px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
}

.analytics-region-bar {
    height: 100%;
    background: #0078d7;
    border-radius: 3px;
    transition: width 0.3s;
}

.analytics-region-value {
    width: 70px;
    flex-shrink: 0;
    text-align: right;
    color: #666;
    font-size: 12px;
}

/* ═══ Loading & Error ═══ */
.analytics-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: #999;
    font-size: 14px;
}

.analytics-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e0e0e0;
    border-top-color: #0078d7;
    border-radius: 50%;
    animation: analytics-spin 0.8s linear infinite;
    margin-right: 10px;
}

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

.analytics-error {
    background: #fff2f0;
    border: 1px solid #ffccc7;
    border-radius: 6px;
    padding: 12px 16px;
    color: #f5222d;
    font-size: 13px;
    margin-bottom: 12px;
}

.analytics-no-data {
    text-align: center;
    padding: 30px;
    color: #999;
    font-size: 14px;
}

/* ═══ Responsive ═══ */
@media (max-width: 768px) {
    .analytics-panel {
        width: 100vw !important;
        height: 100vh !important;
        left: 0 !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        min-width: 100vw;
        min-height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border: none;
        border-radius: 0;
    }

    /* Hide resize handles and minimize/maximize buttons on mobile */
    .analytics-panel .resize-handle,
    .analytics-panel #analytics-minimize-btn,
    .analytics-panel #analytics-maximize-btn {
        display: none !important;
    }

    .analytics-stats-grid {
        grid-template-columns: 1fr;
    }

    .analytics-stat-value {
        font-size: 16px;
    }

    .analytics-chart-controls {
        flex-wrap: wrap;
    }

    .analytics-period-selector {
        flex-wrap: wrap;
    }

    .analytics-status-chart-row {
        flex-direction: column;
        align-items: center;
    }

    .analytics-pie-chart-wrap {
        width: 120px;
        height: 120px;
    }

    .analytics-status-bar-wrap {
        width: 100%;
    }
}
