/* ==============================================
   散户之家 — 暗黑专业盯盘版（游资风）
   深色背景 · 高对比 · 红绿分明 · 数据优先
   ============================================== */

/* ---------- CSS变量 ---------- */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --bg-hover: #1f2940;
    --bg-hover-light: rgba(255,255,255,0.04);
    --bg-input: #0d1117;
    
    --border: #1e2a3a;
    --border-light: #1a2332;
    --border-hover: #2a3a50;
    
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.1);
    --green: #22c55e;
    --green-bg: rgba(34,197,94,0.1);
    --yellow: #eab308;
    --yellow-bg: rgba(234,179,8,0.1);
    --blue: #3b82f6;
    --blue-bg: rgba(59,130,246,0.1);
    --purple: #a78bfa;
    --purple-bg: rgba(167,139,250,0.1);
    
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-card: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
    --radius: 10px;
    --radius-sm: 6px;
    
    --font: "Inter", "PingFang SC", "Microsoft YaHei", "-apple-system", "BlinkMacSystemFont", sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", "Consolas", monospace;
}

/* ---------- 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16.5px; scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: #60a5fa; }
img { max-width: 100%; }
ul, ol { list-style: none; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- 布局 ---------- */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================
   顶栏（紧凑版）
   ============================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10,14,23,0.92);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    height: 44px;
    gap: 6px;
}

/* Logo */
.topbar-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none !important;
    flex-shrink: 0;
    margin-right: 20px;
}
.topbar-logo-icon { font-size: 1.3rem; line-height: 1; }
.topbar-logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1px;
}

/* 导航 */
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    justify-content: center;
}
.topbar-nav a {
    padding: 4px 13px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none !important;
    border-radius: 4px;
    white-space: nowrap;
    transition: all 0.15s;
    line-height: 1.6;
}
.topbar-nav a:hover {
    color: var(--text-primary);
    background: var(--bg-hover-light);
}
.topbar-nav a.active {
    color: var(--text-primary);
    background: var(--bg-hover-light);
}

/* 右侧 */
.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.topbar-btn {
    padding: 4px 15px;
    background: var(--blue);
    color: #fff !important;
    font-size: 0.88rem;
    font-weight: 600;
    border-radius: 4px;
    text-decoration: none !important;
}
.topbar-link {
    color: var(--text-secondary) !important;
    font-size: 0.9rem;
    text-decoration: none !important;
}
.topbar-link:hover { color: var(--text-primary) !important; }
.topbar-icon {
    font-size: 0.95rem;
    text-decoration: none !important;
    padding: 2px 5px;
    border-radius: 3px;
}
.topbar-icon:hover { background: var(--bg-hover-light); }
.topbar-user {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-right: 3px;
}
.topbar-role {
    display: inline-block;
    background: var(--yellow-bg);
    color: var(--yellow);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0 7px;
    border-radius: 8px;
    line-height: 1.5;
}

/* 移动端 */
@media (max-width: 860px) {
    .topbar-inner { padding: 0 10px; gap: 4px; }
    .topbar-nav { gap: 0; }
    .topbar-nav a { padding: 3px 8px; font-size: 0.85rem; }
    .topbar-logo-text { font-size: 0.95rem; }
}

/* ============================================
   页面标题
   ============================================ */
.page-header {
    padding: 30px 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}
