/* 統計 Modal 樣式 */
.stats-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.stats-modal-content {
    background-color: #fff;
    margin: 3% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    animation: modalFadeIn 0.3s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.stats-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.stats-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats-short-code {
    font-family: monospace;
    color: #007bff;
    background: #e7f1ff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 1.1rem;
}

.stats-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stats-close:hover {
    background: #f1f3f5;
    color: #343a40;
}

.stats-tabs {
    display: flex;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    flex-shrink: 0;
}

.stats-tab {
    flex: 1;
    padding: 14px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    color: #6c757d;
    transition: all 0.3s;
    text-align: center;
}

.stats-tab:hover {
    background: #e9ecef;
    color: #495057;
}

.stats-tab.active {
    color: #007bff;
    border-bottom-color: #007bff;
    background: #fff;
}

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

.stats-tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.stats-tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Overview Cards */
.stats-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stats-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stats-card.secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stats-card.success {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stats-card-label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 8px;
}

.stats-card-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.stats-card-change {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* Chart Container */
.stats-chart-container {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 24px;
}

.stats-chart-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 16px;
}

.stats-chart {
    height: 280px;
    position: relative;
}

/* Source List */
.stats-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stats-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f1f3f5;
}

.stats-list-item:last-child {
    border-bottom: none;
}

.stats-list-label {
    font-size: 0.95rem;
    color: #495057;
    max-width: 70%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-list-value {
    font-weight: 600;
    color: #1f2937;
    background: #f3f4f6;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Geo Grid */
.stats-geo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.stats-geo-item {
    background: #f8f9fa;
    padding: 14px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #e9ecef;
}

.stats-geo-country {
    font-size: 0.9rem;
    color: #495057;
    margin-bottom: 6px;
}

.stats-geo-count {
    font-size: 1.3rem;
    font-weight: 700;
    color: #007bff;
}

.stats-geo-percent {
    font-size: 0.8rem;
    color: #6c757d;
}

/* Device Chart */
.stats-device-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 250px;
}

/* Loading & Error States */
.stats-loading {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
}

.stats-loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

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

    100% {
        transform: rotate(360deg);
    }
}

.stats-error {
    text-align: center;
    padding: 60px 20px;
    color: #dc3545;
}

.stats-empty {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
}

/* Responsive */
@media (max-width: 768px) {
    .stats-modal-content {
        width: 95%;
        margin: 5% auto;
        max-height: 90vh;
    }

    .stats-modal-header h2 {
        font-size: 1.2rem;
    }

    .stats-overview-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stats-card {
        padding: 14px;
    }

    .stats-card-value {
        font-size: 1.5rem;
    }

    .stats-chart {
        height: 220px;
    }

    .stats-tab {
        padding: 12px 8px;
        font-size: 0.85rem;
    }

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

@media (max-width: 480px) {
    .stats-modal-header {
        padding: 16px;
    }

    .stats-modal-body {
        padding: 16px;
    }

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