/* ============================================
 * 采购管理系统 - 苹果风格 UI
 * 配色: #F5F5F7 / #FFFFFF / #0071E3
 * ============================================ */

:root {
  --bg-page: #F5F5F7;
  --bg-card: #FFFFFF;
  --bg-hover: #F5F5F7;
  --bg-highlight: #E8F1FD;
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-tertiary: #86868B;
  --color-primary: #0071E3;
  --color-primary-hover: #0077ED;
  --color-primary-active: #006EDB;
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-danger: #FF3B30;
  --border-color: #D2D2D7;
  --border-light: #E8E8ED;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 980px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.12);
  --font-family: -apple-system, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ===== Layout ===== */
.app-layout { min-height: 100vh; display: flex; flex-direction: row; }

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  z-index: 1001;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-brand {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: var(--transition);
  min-height: 44px;
}
.sidebar-nav a:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-nav a.active {
  color: var(--color-primary);
  background: var(--bg-highlight);
  font-weight: 500;
}
.sidebar-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border-light);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 12px;
  color: var(--text-tertiary);
}
.sidebar-logout {
  width: 100%;
  justify-content: center;
}

/* ===== Sidebar Backdrop ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

/* ===== Main Area ===== */
.main-area {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* ===== Topbar (mobile only) ===== */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.container {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 24px;
  flex: 1;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-title { font-size: 20px; font-weight: 600; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); color: #fff; }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); }
.btn-secondary:hover { background: var(--border-light); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #E03430; color: #fff; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #2DB84E; color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}
.btn-outline:hover { background: var(--bg-highlight); }
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-lg { padding: 12px 32px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}
.form-label .required { color: var(--color-danger); }
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: var(--font-family);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(0,113,227,0.1);
}
.form-control::placeholder { color: var(--text-tertiary); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: 13px; color: var(--text-tertiary); margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row > .form-group { flex: 1; }

.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; background: var(--bg-card); border-radius: 0 0 var(--radius-md) var(--radius-md); }
table.data-table {
  width: auto;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-light);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tr:hover { background: var(--bg-hover); }
.data-table tr:last-child td { border-bottom: none; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: rgba(52,199,89,0.12); color: var(--color-success); }
.badge-warning { background: rgba(255,149,0,0.12); color: var(--color-warning); }
.badge-danger  { background: rgba(255,59,48,0.12); color: var(--color-danger); }
.badge-info    { background: rgba(0,113,227,0.12); color: var(--color-primary); }
.badge-default { background: rgba(110,110,115,0.12); color: var(--text-secondary); }

/* ===== Flash Messages ===== */
.flash {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 14px;
}
.flash-success { background: rgba(52,199,89,0.1); color: #1a7d34; }
.flash-error   { background: rgba(255,59,48,0.1); color: #c0352e; }
.flash-info    { background: rgba(0,113,227,0.1); color: #0058b0; }

/* ===== Stats Cards (Dashboard) ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 32px; font-weight: 700; color: var(--text-primary); }
.stat-label { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
}
.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}
.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 32px;
}

/* ===== Image Upload ===== */
.upload-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}
.upload-area:hover { border-color: var(--color-primary); background: var(--bg-highlight); }
.upload-area.dragover { border-color: var(--color-primary); background: var(--bg-highlight); }
.upload-preview {
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-md);
  margin-top: 12px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 24px;
}
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: var(--transition);
}
.pagination a:hover { background: var(--bg-hover); color: var(--text-primary); text-decoration: none; }
.pagination .active { background: var(--color-primary); color: #fff; }

/* ===== Address Parse ===== */
.parse-area {
  background: var(--bg-page);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.parse-area textarea {
  width: 100%;
  min-height: 80px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 14px;
  resize: vertical;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-tertiary);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .title { font-size: 17px; font-weight: 500; margin-bottom: 4px; }

/* ===== Mobile Nav Toggle ===== */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: var(--transition);
}
.nav-toggle span + span { margin-top: 5px; }
.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .sidebar { width: 200px; }
  .main-area { margin-left: 200px; }
}

@media (max-width: 860px) {
  /* 侧边栏改为抽屉 */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-area {
    margin-left: 0;
  }
  /* 顶栏显示 */
  .topbar {
    display: flex;
  }
  .nav-toggle {
    display: flex;
  }
}

@media (max-width: 768px) {
  .container { padding: 12px; }
  .card { padding: 16px; border-radius: var(--radius-lg); }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-title { font-size: 17px; }

  /* 统计卡片 */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 24px; }

  /* 表单 */
  .form-row { flex-direction: column; gap: 0; }
  .form-group { margin-bottom: 16px; }
  .form-control { font-size: 16px; } /* iOS 防缩放 */
  .parse-area textarea { font-size: 16px; } /* iOS 防缩放 */
  .form-label { font-size: 14px; }

  /* 按钮 - 触摸友好 */
  .btn { padding: 10px 20px; font-size: 15px; min-height: 44px; }
  .btn-sm { padding: 8px 16px; font-size: 14px; min-height: 40px; }
  .btn-lg { padding: 14px 28px; font-size: 17px; width: 100%; justify-content: center; min-height: 50px; }
  .card-header .btn { width: auto; }

  /* 表格 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap::before {
    content: '← 左右滑动查看 →';
    display: block;
    text-align: center;
    font-size: 11px;
    color: var(--text-tertiary);
    padding: 4px 0;
  }
  .data-table { font-size: 13px; min-width: 600px; }
  .data-table th, .data-table td { padding: 10px 12px; }

  /* 搜索栏 */
  .search-bar { flex-direction: column; gap: 8px; }
  .search-bar .form-control { width: 100%; }

  /* 分页 */
  .pagination { flex-wrap: wrap; gap: 2px; }
  .pagination a, .pagination span { min-width: 32px; height: 32px; font-size: 13px; }

  /* 批量操作栏 */
  .batch-bar { flex-wrap: wrap; gap: 8px; }

  /* 上传区域 */
  .upload-area { padding: 16px; }

  /* 订单详情网格 */
  .order-detail-grid { grid-template-columns: 1fr !important; }

  /* 登录页 */
  .login-card { padding: 28px 20px; margin: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .card { padding: 12px; }
  .card-header { flex-direction: column; align-items: stretch; }
  .card-header .btn { width: 100%; justify-content: center; }
  .sidebar-brand { font-size: 15px; }
  .login-title { font-size: 20px; }
  .stat-value { font-size: 28px; }

  /* 表格进一步紧凑 */
  .data-table { font-size: 12px; min-width: 500px; }
  .data-table th, .data-table td { padding: 8px 8px; }

  /* 按钮组水平滚动 */
  .btn-group-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    gap: 6px;
    padding-bottom: 4px;
  }
  .btn-group-wrap .btn { white-space: nowrap; flex-shrink: 0; }

  /* 表单底部按钮堆叠 */
  form .btn-lg + .btn-lg,
  form .btn-lg + a.btn-lg,
  form a.btn-lg + .btn-lg,
  form a.btn-lg + a.btn-lg { margin-top: 8px; }
  form .btn-lg { width: 100%; justify-content: center; }
}

/* ===== 小屏幕增强 ===== */
@media (max-width: 360px) {
  .sidebar-brand { font-size: 14px; }
  .container { padding: 8px; }
  .card { padding: 10px; border-radius: var(--radius-md); }
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-bold { font-weight: 600; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; }
.justify-between { justify-content: space-between; } .gap-2 { gap: 8px; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ===== Link ===== */
.link { color: var(--color-primary); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ===== Alert ===== */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; }
.alert-warning { background: rgba(255,149,0,0.1); color: var(--color-warning); border-left: 3px solid var(--color-warning); }

/* ===== Table (通用) ===== */
table.table { width: 100%; border-collapse: collapse; }
table.table th, table.table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-light); font-size: 14px; }
table.table th { font-weight: 600; color: var(--text-secondary); font-size: 13px; text-transform: uppercase; letter-spacing: 0.3px; }
table.table tr:hover { background: var(--bg-hover); }
table.table tr:last-child td { border-bottom: none; }

/* ===== Timeline (订单时间轴) ===== */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 2px; background: var(--border-light); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item:last-child { margin-bottom: 0; }
.timeline-dot {
  position: absolute; left: -28px; top: 0; width: 28px; height: 28px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 3px var(--bg-card);
}
.timeline-content { padding-left: 12px; }
.timeline-title { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.timeline-note { margin-bottom: 2px; }
.timeline-time { }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 90%; max-width: 500px;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-tertiary); padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border-light); display: flex; gap: 8px; justify-content: flex-end; }

/* ===== 移动端订单卡片 ===== */
.order-cards-mobile { display: none; }
.order-card-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border-light);
}
.order-card-item:last-child { border-bottom: none; }
.order-card-item:active { background: var(--bg-hover); }

/* ===== 桌面表格/移动卡片切换 ===== */
@media (max-width: 768px) {
  .table-wrap-desktop { display: none; }
  .order-cards-mobile { display: block; }
}

/* ===== 筛选栏 ===== */
.order-filter-bar { gap: 8px; }
.order-detail-grid { gap: 16px; }
