:root {
  --bg: #f4f7f8;
  --bg-band: #eaf3f1;
  --surface: #ffffff;
  --surface-soft: #f4faf8;
  --ink: #14201e;
  --muted: #66736f;
  --line: #dbe6e3;
  --teal: #0f766e;
  --teal-strong: #0d5f59;
  --blue: #2563eb;
  --amber: #d97706;
  --rose: #be123c;
  --violet: #6d5bd0;
  --shadow: 0 18px 46px rgba(20, 32, 30, 0.10);
  --shadow-soft: 0 8px 24px rgba(20, 32, 30, 0.07);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--bg-band) 0, var(--bg) 320px, #f8faf9 100%),
    var(--bg);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-watermark {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  padding: 7px 11px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  color: rgba(13, 95, 89, 0.72);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 24px 18px;
  color: #f6fffc;
  background:
    linear-gradient(180deg, rgba(9, 49, 48, 0.96), rgba(13, 95, 89, 0.98)),
    #0d5f59;
}

.brand {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand h1,
.topbar h2,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.brand p,
.sync-card p,
.version-card p,
.record-heading p,
.muted {
  margin: 4px 0 0;
  color: inherit;
  opacity: 0.72;
  line-height: 1.6;
}

#accountStatus,
#accountStatusTop {
  white-space: pre-line;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab-button {
  width: 100%;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  text-align: left;
  padding: 0 14px;
  font-weight: 800;
}

.tab-button.active,
.tab-button:hover {
  color: #073b37;
  background: #d6fbf4;
}

.sync-card,
.version-card {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.10);
}

.sync-card {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 12px;
  align-items: start;
  margin-top: auto;
  padding: 14px;
}

.version-card {
  display: grid;
  gap: 4px;
  padding: 13px 14px;
}

.version-card span,
.version-card p {
  color: rgba(255, 255, 255, 0.74);
  font-size: 12px;
}

.version-card strong {
  color: white;
  font-size: 17px;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 7px;
  border-radius: 999px;
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22);
}

.status-dot.online {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}

.status-dot.error {
  background: #fb7185;
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.18);
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
}

.topbar h2 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.12;
  letter-spacing: 0;
}

.topbar-actions,
.record-tools,
.data-actions,
.category-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.account-actions {
  margin-top: 16px;
}

.server-login-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.month-picker {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  box-shadow: var(--shadow-soft);
}

.month-picker input,
.record-tools input,
.record-tools select,
.entry-form input,
.entry-form select {
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.file-button,
.download-button,
.primary-link.small {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 900;
  text-decoration: none;
}

.compact {
  min-height: 36px;
  padding: 0 12px;
}

.primary-button,
.primary-link.small {
  color: white;
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.20);
}

.primary-button:hover,
.primary-link.small:hover {
  background: var(--teal-strong);
}

.secondary-button,
.file-button,
.download-button {
  color: var(--teal-strong);
  background: #e7f5f2;
}

.download-button,
.file-button,
.primary-link.small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.danger-button {
  color: white;
  background: var(--rose);
}

