/* ============================================
   阅律·地推CRM - 响应式样式表
   移动端优先 · 自适应桌面
   ============================================ */

/* ---------- CSS变量 ---------- */
:root {
    --primary: #1A73E8;
    --primary-dark: #1557B0;
    --danger: #E53935;
    --warning: #FB8C00;
    --success: #43A047;
    --bg: #F5F7FA;
    --card: #FFFFFF;
    --text: #202124;
    --text-secondary: #5F6368;
    --border: #E8EAED;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
    --nav-height: 64px;
    --bottom-nav-height: 60px;
    --max-width: 960px;
}

/* ---------- 重置 ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding-bottom: calc(var(--bottom-nav-height) + 16px);
    min-height: 100vh;
}

/* ---------- 桌面端顶部导航 ---------- */
.top-header {
    display: none;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    height: var(--nav-height);
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow);
}
@media (min-width: 768px) {
    body { padding-bottom: 16px; }
    .top-header { display: flex; }
}
.header-left { display: flex; align-items: center; gap: 12px; }
.app-title { font-size: 18px; font-weight: 700; color: var(--text); }
.app-subtitle { font-size: 12px; color: var(--text-secondary); }
.header-nav { margin-left: auto; display: flex; gap: 4px; }
.header-link {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
}
.header-link:hover, .header-link.active {
    background: #E8F0FE;
    color: var(--primary);
}

/* ---------- 移动端底部导航 ---------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
@media (min-width: 768px) {
    .bottom-nav { display: none; }
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 10px;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
    -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-weight: 500; }

/* ---------- 主内容 ---------- */
.main-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 12px;
}
@media (min-width: 768px) {
    .main-content { padding: 24px; }
}

/* ---------- 页面标题 ---------- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.page-header h2 { font-size: 20px; font-weight: 700; }
.date-display { font-size: 13px; color: var(--text-secondary); }
.header-actions { display: flex; gap: 8px; align-items: center; }

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

/* ---------- 统计卡片网格 ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}
@media (min-width: 480px) {
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-card.accent {
    background: linear-gradient(135deg, var(--primary), #4285F4);
    color: white;
}
.stat-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.2;
}
.stat-card.accent .stat-value { color: white; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.stat-card.accent .stat-label { color: rgba(255,255,255,0.85); }
.stat-sub { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.stat-card.accent .stat-sub { color: rgba(255,255,255,0.7); }

/* ---------- 表单 ---------- */
.crm-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 8px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.required { color: var(--danger); }

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26,115,232,0.15);
}
.form-textarea { resize: vertical; min-height: 60px; }
.form-checkbox {
    display: flex;
    gap: 16px;
    padding: 4px 0;
}
.form-checkbox label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}
.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}
.form-section-title {
    font-size: 14px;
    font-weight: 600;
    padding: 8px 0 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

/* ---------- 按钮 ---------- */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary:hover, .btn-primary:active { background: var(--primary-dark); }
.btn-full { width: 100%; }
.btn-sm {
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
}
.btn-sm:hover { background: #E8F0FE; }

/* ---------- 操作按钮网格 ---------- */
.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    text-align: center;
    transition: all 0.2s;
}
.action-btn:hover, .action-btn:active { background: #E8F0FE; border-color: var(--primary); }
.action-btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.action-btn.primary:hover { background: var(--primary-dark); }

/* ---------- Badge标签 ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg);
    color: var(--text-secondary);
}
.badge-red { background: #FFEBEE; color: var(--danger); }
.badge-orange { background: #FFF3E0; color: var(--warning); }
.badge-green { background: #E8F5E9; color: var(--success); }
.badge-blue { background: #E3F2FD; color: var(--primary); }
.badge-gray { background: #F5F5F5; color: #888; }

/* ---------- 乡镇列表 ---------- */
.town-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.town-item:last-child { border-bottom: none; }
.town-item.done { opacity: 0.6; }
.town-info { display: flex; align-items: center; gap: 8px; }
.town-status { font-size: 16px; }
.town-name { font-size: 14px; font-weight: 500; }
.town-stats { font-size: 12px; color: var(--text-secondary); display: flex; gap: 8px; }
.town-priority {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
}
.priority-p1 { background: #FFEBEE; color: var(--danger); }
.priority-p2 { background: #FFF3E0; color: var(--warning); }
.priority-p3 { background: #F5F5F5; color: #999; }
.priority-p4 { background: #F5F5F5; color: #BBB; }

/* ---------- 柱状图 ---------- */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 120px;
    padding: 8px 0;
}
.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}
.bar-track {
    flex: 1;
    width: 100%;
    max-width: 40px;
    background: #F0F0F0;
    border-radius: 4px 4px 0 0;
    display: flex;
    align-items: flex-end;
}
.bar-fill {
    width: 100%;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height 0.3s;
}
.bar-label { font-size: 10px; color: var(--text-secondary); margin-top: 4px; }
.bar-value { font-size: 11px; font-weight: 600; }

/* ---------- 法律需求列表 ---------- */
.needs-list { display: flex; flex-direction: column; gap: 8px; }
.need-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}
.need-icon { font-size: 20px; }
.need-info { display: flex; flex-direction: column; }
.need-name { font-size: 14px; font-weight: 500; }
.need-count { font-size: 12px; color: var(--text-secondary); }

/* ---------- 时间线 ---------- */
.route-timeline { position: relative; padding-left: 32px; }
.route-timeline::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: #E0E0E0;
}
.timeline-item {
    position: relative;
    padding: 8px 0 8px 16px;
}
.timeline-item.done { opacity: 0.5; }
.timeline-dot {
    position: absolute;
    left: -24px;
    top: 10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #E0E0E0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: white;
    z-index: 1;
}
.timeline-dot.start { background: var(--success); }
.timeline-dot.high { background: var(--danger); }
.timeline-dot.mid { background: var(--warning); }
.timeline-dot.end { background: var(--primary); }
.timeline-content { min-width: 0; }
.timeline-time { font-size: 11px; color: var(--text-secondary); }
.timeline-title { font-size: 14px; font-weight: 500; }
.timeline-desc { font-size: 12px; color: var(--text-secondary); }
.timeline-actions { margin-top: 4px; }
.timeline-btn {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
}

/* ---------- 筛选栏 ---------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    padding: 12px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.filter-select { flex: 1; min-width: 100px; font-size: 13px; padding: 8px; }
.search-box { flex: 1; min-width: 150px; }
.search-box input { font-size: 13px; padding: 8px; }

/* ---------- 商户卡片 ---------- */
.merchant-list { display: flex; flex-direction: column; gap: 8px; }
.merchant-card {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 12px;
    box-shadow: var(--shadow);
    border-left: 3px solid var(--warning);
}
.merchant-card.visited { border-left-color: var(--success); }
.merchant-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.merchant-name { font-size: 15px; font-weight: 600; }
.merchant-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; flex-wrap: wrap; }
.merchant-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}
.merchant-actions { display: flex; gap: 6px; align-items: center; }

