/* 策马CRM - 样式表 */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --success: #0d904f;
    --warning: #e6a817;
    --danger: #d93025;
    --bg: #f5f6fa;
    --card: #ffffff;
    --text: #202124;
    --text-secondary: #5f6368;
    --border: #e0e0e0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 8px;
}

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

body {
    font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    user-select: none;
    -webkit-user-select: none;
    overflow-x: hidden;   /* 兜底：禁止页面横向滚动（左滑） */
}

/* 水印层 */
.watermark {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;   /* 裁切超出的水印文字，避免撑出横向滚动（左滑） */
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 100px,
        rgba(0,0,0,0.015) 100px,
        rgba(0,0,0,0.015) 200px
    );
}
.watermark::after {
    content: attr(data-text);
    position: absolute;   /* 相对 .watermark，配合 overflow:hidden 裁切，防止横向溢出 */
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) rotate(-30deg);
    font-size: 60px;
    color: rgba(0,0,0,0.03);
    white-space: nowrap;
    letter-spacing: 40px;
}

/* 顶部导航 */
.navbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.navbar-nav {
    display: flex;
    gap: 4px;
}
.navbar-nav a {
    padding: 8px 16px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}
.navbar-nav a:hover, .navbar-nav a.active {
    background: #e8f0fe;
    color: var(--primary);
}
.navbar-info {
    color: var(--text-secondary);
    font-size: 13px;
}

/* 主容器 */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* 卡片 */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-header {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 统计卡片 */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    text-align: center;
}
.stat-card.clickable {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card.clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.stat-card .stat-num {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
}
.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.stat-card.warning .stat-num { color: var(--warning); }
.stat-card.success .stat-num { color: var(--success); }
.stat-card.danger .stat-num { color: var(--danger); }

/* 时间维度切换（日/周/月） */
.period-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.period-tab {
    padding: 8px 22px;
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.period-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.period-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}

/* 统计卡片内按客服上下排列 */
.stat-card .stat-agent-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 14px;
    text-align: left;
}
.stat-card .stat-agent-name {
    color: var(--text-secondary);
}
.stat-card .stat-num-sm {
    font-weight: 700;
    color: var(--primary);
    font-size: 18px;
}
.stat-card .stat-agent-total {
    border-top: 1px solid var(--border);
    margin-top: 6px;
    padding-top: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}
.stat-card .stat-agent-total .stat-num-sm {
    font-size: 16px;
}
.stat-card .stat-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed var(--border);
    font-weight: 600;
    text-align: left;
}

/* 搜索栏 */
.search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search-bar input, .search-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    color: var(--text);
}
.search-bar input { flex: 1; min-width: 200px; }
.search-bar select { min-width: 120px; }

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-xs { padding: 2px 8px; font-size: 12px; border-radius: 4px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
table th, table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
table th {
    background: #f8f9fa;
    font-weight: 600;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
}
table tbody tr:hover { background: #f8f9ff; }
table tbody tr { cursor: pointer; }

/* 级别标签 */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.badge-default { background: #f1f3f4; color: #999; }

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    flex-wrap: wrap;   /* 按钮多时自动换行，杜绝横向溢出（左滑） */
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 13px;
}
.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* 详情页 */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}
.detail-item {
    padding: 8px 0;
}
.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}
.detail-value {
    font-size: 15px;
    font-weight: 500;
    word-break: break-all;
    overflow-wrap: anywhere;
}

/* 跟进时间线 */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 16px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
}
.timeline-time {
    font-size: 12px;
    color: var(--text-secondary);
}
.timeline-content {
    margin-top: 4px;
    font-size: 14px;
    white-space: pre-wrap;   /* 保留跟进内容里的换行（AI质检多行结果），否则多行会挤成一行 */
    word-break: break-word;
}
.timeline-status {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
    background: #e8f0fe;
    color: var(--primary);
    margin-right: 8px;
}

/* 模态框 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.form-group textarea { min-height: 80px; resize: vertical; }

/* 提示信息 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }

/* 加载动画 */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    color: white;
    font-weight: 500;
    z-index: 9999;
    animation: slideIn 0.3s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 底部 Tab 导航（仅移动端显示） */
.bottom-tabbar {
    display: none;
}

/* 直拨按钮（仅移动端显示，点号码直接用本机 SIM 卡拨打） */
.direct-call {
    display: none;
}

/* 响应式 */
@media (max-width: 768px) {
    .main-container { padding: 12px 12px 64px; }  /* 底部留出 Tab 栏高度，避免内容被遮挡 */
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px 10px; }
    .stat-card .stat-num { font-size: 28px; }

    /* 顶部导航：隐藏横向链接，只留品牌 + 用户信息 */
    .navbar { padding: 0 12px; height: 50px; }
    .navbar-nav { display: none; }
    .navbar-brand { font-size: 16px; }
    .navbar-info { font-size: 12px; }

    /* 底部 Tab 栏 */
    .bottom-tabbar {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 44px;
        background: var(--card);
        border-top: 1px solid var(--border);
        z-index: 200;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .bottom-tabbar a {
        flex: 1;
        min-width: 0;   /* 防止内容撑开导致溢出，保证各 Tab 等宽 */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1px;
        font-size: 10px;
        color: var(--text-secondary);
        text-decoration: none;
    }
    .bottom-tabbar a .tab-icon { font-size: 16px; line-height: 1; }
    .bottom-tabbar a.active { color: var(--primary); font-weight: 600; }

    /* 移动端显示直拨按钮 */
    .direct-call { display: inline-flex; }

    /* 详情页两列 → 单列 */
    .detail-cols { grid-template-columns: 1fr !important; gap: 12px; }
    /* 仪表盘图表区（级别分布 + 最近跟进）两列 → 单列 */
    .normal-charts { grid-template-columns: 1fr !important; }

    /* 卡片头部：标题与右侧按钮组（未评估/未成交/级别）可换行，避免挤压 */
    .card-header { flex-wrap: wrap; row-gap: 8px; }
    /* 客户信息字段强制单列、收紧间距 */
    .detail-grid { grid-template-columns: 1fr !important; gap: 8px; }
    /* 彻底禁止横向溢出：grid/flex 子项可收缩，长文本换行不撑开 */
    .detail-cols > *, .detail-grid > *, .detail-item { min-width: 0 !important; max-width: 100% !important; }
    .card { max-width: 100% !important; }
    #customer-info, #phone-list, #detail-app { min-width: 0; }

    /* 卡片内边距收紧 */
    .card { padding: 14px; }

    /* 模态框：手机全宽居中，避免溢出 */
    .modal { min-width: 0; width: 92vw; max-width: 92vw; padding: 18px 16px; }
    .modal-title { font-size: 16px; }

    /* 触控友好：输入控件 ≥ 40px 高、16px 字（防 iOS 聚焦自动放大） */
    .btn { min-height: 40px; }
    .form-group input, .form-group select, .form-group textarea { font-size: 16px; }
    .form-group textarea { min-height: 90px; }
    .search-bar input, .search-bar select { min-height: 40px; font-size: 16px; }

    /* 搜索栏在手机上纵向堆叠，输入框占满 */
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar input, .search-bar select { width: 100%; min-width: 0; }

    /* Toast 居中偏上，避免被底部 Tab 挡住 */
    .toast { top: 12px; right: 12px; left: 12px; text-align: center; }
}
