:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --ink: #18222d;
  --muted: #65717d;
  --line: #dce3e8;
  --blue: #2764d8;
  --blue-dark: #1847a2;
  --green: #168a55;
  --red: #c93838;
  --amber: #b56a16;
  --shadow: 0 12px 28px rgba(24, 34, 45, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  min-height: 100vh;
}

[hidden] {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 28px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow,
.section-label {
  display: block;
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.16;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.25;
}

.login-note {
  margin: 12px 0 0;
  color: var(--muted);
}

.login-form,
.password-form,
.add-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 8px;
  color: #33404c;
  font-size: 14px;
  font-weight: 650;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(39, 100, 216, 0.12);
}

.primary-button,
.ghost-button,
.small-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 720;
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--blue);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.ghost-button,
.small-button {
  padding: 0 13px;
  color: #26323d;
  background: #fff;
  border-color: var(--line);
}

.ghost-button:hover,
.small-button:hover {
  border-color: #b9c5cf;
}

.danger-button {
  color: var(--red);
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.dashboard-view {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

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

.save-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.save-status[data-tone="success"] {
  color: var(--green);
  background: #ecf7f1;
  border-color: #b9dfca;
}

.save-status[data-tone="danger"] {
  color: var(--red);
  background: #fff0f0;
  border-color: #f2c3c3;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.summary-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-card strong {
  font-size: 25px;
  line-height: 1.1;
}

.summary-card strong[data-tone="positive"],
.positive {
  color: var(--green);
}

.summary-card strong[data-tone="negative"],
.negative {
  color: var(--red);
}

.zero {
  color: var(--muted);
}

.settlement-panel,
.workspace,
.settings-panel {
  margin-top: 12px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settlement-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface-soft);
}

.settlement-panel p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.add-form {
  width: min(380px, 100%);
  grid-template-columns: minmax(0, 1fr) auto;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.finance-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: #fff;
}

.finance-table th,
.finance-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}

.finance-table th {
  color: #3d4a55;
  background: #f0f4f7;
  font-size: 13px;
  font-weight: 780;
}

.finance-table tr:last-child td {
  border-bottom: 0;
}

.table-input {
  min-width: 150px;
}

.amount-input {
  min-width: 132px;
  text-align: right;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mobile-pot-list {
  display: none;
}

.mobile-edit-hint {
  display: none;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.mobile-pot-card {
  display: grid;
  gap: 6px;
  padding: 8px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  touch-action: manipulation;
}

.mobile-pot-card:first-child {
  border-top: 1px solid var(--line);
}

.mobile-pot-card:focus-visible {
  outline: 3px solid rgba(39, 100, 216, 0.16);
  outline-offset: 2px;
  border-color: var(--blue);
  border-radius: 6px;
}

.mobile-pot-card:active {
  background: #f8fafb;
}

.mobile-pot-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.mobile-pot-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 760;
}

.mobile-pot-total {
  min-width: 78px;
  text-align: right;
  font-size: 13px;
  font-weight: 780;
}

.mobile-balance-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 12px;
}

.mobile-balance-value {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.mobile-balance-value em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  font-weight: 700;
}

.mobile-balance-value strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 1.15;
  font-weight: 800;
}

.mobile-gap-value {
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.15;
  font-weight: 800;
}

.mobile-edit-cue {
  min-width: 38px;
  padding: 3px 7px;
  color: var(--blue);
  background: #edf4ff;
  border: 1px solid #c9dcff;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
  font-weight: 780;
}

.mobile-pot-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

body.modal-open {
  overflow: hidden;
}

.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  padding: 14px;
  background: rgba(24, 34, 45, 0.42);
}

.edit-dialog {
  width: min(520px, 100%);
  max-height: calc(100vh - 28px);
  margin: 0 auto;
  overflow: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(24, 34, 45, 0.22);
}

.edit-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  color: #42505d;
  background: #f5f7f8;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  border-color: #b9c5cf;
}

.edit-pot-form {
  display: grid;
  gap: 12px;
}

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

.edit-balance-grid input {
  text-align: right;
  font-size: 18px;
  font-weight: 760;
}

.edit-balance-grid input[readonly] {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.edit-balance-grid input.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(39, 100, 216, 0.14);
}

