/* ============================
   全局变量和主题配置
   ============================ */
:root {
    /* 主要颜色配置 */
    --primary-color: #3498db;    /* 主题色：蓝色 */
    --background-color: #ffffff; /* 背景色：白色 */
    --text-color: #333;         /* 文字颜色：深灰色 */
    --border-color: #eaeaea;    /* 边框颜色：浅灰色 */
    --positive-color: #27ae60;  /* 正值颜色：绿色 */
    --negative-color: #e74c3c;  /* 负值颜色：红色 */
    --hover-color: #f5f5f5;     /* 悬停颜色：超浅灰色 */
    --group-highlight-color: rgba(52, 152, 219, 0.05); /* 分组高亮颜色 */
}

/* 重置默认样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box; /* 使用更合理的盒模型 */
}

/* 基础页面样式 */
body {
    /* 系统默认字体栈，确保在不同操作系统下都有良好的显示效果 */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.4;           /* 行高：适中的阅读体验 */
    color: var(--text-color);   /* 使用主题文字颜色 */
    background-color: var(--background-color);
    font-size: 13px;           /* 基础字体大小 */
    margin: 0;
    min-height: 100vh; /* 确保页面至少有一屏高度 */
}

/* 页面容器 */
.container {
    max-width: 1200px;         /* 最大宽度限制 */
    margin: 0 auto;            /* 水平居中 */
    padding: 10px;             /* 内边距 */
}

/* ============================
   筛选栏组件样式
   ============================ */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
    gap: 15px;
}

.mcap-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-right: 8px;
}

.clickable-header {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.mode-toggle {
    cursor: pointer;
    margin-left: 3px;
    font-weight: bold;
    font-size: 14px;
    color: #555;
    transition: all 0.2s;
    border: none;
    background: none;
    padding: 0;
}

.mode-toggle:hover {
    color: #333;
}

/* 交易所筛选器组 */
.exchange-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 200px;
}

/* 筛选控件容器 */
.filter-controls {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: nowrap;
}

/* 复选框容器 */
.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;          /* 提升可点击区域的用户体验 */
}

.checkbox-container input {
    margin-right: 4px;        /* 复选框和文字的间距 */
}

/* 未平仓量筛选器和成交量筛选器 */
.oi-filter, .volume-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

/* OI/Cap 和 Vol/Cap 筛选器样式 */
.oi-cap-filter, .volume-cap-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.oi-cap-filter input[type="text"], 
.volume-cap-filter input[type="text"] {
    min-width: 48px;
    width: 3ch; /* 初始宽度约为5个字符 */
    padding: 4px 2px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 12px;
}

/* 当输入框获得焦点时自动扩展 */
.oi-cap-filter input[type="text"]:focus, 
.volume-cap-filter input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
    width: 8ch; /* 获得焦点时扩展到约8个字符宽度 */
}

