/* ===== Design Tokens ===== */
:root {
  /* Colors - Financial Business Blue */
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-lighter: #dbeafe;
  --primary-dark: #1e3a8a;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --ink: #1e293b;
  --ink-secondary: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0891b2;
  --info-bg: #cffafe;

  /* Typography */
  --font: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SF Mono", "Fira Code", monospace;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Radius */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --radius-full: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);

  /* Layout */
  --sidebar-w: 220px;
  --topbar-h: 56px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; min-height: 100dvh; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }

/* ===== App Shell ===== */
.app { display: flex; min-height: 100dvh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-3);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: relative;
}
.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: var(--primary-light);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff; font-weight: 700;
}
.sidebar-logo .logo-text {
  font-size: 14px; font-weight: 600; color: #fff;
  line-height: 1.3;
}
.sidebar-nav { flex: 1; padding: var(--space-3) 0; overflow-y: auto; }
.sidebar-nav .nav-section {
  padding: var(--space-2) var(--space-5);
  font-size: 11px; color: #64748b; text-transform: uppercase;
  letter-spacing: 0.05em; margin-top: var(--space-3);
}
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  color: #cbd5e1; font-size: 13px;
  cursor: pointer; transition: all 0.15s;
  border-left: 3px solid transparent;
}
.sidebar-nav .nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.sidebar-nav .nav-item.active {
  background: rgba(59,130,246,0.15);
  color: #fff;
  border-left-color: var(--primary-light);
}
.sidebar-nav .nav-icon { width: 18px; text-align: center; font-size: 15px; }

/* Main area */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky; top: 0; z-index: 50;
}
.topbar .breadcrumb { font-size: 13px; color: var(--muted); }
.topbar .breadcrumb span { color: var(--ink); font-weight: 500; }
.topbar .topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-4); }
.topbar .user-info { display: flex; align-items: center; gap: var(--space-2); }
.topbar .user-avatar {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.topbar .user-name { font-size: 13px; color: var(--ink); font-weight: 500; }
.topbar .user-role { font-size: 11px; color: var(--muted); }
.topbar .btn-icon {
  width: 32px; height: 32px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer; transition: all 0.15s;
  position: relative;
}
.topbar .btn-icon:hover { background: var(--border-light); color: var(--ink); }
.topbar .badge-dot {
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: var(--radius-full);
  background: var(--danger);
}

/* Content */
.content { flex: 1; padding: var(--space-6); }

/* ===== Components ===== */

/* Page title */
.page-title {
  font-size: 20px; font-weight: 600; color: var(--ink);
  margin-bottom: var(--space-5);
  display: flex; align-items: center; gap: var(--space-3);
}
.page-title .subtitle { font-size: 13px; color: var(--muted); font-weight: 400; }

/* Card */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--ink); }
.card-body { padding: var(--space-5); }

/* Stat card */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.stat-card .stat-label { font-size: 12px; color: var(--muted); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--ink); }
.stat-card .stat-trend { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.stat-card .stat-icon {
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: var(--space-2);
}
.stat-icon.blue { background: var(--primary-lighter); color: var(--primary); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.amber { background: var(--warning-bg); color: var(--warning); }
.stat-icon.red { background: var(--danger-bg); color: var(--danger); }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 500;
}
.badge-blue { background: var(--primary-lighter); color: var(--primary); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-amber { background: var(--warning-bg); color: var(--warning); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray { background: var(--border-light); color: var(--muted); }

/* Button */
.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
  border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-hover); border-color: var(--muted); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 14px; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table.data-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}
.data-table thead th {
  background: var(--border-light);
  color: var(--ink-secondary);
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
.data-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  color: var(--ink);
}
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Form */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: 13px; color: var(--ink-secondary); margin-bottom: var(--space-2); font-weight: 500; }
.form-input, .form-select {
  width: 100%; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; color: var(--ink); background: var(--surface);
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--primary-light);
  box-shadow: 0 0 0 3px var(--primary-lighter);
}

