/* ======== 夏进CRM 全局样式 ======== */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --accent: #ff6d00;
    --success: #00c853;
    --warning: #ff9800;
    --danger: #f44336;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #666;
    --text-light: #999;
    --border: #e0e0e0;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
    --sidebar-w: 240px;
    --topbar-h: 56px;
    --bottomnav-h: 60px;
}

* { 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);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ======== 顶部栏 ======== */
.top-bar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.top-bar-left { display: flex; align-items: center; gap: 12px; }
.menu-toggle { background: none; border: none; color: #fff; cursor: pointer; padding: 4px; display: flex; }
.logo { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.date-display { font-size: 13px; opacity: 0.9; }

/* ======== 侧边栏 ======== */
.sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w);
    background: var(--card-bg); box-shadow: 2px 0 8px rgba(0,0,0,0.05);
    padding: 12px 0; overflow-y: auto; z-index: 90; transition: transform 0.3s;
}
.nav-menu { display: flex; flex-direction: column; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 14px 20px;
    color: var(--text-secondary); text-decoration: none; cursor: pointer;
    transition: all 0.2s; border-left: 3px solid transparent; font-size: 14px;
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }

/* ======== 遮罩 ======== */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 85; }
.overlay.show { display: block; }

/* ======== 主内容区 ======== */
.main-content {
    margin-top: var(--topbar-h); margin-left: var(--sidebar-w);
    padding: 16px; min-height: calc(100vh - var(--topbar-h));
}

/* ======== 底部导航（手机端） ======== */
.bottom-nav { display: none; }

/* ======== 通用组件 ======== */
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; color: var(--text); }

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

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    padding: 7px 16px; border-radius: var(--radius-sm); border: none;
    font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-block { width: 100%; }

