:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e6ea;
  --text: #1c252e;
  --text-muted: #6b7785;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #15803d;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1f2832;
    --border: #2a3441;
    --text: #e6edf3;
    --text-muted: #93a1b0;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --success: #4ade80;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

/* Header */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.header-title h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

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

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  font-family: inherit;
  line-height: 1;
}

.btn-sm { padding: 7px 12px; font-size: 13px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover { background: rgba(220, 38, 38, 0.08); }

/* Summary cards */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-label {
  font-size: 13px;
  color: var(--text-muted);
}

.summary-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Toolbar */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.toolbar-col {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}
.toolbar-col .field {
  flex: 1 1 150px;
  min-width: 140px;
}
.toolbar-col .toolbar-meta {
  flex: 0 0 auto;
  margin-left: auto;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-grow { flex: 1; }

.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.field input,
.field select {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.toolbar-meta {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-count {
  font-size: 13px;
  color: var(--text-muted);
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.jersey-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.jersey-table thead th {
  text-align: left;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.jersey-table th.col-num,
.jersey-table td.col-num { text-align: right; font-variant-numeric: tabular-nums; }

.jersey-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.jersey-table tbody tr:last-child td { border-bottom: none; }
.jersey-table tbody tr:hover { background: var(--surface-2); }

/* 合计行渲染到清单上方（表头之下） */
.jersey-table tfoot { display: table-header-group; }
.jersey-table tfoot td {
  padding: 13px 14px;
  background: var(--surface-2);
  font-weight: 700;
  border-bottom: 2px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.jersey-table tfoot .col-label {
  color: var(--text-muted);
  font-weight: 600;
}

.col-img { width: 72px; }
.col-actions { width: 110px; }

.cell-img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
}

.cell-name { font-weight: 600; }

.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.tag-sold { background: rgba(21, 128, 61, 0.14); color: var(--success); }
.tag-unsold { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.profit-pos { color: var(--success); font-weight: 600; }
.profit-neg { color: var(--danger); font-weight: 600; }

.row-actions {
  display: flex;
  gap: 8px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
  font-family: inherit;
}
.link-btn.danger { color: var(--danger); }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.modal-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 24px; line-height: 1; cursor: pointer; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.image-preview { margin-top: 10px; display: flex; align-items: center; gap: 12px; }
.image-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.image-preview[hidden] { display: none; }

.subtotal-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
}
.subtotal-preview strong { font-variant-numeric: tabular-nums; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}

.req { color: var(--danger); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.toast[hidden] { display: none; }

/* Responsive: mobile cards */
@media (max-width: 760px) {
  .app { padding: 16px 12px 48px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .header-title h1 { font-size: 22px; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; }

  .jersey-table thead { display: none; }
  .jersey-table, .jersey-table tbody, .jersey-table tfoot, .jersey-table tr, .jersey-table td { display: block; width: 100%; }
  .jersey-table tbody tr,
  .jersey-table tfoot tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 12px;
    padding: 4px 0;
  }
  .jersey-table tbody td,
  .jersey-table tfoot td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    text-align: right;
  }
  .jersey-table tbody tr td:last-child,
  .jersey-table tfoot tr td:last-child { border-bottom: none; }
  .jersey-table td::before {
    content: attr(data-label);
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }
  .jersey-table td.col-num { text-align: right; }
  .cell-img { margin-left: auto; }
  .col-img { width: auto; }
  .col-actions { width: auto; }
  .row-actions { justify-content: flex-end; }
  .field-row { flex-direction: column; gap: 16px; }
  /* 手机端合计卡片：隐藏空单元格 */
  .jersey-table tfoot td:empty { display: none; }
}

/* 全局：hidden 属性强制隐藏（覆盖 inline-flex / btn 等显示规则） */
[hidden] { display: none !important; }

/* 登录 / 注册 */
#auth-guest { display: inline-flex; gap: 10px; }
#user-box { display: inline-flex; align-items: center; gap: 10px; }
.user-name { font-size: 14px; font-weight: 600; color: var(--text); }

.logged-out { display: flex; justify-content: center; padding: 64px 20px; }
.logged-out-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 460px;
  text-align: center;
  box-shadow: var(--shadow);
}
.logged-out-card h2 { margin: 0 0 10px; font-size: 20px; }
.logged-out-card p { color: var(--text-muted); margin: 0 0 20px; }
.auth-buttons { display: flex; gap: 12px; justify-content: center; }

.auth-dialog { max-width: 400px; }
.auth-error {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.auth-error[hidden] { display: none; }
.auth-switch { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); text-align: center; }
.auth-switch a { color: var(--primary); cursor: pointer; }

/* 删除账号 / 管理员危险操作按钮 */
.btn.danger { color: var(--danger); border-color: rgba(220, 38, 38, .35); }
.btn.danger:hover { background: rgba(220, 38, 38, .12); border-color: rgba(220, 38, 38, .5); }
.admin-hint { color: var(--text-muted); font-size: 13px; margin: 0 0 14px; line-height: 1.5; }
.admin-table { margin-top: 4px; }
.admin-table th, .admin-table td { padding: 10px 12px; }
