/* 新客户活跃跟进 — 转化分析 v0.3
 * 暗黑模式 GitHub 风格深灰蓝
 * 关键设计：自适应行宽 — 容器宽度由父级布局决定，表格用 table-layout:fixed + colgroup 控宽
 */

:root {
    color-scheme: dark;
    --bg-page: #0d1117;
    --bg-elevated: #161b22;
    --bg-elevated-2: #1c2129;
    --bg-hover: #21262d;
    --bg-input: #0d1117;
    --bg-thead: #21262d;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    --border: #30363d;
    --border-strong: #424a53;

    --accent-blue: #58a6ff;
    --accent-blue-bg: #1f6feb;
    --accent-blue-bg-hover: #388bfd;

    --accent-success: #3fb950;
    --accent-warning: #d29922;
    --accent-warning-text: #e3b341;
    --accent-error: #f85149;

    --bg-warning-soft: #2a230f;
    --bg-warning-strong: #3a2f12;
    --bg-detail: #25200d;
    --bg-error-soft: #2d1419;

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    padding: 20px clamp(12px, 2vw, 32px);
    /* 防止任何子元素溢出 viewport 横向 */
    overflow-x: hidden;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ========== Header ========== */
header {
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.5rem; font-weight: 600; }
header .subtitle {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer {
    margin-top: 28px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}
footer a { color: var(--accent-blue); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ========== 步骤卡片 ========== */
.step-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.step-card h2 {
    font-size: 1.05rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.step-no {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent-blue-bg);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.form-row:last-child { margin-bottom: 0; }
.form-row > label:not(.cb) {
    color: var(--text-secondary);
    font-size: 0.88rem;
    min-width: 180px;
}
.dash { color: var(--text-muted); }

input[type="text"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 5px 9px;
    border-radius: 4px;
    font-size: 0.88rem;
    width: 150px;
}
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-blue);
}
#search-box { flex: 1; min-width: 220px; max-width: 480px; }

.multi-check {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
    flex: 1;
}
.cb {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    font-size: 0.88rem;
}
.cb input[type="checkbox"] { cursor: pointer; accent-color: var(--accent-blue); }
.cb .muted { color: var(--text-muted); font-size: 0.78rem; font-style: normal; }
.cb .phone {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: ui-monospace, "Consolas", monospace;
    font-style: normal;
}
.cb.unmatched { opacity: 0.55; cursor: not-allowed; }
.cb.unmatched .warn {
    color: var(--accent-warning);
    font-style: normal;
    font-size: 0.78rem;
}

.btn-sm {
    background: var(--accent-blue-bg);
    color: #fff;
    border: none;
    font-size: 0.78rem;
    padding: 3px 10px;
    margin-left: 8px;
    border-radius: 3px;
    cursor: pointer;
    vertical-align: baseline;
}
.btn-sm:hover {
    background: var(--accent-blue-bg-hover);
}

button {
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.9rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent-blue-bg); color: white; }
button.primary:hover:not(:disabled) { background: var(--accent-blue-bg-hover); }
button.secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
button.secondary:hover:not(:disabled) { background: var(--bg-elevated-2); }

.status { color: var(--text-secondary); font-size: 0.86rem; }
.status.error { color: var(--accent-error); }
.status strong { color: var(--accent-blue); }
.muted { color: var(--text-muted); font-size: 0.83rem; }
.error { color: var(--accent-error); }

.empty-hint {
    background: var(--bg-warning-soft);
    border-left: 4px solid var(--accent-warning);
    padding: 12px 14px;
    border-radius: 4px;
    margin: 8px 0;
}
.empty-rows {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
}

/* ========== 候选客户表（步骤2，4 列，双击触发） ========== */
.scroll-table {
    margin-top: 8px;
    max-height: 480px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}
#candidates-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 0.88rem;
}
/* 列宽规划：序号窄 → 类型(emoji) → 客户名 → 地区 → 5个指标列 → 业态/经手/注册收尾 */
#candidates-table .col-idx       { width: 48px; }
#candidates-table .col-tag       { width: 40px; text-align: center; }
#candidates-table .col-cust-name { width: 12%; min-width: 80px; }
#candidates-table .col-region    { width: 8%; min-width: 60px; }
#candidates-table .col-metric    { width: 7.5%; min-width: 56px; }
#candidates-table .col-btype     { width: 6%; min-width: 52px; }
#candidates-table .col-cats      { width: 13%; min-width: 120px; }
#candidates-table .col-handler   { width: 5%; min-width: 44px; }
#candidates-table .col-reg       { width: 6.5%; min-width: 86px; }