.amount-keypad {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f4f7f9;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.keypad-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.keypad-status strong {
  color: var(--blue);
}

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

.keypad-grid button {
  min-height: 44px;
  padding: 0;
  color: #172331;
  background: #fff;
  border: 1px solid #d8e1e8;
  border-radius: 7px;
  font-size: 18px;
  font-weight: 800;
  touch-action: manipulation;
}

.keypad-grid button:active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.keypad-grid button[data-key="clear"],
.keypad-grid button[data-key="backspace"],
.keypad-grid button[data-key="sign"] {
  color: #33404c;
  background: #eef3f6;
}

.edit-modal-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--muted);
  background: #f4f7f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 740;
}

.edit-modal-summary strong,
.edit-modal-summary span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-modal-message {
  min-height: 18px;
  margin: -2px 0 0;
}

.edit-dialog-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.edit-dialog-actions button {
  min-height: 44px;
}

.settings-panel {
  display: grid;
  grid-template-columns: minmax(180px, 0.5fr) minmax(280px, 1fr);
  gap: 24px;
}

.password-form {
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: end;
}

.password-form .form-message {
  grid-column: 1 / -1;
}

@media (max-width: 860px) {
  .dashboard-view {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .topbar,
  .settlement-panel,
  .section-head,
  .settings-panel {
    display: grid;
  }

  .settings-panel {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: start;
  }

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

  .summary-card {
    min-height: 88px;
    gap: 10px;
    padding: 14px;
  }

  .summary-card strong {
    font-size: 22px;
  }

  .password-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .table-wrap {
    display: none;
  }

  .mobile-pot-list {
    display: grid;
    gap: 0;
  }

  .mobile-edit-hint {
    display: block;
  }
}

@media (max-width: 520px) {
  .login-panel,
  .settlement-panel,
  .workspace,
  .settings-panel {
    padding: 12px;
  }

  h1 {
    font-size: 23px;
  }

  h2 {
    font-size: 18px;
  }

  .eyebrow,
  .section-label {
    margin-bottom: 6px;
    font-size: 11px;
  }

  .dashboard-view {
    width: min(100% - 16px, 1180px);
    padding-bottom: 24px;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 12px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .save-status,
  .ghost-button {
    min-height: 36px;
  }

  .ghost-button {
    padding: 0 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 8px;
  }

  .summary-card {
    min-height: 76px;
    padding: 11px;
  }

  .summary-card span {
    font-size: 12px;
  }

  .summary-card strong {
    font-size: 19px;
  }

  .settlement-panel,
  .workspace,
  .settings-panel {
    margin-top: 8px;
  }

  .settlement-panel {
    gap: 10px;
  }

  .settlement-panel p {
    font-size: 13px;
    line-height: 1.55;
  }

  .section-head {
    gap: 12px;
    margin-bottom: 12px;
  }

  .add-form {
    grid-template-columns: minmax(0, 1fr) 70px;
    gap: 8px;
  }

  .add-form .primary-button {
    padding: 0 10px;
  }

  .mobile-pot-card {
    gap: 4px;
    padding: 7px 0;
  }

  .mobile-pot-head {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 6px;
  }

  .mobile-pot-name {
    font-size: 15px;
  }

  .mobile-pot-total {
    min-width: 64px;
    font-size: 12px;
  }

  .mobile-balance-row {
    gap: 5px 9px;
  }

  .mobile-balance-value {
    gap: 4px;
  }

  .mobile-balance-value em {
    font-size: 11px;
  }

  .mobile-balance-value strong {
    font-size: 12px;
  }

  .mobile-gap-value {
    font-size: 11px;
  }

  .mobile-pot-footer {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    font-size: 11px;
  }

  .mobile-edit-cue {
    min-width: 34px;
    padding: 3px 6px;
    font-size: 11px;
  }

  .edit-modal {
    padding: 0;
  }

  .edit-dialog {
    width: 100%;
    max-height: 90vh;
    padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .edit-dialog-head {
    margin-bottom: 12px;
  }

  .edit-balance-grid {
    gap: 8px;
  }

  .edit-balance-grid input {
    font-size: 16px;
  }

  .amount-keypad {
    gap: 7px;
    padding: 8px;
  }

  .keypad-grid {
    gap: 7px;
  }

  .keypad-grid button {
    min-height: 42px;
    font-size: 17px;
  }

  .edit-modal-summary {
    padding: 9px 10px;
    font-size: 12px;
  }
}
