:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-strong: #f8fbfa;
  --ink: #1d2527;
  --muted: #637173;
  --line: #d6dfdd;
  --primary: #176b5f;
  --primary-dark: #0f4f47;
  --accent: #2f6f8f;
  --accent-soft: #e4f0f6;
  --blue: #385f8e;
  --blue-soft: #e5eef7;
  --green-soft: #e4f1ec;
  --shadow: 0 18px 45px rgba(29, 42, 38, 0.1);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    "PingFang TC",
    "Segoe UI",
    Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.intro {
  margin-bottom: 22px;
}

.intro-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.intro-copy {
  min-width: 0;
}

.global-language {
  width: min(280px, 100%);
  margin-bottom: 0;
}

.global-language select {
  min-height: 42px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.18;
  letter-spacing: 0;
}

h1 {
  max-width: 760px;
  font-size: 2.25rem;
}

h2 {
  font-size: 1.1rem;
}

.intro p:not(.eyebrow) {
  max-width: 800px;
  margin: 12px 0 0;
  color: var(--muted);
}

.status-strip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin-top: 18px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.92rem;
}

.status-strip.ready {
  border-color: rgba(23, 107, 95, 0.28);
  background: var(--green-soft);
  color: var(--primary-dark);
}

.status-strip.error {
  border-color: rgba(180, 95, 53, 0.38);
  background: var(--accent-soft);
  color: #7a351f;
}

.tool-grid,
.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 18px;
  margin-top: 18px;
}

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

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-panel,
.result-panel,
.history-panel,
.comparison-panel,
.living-panel,
.portfolio-panel,
.analysis-grid .panel {
  padding: 20px;
}

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

.local-badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.field small,
.locale-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 95, 0.14);
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 4px 0 14px;
  padding: 0;
  border: 0;
}

.segmented legend {
  grid-column: 1 / -1;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.segmented label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  border-color: rgba(23, 107, 95, 0.55);
  background: var(--green-soft);
  color: var(--primary-dark);
}

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

.example-row button,
.secondary-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 800;
}

.example-row button:hover,
.secondary-action:hover:not(:disabled) {
  border-color: var(--primary);
}

.example-row button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-action {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 900;
}

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

.secondary-action {
  flex: 0 0 auto;
  padding: 8px 12px;
}