.cand-tag {
    display: inline-block;
    min-width: 1.4em;
    text-align: center;
    font-size: 1.05rem;
    line-height: 1;
}
.cand-tag-new::before { content: "·"; color: var(--text-muted); }

.reactivation-hint {
    background: rgba(230, 168, 23, 0.08);
    border-left: 3px solid #e6a817;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.88rem;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.reactivation-hint-icon {
    font-size: 1.1rem;
}
.reactivation-hint-missing {
    color: #e6a817;
}
.reactivation-hint-btypes {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}
.reactivation-quick-add {
    background: rgba(230, 168, 23, 0.12);
    border: 1px solid #e6a817;
    color: #e6a817;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.82rem;
    cursor: pointer;
}
.reactivation-quick-add:hover {
    background: #e6a817;
    color: #fff;
}

.customer-metric {
    color: #e6a817;
    font-weight: 700;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, "Consolas", monospace;
    white-space: nowrap;
}
.customer-metric.muted {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.82rem;
}

@media (prefers-color-scheme: dark) {
    .customer-metric {
        color: #f0c040;
    }
}

/* 可排序列头 */
.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
}
.sortable:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.sort-arrow {
    font-size: 0.7rem;
    color: var(--accent-blue);
    margin-left: 2px;
}

/* 序号列单元格：右对齐 + 等宽数字，便于纵向扫读 */
#candidates-table tbody td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, "Consolas", monospace;
    color: var(--text-secondary);
}

#candidates-table thead th {
    background: var(--bg-thead);
    padding: 8px 10px;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}
#candidates-table tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: middle;
}
#candidates-table tbody tr {
    cursor: pointer;
    user-select: none;
}
#candidates-table tbody tr:hover { background: var(--bg-hover); }
#candidates-table tbody tr:active { background: var(--bg-elevated-2); }
#candidates-table .customer-name {
    color: var(--accent-blue);
    font-weight: 500;
}
.mono { font-family: ui-monospace, "Consolas", monospace; font-size: 0.82rem; white-space: nowrap; }

/* ===== 注册后未下单表：列只有 7 个、空间充裕，横向留白放宽便于阅读 ===== */
#noorder-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
#noorder-table thead th {
    background: var(--bg-thead);
    padding: 10px 20px;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}
#noorder-table tbody td {
    padding: 9px 20px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
/* 纯展示表：仅悬停高亮便于横向读行，不显示可点击光标 */
#noorder-table tbody tr:hover { background: var(--bg-hover); }
#noorder-table .col-idx { width: 56px; }
#noorder-table td.num {
    text-align: right;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-family: ui-monospace, "Consolas", monospace;
}
#noorder-table .customer-name { color: var(--text-primary); font-weight: 600; }

/* ========== 汇总面板（步骤3 内嵌，自动跟随过滤刷新）========== */
.summary-panel {
    margin-top: 14px;
    padding: 12px 14px;
    background: var(--bg-elevated-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    border-left: 3px solid var(--accent-blue);
}
.sp-loading, .sp-error {
    padding: 10px;
    text-align: center;
    color: var(--text-secondary);
}
.sp-error { color: var(--accent-error); }
.sp-content.loading-faded { opacity: 0.5; }

.sp-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-bottom: 12px;
    align-items: baseline;
    font-size: 0.9rem;
}
.sp-stat { color: var(--text-secondary); }
.sp-stat strong {
    color: var(--text-primary);
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}
.sp-stat .sp-v-active { color: var(--accent-success); }
.sp-stat .sp-v-inactive { color: var(--text-secondary); }
.sp-stat em { font-style: normal; }
.sp-sep { color: var(--text-muted); padding: 0 2px; }

.sp-section { margin-top: 12px; }
.sp-title {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

/* 活跃度桶柱条 */
.sp-bar-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 720px;
}
.sp-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
}
.sp-bar-label {
    width: 130px;
    color: var(--text-secondary);
    flex-shrink: 0;
}
.sp-bar-track {
    flex: 1;
    height: 16px;
    background: var(--bg-page);
    border-radius: 2px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.sp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue-bg), var(--accent-blue));
    transition: width 0.3s;
}
.sp-bar-count {
    width: 50px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    font-weight: 600;
}

