:root {
  color-scheme: light;
  --ink: #18221d;
  --muted: #66716a;
  --paper: #faf7ef;
  --panel: #fffdf8;
  --line: #ddd6c8;
  --green: #237a57;
  --red: #b34b42;
  --amber: #d88b2f;
  --blue: #2f5f8f;
  --shadow: 0 16px 42px rgba(68, 55, 31, 0.14);
  --ui-scale: 1;
  --page-pad: 18px;
  --section-gap: 18px;
  --card-pad: 18px;
  --control-h: 42px;
  --compact-control-h: 36px;
  --control-pad-x: 16px;
  --radius: 8px;
  --h1-size: 42px;
  --h2-size: 22px;
  --h3-size: 21px;
  --body-size: 14px;
  --label-size: 13px;
  --button-size: 14px;
  --field-size: 14px;
  --control-group-h: calc(var(--control-h) + 25px);
  --value-size: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(35, 122, 87, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(47, 95, 143, 0.1), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-size: var(--body-size);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

.adaptive-pending .app-shell {
  visibility: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  max-width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  padding: var(--page-pad) var(--page-pad) calc(var(--page-pad) * 2);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--section-gap);
  padding: calc(var(--page-pad) * 0.45) 2px var(--section-gap);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: calc(var(--section-gap) * 0.55);
  flex-wrap: nowrap;
}

.customer-mode .manager-only,
.guest-mode .manager-only {
  display: none !important;
}

body:not(.customer-mode) .customer-only,
.guest-mode .customer-only {
  display: none !important;
}

body:not(.customer-mode) .guest-field {
  display: none;
}

body:not(.auth-mode) .auth-only {
  display: none !important;
}

body[data-viewport-density="compact"] .muted,
body[data-viewport-density="compact"] .eyebrow,
body[data-viewport-density="compact"] label {
  font-size: 12px;
}

body[data-viewport-density="compact"] .tag {
  min-height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

body[data-viewport-density="compact"] .account-button {
  max-width: 108px;
}

body[data-viewport-density="roomy"] .app-shell {
  width: min(1180px, 100%);
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: var(--h1-size);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: var(--h2-size);
}

h3 {
  margin-bottom: 16px;
  font-size: var(--h3-size);
}

.icon-button,
.primary-button,
.account-button,
.secondary-button,
.danger-button {
  min-height: var(--control-h);
  border: 0;
  border-radius: var(--radius);
  font-size: var(--button-size);
  line-height: 1.15;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.icon-button:active,
.primary-button:active,
.account-button:active,
.secondary-button:active,
.danger-button:active {
  transform: translateY(1px);
}

.icon-button {
  width: calc(var(--control-h) + 2px);
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--green);
  font-size: 22px;
}

.primary-button {
  padding: 0 var(--control-pad-x);
  background: var(--green);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(35, 122, 87, 0.22);
}

.account-button {
  max-width: 180px;
  padding: 0 var(--control-pad-x);
  overflow: hidden;
  background: #eef5f1;
  color: var(--green);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secondary-button {
  padding: 0 calc(var(--control-pad-x) * 0.9);
  background: #eef5f1;
  color: var(--green);
  font-weight: 700;
}

.danger-button {
  padding: 0 calc(var(--control-pad-x) * 0.9);
  background: #fae8e5;
  color: var(--red);
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--section-gap);
  padding: var(--card-pad);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.status-panel strong {
  display: block;
  margin: 8px 0 4px;
  color: var(--green);
  font-size: 34px;
  line-height: 1;
}

.status-panel span {
  color: var(--muted);
}

.switch input {
  display: none;
}

.switch span {
  display: block;
  position: relative;
  width: 68px;
  height: 38px;
  border-radius: 999px;
  background: #c9c2b5;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  transition: left 0.2s ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  left: 34px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--section-gap);
  margin: calc(var(--section-gap) * 1.3) 0 var(--section-gap);
}

.toolbar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

#customerIntro {
  display: none;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: calc(var(--section-gap) * 0.65);
}

.toolbar-input,
.toolbar-select {
  width: auto;
  min-width: 150px;
  min-height: var(--control-h);
  background: rgba(255, 253, 248, 0.9);
}

.manager-dashboard {
  margin: calc(var(--section-gap) * 1.05) 0 calc(var(--section-gap) * 1.15);
  padding: calc(var(--card-pad) * 0.95);
  border: 1px solid rgba(221, 214, 200, 0.86);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.96), rgba(243, 247, 240, 0.86)),
    var(--panel);
  box-shadow: 0 14px 34px rgba(68, 55, 31, 0.1);
}