.page-header h1 {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--text-primary);
}
.page-header .subtitle {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ============================================
   卡片系统
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: border-color 0.18s;
}
.card:hover {
    border-color: var(--border-hover);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.card-link {
    font-size: 0.85rem;
    color: var(--blue);
    font-weight: 500;
}
.card-link:hover { color: #60a5fa; }

.card-grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============================================
   大盘指数卡片
   ============================================ */
.index-card { text-align: center; padding: 22px 18px; }
.index-card .index-name { font-size: 0.88rem; color: var(--text-secondary); margin-bottom: 4px; }
.index-card .index-price { font-size: 2rem; font-weight: 700; font-family: var(--font-mono); }
.index-card .index-change { font-size: 1rem; font-weight: 600; font-family: var(--font-mono); }

/* 涨跌色 */
.up { color: var(--red); }
.down { color: var(--green); }

/* ============================================
   情绪仪表盘
   ============================================ */
.sentiment-gauge {
    display: flex;
    align-items: center;
    gap: 18px;
}
.gauge-ring {
    width: 90px;
    height: 90px;
    position: relative;
    flex-shrink: 0;
}
.gauge-ring svg { transform: rotate(-90deg); }
.gauge-ring .bg-circle { fill: none; stroke: var(--bg-hover); stroke-width: 7; }
.gauge-ring .value-circle {
    fill: none;
    stroke-width: 7;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}
.gauge-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-mono);
}
.gauge-level { font-size: 1.1rem; font-weight: 600; margin-bottom: 5px; }
.gauge-stats { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.gauge-stats-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 4px; border-bottom: 1px solid var(--border-light); }
.gauge-stats-row:last-child { border-bottom: none; }
.gauge-stats-row .label { color: var(--text-secondary); }
.gauge-stats-row .num { color: var(--text-primary); font-weight: 600; font-family: var(--font-mono); font-size: 0.95em; }

/* ============================================
   表格
   ============================================ */
.table-wrapper { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
.data-table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.data-table td {
    padding: 9px 11px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}
.data-table tr:hover td { background: var(--bg-hover-light); }
.data-table .code { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.85rem; }
.data-table .price { font-family: var(--font-mono); font-weight: 600; font-size: 1.05em; }
.data-table .pct { font-family: var(--font-mono); font-weight: 600; font-size: 1.05em; }
.data-table .pct.up { color: var(--red); }
.data-table .pct.down { color: var(--green); }

/* ============================================
   连板梯队
   ============================================ */
.echelon-row {
    display: flex;
    align-items: center;
    padding: 7px 14px;
    border-bottom: 1px solid var(--border-light);
    gap: 8px;
}
.echelon-row:last-child { border-bottom: none; }
.echelon-row:hover { background: var(--bg-hover-light); }
.echelon-badge {
    display: inline-block;
    background: linear-gradient(135deg, #dc2626, #f87171);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 2px 10px;
    border-radius: 8px;
    min-width: 40px;
    text-align: center;
}
.echelon-count {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 28px;
}
.echelon-stocks { display: flex; flex-wrap: wrap; gap: 4px 7px; flex: 1; }
.echelon-stock {
    font-size: 0.85rem;
    padding: 2px 7px;
    background: var(--red-bg);
    border-radius: 3px;
    color: var(--red);
    white-space: nowrap;
}
.echelon-stock:hover {
    background: rgba(239,68,68,0.2);
    text-decoration: none;
}

.index-sentiment .idx-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
}
.index-sentiment .idx-row:last-child {
    border-bottom: none;
}

/* ============================================
   标签
   ============================================ */
.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 16px;
    font-size: 0.75rem;
    font-weight: 500;
}
.tag-up { background: var(--red-bg); color: var(--red); }
.tag-down { background: var(--green-bg); color: var(--green); }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tag-yellow { background: var(--yellow-bg); color: var(--yellow); }
.tag-purple { background: var(--purple-bg); color: var(--purple); }

/* ============================================
   表单
   ============================================ */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-family: var(--font);
    transition: border-color 0.18s;
    outline: none;
}
.form-input:focus, .form-textarea:focus {
    border-color: var(--blue);
}
.form-textarea { min-height: 110px; resize: vertical; }
.form-input-sm { padding: 5px 9px; font-size: 0.82rem; }

/* ============================================
   按钮
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 9px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    font-family: var(--font);
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
    background: transparent;
    border-color: var(--border);
    color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-hover-light); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-lg { padding: 14px 30px; font-size: 1rem; }

/* ============================================
   帖子卡片（社区）
   ============================================ */
