/* ============================================================
   components.css — 卡片 / 按钮 / 表格 / 徽章 / 表单 / 弹窗
   ============================================================ */

/* ============================================================
   卡片
   ============================================================ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
  padding: 22px;
}

.card + .card {
  margin-top: 18px;
}

.card h3 {
  font-size: 14.5px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

/* ============================================================
   统计卡
   ============================================================ */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
  transition: transform .22s, box-shadow .22s;
  min-width: 0;
}

.stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.stat .label {
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.8px;
  word-break: break-all;
}

.stat .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.stat .icon {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 19px;
}

.stat.blue   .icon { background: #eef2ff; color: #4f46e5; }
.stat.green  .icon { background: #ecfdf5; color: #10b981; }
.stat.orange .icon { background: #fff7ed; color: #f59e0b; }
.stat.pink   .icon { background: #fdf2f8; color: #ec4899; }
.stat.cyan   .icon { background: #ecfeff; color: #06b6d4; }
.stat.red    .icon { background: #fef2f2; color: #ef4444; }
.stat.purple .icon { background: #faf5ff; color: #a855f7; }

/* ============================================================
   按钮
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 11px;
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--text) !important;
  cursor: pointer;
  font-weight: 500;
  font-size: 13.5px;
  transition: all .18s;
  white-space: nowrap;
  line-height: 1.2;
}

.btn:hover {
  background: var(--bg);
  border-color: var(--border-2);
}

.btn-primary {
  background: var(--primary-grad) !important;
  border: none !important;
  color: #fff !important;
  box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
}

.btn-primary:hover {
  box-shadow: 0 8px 22px rgba(79, 70, 229, .5);
  transform: translateY(-1px);
  color: #fff !important;
}

.btn-primary * {
  color: #fff !important;
}

.btn-danger {
  background: var(--card);
  color: var(--danger) !important;
  border-color: #fee2e2;
}

.btn-danger:hover {
  background: #fef2f2;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
  border-radius: 9px;
}

.btn-success {
  background: #10b981;
  border-color: #10b981;
  color: #fff !important;
}

/* ============================================================
   表格
   ============================================================ */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  width: 100%;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th, td {
  padding: 15px 20px;
  text-align: left;
  font-size: 13.5px;
}

th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg);
}

td a.link {
  color: var(--primary);
  font-weight: 600;
}

td a.link:hover {
  text-decoration: underline;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 56px 0;
}

/* ============================================================
   徽章
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-潜在客户 { background: #eef2ff; color: #4338ca; }
.badge-跟进中   { background: #fff7ed; color: #c2410c; }
.badge-已成交   { background: #ecfdf5; color: #047857; }
.badge-已流失   { background: #fef2f2; color: #b91c1c; }

.level-A { background: #fef2f2; color: #b91c1c; }
.level-B { background: #fff7ed; color: #c2410c; }
.level-C { background: #eff6ff; color: #1d4ed8; }

.stage-初步接洽 { background: #eef2ff; color: #4338ca; }
.stage-需求确认 { background: #eff6ff; color: #1d4ed8; }
.stage-方案报价 { background: #fff7ed; color: #c2410c; }
.stage-谈判     { background: #fdf4ff; color: #a21caf; }
.stage-赢单     { background: #ecfdf5; color: #047857; }
.stage-输单     { background: #fef2f2; color: #b91c1c; }

.badge-高   { background: #fef2f2; color: #b91c1c; }
.badge-中   { background: #fff7ed; color: #c2410c; }
.badge-低   { background: #eff6ff; color: #1d4ed8; }
.badge-待办 { background: #fff7ed; color: #c2410c; }
.badge-完成 { background: #ecfdf5; color: #047857; }
.badge-逾期 { background: #fef2f2; color: #b91c1c; }
.badge-low  { background: #fef2f2; color: #b91c1c; }

.status-待入库 { background: #fff7ed; color: #c2410c; }
.status-已入库 { background: #ecfdf5; color: #047857; }
.status-已取消 { background: #fef2f2; color: #b91c1c; }

.type-采购入库 { background: #ecfdf5; color: #047857; }
.type-销售出库 { background: #eff6ff; color: #1d4ed8; }
.type-退货入库 { background: #f0fdf4; color: #15803d; }
.type-退货出库 { background: #fef2f2; color: #b91c1c; }
.type-其他入库 { background: #f1f5f9; color: #334155; }
.type-其他出库 { background: #f1f5f9; color: #334155; }
.type-盘点     { background: #fdf4ff; color: #a21caf; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 7px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 11.5px;
  margin-right: 4px;
  border: 1px solid var(--border);
}

.doc-no {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.qty-plus  { color: var(--success); font-weight: 700; }
.qty-minus { color: var(--danger); font-weight: 700; }

/* ============================================================
   表单
   ============================================================ */
.form-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 30px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  max-width: 780px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 22px;
}

.form-row {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.form-row.full {
  grid-column: 1 / -1;
}

.form-row label {
  margin-bottom: 7px;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 600;
}

.form-row label .req {
  color: var(--danger);
}

.form-row input,
.form-row select,
.form-row textarea {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  transition: all .18s;
  color: var(--text);
  width: 100%;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--primary);
  background: var(--card);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .10);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.pwd-meter {
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  margin-top: 8px;
  overflow: hidden;
}

.pwd-meter .bar {
  height: 100%;
  width: 0;
  transition: width .3s, background .3s;
}

.pwd-tips {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.pwd-tips.ok  { color: var(--success); }
.pwd-tips.bad { color: var(--danger); }

.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  background: var(--card);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  align-items: center;
  width: 100%;
}

.filter-bar input,
.filter-bar select {
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  transition: all .18s;
  color: var(--text);
}

.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--primary);
  background: var(--card);
}

.filter-bar input {
  flex: 1 1 200px;
  min-width: 0;
}

/* ============================================================
   销售/采购单表格
   ============================================================ */
.sales-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.sales-table th,
.sales-table td {
  padding: 10px;
  border: 1px solid var(--border);
  text-align: left;
  font-size: 13.5px;
}

.sales-table th {
  background: var(--bg);
  font-weight: 600;
}

.sales-table input,
.sales-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

.sales-table .subtotal {
  color: var(--primary);
  font-weight: 600;
  text-align: right;
}

/* ============================================================
   分页
   ============================================================ */
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin: 28px 0;
  flex-wrap: wrap;
}

.pagination a,
.pagination span {
  padding: 9px 15px;
  border-radius: 11px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
}

.pagination a:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ============================================================
   页面头
   ============================================================ */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  gap: 14px;
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -.5px;
}

