/* ===== CSS Variables ===== */
:root {
    --container: 720px;
    color-scheme: light dark;
    --bg: #f7f9fc;
    --fg: #1f2937;
    --muted: #6b7280;
    --primary: #0a84ff;
    --primary-700: #0a6dd4;
    --card-bg: #ffffff;
    --card: #ffffff;  /* Alias for consistency */
    --border: #e5e7eb;
    --border-hover: #d1d5db;
    --input-bg: #ffffff;
    --shadow: 0 8px 20px rgba(2, 6, 23, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --text-muted: #6b7280;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.1);
    /* Status Colors */
    --success: #26a69a;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    /* PWA和价格相关色彩 */
    --price-up: #dc2626;        /* 上涨红色 */
    --price-down: #059669;      /* 下跌绿色 */  
    --price-neutral: #6b7280;   /* 平盘灰色 */
    
    /* PWA状态指示色 */
    --status-online: #10b981;   /* 在线绿色 */
    --status-offline: #ef4444;  /* 离线红色 */
    --status-sync: #3b82f6;     /* 同步蓝色 */
    
    /* 标准字体尺寸系统 */
    --text-xs: 10px;      /* 极小文本 - 图标标签、状态指示 */
    --text-sm: 11px;      /* 小文本 - 辅助信息、提示文字 */
    --text-base: 12px;    /* 普通文本 - 表格内容、标签 */
    --text-md: 13px;      /* 中等文本 - 列表项、次要按钮 */
    --text-lg: 14px;      /* 标准文本 - 正文、主要按钮 */
    --text-xl: 16px;      /* 大文本 - 表单输入、重要信息 */
    --text-2xl: 18px;     /* 子标题 - 卡片标题、区块标题 */
    --text-3xl: 20px;     /* 大标题 - 页面区块标题 */
    --text-4xl: 24px;     /* 页面标题 - 主标题 */
    --text-5xl: 28px;     /* 特大标题 - 强调标题 */
    --text-6xl: 32px;     /* 超大标题 - 价格/数值展示 */
    --text-7xl: 40px;     /* 巨大标题 - 欢迎页/特殊场景 */
    --text-8xl: 48px;     /* 超巨大 - 图标文字、特殊展示 */
    --text-9xl: 64px;     /* 极巨大 - 错误页图标 */
    
    /* 标准间距系统 */
    --space-xs: 4px;      /* 极小间距 - 图标与文本 */
    --space-sm: 8px;      /* 小间距 - 标签间、小元素 */  
    --space-base: 12px;   /* 基础间距 - 表单元素、小卡片 */
    --space-md: 16px;     /* 中等间距 - 卡片间、区块间 */
    --space-lg: 20px;     /* 大间距 - 页面区域、大卡片 */
    --space-xl: 24px;     /* 超大间距 - 页面级别分割 */
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --fg: #e5e7eb;
        --muted: #94a3b8;
        --card-bg: #0f172a;
        --card: #0f172a;  /* Alias for consistency */
        --border: #1e293b;
        --border-hover: #334155;
        --input-bg: #0b1220;
        --shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --text-muted: #94a3b8;
        --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.15);
        /* Status Colors - darker theme */
        --success: #10b981;
        --danger: #dc2626;
        --warning: #d97706;
        
        /* PWA和价格相关色彩 - 暗色主题 */
        --price-up: #f87171;        /* 上涨红色 - 亮一些 */
        --price-down: #34d399;      /* 下跌绿色 - 亮一些 */
        --price-neutral: #9ca3af;   /* 平盘灰色 - 亮一些 */
        
        /* PWA状态指示色 - 暗色主题 */
        --status-online: #34d399;   /* 在线绿色 - 亮一些 */
        --status-offline: #f87171;  /* 离线红色 - 亮一些 */
        --status-sync: #60a5fa;     /* 同步蓝色 - 亮一些 */
    }
}

/* ===== Base Styles ===== */
* {
    box-sizing: border-box;
}

/* 百分比输入框样式 */
.pct {
    position: relative;
}

.pct input {
    padding-right: 28px;
}

