:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-soft: #eef3ee;
  --text: #17211d;
  --muted: #68746e;
  --line: #d9e0dc;
  --green: #1e7a51;
  --green-soft: #e2f2e8;
  --red: #b33b3b;
  --red-soft: #f8e7e4;
  --blue: #2f5f95;
  --shadow: 0 18px 48px rgba(28, 43, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 16px;
}

button:hover {
  border-color: #a8b6ae;
}

.quiet-danger {
  border-color: var(--red-soft);
  background: var(--red-soft);
  color: var(--red);
}

.quiet-danger:hover {
  border-color: var(--red);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

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

.login-panel h1 {
  font-size: clamp(2rem, 7vw, 3.6rem);
}

.workspace {
  display: grid;
  gap: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 520px);
  align-items: end;
  gap: 24px;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

.sync-panel {
  display: grid;
  gap: 8px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.inline-check input {
  width: 18px;
  min-height: 18px;
}

.url-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.icon-button {
  padding: 0;
  font-size: 1.15rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--green);
  outline: 3px solid rgba(30, 122, 81, 0.15);
}

.status {
  min-height: 19px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.field-hint {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.form-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

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

.page-tabs {
  display: inline-flex;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.page-tabs button {
  min-width: 112px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-weight: 750;
}

.page-tabs button.active {
  background: var(--green);
  color: white;
}

.page-panel {
  display: none;
}

.page-panel.active {
  display: block;
}

.metric {
  min-height: 104px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.metric strong {
  font-size: clamp(1.45rem, 3vw, 2.2rem);
  line-height: 1.05;
}

.metric.income {
  background: var(--green-soft);
}

.metric.expense {
  background: var(--red-soft);
}

.metric.balance {
  background: #e7eef8;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.funding-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.balance-layout {
  display: grid;
  gap: 18px;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.import-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

.import-layout .records-panel {
  grid-column: 1 / -1;
}

.entry-form,
.records-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.entry-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.form-header,
.records-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 168px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented label {
  display: block;
  color: var(--text);
  font-size: 0.9rem;
}

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

.segmented span {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 0 10px;
}

.segmented input:checked + span {
  background: var(--green);
  color: white;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.actions,
.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
  font-weight: 750;
}

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

.records-panel {
  overflow: hidden;
}

.records-toolbar {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-note {
  margin: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.toolbar-actions select,
.toolbar-actions input {
  width: 150px;
}

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

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

.pairs-table {
  min-width: 640px;
}

.balance-table {
  min-width: 860px;
}

.import-table {
  min-width: 980px;
}

.import-table th:nth-child(1),
.import-table td:nth-child(1) {
  width: 72px;
}

.import-table th:nth-child(2),
.import-table td:nth-child(2) {
  width: 132px;
}

.import-table th:nth-child(3),
.import-table td:nth-child(3) {
  width: 150px;
}

.import-table th:nth-child(4),
.import-table td:nth-child(4) {
  width: auto;
  min-width: 320px;
}

.import-table th:nth-child(5),
.import-table td:nth-child(5) {
  width: 160px;
}

.import-table th:nth-child(6),
.import-table td:nth-child(6) {
  width: 150px;
}

.toolbar-total {
  color: var(--green);
  font-size: 1.1rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

td {
  font-size: 0.94rem;
}

.subtle-cell {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8rem;
}

.amount-col {
  text-align: right;
}

.action-col {
  width: 96px;
  text-align: right;
}

.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
}

.table-number {
  max-width: 140px;
  min-height: 34px;
  margin-left: auto;
  text-align: right;
}

.table-select {
  min-width: 112px;
  min-height: 34px;
  padding: 0 8px;
}

.table-date {
  min-width: 132px;
  min-height: 34px;
  padding: 0 8px;
}

.tag {
  display: inline-grid;
  min-width: 52px;
  min-height: 28px;
  place-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 750;
}

.tag.income {
  background: var(--green-soft);
  color: var(--green);
}

.tag.expense {
  background: var(--red-soft);
  color: var(--red);
}

.amount.income {
  color: var(--green);
  font-weight: 800;
}

.amount.expense {
  color: var(--red);
  font-weight: 800;
}

.empty {
  margin: 0;
  padding: 28px 18px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    width: min(calc(100vw - 20px), 720px);
    padding: 18px 0;
  }

  .topbar,
  .content-grid,
  .funding-layout,
  .balance-layout,
  .import-layout,
  .settings-layout,
  .summary-grid {
    grid-template-columns: 1fr;
  }

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

  .form-header,
  .records-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented,
  .page-tabs,
  .toolbar-actions select {
    width: 100%;
  }

  .page-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .summary-grid,
  .field-row {
    grid-template-columns: 1fr;
  }

  .records-panel .table-wrap {
    overflow-x: visible;
  }

  .records-panel table,
  .records-panel thead,
  .records-panel tbody,
  .records-panel tr,
  .records-panel td {
    display: block;
    width: 100%;
  }

  .records-panel table {
    min-width: 0;
  }

  .records-panel thead {
    display: none;
  }

  .records-panel tbody {
    display: grid;
    gap: 12px;
    padding: 0 12px 12px;
  }

  .records-panel tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }

  .records-panel td {
    display: grid;
    grid-template-columns: minmax(82px, 35%) 1fr;
    gap: 10px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 11px 12px;
    text-align: right;
  }

  .records-panel td:last-child {
    border-bottom: 0;
  }

  .records-panel td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    text-align: left;
  }

  .records-panel .amount-col,
  .records-panel .action-col {
    text-align: right;
  }

  .records-panel .table-date {
    width: 100%;
    min-width: 0;
  }

  .records-panel .table-number,
  .records-panel .table-select {
    width: 100%;
    max-width: none;
  }

  .records-panel .compact {
    width: 100%;
  }

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