.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.result-empty,
.history-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.rank-card {
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.rank-label,
.rank-copy {
  margin: 0;
  color: var(--muted);
}

.rank-number {
  margin: 6px 0;
  color: var(--primary-dark);
  font-size: 2.5rem;
  line-height: 1;
  font-weight: 950;
}

.distribution-track {
  margin: 18px 0;
}

.track-labels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.track-labels span:nth-child(2),
.track-labels span:nth-child(3),
.track-labels span:nth-child(4) {
  text-align: right;
}

.track {
  position: relative;
  display: flex;
  height: 24px;
  overflow: visible;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #eef2ef;
}

.track-band {
  height: 100%;
}

.band-low {
  width: 50%;
  background: #dde7e3;
}

.band-middle {
  width: 40%;
  background: #a9ccbf;
}

.band-high {
  width: 10%;
  background: #d38a68;
}

.marker {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 16px;
  height: 32px;
  transform: translate(-50%, -50%);
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: white;
  box-shadow: 0 5px 14px rgba(28, 37, 34, 0.22);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
}

.metric-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.metric-grid dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-grid dd {
  margin: 4px 0 0;
  font-weight: 900;
}

.comparison-panel {
  margin-top: 18px;
}

.living-panel {
  margin-top: 18px;
}

.living-intro {
  max-width: 920px;
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.interpretation-box {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
}

.interpretation-box h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.interpretation-box p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.interpretation-country-field {
  max-width: 380px;
  margin-bottom: 14px;
}

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

.interpretation-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.interpretation-item strong {
  display: block;
  color: var(--text);
}

.interpretation-item p {
  margin-top: 4px;
}

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

.living-table th:not(:first-child),
.living-table td:not(:first-child) {
  text-align: right;
}

.living-value {
  display: block;
  font-weight: 900;
}

.index-pill,
.ratio-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 950;
}

.index-pill {
  background: var(--blue-soft);
  color: var(--blue);
}

.ratio-pill {
  background: var(--green-soft);
  color: var(--primary-dark);
}

.ratio-pill.below-median {
  background: var(--accent-soft);
  color: #7a351f;
}

.comparison-controls {
  display: grid;
  grid-template-columns: minmax(260px, 0.45fr) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.compact-segmented {
  margin: 0;
}

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

.comparison-table {
  min-width: 820px;
}

.country-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 150px;
}

.country-code {
  display: inline-grid;
  width: 42px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 950;
}

.country-cell strong,
.money-cell strong {
  display: block;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-weight: 950;
}

.base-row {
  background: var(--surface-strong);
}

.placeholder-cell {
  color: var(--muted);
  text-align: center !important;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

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

td:nth-child(2),
td:nth-child(3),
th:nth-child(2),
th:nth-child(3) {
  text-align: right;
}

.group-list {
  display: grid;
  gap: 10px;
}

.group-row {
  display: grid;
  grid-template-columns: minmax(92px, 0.8fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.group-row:last-child {
  border-bottom: 0;
}

.group-name {
  font-weight: 900;
}

.group-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.portfolio-panel {
  margin-top: 18px;
}

.portfolio-intro {
  max-width: 920px;
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.portfolio-country-field {
  width: min(420px, 100%);
  margin-bottom: 16px;
}

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

.portfolio-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
}

.portfolio-card.is-base {
  border-color: rgba(23, 107, 95, 0.45);
}

.portfolio-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.portfolio-card-heading h3 {
  margin: 0;
  font-size: 1.05rem;
}

.portfolio-card-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.portfolio-estimate-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 900;
  white-space: nowrap;
}

.portfolio-bar {
  display: flex;
  height: 24px;
  margin: 16px 0;
  overflow: hidden;
  border-radius: 7px;
  background: #edf2f1;
}

.portfolio-segment {
  min-width: 0;
  transition: width 160ms ease;
}

.portfolio-segment.deposits,
.portfolio-dot.deposits {
  background: #176b5f;
}

.portfolio-segment.securities,
.portfolio-dot.securities {
  background: #385f8e;
}

.portfolio-segment.insurancePensions,
.portfolio-dot.insurancePensions {
  background: #b56a3b;
}

.portfolio-segment.other,
.portfolio-dot.other {
  background: #899595;
}

.portfolio-breakdown {
  display: grid;
  gap: 7px;
  margin: 0;
}

.portfolio-breakdown div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.portfolio-breakdown dt,
.portfolio-breakdown dd {
  margin: 0;
}

.portfolio-breakdown dt {
  color: var(--muted);
  font-size: 0.86rem;
}

.portfolio-breakdown dd {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.portfolio-source {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.portfolio-source a {
  color: var(--accent);
}

.portfolio-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.portfolio-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.portfolio-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.share-bar {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2f1;
}

.share-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.history-panel {
  margin-top: 18px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(0, 1fr) minmax(92px, 0.5fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.history-date {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.history-income {
  font-weight: 900;
}

.history-position {
  text-align: right;
  color: var(--primary-dark);
  font-weight: 950;
}

.notes {
  margin-top: 18px;
  padding: 4px 0 30px;
  color: var(--muted);
}

.notes h2 {
  margin-bottom: 8px;
  color: var(--ink);
}

.notes p {
  max-width: 86ch;
  margin: 8px 0 0;
}

.notes a {
  color: var(--primary-dark);
  font-weight: 750;
  text-underline-offset: 3px;
}

.not-found-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.not-found-panel {
  width: min(560px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.not-found-icon {
  display: block;
  margin-bottom: 18px;
  border-radius: 16px;
}

.not-found-panel h1 {
  margin: 6px 0 10px;
}

.not-found-panel p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
}

.not-found-link {
  display: inline-flex;
  margin-top: 22px;
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 850;
  text-decoration: none;
}

.not-found-link:hover {
  background: var(--primary-dark);
}

code {
  padding: 2px 5px;
  border-radius: 6px;
  background: #edf2f1;
  color: var(--ink);
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 18px;
  }

  h1 {
    font-size: 1.75rem;
  }

  .intro-top {
    flex-direction: column;
    gap: 16px;
  }

  .global-language {
    width: min(420px, 100%);
  }

  .tool-grid,
  .analysis-grid,
  .field-row,
  .metric-grid,
  .comparison-controls,
  .interpretation-grid,
  .portfolio-comparison {
    grid-template-columns: 1fr;
  }

  .history-row {
    grid-template-columns: 1fr;
  }

  .history-position {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .input-panel,
  .result-panel,
  .history-panel,
  .comparison-panel,
  .living-panel,
  .portfolio-panel,
  .analysis-grid .panel {
    padding: 15px;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented,
  .example-row {
    grid-template-columns: 1fr 1fr;
  }

  .track-labels {
    grid-template-columns: 1fr 1fr;
  }

  .track-labels span {
    text-align: left !important;
  }
}
