:root {
  color-scheme: light;
  --ink: #18202f;
  --muted: #687282;
  --line: #dce2ea;
  --paper: #ffffff;
  --app-bg: #f4f7fa;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --income: #168255;
  --expense: #c2410c;
  --warning: #b7791f;
  --shadow: 0 18px 60px rgba(21, 32, 51, 0.12);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(37, 99, 235, 0.05) 38%, rgba(244, 247, 250, 0) 70%),
    var(--app-bg);
  color: var(--ink);
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(37, 99, 235, 0.08)),
    var(--app-bg);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 4px;
}

.login-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-status.error {
  color: var(--expense);
  font-weight: 700;
}

.login-status.success {
  color: var(--accent-strong);
  font-weight: 700;
}

.app-shell.locked {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: #fff;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #20b8a8;
  color: #07231f;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: #a9b7c8;
}

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

.nav-item,
.icon-button,
.primary-button,
.secondary-button,
.text-button,
.segment {
  border: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-item svg,
.primary-button svg,
.secondary-button svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.92rem;
}

.storage-mode {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.storage-mode.connected {
  color: var(--accent-strong);
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  letter-spacing: 0;
}

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

.topbar-actions,
.toolbar,
.cards-heading,
.panel-header,
.panel-actions,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line);
}

.icon-button:hover {
  background: #e9f5f3;
  color: var(--accent);
}

.icon-button.ghost {
  background: transparent;
  box-shadow: none;
}

.primary-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button.small,
.secondary-button.small {
  min-height: 36px;
  padding: 0 12px;
}

.secondary-button {
  background: #edf2f7;
  color: var(--ink);
}

.text-button {
  background: transparent;
  color: var(--accent);
  padding-inline: 4px;
}

.text-button.compact {
  min-height: auto;
  padding: 4px 0;
  font-weight: 800;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

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

.metric,
.panel,
.table-wrap {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(220, 226, 234, 0.9);
  border-radius: 8px;
  box-shadow: 0 10px 34px rgba(21, 32, 51, 0.06);
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 20px;
  min-height: 130px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent);
}

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

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

.metric.card-debt::before {
  background: #2563eb;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 14px 0 8px;
  font-size: 1.8rem;
}

.content-grid,
.category-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.month-picker {
  grid-auto-flow: column;
  align-items: center;
  gap: 8px;
}

.month-picker input {
  width: 150px;
}

.transaction-list,
.category-bars,
.category-list,
.category-total-list {
  display: grid;
  gap: 10px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.category-pill-row,
.category-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.category-total-row strong {
  color: var(--accent-strong);
}

.category-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.category-chart {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.category-chart-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.35fr) minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.category-chart-row strong {
  color: var(--ink);
}

.category-chart-bar {
  overflow: hidden;
  height: 14px;
  border-radius: 999px;
  background: #e7edf3;
}

.category-chart-fill {
  height: 100%;
  border-radius: inherit;
  background: #2563eb;
}

.transaction-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.transaction-icon,
.transaction-photo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #e9f5f3;
  color: var(--accent);
  font-weight: 800;
}

.transaction-photo,
.transaction-table-photo {
  background-position: center;
  background-size: cover;
}

.transaction-title-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.payment-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  vertical-align: middle;
  font-weight: 700;
}

.payment-label.compact {
  gap: 5px;
}

.payment-thumb {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-position: center;
  background-size: cover;
  flex: 0 0 auto;
}

.payment-label.compact .payment-thumb {
  width: 18px;
  height: 18px;
  border-radius: 6px;
}

.transaction-table-photo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.transaction-meta strong,
.transaction-meta small {
  display: block;
}

.transaction-meta small {
  margin-top: 3px;
  color: var(--muted);
}

.amount {
  font-weight: 800;
  text-align: right;
}

.running-balance {
  color: var(--muted);
  font-weight: 700;
}

.transaction-category {
  font-weight: 800;
}

.transaction-category.income {
  color: var(--ink);
}

.transaction-category.expense {
  color: var(--expense);
}

.payment-credit-card {
  font-weight: 800;
}

.amount.income {
  color: var(--income);
}

.amount.expense {
  color: var(--expense);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed #b8c2ce;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.93rem;
}

.bar-track {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #e7edf3;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #2563eb);
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segment {
  min-width: 72px;
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segment.active {
  background: #dff4f1;
  color: var(--accent-strong);
  font-weight: 700;
}

.select-label,
.search-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.search-label input {
  width: min(260px, 48vw);
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.table-wrap {
  overflow: auto;
}

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

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

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

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

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

.mini-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.mini-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.mini-button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.cards-heading {
  justify-content: space-between;
  margin-bottom: 18px;
}

.cards-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.card-summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
}

.card-summary-strip article {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.card-summary-strip span,
.card-summary-strip small {
  color: #2563eb;
  font-size: 0.9rem;
  font-weight: 700;
}

.card-summary-strip strong {
  color: #1e3a8a;
  font-size: 1.35rem;
}

.card-summary-strip .due strong {
  color: var(--expense);
}

.card-record-panel {
  margin-top: 18px;
}

.card-record-panel .select-label select {
  width: 150px;
}

.card-record-table {
  min-width: 900px;
}

.stock-summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #f8fafc;
}

.stock-summary-strip article {
  display: grid;
  gap: 5px;
}

.stock-summary-strip span,
.stock-summary-strip small {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.stock-summary-strip strong {
  color: var(--ink);
  font-size: 1.35rem;
}

.stock-summary-strip .stock-up strong,
.stock-summary-strip .stock-up small,
.amount.stock-up {
  color: var(--expense);
}

.stock-summary-strip .stock-down strong,
.stock-summary-strip .stock-down small,
.amount.stock-down {
  color: var(--income);
}

.stock-summary-strip .stock-flat strong,
.stock-summary-strip .stock-flat small,
.amount.stock-flat {
  color: var(--muted);
}

#stockQuoteStatus.success {
  color: var(--income);
  font-weight: 700;
}

#stockQuoteStatus.error {
  color: var(--expense);
  font-weight: 700;
}

.stock-table {
  min-width: 1060px;
}

.stock-trade-panel {
  margin-top: 18px;
}

.stock-trade-table {
  min-width: 980px;
}

.trade-type {
  display: inline-flex;
  align-items: center;
  min-width: 52px;
  justify-content: center;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.85rem;
  font-weight: 800;
}

.trade-type.buy {
  background: #eff6ff;
  color: #1d4ed8;
}

.trade-type.sell {
  background: #fef2f2;
  color: var(--expense);
}

.table-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.credit-card-grid,
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.account-card {
  min-height: 176px;
  border-radius: 8px;
  padding: 20px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.92));
  border: 1px solid var(--line);
  box-shadow: 0 10px 34px rgba(21, 32, 51, 0.06);
  position: relative;
  overflow: hidden;
}