.dashboard-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--section-gap);
  margin-bottom: calc(var(--section-gap) * 0.85);
}

.dashboard-heading h2 {
  margin: 2px 0 0;
}

.dashboard-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.dashboard-summary span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef5f1;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.25fr) repeat(3, minmax(180px, 1fr));
  gap: calc(var(--section-gap) * 0.7);
}

.dashboard-card {
  min-width: 0;
  padding: calc(var(--card-pad) * 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
}

.dashboard-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.dashboard-card header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.dashboard-card header strong {
  color: var(--blue);
  font-size: 24px;
  line-height: 1;
}

.attention-card {
  border-color: rgba(216, 139, 47, 0.32);
  background: linear-gradient(135deg, #fffaf2, rgba(255, 253, 248, 0.92));
}

.backup-card {
  background: linear-gradient(135deg, #f4f8fb, rgba(255, 253, 248, 0.94));
}

.dashboard-list {
  display: grid;
  gap: 8px;
}

.dashboard-item {
  margin: 0;
  padding: 9px 10px;
  border-radius: var(--radius);
  background: rgba(243, 247, 240, 0.78);
  color: var(--ink);
  line-height: 1.45;
}

.dashboard-item.danger {
  background: #fff1df;
  color: #8a5415;
  font-weight: 800;
}

.dashboard-item.empty-line {
  color: var(--muted);
}

.compact-list .dashboard-item {
  display: grid;
  gap: 4px;
}

.compact-list b {
  color: var(--muted);
  font-size: 12px;
}

.compact-list span {
  overflow-wrap: anywhere;
}

.dashboard-more-button {
  width: 100%;
  margin-top: 10px;
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mini-metrics div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 9px;
  border-radius: var(--radius);
  background: #f3f7f0;
}

.mini-metrics span {
  color: var(--muted);
  font-size: 11px;
}

.mini-metrics strong {
  color: var(--blue);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.dashboard-foot {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.appointment-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: calc(var(--section-gap) * 0.75);
}

.appointment-card,
.product-type-detail,
.customer-detail,
.customer-list,
.metric,
.ledger-row,
.record-row {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
}

.appointment-card {
  padding: calc(var(--card-pad) * 0.9);
}

.appointment-card header,
.detail-title,
.row-between {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: calc(var(--section-gap) * 0.75);
}

.appointment-card h3,
.detail-title h2 {
  margin-bottom: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf2ee;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tag.pending {
  background: #fff1df;
  color: #9a5a10;
}

.tag.arrived {
  background: #e7f3ee;
  color: var(--green);
}

.tag.closed {
  background: #f4e8e4;
  color: var(--red);
}

.tag.expired {
  background: #ece9e1;
  color: #7b7a72;
}

.appointment-card p {
  color: var(--muted);
  line-height: 1.55;
}

.appointment-card.expired {
  background: rgba(239, 237, 231, 0.78);
  border-color: #d4d0c6;
  box-shadow: none;
}

.appointment-card.expired h3,
.appointment-card.expired p:not(.expired-hint) {
  color: #77766f;
}

.expired-hint {
  display: inline-flex;
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: #fff1df;
  color: #8a5415;
  font-weight: 800;
}

.card-actions {
  display: flex;
  gap: calc(var(--section-gap) * 0.55);
  margin-top: calc(var(--section-gap) * 0.75);
}

.customer-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--section-gap);
}

.customer-mode .customer-layout {
  display: block;
}

.customer-list {
  overflow: hidden;
}

.customer-item {
  width: 100%;
  min-height: 74px;
  padding: calc(var(--card-pad) * 0.65);
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.customer-item.active {
  background: #eef5f1;
}

.customer-item strong {
  display: block;
  margin-bottom: 4px;
}

.customer-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.customer-item strong,
.customer-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-detail {
  min-height: 520px;
  padding: var(--card-pad);
}

.product-type-detail {
  padding: var(--card-pad);
}

.product-view-toolbar {
  justify-content: flex-end;
  margin-top: 0;
}

.customer-mode .customer-detail {
  width: 100%;
  max-width: none;
  min-height: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--section-gap) * 0.65);
  margin: var(--section-gap) 0;
}

.customer-mode .metric-grid {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.metric {
  padding: calc(var(--card-pad) * 0.8);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  color: var(--blue);
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--section-gap) * 0.75);
  margin: calc(var(--section-gap) * 1.2) 0 calc(var(--section-gap) * 0.55);
}

.section-title h3 {
  margin-bottom: 0;
  font-size: 18px;
}

.customer-title-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.customer-title-actions .danger-button {
  min-height: 36px;
  padding: 0 14px;
}

.account-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--section-gap);
  align-items: start;
}

