:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #1d2b3a;
  --muted: #667689;
  --line: #dde5ec;
  --brand: #0f5c6b;
  --brand-soft: #e3f0f2;
  --accent: #c46a1b;
  --danger: #b3261e;
  --green: #1f7a4d;
  --amber: #9a6412;
  --blue: #245f9e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(18, 38, 58, .06), 0 8px 24px rgba(18, 38, 58, .05);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: #f7fafc;
  border-radius: 8px;
  padding: 9px 14px;
  transition: .15s ease;
}
button:hover { background: #eef5f7; border-color: #c6d6df; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: #0b4d59; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }

input, select {
  border: 1px solid #c7d3dd;
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 92, 107, .12); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 26px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: .5px; color: var(--brand); white-space: nowrap; }
.brand span { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 8px; letter-spacing: 0; }
.snapshot { flex: 1; color: var(--muted); font-size: 12.5px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplink { color: var(--brand); text-decoration: none; font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; white-space: nowrap; }
.toplink:hover { background: var(--brand-soft); border-color: #c6d6df; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.user button { padding: 6px 11px; }

main { max-width: 1380px; margin: 0 auto; padding: 22px 26px 60px; }

section { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px; }

.search-panel { padding: 18px 22px; }
.search-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-row input { flex: 1; min-width: 240px; max-width: 520px; }
.search-row select { width: 96px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

.empty { text-align: center; color: var(--muted); padding: 46px 20px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

.customer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.customer-head h2 { margin: 0 0 4px; font-size: 20px; color: var(--brand); }
.muted { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; line-height: 1.5; background: #eef3f7; color: var(--muted); }
.badge.warn { background: #fbeede; color: var(--amber); }
.badge.danger { background: #fbe6e4; color: var(--danger); }
.badge.ok { background: #e3f3ea; color: var(--green); }
.badge.info { background: #e5eef9; color: var(--blue); }

.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.card { background: linear-gradient(180deg, #f4f8fa, #eef4f7); border: 1px solid #e3ebf1; border-radius: 10px; padding: 14px 15px; min-width: 0; }
.card .label { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.card .value { font-size: 24px; font-weight: 700; margin: 4px 0 2px; letter-spacing: .2px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 11.5px; line-height: 1.4; }

.record-cards { display: none; }
.rcard { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px 13px; }
.rcard-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rcard-title { font-weight: 600; line-height: 1.45; word-break: break-word; }
.rcard-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12.5px; margin-top: 7px; }
.rcard-meta b { color: var(--ink); font-weight: 600; }
.rcard-flags { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.5; word-break: break-word; }
.rcard-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.rcard .rowbtn { margin-top: 10px; }

.section-title { margin: 0 0 4px; font-size: 18px; color: var(--brand); }
.staff-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}
.staff-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--muted);
}
.staff-form input, .staff-form select { width: 100%; }
.staff-form button { height: 40px; white-space: nowrap; }
.staff-table td:last-child { white-space: nowrap; }
.staff-table .rowbtn { margin-right: 4px; }
.pwd-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.pwd-form input { width: 100%; }

.breakdown { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin: 4px 0 14px; }
.breakdown span { background: #f2f6f9; border-radius: 6px; padding: 2px 8px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 4px 0 14px; }
.toolbar select { max-width: 240px; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; max-width: 320px; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.toolbar input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 10px 10px; border-bottom: 1px solid #e8eef3; text-align: left; vertical-align: top; }
th { background: #f2f7fa; color: #41566b; font-size: 12.5px; font-weight: 600; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
tbody tr:hover { background: #f8fbfc; }
tbody tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.product { min-width: 220px; }
td.flags { color: var(--muted); font-size: 12.5px; max-width: 300px; }
.rowbtn { padding: 5px 10px; font-size: 12.5px; white-space: nowrap; }

.status { display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 12px; white-space: nowrap; }
.status.ok { background: #e3f3ea; color: var(--green); }
.status.pending { background: #fbeede; color: var(--amber); }
.status.bad { background: #f0f2f5; color: #667689; }
.status.info { background: #e5eef9; color: var(--blue); }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 14px; color: var(--muted); font-size: 13px; }

.notes { font-size: 13px; color: var(--muted); }
.notes summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.notes p { margin: 10px 0; }
.notes ul { margin: 8px 0 0 18px; padding: 0; }
.notes li { margin: 4px 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2f3d;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s ease;
  z-index: 100;
  max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(860px, 94vw);
  max-height: 88vh;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
  color: var(--ink);
}
dialog::backdrop { background: rgba(18, 30, 42, .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.dialog-head h3 { margin: 0; font-size: 17px; }
.dialog-head button { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 0 4px; color: var(--muted); }
.dialog-body { padding: 16px 20px 20px; overflow: auto; max-height: calc(88vh - 60px); }
.detail-meta { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; word-break: break-all; }
.raw-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: 260px; margin-bottom: 14px; }
.raw-wrap table { min-width: 0; }
.raw-wrap td { padding: 7px 10px; font-size: 12.5px; border-bottom: 1px solid #eef2f5; }
.raw-wrap td:first-child { width: 120px; color: var(--muted); white-space: nowrap; }
.reason { background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #3c5064; margin-bottom: 14px; white-space: pre-wrap; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.edit-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.edit-grid label.full { grid-column: 1 / -1; }
.edit-grid label.check { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; }
.edit-grid input[type="number"], .edit-grid input[type="text"] { width: 100%; }
.dialog-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 20% 0%, #dcebf0, transparent), var(--bg); }
.login-card { width: min(400px, 100%); background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 30px; }
.login-card h1 { margin: 0 0 4px; font-size: 21px; color: var(--brand); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 22px; padding: 11px; }
.login-error { min-height: 20px; color: var(--danger); font-size: 13px; margin-top: 10px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }
.login-foot a { color: var(--muted); text-decoration: none; }
.login-foot a:hover { color: var(--brand); }
.site-footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 18px 12px 30px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--brand); }

@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .snapshot { display: none; }
  .staff-form { grid-template-columns: 1fr 1fr; }
  .staff-form button { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  main { padding: 14px 12px 40px; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand { font-size: 16px; }
  .brand span { display: none; }
  section { padding: 16px 14px; border-radius: 10px; }
  .search-row select { width: 84px; }
  .search-row input { min-width: 0; }
  .customer-head { flex-direction: column; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card .value { font-size: 20px; }
  .toolbar select { max-width: none; width: 100%; }
  .toolbar input[type="search"] { max-width: none; width: 100%; }
  .edit-grid { grid-template-columns: 1fr; }
  .staff-form { grid-template-columns: 1fr; }
  #customer .table-wrap { display: none; }
  .record-cards { display: flex; flex-direction: column; gap: 10px; }
  table { min-width: 720px; }
}