/* 业态分布表 */
.sp-table {
    width: 100%;
    max-width: 560px;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.sp-table th, .sp-table td {
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.sp-table th {
    background: var(--bg-thead);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
}
.sp-table .numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.sp-actions {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.sp-actions .muted { margin-left: auto; }

/* ========== Customer Page (独立浏览器标签页) ========== */
header.cp-header {
    position: relative;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.cp-back {
    position: absolute;
    top: 0; right: 0;
    display: flex;
    gap: 8px;
}
.cp-link, .cp-close {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 5px 12px;
    font-size: 0.85rem;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
}
.cp-link:hover, .cp-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
#cp-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 160px;  /* 给右上角按钮留位置 */
}
.cp-header .subtitle {
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ========== 客户详情 Tab 区（已废弃保留，向后兼容） ========== */
.ct-region {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 16px 0;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.ct-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-elevated-2);
    border-bottom: 1px solid var(--border);
    align-items: center;
    min-height: 40px;
}
.ct-empty {
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 4px 4px;
}
.ct-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 4px 6px 12px;
    font-size: 0.88rem;
    border-radius: 4px;
    cursor: pointer;
    max-width: 240px;
    transition: background 0.15s;
}
.ct-tab:hover:not(.active) { background: var(--bg-hover); }
.ct-tab.active {
    background: var(--bg-warning-soft);
    border-color: var(--accent-warning);
    color: var(--text-primary);
    font-weight: 600;
}
.ct-tab .ct-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}
.ct-tab .ct-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    border-radius: 3px;
    transition: background 0.1s;
}
.ct-tab .ct-close:hover {
    background: var(--accent-error);
    color: white;
}
.ct-content {
    padding: 14px 18px;
    /* 让内部表格按容器宽度（不会被任何子元素撑大） */
    min-width: 0;
    overflow: hidden;
}

/* ========== 客户 Tab 内容 ========== */
.ct-tab-content {
    width: 100%;
    min-width: 0;
}
.ct-info h3 {
    color: var(--text-primary);
    font-size: 1.15rem;
    margin-bottom: 8px;
}
.ct-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-bottom: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}
.ct-meta strong { color: var(--text-primary); }
.ct-meta .mono { font-size: 0.85rem; color: var(--text-primary); }

.ct-summary {
    background: var(--bg-warning-soft);
    border-left: 3px solid var(--accent-warning);
    padding: 10px 14px;
    color: var(--accent-warning-text);
    font-size: 0.92rem;
    margin-bottom: 14px;
    border-radius: 4px;
    line-height: 1.7;
}
.ct-summary strong { color: var(--text-primary); }
.ct-dates {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: ui-monospace, "Consolas", monospace;
}

.detail-section { margin-top: 14px; }
.ds-title {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.94rem;
}
.detail-empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 14px;
    text-align: center;
}

/* ========== 详情表（订单明细 + 产品汇总） ==========
   核心：table-layout: fixed + colgroup 控宽 + 商品名称弹性 */
table.detail-table {
    width: 100%;
    background: var(--bg-elevated-2);
    border-collapse: collapse;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    table-layout: fixed;
}
table.detail-table thead {
    background: var(--bg-thead);
}
table.detail-table th, table.detail-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: top;
    color: var(--text-primary);
    text-align: left;
}
table.detail-table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
table.detail-table tbody tr:hover { background: var(--bg-hover); }
table.detail-table .numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-family: ui-monospace, "Consolas", monospace;
    font-size: 0.83rem;
}
table.detail-table .center { text-align: center; }
table.detail-table .mono {
    font-family: ui-monospace, "Consolas", monospace;
    font-size: 0.8rem;
    /* 单据编号 / 日期 等：默认允许在任意字符断行，避免内容超过列宽时溢出叠到下一列 */
    word-break: break-all;
    overflow-wrap: anywhere;
    line-height: 1.3;
}
table.detail-table tr.sub-row td {
    border-top: none;
    color: var(--text-secondary);
}
table.detail-table tfoot tr.detail-total-row td {
    background: var(--bg-warning-strong);
    border-top: 2px solid var(--accent-warning);
    padding: 8px 10px;
    font-size: 0.86rem;
    color: var(--accent-warning-text);
}
table.detail-table tfoot tr.detail-total-row td strong {
    color: var(--accent-warning);
}

/* colgroup 列宽
   - 默认（宽屏 ≥ 1280px）
   - c-name 不设宽度 → 自动占用剩余 */