.record-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: calc(var(--section-gap) * 0.65);
}

.record-list .record-row {
  margin-bottom: 0;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: calc(var(--section-gap) * 0.65);
  align-items: end;
  margin: calc(var(--section-gap) * 0.75) 0;
}

.inline-form > button {
  width: auto;
  min-width: 128px;
  height: var(--control-h);
  min-height: var(--control-h);
  justify-self: start;
  align-self: end;
  padding-left: 20px;
  padding-right: 20px;
}

.account-security-form {
  grid-template-columns: minmax(180px, 320px) minmax(180px, 320px) auto;
  align-items: end;
  column-gap: var(--section-gap);
}

.account-security-form .secondary-button {
  min-width: 138px;
  width: auto;
  padding: 0 18px;
  justify-self: start;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--label-size);
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  font-size: var(--field-size);
  line-height: 1.25;
  padding: calc(var(--control-h) * 0.25) calc(var(--control-pad-x) * 0.75);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(35, 122, 87, 0.12);
}

.password-field {
  position: relative;
  display: block;
  min-width: 0;
}

.password-field input {
  padding-right: calc(var(--control-h) + 12px);
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  width: calc(var(--control-h) - 10px);
  height: calc(var(--control-h) - 10px);
  min-height: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  box-shadow: none;
}

.password-toggle::before {
  content: "";
  width: 18px;
  height: 11px;
  border: 1.8px solid currentColor;
  border-radius: 999px / 720px;
}

.password-toggle::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 1px rgba(255, 253, 248, 0.9);
}

.password-toggle[data-visible="true"]::before {
  opacity: 0.95;
}

.password-toggle[data-visible="true"]::after {
  width: 21px;
  height: 1.8px;
  border-radius: 999px;
  background: currentColor;
  transform: rotate(-42deg);
  box-shadow: 0 0 0 1px rgba(255, 253, 248, 0.9);
}

.password-toggle:active {
  transform: translateY(-50%);
}

.password-toggle:focus-visible {
  outline: 2px solid rgba(35, 122, 87, 0.35);
}

.product-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(130px, 148px) 112px;
  gap: 10px;
  align-items: end;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f3f7f0;
}

.fixed-consumption-picker {
  background: #fbf7ee;
}

.product-picker div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--control-h);
  padding: 0 12px;
  border-radius: var(--radius);
  background: white;
}

.product-picker span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.product-picker strong {
  color: var(--green);
  font-size: 17px;
  line-height: 1.15;
  white-space: nowrap;
}

.compact-action-button {
  min-width: 0;
  min-height: var(--control-h);
  height: var(--control-h);
  padding-left: 12px;
  padding-right: 12px;
  justify-self: stretch;
  align-self: end;
}