.post-card { padding: 14px 18px; }
.post-card .post-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.post-card .post-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.post-card .post-excerpt {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.post-card .post-footer {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============================================
   交割单分析
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
}
.stat-card {
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}
.stat-card .stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-family: var(--font-mono);
}
.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* ============================================
   实用工具
   ============================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.82rem; }
.font-mono { font-family: var(--font-mono); }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================
   底部
   ============================================ */
.footer {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    padding: 24px 20px;
    margin-top: 40px;
    text-align: center;
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}
.footer p { margin: 5px 0; }
.footer .risk { color: var(--yellow); font-weight: 500; }
.footer .source { color: var(--text-muted); font-size: 0.78rem; }

/* ============================================
   分页 / 模态框 / 加载 / 空状态 / Alert
   ============================================ */
.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin: 20px 0;
}
.pagination a, .pagination span {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.pagination a:hover { background: var(--bg-hover-light); color: var(--text-primary); text-decoration: none; }
.pagination .active { background: var(--blue); color: #fff; border-color: var(--blue); }

.modal-overlay { display: none; position: fixed; top:0; left:0; right:0; bottom:0; background: rgba(0,0,0,0.6); z-index: 200; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal-content { background: var(--bg-card); border-radius: var(--radius); padding: 24px; max-width: 460px; width: 90%; max-height: 80vh; overflow-y: auto; border: 1px solid var(--border); }

.loading { text-align: center; padding: 36px 20px; color: var(--text-muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-state p { font-size: 0.92rem; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 14px; line-height: 1.5; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.25); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,0.25); }
.alert-info { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59,130,246,0.25); }

/* 快速概览（复盘页） */
.quick-glance {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
.quick-item {
    text-align: center;
    padding: 10px 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
}
.quick-value { font-size: 1.3rem; font-weight: 700; }
.quick-label { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }

/* 复盘模板网格 */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 10px;
}
.template-card {
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    padding: 12px;
    border: 1px solid var(--border-light);
    cursor: pointer;
    transition: all 0.15s;
}
.template-card:hover {
    border-color: var(--border-hover);
}

/* 个股日K线表 */
.kline-table { font-size: 0.82rem; }
.kline-table .up { color: var(--red); }
.kline-table .down { color: var(--green); }

/* 龙头页情绪总览 */
.mood-card { text-align: center; }

/* 搜索框 */
.search-box {
    display: flex;
    gap: 8px;
}
.search-box .form-input {
    flex: 1;
    max-width: 360px;
}

/* 复刻卡片（review-card） */
.review-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 14px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.review-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.review-date {
    font-weight: 700;
    font-size: 1rem;
}
.review-body {
    padding: 16px;
    line-height: 1.8;
    font-size: 0.9rem;
}
.review-body h3 {
    font-size: 0.95rem;
    margin: 14px 0 6px;
    padding-left: 8px;
    border-left: 3px solid var(--blue);
    color: var(--text-primary);
}
.review-body ul { margin: 5px 0 8px; padding-left: 18px; }
.review-body li { margin-bottom: 3px; color: var(--text-secondary); }
.review-body .highlight-up { color: var(--red); font-weight: 600; }
.review-body .highlight-down { color: var(--green); font-weight: 600; }

/* ===== PWA 移动端优化 ===== */
@media (display-mode: standalone) {
    .topbar {
        padding-top: max(8px, env(safe-area-inset-top, 0px));
    }
    .app-container {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* 移动端触控优化 */
@media (max-width: 480px) {
    .topbar-nav a {
        padding: 6px 8px;
        font-size: 0.75rem;
    }
    .topbar-logo-text {
        display: none;
    }
    .topbar-user {
        display: none;
    }
    .topbar-right {
        gap: 4px;
    }
    .card-grid.grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    .page-header h1 {
        font-size: 1.1rem;
    }
}

/* 禁止长按选择 */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 允许输入框选择 */
input, textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* 底部安全区域 */
.app-container {
    padding-bottom: env(safe-area-inset-bottom, 16px);
}