.account-card.has-image {
  padding-top: 0;
}

.account-photo {
  height: 132px;
  margin: 0 -20px 18px;
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid var(--line);
}

.account-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--account-color);
}

.credit-card {
  min-height: 190px;
  border-radius: 8px;
  padding: 20px;
  color: var(--ink);
  box-shadow: var(--shadow);
  border: 1px solid #bfdbfe;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
}

.credit-card.has-image {
  padding-top: 0;
}

.card-photo {
  height: 132px;
  margin: 0 -20px 18px;
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid #bfdbfe;
}

.credit-card-top,
.credit-card-bottom,
.card-progress-label,
.account-card-top,
.account-detail,
.category-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-card h3,
.credit-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.account-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.account-balance {
  margin: 28px 0 18px;
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--ink);
}

.account-detail {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.account-detail strong {
  color: var(--ink);
}

.account-ledger-panel {
  margin-top: 18px;
}

.account-ledger-table {
  min-width: 980px;
}

.cash-balance-panel {
  margin-bottom: 18px;
}

.cash-balance-row {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(180px, 1fr);
  gap: 16px;
  align-items: end;
}

.currency-input-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.currency-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.currency-input span {
  padding: 0 12px;
  color: var(--ink);
  font-weight: 900;
}

.currency-input input {
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  min-height: 44px;
}

.cash-current-balance {
  display: grid;
  gap: 6px;
}

.cash-current-balance span {
  color: var(--muted);
  font-weight: 700;
}

.cash-current-balance strong {
  color: var(--ink);
  font-size: 1.55rem;
}

.account-ledger-group td {
  padding: 14px 16px;
  background: #f1f5f9;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.account-ledger-group td,
.account-ledger-group span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-ledger-group small {
  color: var(--muted);
  font-weight: 700;
}

.image-preview-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.transaction-image-preview,
.account-image-preview,
.card-image-preview {
  display: grid;
  place-items: center;
  width: 96px;
  height: 64px;
  border: 1px dashed #b8c2ce;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  overflow: hidden;
  background-position: center;
  background-size: cover;
}

.transaction-image-preview.has-image,
.account-image-preview.has-image,
.card-image-preview.has-image {
  color: transparent;
  border-style: solid;
}

.credit-card small {
  color: var(--muted);
}

.card-number {
  margin: 24px 0 20px;
  font-size: 1.4rem;
  letter-spacing: 3px;
}

.card-progress {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.statement-cycle {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-settle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.settle-button {
  border: 1px solid #1d4ed8;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
}

.settle-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.settle-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
}

.settle-summary strong {
  color: var(--ink);
  font-size: 1.1rem;
}

.card-progress .bar-track {
  background: #dbeafe;
}

.card-progress .bar-fill {
  background: #2563eb;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #e9f5f3;
  color: var(--accent-strong);
}

.summary-row strong {
  color: var(--ink);
}

.monthly-category-panel {
  margin-top: 18px;
}

.monthly-table-wrap {
  box-shadow: none;
}

.monthly-category-table {
  min-width: 1160px;
}

.monthly-category-table th:first-child,
.monthly-category-table td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}

dialog {
  width: min(680px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-card {
  padding: 22px;
}

.small-dialog {
  width: min(480px, calc(100vw - 28px));
}

.dialog-header {
  justify-content: space-between;
  margin-bottom: 18px;
}

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

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

.balance-preview {
  color: var(--accent-strong);
  font-weight: 700;
}

.balance-preview.warning {
  color: var(--expense);
}

.full {
  grid-column: 1 / -1;
}

textarea {
  resize: vertical;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--line);
}

.swatch.active {
  box-shadow: 0 0 0 3px var(--accent);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .nav-item {
    justify-content: center;
    padding: 0 8px;
  }

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

@media (max-width: 680px) {
  .main {
    padding: 18px 14px 28px;
  }

  .topbar,
  .cards-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .card-summary-strip,
  .stock-summary-strip {
    grid-template-columns: 1fr;
  }

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

  .nav-item {
    font-size: 0;
  }

  .nav-item svg {
    width: 22px;
    height: 22px;
  }

  .summary-grid,
  .content-grid,
  .category-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .transaction-item {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .transaction-item .amount {
    grid-column: 2;
    text-align: left;
  }

}