.product-type-panel {
  margin-bottom: calc(var(--section-gap) * 1.25);
  padding: calc(var(--card-pad) * 0.85);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(243, 247, 240, 0.72);
}

.product-type-panel .section-title {
  margin-top: 0;
}

.product-type-list {
  display: grid;
  gap: 8px;
}

.product-type-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 150px) minmax(130px, 170px) auto auto;
  gap: calc(var(--section-gap) * 0.55);
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
}

.product-type-row button {
  min-width: 76px;
}

.product-type-new {
  margin-top: 10px;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, 150px) minmax(130px, 170px) minmax(110px, auto);
  background: #f7fbf8;
}

.ledger-row,
.record-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: calc(var(--section-gap) * 0.65);
  align-items: center;
  margin-bottom: 8px;
  padding: calc(var(--card-pad) * 0.65);
}

.ledger-row span,
.record-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ledger-row span:nth-child(2),
.record-row span:nth-child(2) {
  justify-self: center;
  text-align: center;
}

.ledger-row strong,
.record-row strong {
  justify-self: end;
  text-align: right;
  white-space: nowrap;
}

.request-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.request-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(var(--section-gap) * 0.75);
  padding: calc(var(--card-pad) * 0.65);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
}

.request-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.ledger-row strong,
.record-row strong {
  color: var(--blue);
}

.round-off-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2ee;
  color: var(--green);
  font-style: normal;
  font-weight: 800;
}

.income strong {
  color: var(--green);
}

.expense strong {
  color: var(--red);
}

.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  border: 0;
  padding: 0;
  background: rgba(24, 34, 29, 0.38);
  place-items: center;
  z-index: 1000;
}

.modal[hidden] {
  display: none !important;
}

.modal.is-open {
  display: grid;
}

