/* ========== Reset & Variables ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-bg: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
  --sidebar-w: 240px;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }

/* ========== Login Page ========== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 48px 40px; width: 400px; box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); }
.login-card h1 { text-align: center; font-size: 24px; color: var(--gray-800); margin-bottom: 8px; }
.login-card .subtitle { text-align: center; color: var(--gray-400); font-size: 14px; margin-bottom: 32px; }
.login-card label { display: block; font-size: 14px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.login-card input { width: 100%; padding: 12px 16px; border: 2px solid var(--gray-200); border-radius: var(--radius); font-size: 15px; outline: none; transition: border-color .2s; }
.login-card input:focus { border-color: var(--primary); }
.login-card .error { color: var(--danger); font-size: 13px; margin-top: 8px; display: none; }
.login-card .btn { width: 100%; margin-top: 20px; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius); font-size: 16px; font-weight: 500; cursor: pointer; transition: background .2s; }
.login-card .btn:hover { background: #4338ca; }
.login-card .hint { text-align: center; color: var(--gray-400); font-size: 12px; margin-top: 16px; }

/* ========== Layout ========== */
.app-layout { display: flex; min-height: 100vh; }
/* ★ 侧边栏：整体不滚动，只有中间 nav 区域滚动，底部「退出登录」永远钉在可见区域 */
.sidebar { width: var(--sidebar-w); background: #fff; border-right: 1px solid var(--gray-200); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 10; overflow: hidden; }
.sidebar-logo { padding: 24px 20px; border-bottom: 1px solid var(--gray-100); flex-shrink: 0; }
.sidebar-logo h2 { font-size: 18px; color: var(--primary); }
.sidebar-logo span { font-size: 12px; color: var(--gray-400); }
/* ★ min-height:0 是关键：否则 flex 子项无法收缩，nav 会把底部按钮顶出可视区 */
.sidebar nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px 0; }
.sidebar nav::-webkit-scrollbar { width: 6px; }
.sidebar nav::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
.sidebar nav::-webkit-scrollbar-thumb:hover { background: var(--gray-300); }
/* ★ 底部固定区：永远可见，不随 nav 滚动 */
.sidebar-footer { flex-shrink: 0; padding: 12px 16px; border-top: 1px solid var(--gray-100); background: #fff; }
/* ★ 当前登录用户信息模块 */
.current-user { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--gray-50); border-radius: var(--radius); min-width: 0; }
.current-user .cu-avatar { flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.current-user .cu-meta { min-width: 0; flex: 1; }
.current-user .cu-name { font-size: 13px; font-weight: 600; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.current-user .cu-username { font-size: 11px; color: var(--gray-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.current-user .cu-pwd { flex-shrink: 0; font-size: 11px; color: var(--primary); background: var(--primary-bg); padding: 3px 8px; border-radius: 12px; white-space: nowrap; }
.current-user:hover { background: var(--gray-100); cursor: pointer; }
.sidebar-footer .btn-logout { width: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; font-size: 13px; color: var(--gray-600); }
.sidebar-footer .btn-logout:hover { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.sidebar-footer .btn-logout .icon { font-size: 14px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 12px 20px; margin: 2px 8px; border-radius: var(--radius); cursor: pointer; font-size: 14px; color: var(--gray-600); transition: all .15s; text-decoration: none; }
.nav-item:hover { background: var(--gray-50); color: var(--gray-800); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); font-weight: 500; }
.nav-item .icon { font-size: 18px; width: 20px; text-align: center; }
.nav-section { font-size: 11px; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: .5px; padding: 16px 20px 6px; }
.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 32px; min-height: 100vh; }
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 24px; font-weight: 600; color: var(--gray-900); }
.page-header p { color: var(--gray-500); font-size: 14px; margin-top: 4px; }

/* ========== Cards & Stats ========== */
.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 13px; color: var(--gray-500); }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--gray-900); margin: 6px 0; }
.stat-card .sub { font-size: 12px; color: var(--gray-400); }
.stat-card.success .value { color: var(--success); }
.stat-card.warning .value { color: var(--warning); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.info .value { color: var(--info); }

/* ===== 运营商保证金进度条 ===== */
.progress { height: 8px; background: var(--gray-200); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress-bar.done { background: var(--success); }
.progress-bar.settling { background: var(--warning); }
.progress-bar.released { background: var(--gray-400); }

.charts-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.chart-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.chart-card h3 { font-size: 15px; font-weight: 600; color: var(--gray-800); margin-bottom: 16px; }

/* ========== Table ========== */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 13px; outline: none; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); }
.toolbar input { min-width: 200px; }
.toolbar .spacer { flex: 1; }
.btn { padding: 8px 16px; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338ca; }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--gray-300); color: var(--gray-600); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ★ 通用显隐工具类：配合 classList.toggle 使用，不触碰元素内联样式
   （运力库 Tab 切换场景：#lead-stats 内联 display:flex 不能被 style.display='' 抹掉） */
.hide { display: none !important; }

.table-wrapper { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: hidden; }
.table-wrapper table { min-width: 100%; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--gray-50); padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--gray-200); }
td { padding: 12px 16px; font-size: 13px; color: var(--gray-700); border-bottom: 1px solid var(--gray-100); }
tr:hover { background: var(--gray-50); }
tr:last-child td { border-bottom: none; }
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 16px; font-size: 13px; color: var(--gray-500); border-top: 1px solid var(--gray-100); }
.pagination .btns { display: flex; gap: 6px; }