.detail-table col.c-idx  { width: 40px; }
.detail-table col.c-num  { width: 145px; }
.detail-table col.c-date { width: 88px; }
.detail-table col.c-qty  { width: 75px; }
.detail-table col.c-amt  { width: 95px; }
.detail-table col.c-cnt  { width: 65px; }
.detail-table col.c-flag { width: 60px; }

/* 中宽屏 (900-1280px) */
@media (max-width: 1280px) {
    .detail-table col.c-num  { width: 120px; }
    .detail-table col.c-amt  { width: 88px; }
    .detail-table col.c-qty  { width: 70px; }
}

/* 窄屏 (<900px)：单号 / 数值列固定，详情表 min-width 较大，让商品名拿足空间多行展开 */
@media (max-width: 900px) {
    .detail-table col.c-num  { width: 135px; }
    .detail-table col.c-date { width: 82px; }
    .detail-table col.c-qty  { width: 60px; }
    .detail-table col.c-amt  { width: 78px; }
    .detail-table col.c-flag { width: 52px; }
    .detail-table col.c-idx  { width: 36px; }
    table.detail-table { font-size: 0.78rem; min-width: 780px; }
    /* 商品名称单元格：明显的多行换行，行间距充裕，更易阅读 */
    table.detail-table tbody td:not(.numeric):not(.mono):not(.center) {
        line-height: 1.45;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

/* ========== Loading / Error ========== */
.loading {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
}
.error-region {
    background: var(--bg-error-soft);
    border: 1px solid var(--accent-error);
    border-radius: 8px;
    padding: 14px 18px;
    margin: 16px 0;
    display: flex;
    gap: 14px;
    align-items: flex-start;
}
.error-region .error-icon { font-size: 1.6rem; }
.error-region strong { color: var(--accent-error); font-size: 1.05rem; }
.error-region p { color: var(--text-primary); margin: 6px 0 10px; }

.hidden { display: none !important; }


/* ============================================================
 * 响应式（手机 / 平板）
 * 断点：≤900px 平板/大屏手机；≤600px 手机
 * 设计：标签上下堆叠；表格横向滚动 + min-width；按钮触摸 ≥36px 高
 * ============================================================ */

/* === 平板 / 大屏手机 === */
@media (max-width: 900px) {
    /* mono 单元格（单据编号 / 日期 / 商城注册时间）允许换行
     * 不写这条的话，.mono { white-space: nowrap } 会让长单号溢出盖到下一列 */
    table.detail-table td.mono,
    #candidates-table td.mono {
        white-space: normal;
        word-break: break-all;
        line-height: 1.3;
    }

    body {
        padding: 14px 12px;
    }
    header h1 { font-size: 1.3rem; }
    header .subtitle { font-size: 0.85rem; }
    .step-card { padding: 12px 14px; margin-bottom: 12px; }
    .step-card h2 { font-size: 1rem; }

    /* form-row：label 占整行，inputs 紧跟 */
    .form-row {
        gap: 6px 10px;
    }
    .form-row > label:not(.cb) {
        min-width: 100%;
        margin-bottom: 2px;
    }
    /* 日期 picker 输入框窄一点但仍可点击 */
    input[type="text"] { padding: 7px 10px; }

    /* 多 checkbox 列表更紧凑 */
    .multi-check { gap: 5px 10px; }

    /* 汇总统计：换行更紧凑 */
    .sp-stats { gap: 4px 12px; font-size: 0.86rem; }
    .sp-stat strong { font-size: 0.98rem; }

    /* 候选表压缩列宽 */
    #candidates-table .col-idx       { width: 42px; }
    #candidates-table .col-cust-name { width: 11%; min-width: 68px; }
    #candidates-table .col-region    { width: 7%; min-width: 50px; }
    #candidates-table .col-metric    { width: 8.8%; min-width: 60px; }
    #candidates-table .col-btype     { width: 6%; min-width: 48px; }
    #candidates-table .col-handler   { width: 7%; min-width: 52px; }
    #candidates-table .col-reg       { width: 6%; min-width: 60px; }
    .customer-metric { font-size: 0.82rem; }
    .customer-metric.muted { font-size: 0.74rem; }
    #candidates-table { font-size: 0.85rem; }

    /* 详情表区域开横滚（colgroup 列宽继续生效，宽度不够时左右刷） */
    .detail-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* iOS 触摸滚动 */
    }
    table.detail-table { min-width: 640px; }

    /* 业态表 */
    .sp-table { font-size: 0.82rem; }

    /* 桶分布柱条 label 略窄 */
    .sp-bar-label { width: 110px; }

    /* 客户详情页 header：close 按钮放右下而不是浮动右上 */
    .cp-back { position: static; margin-bottom: 8px; justify-content: flex-end; }
    #cp-title { margin-right: 0; font-size: 1.3rem; }
}