/* ---------- 拜访历史 ---------- */
.history-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.history-merchant { font-size: 14px; font-weight: 600; }
.history-town { font-size: 12px; color: var(--text-secondary); }
.history-date { font-size: 11px; color: var(--text-secondary); margin-left: auto; }
.history-detail { margin: 4px 0; display: flex; gap: 6px; flex-wrap: wrap; }
.history-feedback, .history-needs {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 8px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    margin-top: 4px;
}

/* ---------- 弹窗 ---------- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}
.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    color: var(--text-secondary);
}

/* ---------- 地图标注 ---------- */
.marker-icon { background: none !important; border: none !important; }
.marker-high, .marker-mid {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
    font-weight: 700;
    font-size: 11px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.marker-high {
    width: 28px;
    height: 28px;
    background: var(--danger);
    border: 2px solid white;
}
.marker-mid {
    width: 24px;
    height: 24px;
    background: var(--warning);
    border: 2px solid white;
}
.marker-num { line-height: 1; }

/* ---------- 空状态 ---------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}
.empty-state p { font-size: 14px; }

/* ---------- 工具类 ---------- */
.text-link { color: var(--primary); cursor: pointer; text-decoration: none; }
.text-green { color: var(--success); }
.text-gray { color: var(--text-secondary); }

/* ---------- 浮动按钮 ---------- */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 20px);
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 20px;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}
@media (min-width: 768px) {
    .fab { display: none !important; }
}

/* ---------- 桌面端自适应调整 ---------- */
@media (min-width: 768px) {
    .stats-grid { gap: 12px; }
    .stat-card { padding: 18px; }
    .stat-value { font-size: 32px; }
    .merchant-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .filter-bar { flex-wrap: nowrap; }
    .form-row { gap: 12px; }
}
@media (min-width: 1024px) {
    .merchant-list { grid-template-columns: repeat(3, 1fr); }
}
