/* ── Stock 看板样式 - 自适应 H5/PC ── */

:root {
    --bg: #0f1923;
    --card-bg: #1a2736;
    --card-border: #2a3a4a;
    --text: #e0e6ed;
    --text-dim: #7a8a9a;
    --red: #e74c3c;
    --green: #2ecc71;
    --red-bg: rgba(231, 76, 60, 0.15);
    --green-bg: rgba(46, 204, 113, 0.15);
    --accent: #3498db;
    --accent-dim: #2980b9;
    --overlay-bg: rgba(0,0,0,0.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

.price-up { color: var(--red); }
.price-down { color: var(--green); }

.container {
    max-width: 2000px;
    margin: 0 auto;
    padding: 12px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.header h1 { font-size: 18px; font-weight: 600; color: var(--text); }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

#ws-status { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.ws-connected { background: var(--green-bg); color: var(--green); }
.ws-reconnecting { background: rgba(241, 196, 15, 0.15); color: #f1c40f; }
.ws-disconnected, .ws-failed { background: var(--red-bg); color: var(--red); }

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 12px;
}

.card h2 { font-size: 14px; color: var(--text-dim); margin-bottom: 12px; font-weight: 500; }

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

.account-item { text-align: center; padding: 8px; }
.account-item .label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.account-item .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.loading, .error { text-align: center; padding: 40px 16px; color: var(--text-dim); }
.error { color: var(--red); display: none; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 500px; }

thead th {
    text-align: right; padding: 8px 6px; color: var(--text-dim);
    font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}
thead th:first-child { text-align: left; }

/* 可排序列标题 */
th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.2s;
}
th.sortable:hover {
    color: var(--text);
}
th.sortable.sort-asc::after {
    content: ' \25B2';
    color: var(--accent);
    font-size: 10px;
}
th.sortable.sort-desc::after {
    content: ' \25BC';
    color: var(--accent);
    font-size: 10px;
}

tbody td {
    padding: 10px 6px; border-bottom: 1px solid rgba(42, 58, 74, 0.5);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }

/* 行可点击 */
.clickable-row { cursor: pointer; transition: background 0.2s; }
.clickable-row:hover { background: rgba(52, 152, 219, 0.08); }

td.num {
    text-align: right; font-variant-numeric: tabular-nums;
    font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
    white-space: nowrap;
}

.stock-name { text-align: left !important; }
.stock-code { font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace; font-size: 12px; color: var(--text-dim); }
.stock-name-text { font-size: 13px; font-weight: 500; }
.latest-price { font-weight: 700; font-size: 14px; }
.profit-num { font-size: 11px; margin-top: 2px; }
.time-col { color: var(--text-dim); font-size: 11px; font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace; }

.empty { text-align: center !important; color: var(--text-dim); padding: 30px !important; }

/* 闪烁动画 */
@keyframes flash-red { 0%, 100% { background: transparent; } 50% { background: var(--red-bg); } }
@keyframes flash-green { 0%, 100% { background: transparent; } 50% { background: var(--green-bg); } }
.flash.price-up { animation: flash-red 0.5s ease-in-out; border-radius: 4px; padding: 0 4px; }
.flash.price-down { animation: flash-green 0.5s ease-in-out; border-radius: 4px; padding: 0 4px; }

/* ── 详情弹窗 ── */
.detail-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.detail-panel {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 12px; max-width: 520px; width: 100%;
    max-height: 80vh; overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.detail-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; border-bottom: 1px solid var(--card-border);
}

.detail-header span { font-size: 16px; font-weight: 600; }
.detail-close {
    background: none; border: none; color: var(--text-dim);
    font-size: 24px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.detail-close:hover { color: var(--text); }

/* ── 确认弹窗 ── */
.confirm-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; align-items: center; justify-content: center;
    padding: 16px;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.confirm-dialog {
    background: var(--card-bg); border: 1px solid var(--card-border);
    border-radius: 12px; max-width: 360px; width: 100%;
    padding: 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    text-align: center;
}
.confirm-title {
    font-size: 16px; font-weight: 600; color: var(--text);
    margin-bottom: 12px;
}
.confirm-message {
    font-size: 14px; color: var(--text-dim);
    margin-bottom: 20px;
}
.confirm-actions {
    display: flex; gap: 12px; justify-content: center;
}
.confirm-btn {
    padding: 8px 24px; border: none; border-radius: 6px;
    font-size: 14px; cursor: pointer; transition: opacity 0.2s;
}
.confirm-btn:hover { opacity: 0.85; }
.confirm-btn-cancel {
    background: var(--card-border); color: var(--text);
}
.confirm-btn-ok {
    background: #e74c3c; color: white;
}

.detail-body { padding: 12px 16px 16px; }

.detail-row {
    display: flex; justify-content: space-between;
    padding: 6px 0; border-bottom: 1px solid rgba(42,58,74,0.3);
    font-size: 13px; line-height: 1.6;
}
.detail-row:last-child { border-bottom: none; }

.detail-label { color: var(--text-dim); flex-shrink: 0; margin-right: 12px; }
.detail-value { text-align: right; word-break: break-all; max-width: 60%; }
.detail-value.wrap { text-align: left; word-break: break-word; max-width: 90%; }

.detail-section {
    margin-top: 12px; padding-top: 10px;
    border-top: 1px solid var(--card-border);
}
.detail-section-title { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 6px; }

.footer { text-align: center; padding: 16px; font-size: 11px; color: var(--text-dim); }

/* ── 响应式 ── */
@media (min-width: 768px) {
    .container { padding: 20px 24px; }
    .header h1 { font-size: 22px; }
    .account-item .value { font-size: 26px; }
    table { font-size: 14px; }
    .latest-price { font-size: 15px; }
    thead th, tbody td { padding: 10px 12px; }
    .detail-panel { max-width: 520px; }
}

@media (min-width: 1024px) {
    .account-grid { gap: 24px; }
    .account-item { padding: 12px; }
}

/* ── 移动端适配 ── */
@media (max-width: 767px) {
    .container { padding: 8px; }
    .header h1 { font-size: 15px; }
    .header-right { font-size: 11px; gap: 6px; }
    .card { padding: 10px; border-radius: 8px; }
    .card h2 { font-size: 13px; margin-bottom: 8px; }
    
    /* 账户概览 2列 */
    .account-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .account-item { padding: 4px; }
    .account-item .value { font-size: 16px; }
    .account-item .label { font-size: 11px; }
    
    /* 手机端隐藏表格 (使用卡片) */
    .table-wrap { display: none; }
    #clearing-cards { display: block; }
    
    /* 表格紧凑 */
    table { font-size: 11px; min-width: 600px; }
    thead th { padding: 6px 3px; font-size: 10px; }
    tbody td { padding: 7px 3px; }
    .stock-code { font-size: 10px; }
    .stock-name-text { font-size: 11px; }
    .latest-price { font-size: 12px; }
    

    /* 详情弹窗居中 */
    .detail-overlay { padding: 12px; align-items: center; }
    .detail-panel { max-width: 96%; max-height: 90vh; border-radius: 12px; }
    .detail-body { padding: 10px 14px 14px; }
    .detail-row { font-size: 12px; }
}

/* ── 超小屏 ── */
@media (max-width: 420px) {
    .account-grid { grid-template-columns: repeat(2, 1fr); gap: 4px; }
    .account-item .value { font-size: 14px; }
    table { font-size: 10px; min-width: 520px; }
    thead th { padding: 4px 2px; font-size: 9px; }
    tbody td { padding: 5px 2px; }
    .header h1 { font-size: 13px; }
}
/* ── 持仓卡片 (移动端) ── */
.pos-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: background 0.2s;
}
.pos-card:active { background: rgba(52, 152, 219, 0.1); }
.pos-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--card-border);
}
.pos-card-header .stock-code { font-size: 12px; }
.pos-card-header .stock-name-text { font-size: 14px; font-weight: 600; }
.pos-card-body { display: flex; flex-direction: column; gap: 6px; }
.pos-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.pos-card-label {
    font-size: 11px;
    color: var(--text-dim);
    min-width: 32px;
}
.pos-card-val {
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    font-family: "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
    text-align: right;
    min-width: 60px;
}
.pos-card-val.price-up { color: var(--red); }
.pos-card-val.price-down { color: var(--green); }
.clickable-card { cursor: pointer; }