/* Progress / Timeline */
.timeline { position: relative; padding-left: var(--space-8); }
.timeline::before {
  content: ''; position: absolute; left: 11px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; padding-bottom: var(--space-5); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -29px; top: 2px;
  width: 24px; height: 24px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  border: 3px solid var(--surface);
}
.timeline-dot.done { background: var(--success); color: #fff; }
.timeline-dot.active { background: var(--primary); color: #fff; }
.timeline-dot.pending { background: var(--border); color: var(--muted); }
.timeline-content h4 { font-size: 13px; font-weight: 600; color: var(--ink); }
.timeline-content .timeline-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.timeline-content .timeline-desc { font-size: 12px; color: var(--ink-secondary); margin-top: 4px; }

/* Guarantee chain layer */
.guarantee-layer {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  display: flex; gap: var(--space-5);
  align-items: flex-start;
}
.guarantee-layer .layer-number {
  width: 40px; height: 40px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.layer-number.l1 { background: var(--primary); }
.layer-number.l2 { background: var(--info); }
.layer-number.l3 { background: var(--warning); }
.layer-number.l4 { background: var(--success); }
.guarantee-layer .layer-body { flex: 1; }
.guarantee-layer .layer-title { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: var(--space-1); }
.guarantee-layer .layer-desc { font-size: 12px; color: var(--muted); margin-bottom: var(--space-3); }
.guarantee-layer .layer-info { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.guarantee-layer .layer-info-item { font-size: 12px; }
.guarantee-layer .layer-info-item .label { color: var(--muted); }
.guarantee-layer .layer-info-item .value { color: var(--ink); font-weight: 500; }

/* Alert bar */
.alert-bar {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  display: flex; align-items: center; gap: var(--space-3);
  font-size: 13px;
  margin-bottom: var(--space-3);
}
.alert-bar.warning { background: var(--warning-bg); color: var(--warning); }
.alert-bar.danger { background: var(--danger-bg); color: var(--danger); }
.alert-bar.info { background: var(--info-bg); color: var(--info); }

/* Tabs */
.tabs {
  display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-5);
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: 13px; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap; flex-shrink: 0;
}
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); }
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: 13px; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

/* Progress bar */
.progress-bar { height: 6px; background: var(--border-light); border-radius: var(--radius-full); overflow: hidden; }
.progress-bar .fill { height: 100%; border-radius: var(--radius-full); transition: width 0.3s; }
.progress-bar .fill.blue { background: var(--primary-light); }
.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.amber { background: var(--warning); }
.progress-bar .fill.red { background: var(--danger); }

/* Login page */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-6);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 400px; max-width: 100%;
  padding: var(--space-8);
}
.login-card .login-logo {
  text-align: center; margin-bottom: var(--space-6);
}
.login-card .login-logo .logo-circle {
  width: 56px; height: 56px; border-radius: var(--radius-lg);
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; margin-bottom: var(--space-3);
}
.login-card .login-title { font-size: 18px; font-weight: 600; color: var(--ink); }
.login-card .login-subtitle { font-size: 13px; color: var(--muted); margin-top: var(--space-1); }

/* ===== Mobile Navigation (hamburger + off-canvas) ===== */
.menu-toggle {
  display: none;
  width: 36px; height: 36px;
  margin-right: var(--space-2);
  border: none; background: transparent;
  color: var(--ink-secondary);
  font-size: 20px; line-height: 1;
  cursor: pointer; border-radius: var(--radius);
  flex-shrink: 0;
  align-items: center; justify-content: center;
}
.menu-toggle:hover { background: var(--border-light); color: var(--ink); }
.sidebar-close {
  display: none;
  position: absolute; top: 50%; right: 14px; transform: translateY(-50%);
  width: 30px; height: 30px;
  border: none; background: rgba(255,255,255,0.12);
  color: #cbd5e1; font-size: 16px; line-height: 1;
  cursor: pointer; border-radius: var(--radius);
}
.sidebar-close:hover { background: rgba(255,255,255,0.22); color: #fff; }
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 90;
  opacity: 0; transition: opacity 0.2s ease;
}
body.sidebar-open .sidebar-overlay { display: block; opacity: 1; }

/* 移动端底部 Tab 栏（桌面隐藏，移动端启用） */
.mobile-tabbar { display: none; }