/* APR筛选器 */
.apr-filter {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.apr-filters-container {
    display: flex;
    gap: 15px;
}

.apr-positive, .apr-negative {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 滑动条样式 */
.oi-filter input[type="range"],
.volume-filter input[type="range"],
.apr-filter input[type="range"] {
    width: 80px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* 搜索框样式 */
.search-box {
    min-width: 150px;
}

.search-box input {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 100%;
}

/* 最后更新时间显示 */
.last-updated {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
}

/* ============================
   加载状态组件
   ============================ */
.loading-indicator {
    text-align: center;
    padding: 20px;
}

/* 加载动画 */
.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 3px solid var(--primary-color); /* 动画主色 */
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* 旋转动画定义 */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================
   错误提示样式
   ============================ */
.error-message {
    background-color: #ffebee; /* 淡红色背景 */
    color: #c62828;           /* 深红色文字 */
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    text-align: center;
    font-size: 12px;
}

/* ============================
   数据表格样式
   ============================ */
.data-table-container {
    overflow-x: auto;         /* 允许横向滚动 */
}

/* 表格基础样式 */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    line-height: 1.2;
}

/* 表格单元格通用样式 */
.data-table th,
.data-table td {
    padding: 4px 8px;
    text-align: left;
}

/* 表头样式 */
.data-table th {
    font-weight: 500;
    cursor: pointer;          /* 可点击排序 */
    user-select: none;        /* 禁止文字选择 */
    color: #666;
    border-bottom: 1px solid #eee;
    padding-bottom: 6px;
}

/* 表头悬停效果 */
.data-table th:hover {
    color: #333;              /* 加深颜色 */
}

/* 表格行悬停效果 */
.data-table tbody tr:hover {
    background-color: var(--hover-color);
}

/* 正负值颜色标识 */
.data-table .positive {
    color: var(--positive-color);
}

.data-table .negative {
    color: var(--negative-color);
}

/* 数字列对齐方式 */
.data-table td:nth-child(7),  /* APR */
.data-table td:nth-child(8),  /* Funding */
.data-table td:nth-child(9),  /* Next Time */
.data-table td:nth-child(10), /* Swap Bid */
.data-table td:nth-child(11), /* Spot Ask */
.data-table td:nth-child(12)  /* Open diff */ {
    text-align: right;        /* 数字右对齐 */
    padding-right: 12px;      /* 增加右侧padding */
}

/* 对应的表头也右对齐 */
.data-table th:nth-child(7),
.data-table th:nth-child(8),
.data-table th:nth-child(9),
.data-table th:nth-child(10),
.data-table th:nth-child(11),
.data-table th:nth-child(12) {
    text-align: right;
    padding-right: 12px;
}

/* 时间列对齐方式 */
.data-table .time-cell {
    text-align: right;         /* 左对齐 */
    white-space: pre;         /* 保留空格 */
    width: 120px;            /* 固定宽度 */
    min-width: 120px;        /* 最小宽度 */
}

/* ============================
   响应式布局适配
   ============================ */
@media (max-width: 1200px) {
    .filter-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .filter-controls {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .exchange-filters {
        width: 100%;
    }
    
    .apr-filters-container {
        flex-direction: column;
        gap: 8px;
    }
}

/* 资金费率链接样式 */
.funding-rate-link {
    text-decoration: none;
    display: flex;
    justify-content: right;
    align-items: center;
    width: 100%;
    cursor: pointer;
}

.toggle-icon {
    font-size: 10px;
    margin-left: 4px;
}

/* 图表行样式 */
.chart-row {
    background-color: #ffffff;
    transition: all 0.3s ease;
    padding: 0;
    margin: 0;
}

.chart-container {
    padding: 0;
    position: relative;
    background-color: #ffffff;
    border: none;
    margin: 0;
}

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

.chart-title {
    font-weight: bold;
    display: flex;
    align-items: center;
}

.close-btn {
    margin-left: 10px;
    padding: 2px 8px;
    background: #e9ecef;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.close-btn:hover {
    background: #dee2e6;
}

.chart-stats {
    display: flex;
    gap: 15px;
}

.stat-item {
    display: flex;
    align-items: center;
}

.stat-label {
    margin-right: 5px;
    color: #6c757d;
}

.stat-value {
    font-weight: bold;
}

.chart-body {
    height: 150px;
    position: relative;
    margin: 0;
    padding: 0;
    border: none;
}

.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-stats {
        margin-top: 10px;
    }
    
    .chart-body {
        height: 150px;
    }
}

/* 调试控制样式 */
.debug-controls {
    margin-top: 10px;
    padding: 5px;
    background-color: #f0f0f0;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.debug-button {
    padding: 5px 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.debug-button:hover {
    background-color: #0056b3;
}

.connected {
    color: green;
    font-weight: bold;
}

.disconnected {
    color: red;
    font-weight: bold;
}

/* 图表样式 */
.chart-container {
    position: relative;
    width: 100%;
    padding: 0;
    background-color: #ffffff;
    border-radius: 0;
    margin: 0;
    box-shadow: none;
}

.chart-body {
    height: 300px;
    position: relative;
}

.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid #3498db;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

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

.price-link {
    text-decoration: none;  /* 去除下划线 */
    color: inherit;         /* 使用继承的颜色 */
    display: flex;
    justify-content: right ;
    align-items: center;
    width: 100%;
    cursor: pointer;
}

/* 币种名称样式 */
.coin-name {
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.coin-name:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.active-coin {
    font-weight: bold;
    background-color: rgba(52, 152, 219, 0.1);
}

.highlight-row {
    background-color: var(--group-highlight-color);
}

html {
    overflow-y: scroll; /* 始终显示垂直滚动条 */
    padding-left: calc(100vw - 100%); /* 防止滚动条出现时页面发生位移 */
}