/* ======== 统计卡片 ======== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px;
    position: relative; overflow: hidden;
}
.stat-card .stat-icon { position: absolute; right: 12px; top: 12px; opacity: 0.15; font-size: 36px; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: var(--text); }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); }
.stat-card.highlight { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.stat-card.highlight .stat-value, .stat-card.highlight .stat-label { color: #fff; }
.stat-card.accent { background: linear-gradient(135deg, var(--accent), #e65100); color: #fff; }
.stat-card.accent .stat-value, .stat-card.accent .stat-label { color: #fff; }
.stat-card.warning { background: linear-gradient(135deg, var(--warning), #e65100); color: #fff; }
.stat-card.warning .stat-value, .stat-card.warning .stat-label { color: #fff; }

/* ======== 工具栏 ======== */
.toolbar { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.search-box {
    flex: 1; min-width: 140px; padding: 6px 10px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 12px; outline: none; background: var(--card-bg);
}
.search-box:focus { border-color: var(--primary); }
.select-box {
    padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; outline: none; background: var(--card-bg); cursor: pointer; min-width: auto;
}

/* ======== 数据列表 ======== */
.list-item {
    background: var(--card-bg); border-radius: var(--radius); padding: 14px 16px;
    box-shadow: var(--shadow); margin-bottom: 10px; display: flex; align-items: center;
    justify-content: space-between; gap: 12px; cursor: pointer; transition: all 0.2s;
}
.list-item:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.list-item-sub { font-size: 13px; color: var(--text-secondary); display: flex; gap: 12px; flex-wrap: wrap; }
.list-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ======== 标签 ======== */
.tag {
    display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
}
.tag-blue { background: #e3f2fd; color: #1565c0; }
.tag-green { background: #e8f5e9; color: #2e7d32; }
.tag-orange { background: #fff3e0; color: #e65100; }
.tag-red { background: #ffebee; color: #c62828; }
.tag-gray { background: #f5f5f5; color: #616161; }
.tag-purple { background: #f3e5f5; color: #7b1fa2; }

/* ======== 弹窗 ======== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
    background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 600px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card-bg); z-index: 1; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-light); padding: 0 4px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ======== 表单 ======== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-label .required { color: var(--danger); }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; outline: none; transition: border 0.2s; background: var(--card-bg); color: var(--text);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); }
.form-textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ======== 图片上传 ======== */
.img-upload-area {
    border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 20px;
    text-align: center; cursor: pointer; transition: all 0.2s; color: var(--text-light);
}
.img-upload-area:hover { border-color: var(--primary); color: var(--primary); }
.img-preview-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.img-preview { width: 80px; height: 80px; border-radius: var(--radius-sm); object-fit: cover; position: relative; }
.img-preview img { width: 100%; height: 100%; border-radius: var(--radius-sm); object-fit: cover; }
.img-preview .remove-img { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* ======== Toast ======== */
.toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: rgba(0,0,0,0.8); color: #fff; padding: 12px 24px; border-radius: 24px;
    font-size: 14px; z-index: 300; transition: transform 0.3s; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ======== 空状态 ======== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 15px; }

/* ======== 详情页 ======== */
.detail-section { margin-bottom: 20px; }
.detail-section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); color: var(--primary); }
.detail-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-info-item { display: flex; flex-direction: column; gap: 2px; }
.detail-info-label { font-size: 12px; color: var(--text-light); }
.detail-info-value { font-size: 14px; color: var(--text); font-weight: 500; }

/* ======== 图表 ======== */
.chart-container { background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.chart-bar { display: flex; align-items: end; gap: 8px; height: 120px; padding: 10px 0; }
.chart-bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar-fill { width: 100%; background: linear-gradient(to top, var(--primary), #4fc3f7); border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.5s; }
.chart-bar-label { font-size: 11px; color: var(--text-light); }
.chart-bar-value { font-size: 12px; font-weight: 600; color: var(--text); }

/* ======== 按钮组 ======== */
.btn-group-sm { display: flex; gap: 4px; }
.icon-btn { background: none; border: none; padding: 6px; cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.icon-btn:hover { background: var(--primary-light); }
.icon-btn.edit { color: var(--primary); }
.icon-btn.delete { color: var(--danger); }
.icon-btn.view { color: var(--success); }

/* ======== 更多页面网格 ======== */
.more-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.more-item {
    background: var(--card-bg); border-radius: var(--radius); padding: 20px 12px; text-align: center;
    cursor: pointer; transition: all 0.2s; box-shadow: var(--shadow);
}
.more-item:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.more-item svg { width: 32px; height: 32px; margin-bottom: 8px; color: var(--primary); }
.more-item span { font-size: 13px; font-weight: 600; color: var(--text); }

/* ======== 进度条 ======== */
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--success); border-radius: 4px; transition: width 0.5s; }

/* ======== 响应式 ======== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); z-index: 95; }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 12px; padding-bottom: 80px; }
    .bottom-nav {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottomnav-h);
        background: var(--card-bg); box-shadow: 0 -2px 8px rgba(0,0,0,0.08); z-index: 100;
        justify-content: space-around; align-items: center;
    }
    .bottom-nav-item {
        display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1;
        color: var(--text-light); cursor: pointer; text-decoration: none; font-size: 11px; padding: 6px 0;
    }
    .bottom-nav-item.active { color: var(--primary); }
    .bottom-nav-center { position: relative; }
    .nav-fab {
        width: 48px; height: 48px; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
        border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff;
        margin-top: -20px; box-shadow: 0 4px 12px rgba(26,115,232,0.4);
    }
    .bottom-nav-center span { margin-top: 2px; }
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    .detail-info-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .modal { max-width: 100%; max-height: 95vh; border-radius: var(--radius); }
    .toast { bottom: 80px; }
    .menu-toggle { display: flex; }
    .list-item-actions { flex-direction: column; }
}

@media (min-width: 769px) {
    .menu-toggle { display: none; }
    .overlay { display: none !important; }
}

/* ======== 滚动条美化 ======== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ======== 加载动画 ======== */
.loading { display: flex; justify-content: center; align-items: center; padding: 40px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ======== 分段标题 ======== */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h3 { font-size: 16px; font-weight: 700; }

/* ======== 链接列表（导出页） ======== */
.export-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    margin-bottom: 12px; display: flex; align-items: center; gap: 16px; cursor: pointer; transition: all 0.2s;
}
.export-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); border-left: 4px solid var(--primary); }
.export-card-icon { width: 48px; height: 48px; background: var(--primary-light); border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--primary); flex-shrink: 0; }
.export-card-info { flex: 1; }
.export-card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.export-card-desc { font-size: 13px; color: var(--text-secondary); }

/* ======== PWA / APP 原生体验优化 ======== */

/* 安全区域适配（iPhone刘海/底部横条） */
@supports (padding: max(0px)) {
    .top-bar {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
    }
    .sidebar {
        top: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
    }
    .main-content {
        margin-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
    }
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0);
        height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0));
    }
    .main-content {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0));
    }
}

/* 禁用iOS弹性滚动 */
html, body {
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

/* PWA standalone模式：隐藏顶部栏日期节省空间 */
@media (display-mode: standalone) {
    .date-display { display: none; }
    .top-bar { padding-left: 16px; }
    .logo { font-size: 17px; }
}

/* 触摸优化：增大点击区域 */
@media (max-width: 768px) {
    .nav-item { padding: 16px 20px; }
    .list-item { padding: 16px; }
    .btn { min-height: 44px; }
    .icon-btn { min-width: 40px; min-height: 40px; }
    .form-input, .form-select, .form-textarea { min-height: 44px; }

    /* v111: 手机端顶部栏精简 */
    .top-bar { padding: 0 10px; }
    .logo { font-size: 15px; }
    .date-display { display: none; }
    .top-bar-left { gap: 6px; }
    .top-bar-right { display: flex; align-items: center; gap: 4px; }
}

/* 启动画面背景 */
body { background: var(--bg); }

/* 离线状态指示器 */
.offline-banner {
    position: fixed; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
    left: 0; right: 0; background: var(--warning); color: #fff;
    text-align: center; padding: 6px; font-size: 12px; z-index: 99;
    display: none;
}
.offline-banner.show { display: block; }

/* 安装提示弹窗动画 */
#installPrompt {
    animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