/* Responsive */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  /* 移动端：隐藏左侧抽屉与汉堡，改用底部 Tab 栏（原生 App 式导航） */
  .menu-toggle { display: none; }
  .sidebar { display: none; }
  .sidebar-overlay { display: none !important; }
  .main { margin-left: 0; min-height: 100dvh; }

  /* 底部 Tab 栏：作为 body 直接子元素 fixed 在视口底部，常驻可见 */
  .mobile-tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.08);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
  }
  .mobile-tabbar::-webkit-scrollbar { display: none; }
  .mobile-tabbar .tab-item {
    flex: 1 0 auto;
    min-width: 64px; max-width: 96px;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    gap: 3px; color: var(--muted); font-size: 11px;
    text-decoration: none;
    padding: 8px 4px 6px;
    position: relative;
    transition: color 0.15s;
  }
  .mobile-tabbar .tab-item.active {
    color: var(--primary);
    font-weight: 600;
  }
  .mobile-tabbar .tab-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 50%; transform: translateX(-50%);
    width: 20px; height: 3px;
    background: var(--primary);
    border-radius: 0 0 2px 2px;
  }
  .mobile-tabbar .tab-icon { font-size: 22px; line-height: 1; }
  .mobile-tabbar .tab-label { line-height: 1.2; white-space: nowrap; }

  /* 移动端网格：4 列统计卡片改为 2×2，充分利用宽度 */
  .grid-4 { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* 内容区底部留出 Tab 栏高度，避免内容被遮挡 */
  .content { padding: var(--space-4); padding-bottom: calc(60px + env(safe-area-inset-bottom) + var(--space-4)); }

  /* 统计卡片在移动端更紧凑 */
  .stat-card { padding: var(--space-4); gap: var(--space-1); }
  .stat-card .stat-icon { width: 32px; height: 32px; font-size: 16px; margin-bottom: 0; }
  .stat-card .stat-label { font-size: 11px; }
  .stat-card .stat-value { font-size: 22px; }

  /* 顶栏紧凑化：隐藏面包屑与角色行，缩小图标 */
  .topbar { padding: 0 var(--space-4); gap: var(--space-2); }
  .topbar .breadcrumb { display: none; }
  .topbar .user-role { display: none; }
  .topbar .user-avatar { width: 30px; height: 30px; font-size: 12px; }
  .topbar .btn-icon { width: 30px; height: 30px; }
  .topbar .user-name { font-size: 12px; }

  /* 导航项触摸友好（≥44px 点击高度） */
  .sidebar-nav .nav-item { padding-top: 14px; padding-bottom: 14px; font-size: 14px; }

  /* 页面标题允许换行，避免与右侧按钮挤压 */
  .page-title { flex-wrap: wrap; gap: var(--space-2); font-size: 18px; margin-bottom: var(--space-4); }
  .page-title .subtitle { font-size: 12px; }

  /* 卡片移动端紧凑 */
  .card-header { padding: var(--space-3) var(--space-4); }
  .card-body { padding: var(--space-4); }

  /* 表格：横向滚动更顺滑，并保底最小宽度防止列被压扁 */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  .table-wrap::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; width: 24px;
    background: linear-gradient(to right, transparent, var(--surface));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
  }
  .table-wrap.is-scrollable::after { opacity: 1; }
  .data-table { min-width: 680px; }
  .sub-row .sub-table table { min-width: 560px; }

  /* 筛选栏：移动端垂直堆叠 */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }
  .filter-bar .filter-item .form-select,
  .filter-bar .filter-item .form-input,
  .filter-bar .search-input {
    min-width: auto; width: 100%;
  }
  .filter-bar .filter-actions {
    justify-content: flex-end;
    margin-top: var(--space-1);
  }

  /* 表单输入框 16px，避免 iOS 聚焦时整页自动放大 */
  .form-input, .form-select { font-size: 16px; }

  /* 按钮触摸高度 */
  .btn { min-height: 40px; }

  /* 登录卡片窄屏减小内边距 */
  .login-card { padding: var(--space-6); }
  .login-page { padding: var(--space-4); }

  /* 时间线在小屏减少左缩进 */
  .timeline { padding-left: var(--space-6); }
  .timeline-dot { left: -21px; }

  /* 担保链层纵向堆叠，避免横向溢出 */
  .guarantee-layer { flex-direction: column; gap: var(--space-3); }
  .guarantee-layer .layer-info { gap: var(--space-4); }
}
