/**
 * AI 使用統計 Dashboard 樣式
 */

/* 通用樣式 */
.ai-usage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 16px 0;
    border-bottom: 1px solid #E8E5E0;
}

.ai-usage-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 系統健康狀態列 */
.health-status-bar {
    background: #fff;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

.health-status {
    font-size: 16px;
    font-weight: 600;
    color: #1F2937;
}

.health-updated {
    color: #78716C;
    font-size: 13px;
}

.health-metrics {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
}

@media (max-width: 1024px) {
    .health-metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .health-metrics { grid-template-columns: repeat(2, 1fr); }
}

.health-metric {
    text-align: center;
    padding: 8px;
}

.metric-label {
    font-size: 12px;
    color: #78716C;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: #1F2937;
    line-height: 1.2;
}

.metric-sub {
    font-size: 12px;
    color: #78716C;
    margin-top: 4px;
}

.metric-sub.positive { color: #10B981; }
.metric-sub.negative { color: #EF4444; }

/* Provider 狀態點 */
.provider-dot { font-size: 14px; margin: 0 2px; }
.provider-dot.online { color: #10B981; }
.provider-dot.offline { color: #EF4444; }
.provider-dot.degraded { color: #F59E0B; }
.provider-dot.unknown { color: #A8A29E; }

/* 進度條 */
.metric-progress {
    height: 6px;
    background: #E8E5E0;
    border-radius: 3px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--color-accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* 警報 */
.health-alerts {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #E8E5E0;
}

.alert {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
}
.alert:last-child { margin-bottom: 0; }
.alert-warning { background: #FEF3C7; color: #92400E; border-left: 3px solid #F59E0B; }
.alert-error { background: #FEE2E2; color: #991B1B; border-left: 3px solid #EF4444; }

/* 區塊容器 */
.section {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.section h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1F2937;
    margin: 0 0 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section.loading {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #78716C;
}

/* Fallback 層級分析 */
.fallback-analysis .fallback-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

@media (max-width: 1024px) {
    .fallback-analysis .fallback-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .fallback-analysis .fallback-grid { grid-template-columns: 1fr; }
}

.layer-card {
    background: #FAF9F6;
    border-radius: 8px;
    padding: 16px;
    border: 1px solid #E8E5E0;
    transition: box-shadow 0.2s;
}

.layer-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.layer-card.layer-1 { border-left: 4px solid #3B82F6; }
.layer-card.layer-2 { border-left: 4px solid #8B5CF6; }
.layer-card.layer-3 { border-left: 4px solid #F97316; }
.layer-card.layer-4 { border-left: 4px solid #10B981; }

.layer-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.layer-badge {
    background: #1F2937;
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.layer-name {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

.layer-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.layer-stats .stat { text-align: center; }
.layer-stats .stat-value { font-size: 18px; font-weight: 700; color: #1F2937; }
.layer-stats .stat-label { font-size: 11px; color: #78716C; }

/* 洞察區域 */
.insights {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #E8E5E0;
}

.insight {
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 8px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.insight:last-child { margin-bottom: 0; }
.insight-info { background: #EFF6FF; color: #1E40AF; }
.insight-warning { background: #FEF3C7; color: #92400E; }
.insight-error { background: #FEE2E2; color: #991B1B; }

/* 功能模組分佈 */
.feature-breakdown .feature-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

@media (max-width: 768px) {
    .feature-breakdown .feature-cards { grid-template-columns: 1fr; }
}

.feature-card {
    background: #FAF9F6;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    border: 1px solid #E8E5E0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.feature-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.feature-icon { font-size: 32px; margin-bottom: 8px; }
.feature-name { font-size: 14px; font-weight: 600; color: #1F2937; margin-bottom: 12px; }
.feature-stats { font-size: 13px; color: #78716C; line-height: 1.6; }
.feature-stats div { margin-bottom: 4px; }

/* 請求明細表 */
.requests-table table { width: 100%; border-collapse: collapse; }

.requests-table thead th {
    background: #FAF9F6;
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #78716C;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #E8E5E0;
}

.requests-table tbody tr {
    border-bottom: 1px solid #E8E5E0;
    transition: background 0.15s;
}

.requests-table tbody tr:hover { background: #FAF9F6; }

.requests-table tbody td {
    padding: 12px 16px;
    font-size: 13px;
    color: #374151;
}

.requests-table .pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    font-size: 13px;
    color: #78716C;
}

/* 用戶詳情面板 */
.user-detail-panel {
    background: #FAF9F6;
    padding: 20px;
    border-radius: 8px;
    margin-top: 8px;
}

.user-detail-loading {
    padding: 40px;
    text-align: center;
    color: #78716C;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 1024px) {
    .detail-grid { grid-template-columns: 1fr; }
}

.detail-section {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #E8E5E0;
}

.detail-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 12px 0;
}

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

.detail-stats .stat { text-align: center; }
.detail-stats .stat-label { font-size: 11px; color: #78716C; display: block; }
.detail-stats .stat-value { font-size: 18px; font-weight: 700; color: #1F2937; }

/* Fallback 分佈進度條 */
.fallback-bars { display: flex; flex-direction: column; gap: 8px; }

.fallback-bar { display: flex; align-items: center; gap: 8px; }
.fallback-bar .layer-label { font-size: 12px; font-weight: 600; color: #374151; width: 24px; }

.fallback-bar .bar-track {
    flex: 1;
    height: 8px;
    background: #E8E5E0;
    border-radius: 4px;
    overflow: hidden;
}

.fallback-bar .bar-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.fallback-bar .bar-percent { font-size: 12px; color: #78716C; width: 40px; text-align: right; }

/* 模型費用明細 */
.model-breakdown {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #E8E5E0;
    margin-bottom: 20px;
}

.model-breakdown h4 { font-size: 14px; font-weight: 600; color: #374151; margin: 0 0 12px 0; }
.model-row { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.model-row:last-child { margin-bottom: 0; }
.model-name { font-size: 13px; color: #374151; width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.model-bar-track { flex: 1; height: 6px; background: #E8E5E0; border-radius: 3px; overflow: hidden; }
.model-bar-fill { height: 100%; background: #8B5CF6; border-radius: 3px; }
.model-cost { font-size: 12px; color: #78716C; width: 100px; text-align: right; }

/* 最近請求 */
.recent-requests {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #E8E5E0;
}

.recent-requests h4 { font-size: 14px; font-weight: 600; color: #374151; margin: 0 0 12px 0; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table td { padding: 8px 12px; border-bottom: 1px solid #E8E5E0; color: #374151; }
.mini-table tr:last-child td { border-bottom: none; }

.recent-requests > a {
    display: inline-block;
    margin-top: 12px;
    font-size: 13px;
    color: var(--color-accent);
    text-decoration: none;
}
.recent-requests > a:hover { text-decoration: underline; }

/* 核心指標卡片 */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

@media (max-width: 1024px) { .stats-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .stats-cards { grid-template-columns: 1fr; } }

.stats-card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stats-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stats-card-icon.requests { background: #DBEAFE; }
.stats-card-icon.tokens { background: #D1FAE5; }
.stats-card-icon.cost { background: #FEE2E2; }
.stats-card-icon.users { background: #E0E7FF; }

.stats-card-content { flex: 1; }
.stats-card-value { font-size: 24px; font-weight: 700; color: #1F2937; }
.stats-card-label { font-size: 13px; color: #78716C; }

/* 用戶排行 */
.user-ranking table { width: 100%; border-collapse: collapse; }

.user-ranking thead th {
    background: #FAF9F6;
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #78716C;
    border-bottom: 1px solid #E8E5E0;
}

.user-ranking tbody td {
    padding: 10px 12px;
    font-size: 13px;
    color: #374151;
    border-bottom: 1px solid #E8E5E0;
}

.user-ranking tbody tr:hover { background: #FAF9F6; }

.rank-badge {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}
.rank-badge.gold { background: #FEF3C7; color: #92400E; }
.rank-badge.silver { background: #E8E5E0; color: #374151; }
.rank-badge.bronze { background: #FED7AA; color: #9A3412; }

/* 成本趨勢圖表 */
.cost-trend .chart-container { height: 300px; margin-top: 16px; }

/* 展開按鈕 */
.btn-expand {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 12px;
    color: #78716C;
    transition: color 0.15s;
}
.btn-expand:hover { color: #374151; }

/* 刷新按鈕 */
.btn-refresh {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--color-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}
.btn-refresh:hover { background: var(--color-accent-hover); }

/* 錯誤狀態 */
.error-state { text-align: center; padding: 40px; color: #EF4444; }
.error-state .error-icon { font-size: 48px; margin-bottom: 16px; }
.error-state .error-message { font-size: 14px; margin-bottom: 16px; }

.retry-btn {
    padding: 8px 16px;
    background: #fff;
    border: 1px solid #D6D3CE;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.retry-btn:hover { background: #F5F3EE; }

/* 區塊摺疊功能 */
.section-header-collapsible {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.section-header-collapsible h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.collapse-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    color: #78716C;
}

.section.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    max-height: 2000px;
    opacity: 1;
}

.section.collapsed .section-content {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.section.collapsed {
    padding-bottom: 16px;
}