/* === 手机（窄）=== */
@media (max-width: 600px) {
    body {
        padding: 10px 8px;
        font-size: 14px;
    }
    header { margin-bottom: 10px; padding-bottom: 8px; }
    header h1 { font-size: 1.15rem; }
    header .subtitle { font-size: 0.78rem; line-height: 1.4; }

    .step-card { padding: 10px 12px; }
    .step-card h2 {
        font-size: 0.92rem;
        gap: 6px;
    }
    .step-no {
        width: 22px; height: 22px; font-size: 0.78rem;
    }

    /* 触摸友好的按钮 */
    button {
        padding: 8px 14px;
        font-size: 0.88rem;
        min-height: 36px;
    }
    button.row-detail-btn { min-height: 32px; padding: 5px 10px; }

    /* form-row 完全单列堆叠 */
    .form-row > label:not(.cb) {
        font-size: 0.85rem;
        margin-bottom: 0;
    }
    input[type="text"] {
        width: 100%;
        max-width: 100%;
    }
    #search-box {
        min-width: 0;
        max-width: 100%;
    }
    /* 日期起止两个 input 各占约 47% */
    #reg-start, #reg-end,
    #analysis-start, #analysis-end {
        width: calc(50% - 16px);
        min-width: 0;
    }
    .dash { font-size: 0.85rem; }

    /* 多 checkbox 列表手机更紧凑 + 触摸 padding */
    .multi-check { gap: 8px 10px; }
    .cb {
        font-size: 0.85rem;
        padding: 2px 0;  /* 加点垂直 padding 方便点 */
    }
    .cb .muted { font-size: 0.75rem; }

    /* 汇总统计：每条占整行 */
    .sp-stats {
        flex-direction: column;
        align-items: flex-start;
        gap: 3px;
    }
    .sp-sep { display: none; }

    /* 桶柱条 label 更短 */
    .sp-bar-label {
        width: 88px;
        font-size: 0.78rem;
    }
    .sp-bar-count { width: 36px; font-size: 0.82rem; }

    /* 业态表更紧凑 */
    .sp-table { font-size: 0.78rem; }
    .sp-table th, .sp-table td { padding: 4px 6px; }

    /* === 候选表：≤600px 卡片化，客户名称占整行可换行 === */
    #candidates-table {
        display: block;
        table-layout: auto;
        font-size: 0.85rem;
    }
    #candidates-table thead { display: none; }
    #candidates-table tbody { display: block; }
    #candidates-table tbody tr {
        display: block;
        position: relative;
        padding: 8px 10px 9px;
        border-bottom: 1px solid var(--border);
        cursor: pointer;
    }
    #candidates-table tbody tr:hover,
    #candidates-table tbody tr:active {
        background: var(--bg-hover);
    }
    #candidates-table tbody td {
        display: block;
        padding: 0;
        border: none;
    }

    /* 序号挤到右上角，弱化 */
    #candidates-table tbody td.num {
        position: absolute;
        top: 8px;
        right: 10px;
        font-size: 0.72rem;
        color: var(--text-muted);
        font-weight: 400;
    }

    /* 客户名称：第一行，醒目，可换行多行 */
    #candidates-table .customer-name {
        font-size: 0.96rem;
        font-weight: 600;
        line-height: 1.4;
        padding-right: 44px;       /* 给右上角的序号让位 */
        margin-bottom: 4px;
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* 地区 / 指标 / 业态 / 经手人 / 注册时间：合并成紧凑的次行，分隔点 · 隔开 */
    #candidates-table tbody td:nth-child(3),
    #candidates-table tbody td:nth-child(4),
    #candidates-table tbody td:nth-child(5),
    #candidates-table tbody td:nth-child(6),
    #candidates-table tbody td:nth-child(7),
    #candidates-table tbody td:nth-child(8),
    #candidates-table tbody td:nth-child(9),
    #candidates-table tbody td:nth-child(10),
    #candidates-table tbody td:nth-child(11) {
        display: inline;
        font-size: 0.78rem;
        color: var(--text-secondary);
    }
    #candidates-table tbody td:nth-child(3):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(4):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(5):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(6):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(7):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(8):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(9):not(:empty) + td:not(:empty)::before,
    #candidates-table tbody td:nth-child(10):not(:empty) + td:not(:empty)::before {
        content: " · ";
        color: var(--text-muted);
    }

    /* 卡片模式下取消固定宽度 */
    #candidates-table .col-idx,
    #candidates-table .col-cust-name,
    #candidates-table .col-region,
    #candidates-table .col-btype,
    #candidates-table .col-handler,
    #candidates-table .col-reg,
    #candidates-table .col-metric { width: auto; }
    .customer-metric { white-space: normal; font-size: 0.76rem; }
    .customer-metric.muted { font-size: 0.72rem; }

    /* 让候选表也允许横向滚 */
    .scroll-table { max-height: 60vh; }

    /* 详情表手机端字体最小化 + 强制可滚 */
    table.detail-table { font-size: 0.76rem; min-width: 720px; }
    .detail-table th, .detail-table td { padding: 4px 6px; }
    /* 单号列：稍宽确保 20 字符单号最多两行 */
    .detail-table col.c-num  { width: 125px; }
    .detail-table col.c-date { width: 78px; }

    /* 客户详情页 ct-meta 单列 */
    .ct-meta {
        flex-direction: column;
        gap: 3px;
        font-size: 0.83rem;
    }
    .ct-summary {
        font-size: 0.85rem;
        padding: 8px 10px;
        line-height: 1.6;
    }
    #cp-title { font-size: 1.1rem; }

    /* 操作按钮区紧凑 */
    .sp-actions { gap: 8px; }
    .sp-actions .muted { margin-left: 0; width: 100%; }
}