#positions-cards { display: flex; flex-direction: column; align-items: center; }
#clearing-cards { display: flex; flex-direction: column; align-items: center; }
.pos-card { width: 96%; max-width: 450px; }

@media (min-width: 768px) {
    #positions-cards { display: none; }
    #clearing-cards { display: none; }
}

/* ── 交易弹窗 ── */
.trade-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
    display: none; align-items: center; justify-content: center;
    padding: 16px;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
.trade-panel {
    background: var(--card-bg, #1a2430);
    border: 1px solid var(--card-border, #2a3a4a);
    border-radius: 12px;
    width: 100%; max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.trade-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 18px; border-bottom: 1px solid rgba(42,58,74,0.4);
    font-size: 15px; font-weight: bold;
}
.trade-close {
    background: none; border: none; color: var(--text-dim);
    font-size: 22px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.trade-body { padding: 16px 18px; }
.trade-field { margin-bottom: 12px; }
.trade-field label {
    display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px;
}
.trade-field input {
    width: 100%; box-sizing: border-box;
    background: rgba(255,255,255,0.06); border: 1px solid var(--card-border);
    border-radius: 6px; color: var(--text); padding: 8px 10px; font-size: 14px;
    outline: none;
}
.trade-field input:focus { border-color: #667eea; }
.trade-field input[readonly] { opacity: 0.7; }
.trade-hint {
    font-size: 12px; color: var(--text-dim); line-height: 1.5;
    background: rgba(102,126,234,0.08); border-radius: 6px; padding: 8px 10px;
    margin-top: 4px;
}
.trade-actions {
    display: flex; justify-content: center; gap: 10px;
    padding: 12px 18px 18px;
}

/* 持仓列表操作按钮 */
.trade-btn {
    background: #e74c3c; color: white; border: none;
    border-radius: 4px; padding: 4px 12px;
    font-size: 12px; cursor: pointer; white-space: nowrap;
}
.trade-btn:hover { opacity: 0.85; }

/* 交易弹窗：代码输入下方股票名称提示 */
.trade-name-hint {
    font-size: 13px; color: #7ee787; margin-top: 4px; min-height: 16px;
}
.trade-name-hint:empty { display: none; }