.ghost-button {
  color: var(--muted);
  background: #f3f6f6;
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric,
.panel {
  border: 1px solid rgba(219, 230, 227, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  position: relative;
  overflow: hidden;
  min-height: 120px;
  padding: 18px;
}

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

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

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

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric strong {
  display: block;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.metric.income strong {
  color: var(--blue);
}

.metric.expense strong {
  color: var(--rose);
}

.metric.balance strong {
  color: var(--teal-strong);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(300px, 410px) minmax(0, 1fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.chart-panel {
  grid-column: 1 / -1;
}

.chart-panel .chart {
  min-height: 260px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading span {
  color: var(--muted);
}

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

.asset-cards article,
.asset-readout div,
.account-data-summary div,
.year-totals article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.asset-cards article {
  padding: 14px;
}

.asset-cards span,
.asset-readout span,
.account-data-summary span,
.year-totals span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 7px;
}

.asset-cards strong,
.asset-readout strong,
.account-data-summary strong,
.year-totals strong {
  display: block;
  color: var(--teal-strong);
  overflow-wrap: anywhere;
}

.asset-cards strong {
  font-size: 24px;
}

.entry-form,
.asset-form,
.transfer-form {
  display: grid;
  gap: 14px;
}

.entry-form label,
.asset-form label,
.transfer-form label,
.filter-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.entry-form label input,
.entry-form label select,
.asset-form label input,
.transfer-form label input,
.transfer-form label select,
.category-form input,
.category-form select,
.record-tools input,
.record-tools select,
.server-login-grid input,
.filter-grid input,
.filter-grid select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 8px;
  background: #edf5f4;
}

.segment {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.segment.active {
  color: white;
  background: var(--teal);
}

.asset-readout,
.account-data-summary,
.year-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.asset-readout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 14px;
}

.asset-readout div,
.account-data-summary div,
.year-totals article {
  padding: 12px;
}

.guarded-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

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

.form-actions > * {
  flex: 1 1 120px;
}

.category-form {
  margin-top: 14px;
}

.category-form input,
.category-form select {
  flex: 1 1 160px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.tag-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
}

.tag-pill button {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  color: white;
  background: var(--rose);
}

.summary-page {
  display: grid;
  gap: 14px;
}

.summary-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 520px);
  gap: 20px;
  align-items: center;
  color: white;
  background: linear-gradient(135deg, #0d5f59, #2563eb);
}

.summary-hero .eyebrow,
.summary-hero .muted,
.summary-hero p {
  color: white;
}

.summary-hero h3 {
  margin: 0;
  font-size: clamp(26px, 4vw, 44px);
  letter-spacing: 0;
}

.summary-hero p {
  max-width: 720px;
  line-height: 1.7;
  opacity: 0.88;
}

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

.summary-kpis article {
  min-width: 0;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.summary-kpis span {
  display: block;
  opacity: 0.76;
  margin-bottom: 6px;
}

.summary-kpis strong {
  font-size: 24px;
  overflow-wrap: anywhere;
}

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

.records-list {
  margin-top: 4px;
}

.category-list,
.records-list,
.insight-list {
  display: grid;
  gap: 10px;
}

.insight-list {
  padding: 0;
  margin: 0;
}

.insight {
  padding: 12px;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: var(--surface-soft);
  line-height: 1.6;
}

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

.category-row {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 12px;
  align-items: center;
}

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

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--amber);
}

.donut {
  width: min(220px, 64vw);
  aspect-ratio: 1;
  position: relative;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: #edf2f1;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 38px;
  border-radius: inherit;
  background: white;
}

.legend,
.donut-legend {
  display: grid;
  gap: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.chart {
  display: grid;
  grid-template-columns: repeat(31, minmax(8px, 1fr));
  align-items: end;
  gap: 6px;
  min-height: 220px;
  padding-top: 10px;
}

.chart-day {
  display: grid;
  align-content: end;
  gap: 3px;
  min-height: 175px;
}

.chart-bar,
.year-bar {
  min-height: 2px;
  border-radius: 6px 6px 0 0;
}

.chart-bar.income,
.year-bar.income {
  background: var(--blue);
}

.chart-bar.expense,
.year-bar.expense {
  background: var(--rose);
}

.chart-label,
.year-month span {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.year-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(26px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 230px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.year-month {
  display: grid;
  min-height: 200px;
  align-content: end;
  gap: 4px;
}

.record {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.record-main strong {
  display: block;
}

.record-main span {
  color: var(--muted);
}

.record-amount {
  font-weight: 900;
  white-space: nowrap;
}

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

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

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

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
}

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

code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #eef2f1;
}

.steps {
  margin: 14px 0 0;
  padding-left: 22px;
  line-height: 1.8;
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 58px;
  max-width: min(680px, calc(100vw - 36px));
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  padding: 12px 14px;
  border-radius: 8px;
  color: white;
  background: #14201e;
  box-shadow: var(--shadow);
  line-height: 1.55;
  white-space: pre-line;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.update-banner {
  position: fixed;
  right: 18px;
  bottom: 18px;
  left: 18px;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.update-banner.show {
  display: flex;
}

@media (max-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: static;
    height: auto;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 14px;
  }

  .brand p,
  .sync-card {
    display: none;
  }

  .brand {
    grid-template-columns: 44px 1fr;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .brand h1 {
    font-size: 24px;
  }

  .version-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
  }

  .version-card p {
    display: none;
  }

  .tabs {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    z-index: 10;
    display: flex;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    gap: 4px;
    padding: 6px;
    border: 1px solid rgba(15, 118, 110, 0.18);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 32px rgba(20, 32, 30, 0.18);
    backdrop-filter: blur(12px);
  }

  .tab-button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 52px;
    color: var(--muted);
    font-size: 15px;
    padding-inline: 6px;
    text-align: center;
    white-space: nowrap;
  }

  .tab-button.active,
  .tab-button:hover {
    color: white;
    background: var(--teal);
  }

  .content {
    padding: 18px 14px 92px;
  }

  .app-watermark {
    bottom: 76px;
  }

  .topbar,
  .summary-hero {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr auto;
  }

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

@media (max-width: 640px) {
  .topbar-actions,
  .filter-grid,
  .asset-cards,
  .asset-readout,
  .account-data-summary,
  .year-totals,
  .summary-kpis {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7fbfa;
  }

  .filter-grid label {
    gap: 7px;
  }

  .filter-grid label span {
    font-size: 14px;
  }

  .filter-grid input,
  .filter-grid select {
    min-height: 52px;
    font-size: 16px;
  }

  .panel {
    padding: 16px;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .topbar-actions > *,
  .month-picker,
  .data-actions,
  .record-tools {
    width: 100%;
  }

  .month-picker input {
    min-width: 0;
    width: 100%;
  }

  .month-picker span {
    white-space: nowrap;
  }

  .record {
    grid-template-columns: 1fr;
  }

  .record-actions {
    justify-content: flex-end;
  }

  .record-tools input,
  .record-tools select,
  .data-actions button,
  .file-button {
    flex: 1 1 180px;
  }

  .category-row {
    grid-template-columns: 92px 1fr;
  }

  .category-row strong {
    grid-column: 1 / -1;
  }

  .chart {
    gap: 3px;
    overflow-x: auto;
    grid-template-columns: repeat(31, 16px);
    padding-bottom: 8px;
  }
}