.dialog-card {
  width: min(440px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal.force-closed {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.dialog-card h4 {
  margin: 0;
  font-size: 17px;
}

.audit-dialog {
  width: min(760px, calc(100% - 28px));
}

.dialog-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.dialog-title-row h3 {
  margin-bottom: 4px;
}

.audit-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 220px);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(243, 247, 240, 0.66);
}

.audit-list {
  display: grid;
  gap: 8px;
  max-height: min(52vh, 520px);
  overflow: auto;
  padding-right: 2px;
}

.audit-row {
  display: grid;
  grid-template-columns: 118px minmax(104px, 140px) minmax(86px, 110px) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
}

.audit-row time {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.audit-row strong {
  color: var(--ink);
  font-size: 15px;
}

.audit-row span {
  color: var(--green);
  font-weight: 800;
}

.audit-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.login-panels {
  display: block;
}

.login-panels form {
  display: none;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.login-panels form.active {
  display: grid;
}

body.auth-login [data-auth-switch="login"],
body.auth-register [data-auth-switch="register"],
body.auth-recover [data-auth-switch="recover"],
body.auth-manager [data-auth-switch="manager"] {
  display: none;
}

menu {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 0;
  padding: 0;
}

menu button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
}

/* Pad：保留横向信息密度，但避免桌面多列在 768–1024px 视口中挤压 */
@media (min-width: 761px) and (max-width: 1024px) {
  :root {
    --page-pad: 16px;
    --section-gap: 14px;
    --card-pad: 15px;
    --control-pad-x: 13px;
  }

  .app-shell {
    width: 100%;
  }

  .topbar {
    gap: 12px;
  }

  .top-actions {
    gap: 8px;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid .dashboard-card:first-child {
    grid-column: 1 / -1;
  }

  .customer-layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .customer-mode .metric-grid,
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .metric {
    padding: 13px 11px;
  }

  .metric strong {
    font-size: 21px;
  }

  .inline-form,
  .account-security-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-form > button,
  .account-security-form .secondary-button {
    width: 100%;
    justify-self: stretch;
  }

  .inline-form > button {
    grid-column: 1 / -1;
  }

  .account-security-form .secondary-button {
    grid-column: 1 / -1;
  }

  .product-picker {
    grid-template-columns: minmax(0, 1fr) minmax(120px, 140px) 104px;
  }

  .product-type-row {
    grid-template-columns: minmax(150px, 1fr) minmax(100px, 125px) minmax(110px, 135px) auto auto;
    gap: 8px;
  }

  .audit-dialog {
    width: min(760px, calc(100% - 32px));
  }
}

/* Pad 客户档案：横向空间优先，操作区保持稳定的触控节奏 */
@media (min-width: 761px) and (max-width: 1024px) {
  #customerView .toolbar.compact {
    align-items: flex-start;
    margin-top: 10px;
    padding: 15px 16px;
    border: 1px solid rgba(221, 214, 200, 0.9);
    border-radius: 12px;
    background: rgba(255, 253, 248, 0.72);
  }

  #customerView .toolbar.compact h2 {
    margin-bottom: 2px;
    letter-spacing: -0.02em;
  }

  #customerView .customer-toolbar-actions {
    display: grid;
    grid-template-columns: minmax(150px, 1.35fr) minmax(120px, 1fr) repeat(3, minmax(82px, auto));
    align-items: center;
    gap: 8px;
    width: min(100%, 680px);
  }

  #customerView .customer-toolbar-actions .toolbar-input,
  #customerView .customer-toolbar-actions .toolbar-select,
  #customerView .customer-toolbar-actions button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  #customerView .customer-toolbar-actions button {
    padding-inline: 10px;
    font-size: 13px;
  }

  #customerView .customer-layout {
    grid-template-columns: 238px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  #customerView .customer-list {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 170px);
    overflow: auto;
    border-color: rgba(35, 122, 87, 0.22);
    box-shadow: 0 12px 28px rgba(68, 55, 31, 0.08);
  }

  #customerView .customer-item {
    min-height: 82px;
    padding: 14px 15px;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
  }

  #customerView .customer-item:hover,
  #customerView .customer-item:focus-visible {
    background: #f3f8f4;
  }

  #customerView .customer-item.active {
    border-left-color: var(--green);
    background: #eaf4ee;
  }

  #customerView .customer-item span {
    font-size: 12px;
  }

  #customerView .customer-detail {
    min-height: 600px;
    padding: 20px;
    border-color: rgba(35, 122, 87, 0.2);
    box-shadow: 0 14px 32px rgba(68, 55, 31, 0.08);
  }

  #customerView .detail-title {
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--line);
  }

  #customerView .detail-title h2 {
    font-size: 24px;
  }

  #customerView .metric-grid,
  #customerView .customer-mode .metric-grid {
    gap: 10px;
    margin: 16px 0 18px;
  }

  #customerView .metric {
    min-height: 96px;
    padding: 14px;
    border: 0;
    background: #f4f8f4;
  }

  #customerView .metric strong {
    margin-top: 9px;
    font-size: 22px;
  }

  #customerView .product-picker {
    margin-bottom: 12px;
    padding: 13px;
    border-radius: 10px;
  }

  #customerView .section-title {
    margin-top: 20px;
  }

  /* Pad 上把表单操作收回同一行，减少无意义的纵向滚动 */
  #customerView .inline-form[data-deposit-form],
  #customerView .account-security-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 132px;
    gap: 10px;
    align-items: end;
  }

  #customerView .inline-form[data-deposit-form] > button,
  #customerView .account-security-form .secondary-button {
    grid-column: auto;
    width: 100%;
    min-width: 0;
    justify-self: stretch;
  }
}