.pct .suffix {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

/* 小按钮样式已移至components.css的btn--sm */

body {
    font-family: -apple-system, system-ui, Segoe UI, Roboto, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-size: 14px;
    line-height: 1.5;
}

/* ===== Header (已迁移到components.css的nav-bar组件) ===== */
/* 原有header样式已迁移到components.css，使用BEM规范的.nav-bar组件替代 */

/* ===== Info Bar ===== */
.info-bar {
    position: sticky;
    top: 52px;
    z-index: 9;
    background: transparent;
    border-bottom: none;
}

.info-bar .inner {
    max-width: var(--container);
    width: 100%;
    margin: 0 auto;
    padding: 6px 16px;
    white-space: nowrap;
    overflow-x: auto;
    color: var(--muted);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tag {
    margin-left: 8px;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.15);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

@media (prefers-color-scheme: light) {
    .tag {
        background: rgba(0, 0, 0, 0.15);
        color: #0b1220;
    }
}

@media (prefers-color-scheme: light) {
    .tag {
        background: transparent;
        color: var(--muted);
    }
}

.tag:empty {
    display: none;
}

/* 余额样式与策略页一致：不加粗、不带背景 */
#bal_summary_text {
    background: transparent;
    font-weight: 600;
    padding: 0;
    margin: 0;
}

/* ===== Main Layout ===== */
main {
    padding: var(--space-md);
    max-width: var(--container);
    margin: 0 auto;
    display: grid;
    gap: var(--space-md);
}

/* .card 样式以 components.css 为唯一来源，避免重复定义导致视觉不一致 */

.muted {
    color: var(--muted);
    font-size: var(--text-base);
}

/* ===== Forms ===== */
label {
    display: block;
    margin: 8px 0 6px;
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--muted);
}

input {
    width: 100%;
    padding: 12px 12px;
    font-size: var(--text-xl);
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--fg);
}


input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.15);
}


.pct {
    position: relative;
}

.pct input {
    padding-right: 28px;
}

.pct .suffix {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-base);
}

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

/* ===== Buttons ===== */
/* 所有按钮样式已统一迁移至 components.css 的 .btn 组件系统 */

.actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: var(--space-base);
    padding: 10px 16px;
    background: color-mix(in srgb, var(--bg), transparent 15%);
    backdrop-filter: blur(6px);
    border-top: 1px solid var(--border);
}

/* ===== Tables - 已移至components.css统一管理 ===== */

/* ===== Tags ===== */
.tag {
    margin-left: 8px;
    padding: 2px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.15);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

@media (prefers-color-scheme: light) {
    .tag {
        background: transparent;
        color: var(--muted);
    }
}

.tag:empty {
    display: none;
}

/* ===== Balance Info ===== */
#bal_summary_text {
    background: transparent;
    font-weight: 600;
    padding: 0;
    margin: 0;
}

/* ===== Mobile Optimizations ===== */
@media (max-width: 560px) {
    .table {
        min-width: 0;
    }

    .table th,
    .table td {
        padding: 6px;
        font-size: var(--text-md);
        white-space: nowrap;
    }

    #levels_tbody input {
        font-size: 16px;
        min-width: 120px;
    }
}

/* ===== Chart Specific Styles ===== */
.chart-container {
    width: 100%;
    height: 500px;
    position: relative;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--muted);
    font-size: 16px;
}

/* .controls 特化样式已迁移，避免覆盖通用按钮色彩。请使用页面专用类（如 .chart-controls）。 */

.price-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.price-item {
    text-align: center;
}

.price-label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.price-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--fg);
}

.price-change.positive {
    color: #26a69a;
}

.price-change.negative {
    color: #ef5350;
}

/* ===== Unified Component Styles ===== */
/* Status badges */
.positive {
    color: var(--success);
}

.negative {
    color: var(--danger);
}

.neutral {
    color: var(--muted);
}

/* Status badges with background */
.status-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-healthy {
    background: color-mix(in srgb, var(--success), transparent 80%);
    color: var(--success);
}

.status-warning {
    background: color-mix(in srgb, var(--warning), transparent 80%);
    color: var(--warning);
}

.status-critical {
    background: color-mix(in srgb, var(--danger), transparent 80%);
    color: var(--danger);
}

.status-unknown {
    background: color-mix(in srgb, var(--muted), transparent 80%);
    color: var(--muted);
}

/* Grid layouts */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

/* 按钮样式已移至 components.css 统一管理 */

/* Modal styles - 已移至components.css统一管理，避免样式冲突 */

.modal-content {
    background: var(--card);
    margin: 15% auto;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 80%;
    max-width: 500px;
    position: relative;
    box-shadow: var(--shadow);
}

.close {
    color: var(--muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--fg);
}

/* Loading and error states */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--muted);
    font-size: 16px;
}

.error {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    color: var(--danger);
    font-size: 16px;
    text-align: center;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .status-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        width: 95%;
        margin: 10% auto;
    }
}