/* === 超窄手机 (≤380px，例如 iPhone SE) === */
@media (max-width: 380px) {
    body { padding: 8px 6px; }
    header h1 { font-size: 1.05rem; }
    .step-card { padding: 8px 10px; }
    .step-card h2 { font-size: 0.85rem; }
    table.detail-table { font-size: 0.72rem; min-width: 680px; }
    .detail-table col.c-num  { width: 115px; }

    /* 候选卡片：进一步压缩 padding 与字号 */
    #candidates-table tbody tr { padding: 7px 8px 8px; }
    #candidates-table .customer-name {
        font-size: 0.9rem;
        padding-right: 38px;
    }
    #candidates-table tbody td.num { top: 7px; right: 8px; }
    #candidates-table tbody td:nth-child(3),
    #candidates-table tbody td:nth-child(4),
    #candidates-table tbody td:nth-child(5),
    #candidates-table tbody td:nth-child(6),
    #candidates-table tbody td:nth-child(7),
    #candidates-table tbody td:nth-child(8),
    #candidates-table tbody td:nth-child(9),
    #candidates-table tbody td:nth-child(10),
    #candidates-table tbody td:nth-child(11) { font-size: 0.74rem; }
}

/* ===== 候选客户 / 注册后未下单 Tab ===== */
.tab-bar { display: flex; gap: 4px; margin: 10px 0 8px; border-bottom: 1px solid var(--border); }
.tab-btn {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-secondary); padding: 8px 16px; font-size: 14px;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-btn.active { color: var(--text-primary); border-bottom-color: #58a6ff; font-weight: 600; }
.tab-pane.hidden { display: none; }

/* ===== 主表:一级/二级品类(数量)明细列 ===== */
.col-cats { white-space: normal; word-break: break-word; line-height: 1.45; font-size: 12px; color: var(--text-secondary); }
.col-cats b { color: var(--text-primary); font-weight: 600; }
/* 商城注册时间收窄:日期时间换两行、缩小字号,不裁切 */
#candidates-table .col-reg .mono { white-space: normal; font-size: 0.72rem; }

/* ===== 登录页面 ===== */
.login-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    max-width: 400px;
    margin: 0 auto;
}

.app-title {
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 40px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    color: #999;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    height: 48px;
    padding: 0 12px;
    font-size: 16px;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1e1e1e;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

.form-group input::placeholder {
    color: #555;
}

.form-group input:focus {
    border-color: #5c9cd5;
}

.btn {
    height: 48px;
    padding: 0 16px;
    font-size: 16px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
}

.btn:active {
    opacity: 0.8;
}

.btn-primary {
    background-color: #5c9cd5;
    color: #fff;
}

.btn-primary:hover {
    background-color: #4a8bc2;
}

.btn-block {
    width: 100%;
    margin-top: 8px;
}

.error-msg {
    color: #e74c3c;
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
}
