:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #24232a;
  background: #fff;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #fff;
}

body {
  min-height: 100vh;
  margin: 0;
  background: #fff;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] {
  display: none !important;
}

.tool-header {
  height: 66px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
}

.tool-header-inner {
  width: min(1180px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.tool-header h1 {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 27px;
  line-height: 1;
  letter-spacing: 0;
}

.back-link {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #4c4a52;
  font-size: 15px;
  font-weight: 600;
}

.back-link:hover {
  color: #e84c68;
}

.back-link svg {
  width: 22px;
  height: 22px;
}

.header-spacer {
  width: 1px;
  justify-self: end;
}

.tool-main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.flash {
  margin-bottom: 16px;
  padding: 11px 14px;
  border: 1px solid;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
}

.flash-success {
  border-color: #a9d7cb;
  background: #f3fbf8;
  color: #247768;
}

.flash-error {
  border-color: #f3b2bd;
  background: #fff5f7;
  color: #b62f4d;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.balance-card {
  min-height: 146px;
  padding: 20px 28px;
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  gap: 24px;
  border: 1px solid var(--balance-accent);
  border-radius: 8px;
  background: #fff;
}

.balance-card img {
  width: 82px;
  height: 82px;
  border: 2px solid var(--balance-accent);
  border-radius: 50%;
  object-fit: cover;
}

.balance-card h2 {
  margin: 0 0 4px;
  color: #35323a;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0;
}

.balance-card p {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.balance-card strong {
  color: var(--balance-accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 48px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.balance-card p span {
  color: #4c4952;
  font-size: 17px;
}

.balance-rose {
  --balance-accent: #e94d68;
}

.balance-teal {
  --balance-accent: #369694;
}

.action-panel {
  margin-top: 22px;
  padding: 16px 20px 20px;
  border: 1px solid #dfe2e7;
  border-radius: 8px;
  background: #fff;
}

.segmented {
  width: 284px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  border: 1px solid #d9dde3;
  border-radius: 8px;
  overflow: hidden;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  min-height: 42px;
  display: grid;
  place-items: center;
  color: #4a4850;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

.segmented input:checked + label {
  background: #e94d68;
  color: #fff;
}

.segmented input:focus-visible + label {
  outline: 2px solid #24232a;
  outline-offset: -3px;
}

.operation-fields {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(120px, 0.8fr) 180px minmax(200px, 1.4fr) 112px;
  align-items: end;
  gap: 14px;
}

.operation-form.mode-use .operation-fields {
  grid-template-columns: minmax(170px, 1fr) 180px minmax(240px, 1.6fr) 112px;
}

.field {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.field > span:first-child {
  color: #57545d;
  font-size: 13px;
  font-weight: 700;
}

.field select,
.field > input,
.recipient-field output {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #d8dce2;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: #29272f;
  font-size: 15px;
}

.field select:focus,
.field > input:focus {
  border-color: #e94d68;
  box-shadow: 0 0 0 3px rgba(233, 77, 104, 0.12);
}

.recipient-field output {
  display: flex;
  align-items: center;
  font-weight: 700;
}

.stepper {
  height: 44px;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  border: 1px solid #d8dce2;
  border-radius: 8px;
  overflow: hidden;
}

.stepper button {
  display: grid;
  place-items: center;
  border: 0;
  background: #f7f8fa;
  color: #4e4b54;
}

.stepper button:hover {
  background: #eef0f3;
  color: #e94d68;
}

.stepper button:focus-visible {
  outline: 2px solid #e94d68;
  outline-offset: -3px;
}

.stepper svg {
  width: 18px;
  height: 18px;
}

.stepper input {
  min-width: 0;
  border: 0;
  border-right: 1px solid #d8dce2;
  border-left: 1px solid #d8dce2;
  outline: none;
  background: #fff;
  color: #29272f;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  appearance: textfield;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.note-field input::placeholder {
  color: #a3a0a8;
}

.record-button {
  height: 44px;
  border: 1px solid #e94d68;
  border-radius: 8px;
  background: #e94d68;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  transition: background-color 160ms ease, transform 160ms ease;
}

.record-button:hover {
  background: #d93f5b;
}

.record-button:active {
  transform: translateY(1px);
}

.record-button:focus-visible {
  outline: 2px solid #24232a;
  outline-offset: 2px;
}

.history-section {
  margin-top: 28px;
}

.history-title-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.history-title-row h2 {
  margin: 0;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 21px;
  line-height: 1.35;
  letter-spacing: 0;
}

.history-title-row > span {
  color: #77737d;
  font-size: 13px;
}

.history-columns,
.history-row {
  display: grid;
  grid-template-columns: 150px minmax(240px, 1.3fr) minmax(160px, 1fr) 130px 44px;
  align-items: center;
  gap: 14px;
}

.history-columns {
  min-height: 40px;
  padding: 0 12px;
  border-top: 1px solid #dfe2e7;
  border-bottom: 1px solid #dfe2e7;
  color: #68646e;
  font-size: 12px;
  font-weight: 700;
}

.history-row {
  min-height: 64px;
  padding: 10px 12px;
  border-bottom: 1px solid #e7e9ed;
  font-size: 14px;
}

.history-row time {
  color: #69656f;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.history-event {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.history-event img {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  object-fit: cover;
}

.history-event strong,
.person-name {
  font-weight: 700;
}

.tone-rose {
  color: #df4562;
}

.tone-teal {
  color: #278987;
}

.history-note,
.history-balance {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #55515b;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-balance {
  color: #3f7f79;
  font-size: 13px;
  font-weight: 700;
}

.delete-form {
  margin: 0;
  justify-self: end;
}

.delete-form button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #77737c;
}

.delete-form button:hover {
  background: #fff1f4;
  color: #d93f5b;
}

.delete-form button:focus-visible {
  outline: 2px solid #e94d68;
  outline-offset: 1px;
}

.delete-form svg {
  width: 19px;
  height: 19px;
}

.empty-state {
  margin: 0;
  padding: 44px 16px;
  border-top: 1px solid #dfe2e7;
  border-bottom: 1px solid #dfe2e7;
  color: #85818a;
  text-align: center;
}

.pagination {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.pagination a {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #d8dce2;
  border-radius: 6px;
  color: #57535d;
  font-size: 13px;
}

.pagination a[aria-current="page"] {
  border-color: #e94d68;
  background: #e94d68;
  color: #fff;
}

@media (max-width: 900px) {
  .operation-fields,
  .operation-form.mode-use .operation-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-button {
    grid-column: 1 / -1;
  }

  .history-columns,
  .history-row {
    grid-template-columns: 130px minmax(210px, 1.3fr) minmax(130px, 1fr) 110px 40px;
    gap: 10px;
  }
}

@media (max-width: 720px) {
  .tool-header {
    height: 58px;
  }

  .tool-header-inner,
  .tool-main {
    width: calc(100% - 28px);
  }

  .tool-header h1 {
    font-size: 23px;
  }

  .back-link span {
    display: none;
  }

  .tool-main {
    padding: 16px 0 30px;
  }

  .balance-grid {
    gap: 10px;
  }

  .balance-card {
    min-height: 116px;
    padding: 13px;
    grid-template-columns: 54px 1fr;
    gap: 10px;
  }

  .balance-card img {
    width: 50px;
    height: 50px;
  }

  .balance-card h2 {
    margin-bottom: 5px;
    font-size: 15px;
    white-space: nowrap;
  }

  .balance-card strong {
    font-size: 36px;
  }

  .balance-card p span {
    font-size: 14px;
  }

  .action-panel {
    margin-top: 16px;
    padding: 14px;
  }

  .segmented {
    width: 100%;
  }

  .operation-fields,
  .operation-form.mode-use .operation-fields {
    margin-top: 14px;
    grid-template-columns: 1fr;
    gap: 11px;
  }

  .record-button {
    grid-column: auto;
  }

  .history-section {
    margin-top: 22px;
  }

  .history-title-row h2 {
    font-size: 19px;
  }

  .history-columns {
    display: none;
  }

  .history-row {
    position: relative;
    min-height: 0;
    padding: 13px 44px 13px 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .history-row time {
    order: 2;
  }

  .history-event {
    order: 1;
  }

  .history-note {
    order: 3;
    font-size: 13px;
  }

  .history-balance {
    order: 4;
  }

  .delete-form {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
  }

  .empty-state {
    padding: 36px 12px;
  }
}

@media (max-width: 360px) {
  .balance-card {
    min-height: 108px;
    padding: 10px;
    grid-template-columns: 44px 1fr;
    gap: 8px;
  }

  .balance-card img {
    width: 42px;
    height: 42px;
  }

  .balance-card h2 {
    font-size: 13px;
  }

  .balance-card strong {
    font-size: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