@media (max-width: 760px) {
  /* 登录/注册弹窗按钮在窄屏整齐 2 列 */
  menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  menu button {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* 取消和退出按钮在窄屏占整行，方便点击 */
  menu [data-close-dialog],
  menu #logoutButton {
    grid-column: 1 / -1;
  }

  .app-shell {
    width: 100%;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px 10px;
    padding-top: 4px;
    padding-bottom: calc(var(--section-gap) * 1.05);
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  .topbar h1 {
    max-width: 6em;
    line-height: 1.18;
  }

  .topbar .eyebrow {
    margin-bottom: 2px;
  }

  .topbar .muted {
    margin-top: 4px;
    line-height: 1.35;
  }

  .top-actions {
    display: flex;
    flex-shrink: 0;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 7px;
    padding-top: 2px;
  }

  .top-actions .secondary-button,
  .account-button {
    min-height: var(--compact-control-h);
    padding-left: 11px;
    padding-right: 11px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1;
  }

  .top-actions .secondary-button {
    max-width: 112px;
  }

  .account-button {
    max-width: 116px;
  }

  .toolbar,
  .detail-title,
  .row-between {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: flex-start;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }

  .toolbar-input,
  .toolbar-select,
  .toolbar-actions button {
    width: 100%;
  }

  .toolbar-input {
    grid-column: 1 / -1;
  }

  .toolbar-select {
    grid-column: 1 / -1;
  }

  .toolbar-actions button {
    min-height: calc(var(--compact-control-h) + 4px);
    padding-left: 10px;
    padding-right: 10px;
    font-size: 14px;
  }

  .manager-mode #dashboardView > .toolbar .toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .manager-mode #customerView .customer-toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .manager-mode #dashboardView > .toolbar .toolbar-actions button {
    min-height: 38px;
    padding-left: 6px;
    padding-right: 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  .manager-mode #customerView .customer-toolbar-actions button {
    min-height: 38px;
    padding-left: 5px;
    padding-right: 5px;
    font-size: 12px;
    white-space: nowrap;
  }

  .status-panel {
    align-items: center;
    min-height: 0;
    padding: 11px 12px;
    gap: 10px;
  }

  .status-panel strong {
    margin: 4px 0 3px;
    font-size: 24px;
  }

  .status-panel .muted {
    font-size: 12px;
  }

  .status-panel span {
    display: block;
    font-size: 12px;
    line-height: 1.35;
  }

  .switch span {
    width: 52px;
    height: 30px;
  }

  .switch span::after {
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
  }

  .switch input:checked + span::after {
    left: 25px;
  }

  .customer-mode .toolbar.compact {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 8px 10px;
  }

  .customer-mode .toolbar.compact .toolbar-actions {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end;
    width: auto;
  }

  .customer-mode .toolbar.compact .toolbar-actions button {
    width: auto;
    min-width: 92px;
  }

  .manager-dashboard {
    padding: 12px;
  }

  .dashboard-heading {
    flex-direction: column;
  }

  .dashboard-summary {
    justify-content: flex-start;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .mini-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .audit-dialog {
    width: calc(100% - 20px);
    padding: 16px;
  }

  .audit-toolbar {
    grid-template-columns: 1fr;
  }

  .audit-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 6px 10px;
    padding: 11px 12px;
  }

  .audit-row time {
    grid-column: 1 / 2;
  }

  .audit-row strong {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    justify-self: end;
    text-align: right;
  }

  .audit-row span,
  .audit-row p {
    grid-column: 1 / -1;
  }

  .customer-title-actions {
    justify-content: flex-start;
  }

  .customer-layout {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
  }

  .customer-detail {
    width: 100%;
    padding: 14px;
  }

  .customer-list {
    display: grid;
    grid-template-columns: 1fr;
    max-height: none;
    overflow: visible;
  }

  .customer-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 10px;
    min-width: 0;
    min-height: 68px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .customer-item strong {
    grid-column: 1 / -1;
  }

  .customer-item span:first-of-type {
    grid-column: 1 / 2;
  }

  .customer-item span:last-of-type {
    grid-column: 2 / 3;
    justify-self: end;
    text-align: right;
  }

  .inline-form,
  .account-security-form,
  .product-picker,
  .account-grid,
  .login-panels {
    grid-template-columns: 1fr;
  }

  .inline-form > button,
  .compact-action-button {
    width: 100%;
    justify-self: stretch;
  }

  .metric-grid,
  .customer-mode .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid {
    gap: 6px;
  }

  .metric {
    min-height: calc(var(--control-h) + 30px);
    padding: 9px 8px;
  }

  .metric span {
    font-size: 11px;
  }

  .metric strong {
    margin-top: 6px;
    font-size: calc(17px * var(--ui-scale));
    word-break: keep-all;
    overflow-wrap: normal;
  }

  .metric:first-child strong {
    font-size: calc(16px * var(--ui-scale));
  }

  .product-picker {
    padding: 12px;
  }

  .product-picker div {
    min-height: var(--control-h);
    padding: 12px;
  }

  .product-picker strong {
    font-size: 17px;
  }

  .product-picker .compact-action-button {
    min-height: var(--control-h);
  }

  .product-type-panel {
    padding: 12px;
  }

  .product-type-row,
  .product-type-new {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .product-type-row label {
    grid-column: 1 / -1;
  }

  .product-type-row button {
    width: 100%;
    min-width: 0;
  }

  .ledger-row,
  .record-row {
    gap: 8px;
    padding: 10px 12px;
  }

  .ledger-row {
    grid-template-columns: minmax(110px, 1fr) minmax(52px, 72px) minmax(76px, 1fr);
  }

  .ledger-row span:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ledger-row span:nth-child(2) {
    justify-self: center;
    text-align: center;
    white-space: nowrap;
  }

  .record-row {
    grid-template-columns: minmax(0, 1fr) minmax(74px, auto);
  }

  .record-row span:first-child {
    grid-column: 1 / 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .record-row span:nth-child(2) {
    grid-column: 1 / 2;
    color: var(--muted);
    font-size: 13px;
  }

  .record-row strong {
    grid-column: 2 / 3;
    grid-row: 1 / span 2;
    justify-self: end;
    white-space: nowrap;
  }

  .ledger-row strong {
    justify-self: end;
    text-align: right;
    white-space: nowrap;
  }

  .record-list {
    grid-template-columns: 1fr;
  }

  .account-security-form .secondary-button {
    width: 100%;
    justify-self: stretch;
  }

  .status-panel strong {
    font-size: 24px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar {
    gap: 7px 8px;
  }

  .top-actions {
    gap: 6px;
  }

  .top-actions .secondary-button,
  .account-button {
    min-height: 34px;
    padding-left: 9px;
    padding-right: 9px;
    font-size: 12px;
  }

  .top-actions .secondary-button {
    max-width: 104px;
  }

  .account-button {
    max-width: 104px;
  }

  .toolbar-actions {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .manager-mode #dashboardView > .toolbar .toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .manager-mode #customerView .customer-toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .toolbar-actions .primary-button,
  .toolbar-actions .secondary-button,
  .toolbar-actions .danger-button {
    min-height: 40px;
    padding-left: 8px;
    padding-right: 8px;
    font-size: 13px;
  }

  .manager-mode #dashboardView > .toolbar .toolbar-actions .primary-button,
  .manager-mode #dashboardView > .toolbar .toolbar-actions .secondary-button {
    min-height: 36px;
    padding-left: 4px;
    padding-right: 4px;
    font-size: 11px;
  }

  .manager-mode #customerView .customer-toolbar-actions .primary-button,
  .manager-mode #customerView .customer-toolbar-actions .secondary-button {
    min-height: 36px;
    padding-left: 4px;
    padding-right: 4px;
    font-size: 11px;
  }

  .customer-detail {
    padding: 12px;
  }

  .metric-grid {
    gap: 6px;
  }

  .metric {
    min-height: 88px;
    padding: 10px 8px;
  }

  .metric strong {
    font-size: 18px;
    line-height: 1.15;
  }

  .metric:first-child strong {
    font-size: 17px;
  }

  .ledger-row {
    grid-template-columns: minmax(96px, 1fr) minmax(44px, 58px) minmax(72px, 1fr);
    gap: 6px;
    padding: 10px;
  }

  .record-row {
    gap: 6px 10px;
    padding: 10px;
  }

  .record-row span:nth-child(2) {
    text-align: left;
    justify-self: start;
  }
}