/* ========== Status Badges ========== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-accepted { background: #dbeafe; color: #1e40af; }
.badge-picking { background: #e0e7ff; color: #3730a3; }
.badge-delivering { background: #d1fae5; color: #065f46; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-review { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
/* ★ 超时判定徽章（管理后台订单列表）：准时=绿、超时=红 */
.badge-ontime { background: #d1fae5; color: #065f46; }
.badge-overtime { background: #fee2e2; color: #991b1b; font-weight: 600; }

/* ★ 一单多取件码：订单列表「取件码」列（最多 5 个） */
.pickup-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.badge-codecount { background: #ede9fe; color: #5b21b6; font-weight: 600; cursor: help; }

/* ========== Modal ========== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 12px; padding: 28px; width: 480px; max-width: 90vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); }
.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.modal label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-600); margin-bottom: 4px; margin-top: 12px; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 13px; outline: none; margin-bottom: 8px; }
.modal input:focus, .modal select:focus, .modal textarea:focus { border-color: var(--primary); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ========== Assign Modal（派单弹窗） ========== */
.assign-rider-list { max-height: 55vh; overflow-y: auto; border: 1px solid var(--gray-200); border-radius: var(--radius); background: #fff; }
.rider-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.rider-table thead { position: sticky; top: 0; z-index: 1; }
.rider-table thead th { padding: 10px 12px; text-align: left; font-size: 12px; font-weight: 600; color: var(--gray-600); background: var(--gray-50); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
.rider-table tbody td { padding: 12px; font-size: 13px; color: var(--gray-700); border-bottom: 1px solid var(--gray-100); vertical-align: top; word-break: break-word; }
.rider-table tbody tr.rider-tr { cursor: pointer; transition: background-color .12s; }
.rider-table tbody tr.rider-tr:hover { background: var(--primary-bg); }
.rider-table tbody tr.rider-tr.selected { background: var(--primary-bg); }
.rider-table tbody tr.rider-tr.selected td { border-bottom-color: var(--primary-light); }
.rider-table tbody tr.rider-tr:last-child td { border-bottom: none; }
.rider-table input[type="radio"] { accent-color: var(--primary); cursor: pointer; width: 16px; height: 16px; margin: 0; }

/* ★ 当前配送员行（改派场景）：醒目黄底 + 左侧橙色色条，禁止选中 */
.rider-table tbody tr.rider-tr.current-rider { background: #fef3c7; cursor: not-allowed; box-shadow: inset 4px 0 0 0 #f59e0b; }
.rider-table tbody tr.rider-tr.current-rider td { border-bottom-color: #fde68a; }
.rider-table tbody tr.rider-tr.current-rider:hover { background: #fde68a; }
.rider-table tbody tr.rider-tr.current-rider td:first-child { font-weight: 700; color: #92400e; }
.current-tag { display: inline-block; padding: 3px 10px; background: #f59e0b; color: #fff; border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap; line-height: 1.4; box-shadow: 0 1px 2px rgba(245, 158, 11, 0.3); }
.badge.badge-current { background: #f59e0b; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; display: inline-block; }
/* ★ 通知能力徽章：未绑定微信（红色）/ 未绑服务号（橙色） */
.badge.badge-warning { background: #dc2626; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; display: inline-block; }
.badge.badge-sa-warn { background: #f59e0b; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; display: inline-block; }

/* ========== Tabs ========== */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; }
.tab { padding: 10px 20px; font-size: 14px; color: var(--gray-500); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* ========== Detail Card ========== */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-item { padding: 8px 0; }
.detail-item .dl { font-size: 12px; color: var(--gray-400); }
.detail-item .dv { font-size: 14px; color: var(--gray-800); margin-top: 2px; }

/* ========== Toast ========== */
.toast { position: fixed; top: 24px; right: 24px; padding: 12px 24px; border-radius: var(--radius); color: #fff; font-size: 14px; z-index: 200; animation: slideIn .3s ease; box-shadow: var(--shadow-lg); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Loading ========== */
.loading { text-align: center; padding: 40px; color: var(--gray-400); }
.empty { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty .icon { font-size: 48px; margin-bottom: 12px; }

/* ========== Dashboard specific ========== */
.pending-list { list-style: none; }
.pending-list li { padding: 10px 0; border-bottom: 1px solid var(--gray-100); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.pending-list li:last-child { border-bottom: none; }

/* ========== 异常单处理工作台 ========== */
.issue-card { background: #fff; border-radius: var(--radius); padding: 16px 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.issue-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; }
.issue-card-body { font-size: 13px; color: var(--gray-600); display: flex; flex-direction: column; gap: 8px; }
.issue-card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.issue-photo { width: 96px; height: 96px; object-fit: cover; border-radius: 6px; margin: 6px 8px 0 0; cursor: zoom-in; border: 1px solid var(--gray-200); }
.issue-statement { padding: 6px 8px; background: var(--gray-50); border-radius: 6px; margin-top: 4px; }
.muted { color: var(--gray-400); font-size: 12px; }
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 300; }
.modal-overlay .modal { background: #fff; border-radius: 12px; padding: 24px; width: 90%; box-shadow: var(--shadow-lg); }
.modal-overlay textarea { border: 2px solid var(--gray-200); border-radius: var(--radius); padding: 10px; font-size: 14px; outline: none; }
.modal-overlay textarea:focus { border-color: var(--primary); }

/* ========== Responsive ========== */
@media (max-width: 1024px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } .charts-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .stats-grid { grid-template-columns: repeat(1, 1fr); } }
