/* ============================================================
 * 黑马智同 CRM · 移动端适配样式 (mobile.css)
 * 响应式布局 · 触控优化 · 底部导航 · 卡片式列表
 * ============================================================ */

/* ---------- 移动端检测与基础 ---------- */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 280px;
    --topbar-h: 56px;
    --bottom-nav-h: 64px;
  }

  /* 基础重置 */
  html { font-size: 14px; }
  body {
    font-size: 13px;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior-y: none;
  }

  /* ---------- 侧边栏变抽屉 ---------- */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 100;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* 抽屉遮罩 */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t) var(--ease);
  }
  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------- 主区域 ---------- */
  .main {
    width: 100%;
  }

  /* 顶栏 */
  .topbar {
    padding: 0 12px;
  }
  .topbar-left {
    gap: 8px;
  }
  .page-title {
    font-size: 16px;
    font-weight: 600;
  }
  .topbar-right {
    gap: 4px;
  }
  /* 隐藏全局搜索，改为点击展开 */
  .search-global {
    display: none;
  }
  .search-global.mobile-show {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 50;
    padding: 0 12px;
    align-items: center;
    gap: 8px;
  }
  .search-global.mobile-show input {
    flex: 1;
  }
  .search-global.mobile-show .search-back {
    display: flex;
  }
  .search-back {
    display: none;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    color: var(--text-2);
  }

  /* 主题切换精简 */
  .theme-switch {
    gap: 0;
  }
  .theme-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }
  .theme-btn[data-theme-mode="system"] {
    display: none;
  }

  /* ---------- 内容区域 ---------- */
  .content {
    padding: 12px;
    padding-bottom: calc(var(--bottom-nav-h) + 16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ---------- 仪表盘 ---------- */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .stat-card {
    padding: 14px !important;
  }
  .stat-value {
    font-size: 22px !important;
  }
  .stat-label {
    font-size: 11px !important;
  }

  /* 快捷入口 */
  .quick-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
  }
  .quick-grid button {
    height: 64px !important;
    width: 100% !important;
    font-size: 11px !important;
  }

  /* ---------- 表格转卡片 ---------- */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table.data-table {
    min-width: 600px;
  }
  /* 客户列表 - 卡片模式 */
  .customer-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .customer-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
  }
  .customer-card-item:active {
    background: var(--surface-2);
  }
  .customer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
  }
  .customer-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
  }
  .customer-card-meta {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
  }
  .customer-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-2);
    margin-top: 6px;
  }

  /* 合同列表 - 卡片模式 */
  .contract-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .contract-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
  }
  .contract-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
  }
  .contract-card-no {
    font-size: 12px;
    color: var(--text-3);
    font-family: monospace;
  }
  .contract-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-top: 2px;
  }
  .contract-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-2);
    margin-top: 6px;
  }
  .contract-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  /* 回款列表 - 卡片模式 */
  .payment-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .payment-card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
  }
  .payment-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
  }
  .payment-card-amount {
    font-size: 18px;
    font-weight: 700;
    color: var(--pri);
  }
  .payment-card-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-2);
    margin-top: 4px;
  }
  .payment-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
  }

  /* ---------- 筛选栏 ---------- */
  .filter-bar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .filter-bar input,
  .filter-bar select {
    width: 100% !important;
    min-width: 0 !important;
    height: 38px;
  }
  .filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  /* ---------- 按钮优化 ---------- */
  .btn {
    height: 40px;
    padding: 0 14px;
  }
  .btn-sm {
    height: 32px;
    padding: 0 10px;
    font-size: 12px;
  }
  .btn-icon {
    width: 40px;
    height: 40px;
  }

  /* 操作按钮 */
  .table-actions {
    gap: 4px;
  }
  .act-btn {
    width: 36px;
    height: 36px;
  }

  /* ---------- 模态框全屏 ---------- */
  .modal-overlay {
    padding: 0;
  }
  .modal-dialog {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    transform: translateY(0) scale(1) !important;
  }
  .modal-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 5;
  }
  .modal-head h3 {
    font-size: 16px;
  }
  .modal-body {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-foot {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    background: var(--surface);
    z-index: 5;
  }
  .modal-foot .btn {
    flex: 1;
  }

  /* 表单字段全宽 */
  .modal-body .field.full,
  .modal-body .field {
    width: 100% !important;
  }
  .modal-grid {
    display: block !important;
  }
  .modal-grid > * {
    width: 100% !important;
  }

  /* ---------- 详情页 ---------- */
  .detail-back {
    padding: 8px 0;
    font-size: 14px;
  }
  .detail-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }
  .tab {
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 13px;
  }
  .section-title {
    font-size: 14px;
    margin: 16px 0 8px;
  }

  /* ---------- 抽屉 ---------- */
  .drawer {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ---------- 跟进时间线 ---------- */
  .timeline-item {
    padding-left: 28px;
  }
  .timeline-head {
    flex-wrap: wrap;
    gap: 6px;
  }
  .timeline-time {
    font-size: 11px;
  }
  .timeline-body {
    font-size: 13px;
    margin-top: 4px;
  }

  /* ---------- 项目卡片 ---------- */
  .project-card {
    padding: 14px !important;
  }
  .project-stage-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .project-stage-table table {
    min-width: 400px;
  }

  /* ---------- 登录页 ---------- */
  .login-card {
    width: 92vw;
    padding: 24px 20px;
    border-radius: var(--radius-lg);
  }
  .login-logo {
    gap: 10px;
    margin-bottom: 20px;
  }
  .logo-text h1 {
    font-size: 18px;
  }
  .logo-text p {
    font-size: 11px;
  }
  .login-form .btn-primary {
    height: 44px;
    font-size: 15px;
  }
  .login-hint {
    gap: 4px;
  }
  .role-chip {
    font-size: 10px;
    padding: 3px 7px;
  }
  .login-foot {
    font-size: 10px;
    margin-top: 16px;
  }

  /* ---------- 底部导航栏 ---------- */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--glass);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 90;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 100%;
    flex: 1;
    color: var(--text-3);
    font-size: 10px;
    font-weight: 500;
    transition: color var(--t-fast) var(--ease);
    position: relative;
  }
  .bottom-nav-item svg {
    width: 22px;
    height: 22px;
  }
  .bottom-nav-item.active {
    color: var(--pri);
  }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 32px;
    height: 3px;
    background: var(--pri);
    border-radius: 0 0 4px 4px;
  }

  /* 菜单按钮在移动端显示 */
  .menu-toggle {
    display: flex !important;
  }

  /* 隐藏桌面端侧边栏品牌 */
  .sidebar-brand .brand-name {
    display: block;
  }

  /* 搜索按钮（移动端） */
  .mobile-search-btn {
    display: flex;
  }

  /* 分页 */
  .pagination {
    gap: 4px;
  }
  .pagination button {
    min-width: 36px;
    height: 36px;
    font-size: 12px;
  }

  /* 通知抽屉全宽 */
  .drawer {
    width: 100% !important;
  }

  /* 标签和徽章缩小 */
  .badge {
    font-size: 11px;
    padding: 2px 8px;
  }

  /* 卡片内边距减小 */
  .card-pad {
    padding: 14px;
  }

  /* 客户详情头部 */
  .detail-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* 联系人列表 */
  .contact-list {
    gap: 8px;
  }
  .contact-item {
    padding: 10px;
  }

  /* 附件 */
  .attachment {
    padding: 8px;
  }
  .attach-info {
    min-width: 0;
  }
  .attach-name {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ---------- 平板适配 ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
  :root {
    --sidebar-w: 200px;
  }
  .stat-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .content {
    padding: 16px;
  }
}

/* ---------- 底部导航栏（桌面隐藏） ---------- */
.bottom-nav {
  display: none;
}
.mobile-search-btn {
  display: none;
}
.search-back {
  display: none;
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
  }
  .mobile-search-btn {
    display: flex;
  }
}

/* ---------- 触控优化 ---------- */
@media (hover: none) and (pointer: coarse) {
  .btn:hover,
  .nav-item:hover,
  .act-btn:hover {
    transform: none;
  }
  .btn:active,
  .nav-item:active,
  .act-btn:active {
    transform: scale(0.96);
    transition: transform 0.1s;
  }
}