/* ============================================================
   详情 / 跟进
   ============================================================ */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.detail-list p {
  display: flex;
  padding: 11px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13.5px;
}

.detail-list p:last-child {
  border-bottom: none;
}

.detail-list p strong {
  color: var(--muted);
  font-weight: 500;
  min-width: 92px;
  flex-shrink: 0;
}

.follow-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 20px;
}

.follow-form textarea {
  padding: 13px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  resize: vertical;
  background: var(--bg);
  transition: all .2s;
}

.follow-form textarea:focus {
  border-color: var(--primary);
  background: var(--card);
}

.follow-list {
  list-style: none;
}

.follow-list li {
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.follow-list li:last-child {
  border-bottom: none;
}

.follow-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ============================================================
   进度条 / 任务列表
   ============================================================ */
.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 6px;
}

.progress .bar {
  height: 100%;
  background: var(--primary-grad);
  border-radius: 999px;
  transition: width .4s;
}

.task-list {
  list-style: none;
}

.task-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: all .18s;
}

.task-list li:hover {
  background: var(--bg);
}

.task-list .check {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all .2s;
  color: transparent;
  font-size: 12px;
}

.task-list .check.done {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ============================================================
   头像
   ============================================================ */
.avatar-fallback {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  background: var(--primary-grad);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(79, 70, 229, .35);
}

.avatar-preview-wrap {
  width: 96px;
  height: 96px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border-radius: 24px;
}

.avatar-preview-wrap img {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================================
   弹窗
   ============================================================ */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
  animation: fadeIn .18s ease;
}

.modal-mask.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--card);
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  padding: 26px 26px 22px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: pop .22s ease;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.modal .modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.modal .modal-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.modal .modal-icon.warn { background: #fef2f2; color: var(--danger); }
.modal .modal-icon.info { background: var(--primary-soft); color: var(--primary); }
.modal .modal-icon.ok   { background: #ecfdf5; color: var(--success); }

.modal h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal .modal-body {
  color: var(--text-2);
  font-size: 13.5px;
  margin: 6px 0 18px;
  line-height: 1.7;
}

.modal .modal-body input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  background: var(--bg);
  margin-top: 8px;
  transition: all .18s;
  color: var(--text);
}

.modal .modal-body input:focus {
  border-color: var(--primary);
  background: var(--card);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .10);
}

