/* ============ 全局变量 ============ */
:root {
  --bg: #f5f7fb;
  --bg2: #ffffff;
  --ink: #1a2332;
  --muted: #6b7a90;
  --rule: #e2e8f0;
  --accent: #2563eb;
  --accent2: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --sidebar-bg: #1e293b;
  --sidebar-ink: #cbd5e1;
  --sidebar-active: #334155;
  --sidebar-hover: #293548;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ 布局 ============ */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #334155;
}

.logo {
  font-size: 32px;
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text .app-name {
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}

.logo-text .app-sub {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-title {
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--sidebar-ink);
  text-decoration: none;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 14px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  text-decoration: none;
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: var(--accent2);
}

.nav-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid #334155;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}

.logout-link {
  font-size: 12px;
  color: #94a3b8;
}

.user-actions {
  font-size: 12px;
  margin-top: 2px;
}

.user-action-link {
  font-size: 12px;
  color: #94a3b8;
  text-decoration: none;
  transition: color 0.2s;
}

.user-action-link:hover {
  color: #fff;
}

.user-action-sep {
  color: #475569;
  margin: 0 4px;
}

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 24px 28px;
  min-height: 100vh;
}

/* ============ 页面标题 ============ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
}

.page-actions {
  display: flex;
  gap: 10px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border-color: transparent;
}

.btn-primary:hover {
  opacity: 0.9;
  color: #fff;
  border-color: transparent;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: transparent;
}

.btn-success:hover { opacity: 0.9; color: #fff; }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn-danger:hover { opacity: 0.9; color: #fff; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ============ 卡片 ============ */
.card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============ 统计卡片 ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.stat-card.blue::before { background: var(--accent); }
.stat-card.green::before { background: var(--success); }
.stat-card.amber::before { background: var(--warning); }
.stat-card.purple::before { background: var(--purple); }
.stat-card.red::before { background: var(--danger); }
.stat-card.cyan::before { background: var(--accent2); }

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ============ 数据看板网格 ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.dashboard-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ============ 列表 ============ */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
}

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input[type="text"] {
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12.5px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ============ 标签/状态 ============ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.6;
}

.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #047857; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-cyan { background: #cffafe; color: #0e7490; }

/* ============ 表单 ============ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group.full { grid-column: 1 / -1; }

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  margin-top: 10px;
}

/* ============ Flash 消息 ============ */
.flash-container {
  margin-bottom: 16px;
}

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 13.5px;
}

.flash-success { background: #d1fae5; color: #065f46; }
.flash-danger { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-info { background: #dbeafe; color: #1e40af; }

/* ============ 详情页 ============ */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.detail-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}

.detail-meta {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.info-item {
  background: #f8fafc;
  padding: 12px 14px;
  border-radius: 8px;
}

.info-item .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.info-item .value {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.detail-section {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-content {
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--ink);
}

/* ============ 时间线/里程碑 ============ */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--rule);
}

.timeline-item {
  position: relative;
  padding-bottom: 16px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #cbd5e1;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px #cbd5e1;
}

/* 里程碑时间线圆点：紫=完成、琥珀=进行中、红=延期、青=待开始
   （与支付进度绿/蓝/灰的配色完全区分） */
.timeline-item.completed::before { background: var(--purple); box-shadow: 0 0 0 2px var(--purple); }
.timeline-item.in_progress::before { background: var(--warning); box-shadow: 0 0 0 2px var(--warning); }
.timeline-item.delayed::before { background: var(--danger); box-shadow: 0 0 0 2px var(--danger); }
.timeline-item.pending::before { background: #06b6d4; box-shadow: 0 0 0 2px #06b6d4; }

.timeline-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.milestone-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.timeline-item:hover .milestone-actions {
  opacity: 1;
}

.milestone-edit-btn, .milestone-delete-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.milestone-edit-btn:hover {
  background: #dbeafe;
  color: var(--primary);
}

.milestone-delete-btn:hover {
  background: #fee2e2;
  color: var(--danger);
}

.timeline-date {
  font-size: 12px;
  color: var(--muted);
}

/* ============ 支付进度 ============ */
.payment-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.payment-item {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px;
  position: relative;
  border-left: 4px solid var(--rule);
  transition: all 0.2s;
}

.payment-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.payment-item.paid { border-left-color: var(--success); }
.payment-item.partial { border-left-color: var(--accent); }
.payment-item.pending { border-left-color: var(--muted); }

.payment-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}

.payment-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.payment-order {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.payment-item.paid .payment-order { background: var(--success); }
.payment-item.partial .payment-order { background: var(--accent); }

.payment-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}

.payment-amount {
  text-align: right;
  flex-shrink: 0;
}

.planned-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  display: block;
}

.payment-item.paid .planned-amount { color: var(--success); text-decoration: line-through; opacity: 0.7; }

.actual-amount {
  font-size: 12.5px;
  color: var(--success);
  font-weight: 500;
}

.payment-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.payment-type-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 500;
}

.type-advance { background: #fef3c7; color: #92400e; }
.type-progress { background: #dbeafe; color: #1e40af; }
.type-settlement { background: #d1fae5; color: #065f46; }
.type-retention { background: #ede9fe; color: #5b21b6; }

.payment-stage {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.payment-conditions {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 6px;
}

.payment-remark {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.payment-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.payment-item:hover .payment-actions {
  opacity: 1;
}

.payment-edit-btn, .payment-delete-btn {
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.payment-edit-btn:hover { background: #dbeafe; color: var(--primary); }
.payment-delete-btn:hover { background: #fee2e2; color: var(--danger); }

.payment-edit-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

/* ============ 列表项 ============ */
.list-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.list-item:last-child { border-bottom: none; }

.list-item-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.list-item-desc {
  font-size: 12.5px;
  color: var(--muted);
}

/* ============ 登录页 ============ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-logo {
  font-size: 48px;
  text-align: center;
  margin-bottom: 16px;
}

.login-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 28px;
}

.login-form .form-group { margin-bottom: 14px; }
.login-form .form-group label { font-size: 13px; }

.login-tip {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ============ 空状态 ============ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-size: 14px;
}

/* ============ 进度条 ============ */
.progress-bar {
  height: 6px;
  background: var(--rule);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width 0.3s;
}

/* ============ 模态框触发区域 ============ */
.add-section {
  background: #f8fafc;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  padding: 14px;
  margin-top: 12px;
}

.add-section summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
}

.add-section summary::before {
  content: '+ ';
  font-weight: 700;
}

/* ============ 响应式 ============ */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .info-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
}

/* ============ 列表排序表头 ============ */
th a.th-sort {
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
th a.th-sort:hover { color: var(--accent); }
th a.th-sort.active {
  color: var(--accent);
  font-weight: 600;
}
