:root {
  --ink: #14201c;
  --muted: #4d5c56;
  --line: rgba(20, 32, 28, 0.12);
  --panel: rgba(255, 252, 247, 0.88);
  --panel-solid: #fffaf3;
  --accent: #0f6a56;
  --accent-soft: #d7efe7;
  --zero: #8a968f;
  --shadow: 0 18px 50px rgba(20, 32, 28, 0.08);
  --radius: 18px;
  --font-display: 'Literata', 'Noto Serif TC', Georgia, serif;
  --font-body: 'Manrope', 'Noto Sans TC', 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 12% 18%, rgba(15, 106, 86, 0.14), transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(196, 145, 74, 0.16), transparent 28%),
    linear-gradient(160deg, #f3efe6 0%, #e7f0eb 46%, #f7f4ee 100%);
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(20, 32, 28, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 32, 28, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.page {
  position: relative;
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.5rem 0 4rem;
}

.hero {
  animation: rise 0.7s ease both;
  margin-bottom: 2rem;
}

.brand {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 0.95;
  color: var(--accent);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-body);
  font-size: clamp(1.2rem, 2.4vw, 1.55rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lede {
  max-width: 34rem;
  margin: 0.75rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.login-page {
  display: flex;
  align-items: center;
  min-height: 100vh;
}

.login-hero {
  width: min(36rem, 100%);
  margin-bottom: 0;
}

.login-error {
  margin-top: 1rem;
  max-width: 28rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 0.7rem 1.15rem;
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #f7fffb;
}

.btn-primary:hover:not(:disabled) {
  background: #0c5747;
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(20, 32, 28, 0.04);
}

.btn-icon {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn-icon:hover {
  background: rgba(20, 32, 28, 0.06);
  color: var(--ink);
}

.transaction-dialog {
  width: min(28rem, calc(100% - 1.5rem));
  max-width: calc(100% - 1.5rem);
  max-height: min(92vh, 44rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  color: var(--ink);
  overflow: hidden;
}

#transaction-form {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  min-width: 0;
  max-height: min(92vh, 44rem);
}

#transaction-form .dialog-body {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

#transaction-form .dialog-header,
#transaction-form .dialog-footer {
  flex-shrink: 0;
}

.transactions-list-dialog {
  width: min(72rem, calc(100% - 1.5rem));
  max-height: min(90vh, 52rem);
}

.list-dialog-shell {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 52rem);
}

.transactions-list-dialog .dialog-body.list-filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.filter-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.list-status {
  margin: 0;
  padding: 0 1.2rem 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.list-table-wrap {
  padding: 0 1.2rem 1rem;
  max-height: 24rem;
  overflow: auto;
}

.transactions-table {
  min-width: 760px;
}

.transactions-table th,
.transactions-table td {
  text-align: left;
  white-space: nowrap;
}

.transactions-table th:nth-child(6),
.transactions-table td:nth-child(6) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.transactions-table .row-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  border-radius: 8px;
}

.btn-danger {
  background: transparent;
  border-color: rgba(138, 47, 47, 0.28);
  color: #8a2f2f;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(138, 47, 47, 0.08);
}

.edit-footer {
  padding: 1rem 0 0;
  border-top: 0;
}

.type-deposit {
  color: var(--accent);
  font-weight: 600;
}

.type-withdrawal {
  color: #8a2f2f;
  font-weight: 600;
}

.type-transfer {
  color: #6a4c1d;
  font-weight: 600;
}

.transaction-dialog::backdrop {
  background: rgba(20, 32, 28, 0.42);
  backdrop-filter: blur(3px);
}

.transaction-dialog[open] {
  animation: rise 0.28s ease both;
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.2rem;
}

.dialog-header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(215, 239, 231, 0.55), transparent);
}

.dialog-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
}

.dialog-body {
  display: grid;
  gap: 0.9rem;
  padding: 1.15rem 1.2rem 0.4rem;
  min-width: 0;
}

.dialog-footer {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  max-width: 100%;
}

.field span {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.field em {
  font-style: normal;
  font-weight: 500;
  opacity: 0.8;
}

.field input,
.field select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.98rem;
  padding: 0.65rem 0.75rem;
}

/* iOS/WebKit date controls have a large intrinsic min-width. */
.field input[type='date'] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(15, 106, 86, 0.28);
  border-color: var(--accent);
}

.form-error {
  margin: 0;
  color: #8a2f2f;
  background: rgba(138, 47, 47, 0.08);
  border: 1px solid rgba(138, 47, 47, 0.18);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font-size: 0.9rem;
}

.settings-panel {
  animation: rise 0.7s ease 0.08s both;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow: hidden;
  max-width: 36rem;
}

.settings-panel-header {
  padding: 1.25rem 1.35rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(215, 239, 231, 0.55), transparent);
}

.settings-panel-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
}

.settings-panel-header p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.settings-panel-body {
  display: grid;
  gap: 0.9rem;
  padding: 1.2rem 1.35rem 1.4rem;
}

.settings-status {
  margin: 0;
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 600;
}

.status {
  animation: rise 0.7s ease 0.08s both;
  color: var(--muted);
}

.dashboard {
  display: grid;
  gap: 1.25rem;
}

.account-panel {
  animation: rise 0.7s ease both;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.account-panel:nth-child(2) {
  animation-delay: 0.1s;
}

.account-panel:nth-child(3) {
  animation-delay: 0.18s;
}

.account-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.35rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(215, 239, 231, 0.55), transparent);
}

.account-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
}

.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.total-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  font-size: 0.92rem;
}

.total-chip span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  padding: 0.85rem 1rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--panel-solid);
  font-weight: 600;
}

thead th {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 250, 243, 0.95);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  transition: background-color 0.2s ease;
}

tbody tr:hover {
  background: rgba(215, 239, 231, 0.35);
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.amount.is-zero {
  color: var(--zero);
  font-weight: 500;
}

.error {
  color: #8a2f2f;
  background: rgba(138, 47, 47, 0.08);
  border: 1px solid rgba(138, 47, 47, 0.18);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .page {
    width: min(100% - 1.25rem, 1120px);
    padding-top: 1.5rem;
  }

  .account-header {
    padding: 1rem;
  }

  .transaction-dialog {
    width: calc(100% - 1.25rem);
    max-width: calc(100% - 1.25rem);
  }

  .field input[type='date'] {
    font-size: 1rem;
  }

  .transactions-list-dialog .dialog-body.list-filters {
    grid-template-columns: 1fr;
  }
}