.modal .modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-head {
  position: relative;
}

.modal-close {
  position: absolute;
  right: -4px;
  top: -4px;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  background: transparent;
  border: 0;
  line-height: 1;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--danger);
}

/* ============================================================
   Toast
   ============================================================ */
.toast-wrap {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 20px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .16), 0 2px 6px rgba(15, 23, 42, .06);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn .3s cubic-bezier(.16, 1, .3, 1);
  min-width: 200px;
  pointer-events: auto;
  color: var(--text);
  word-break: break-word;
}

.toast .toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.toast.success .toast-icon { background: linear-gradient(135deg, #10b981, #34d399); }
.toast.error   .toast-icon { background: linear-gradient(135deg, #ef4444, #f87171); }
.toast.success { border-left: 3px solid #10b981; }
.toast.error   { border-left: 3px solid #ef4444; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px) scale(.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ============================================================
   批量操作栏
   ============================================================ */
.bulk-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #eef2ff, #f5f3ff);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(79, 70, 229, .10);
  animation: slideDown .25s ease;
}

body.dark .bulk-bar {
  background: linear-gradient(135deg, #1e1b4b, #2e1065);
  border-color: #4c1d95;
}

.bulk-bar .bulk-info {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--primary);
  margin-right: auto;
}

.bulk-bar .bulk-info strong {
  font-size: 16px;
  color: var(--primary);
}

body.dark .bulk-bar .bulk-info,
body.dark .bulk-bar .bulk-info strong {
  color: #a5b4fc;
}

.row-check,
#checkAll {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  display: block;
  margin: 0 auto;
}

/* ============================================================
   无权限提示卡片
   ============================================================ */
.permission-denied-wrap {
  display: grid;
  place-items: center;
  min-height: 60vh;
  padding: 20px;
}

.permission-denied-card {
  max-width: 480px;
  text-align: center;
  padding: 48px 40px;
  animation: pop .25s ease;
}

.permission-denied-card .pd-icon {
  font-size: 64px;
  margin-bottom: 16px;
  line-height: 1;
}

.permission-denied-card .pd-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

.permission-denied-card .pd-desc {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
  margin-bottom: 24px;
}

.permission-denied-card .pd-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ============================================================
   响应式
   ============================================================ */

/* 中屏（≤1200px）：stats 4 列、表单也适配 */
@media (max-width: 1200px) {
  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* 平板（≤992px）：stats 3 列、detail 单列、form 单列 */
@media (max-width: 992px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .detail-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* 小平板（≤768px）：stats 2 列 */
@media (max-width: 768px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .stat {
    padding: 16px;
  }
  .stat .value {
    font-size: 22px;
  }
  .stat .icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
    right: 12px;
    top: 12px;
  }
  .form-card {
    padding: 22px;
  }
  .page-head h1 {
    font-size: 19px;
  }
}

/* 手机（≤640px）：stats 2 列、toast 占满、按钮换行 */
@media (max-width: 640px) {
  .toast-wrap {
    top: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
  .toast {
    min-width: 0;
    width: 100%;
  }
  .modal {
    padding: 22px 20px 18px;
  }
  .modal .modal-foot {
    flex-direction: column-reverse;
  }
  .modal .modal-foot .btn {
    width: 100%;
    justify-content: center;
  }
  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }
  .btn-sm {
    padding: 5px 9px;
    font-size: 12px;
  }
  .pagination a,
  .pagination span {
    padding: 7px 12px;
    font-size: 12.5px;
  }
}

/* 超小屏（≤420px）：stats 1 列 */
@media (max-width: 420px) {
  .stats {
    grid-template-columns: 1fr;
  }
  .form-card {
    padding: 18px;
  }
  .card {
    padding: 16px;
  }
}

/* ============================================================
   打印
   ============================================================ */
@media print {
  .bulk-bar,
  .toast-wrap,
  .modal-mask,
  .toolbar,
  .filter-bar,
  .scope-tip {
    display: none !important;
  }
}