#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header / nav ─────────────────────────────────────────────── */

.app-header {
  background: var(--wood);
  background-image:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.07) 0px, rgba(0, 0, 0, 0.07) 2px, transparent 2px, transparent 16px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.06));
  border-bottom: 4px solid var(--wood-dark);
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 0 24px;
  height: 58px;
  flex-shrink: 0;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 24px;
}

.app-header__word {
  font-family: var(--font-pixel);
  font-size: 26px;
  color: var(--header-word);
  letter-spacing: 0.02em;
}

.app-nav {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  /* When the tabs don't fit beside the brand and status, scroll the tab row
     sideways instead of pushing the header (and the page) wider than the screen. */
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.app-header__brand,
.app-header__status { flex-shrink: 0; }

.nav-tab {
  background: transparent;
  color: var(--wood-text);
  border: 1px solid var(--wood-dark);
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-pixel);
  cursor: pointer;
  white-space: nowrap;
}

.nav-tab--active {
  background: var(--bg);
  color: var(--ink);
  padding: 12px 16px 10px;
}

/* Icon and short label only show in the phone tab bar (responsive.css). */
.nav-tab__icon,
.nav-tab__short { display: none; }

.app-header__status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--wood-text);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Pages ────────────────────────────────────────────────────── */

.page {
  display: none;
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 40px;
  flex-direction: column;
  gap: 18px;
}

.page--active { display: flex; }

#page-dashboard,
#page-analytics,
#page-transactions,
#page-etf,
#page-sectors {
  max-width: 1400px;
}

/* ── Panels ───────────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft-sm);
  padding: 1.1rem;
}

.panel--table,
.panel--quotes {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 0;
}

.panel-title {
  font-family: var(--font-pixel);
  font-size: 16px;
}

/* ── Stats strip (Dashboard) ──────────────────────────────────── */

.stats-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.stat {
  flex: 1;
  min-width: 12rem;
  background: var(--panel-accent);
  border: 1px solid var(--panel-border);
  border-top: 3px solid var(--wood);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--stat-shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat > span:first-child {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.stat--maint { border-top-color: var(--accent); }
.stat--bench { border-top-color: var(--wood); }

.stat--danger strong { color: var(--up); }
.stat--caution strong { color: var(--caution); }

.stat-daily-change {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}
.stat-daily-change--up   { color: var(--up); }
.stat-daily-change--down { color: var(--down); }
.stat-daily-change--flat { color: var(--muted); }

/* Return pill with its 持有 / 總報酬 switch, and the P&L breakdown under it. */
.return-mode {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.return-mode__switch {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.return-mode__btn {
  padding: 2px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-pixel);
  font-size: 11px;
  cursor: pointer;
}

.return-mode__btn--active {
  background: var(--wood);
  color: var(--header-word);
}

.stat-return-detail {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

.stat-return-detail .up   { color: var(--up); }
.stat-return-detail .down { color: var(--down); }

.stat__tickers {
  font-family: var(--font-mono);
  font-size: 14px;
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.stat-ticker--up   { color: var(--up); }
.stat-ticker--down { color: var(--down); }
.stat-ticker--flat { color: var(--muted); }

/* ── Dashboard two-column layout ──────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(20rem, 0.6fr);
  gap: 1.25rem;
  min-height: 0;
  flex: 1;
}

.panel__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ── Home page ────────────────────────────────────────────────── */

/* The village hero (village.css) runs edge to edge; everything under it sits
   in the usual centred column. */
#page-home {
  max-width: none;
  padding: 0 0 40px;
}

.home-body {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.home-grid {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex-wrap: wrap;
}

.home-house-card {
  flex: 1.5;
  min-width: 20rem;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.home-house-card__top {
  display: flex;
  gap: 20px;
  align-items: center;
}

.home-house-card__badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--kraft-text);
  background: var(--kraft-bg);
  border: 1px solid var(--kraft-border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  margin-bottom: 6px;
}

.home-progress {
  border-top: 1px dashed var(--panel-border);
  padding-top: 14px;
}

.home-progress__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-family: var(--font-pixel);
  font-size: 15px;
}

.home-progress__bar {
  height: 12px;
  background: var(--progress-track);
  border: 1px solid var(--progress-track-border);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.home-progress__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0 3px, transparent 3px 8px);
  transition: width 0.4s ease;
}

.home-side {
  flex: 1;
  min-width: 16rem;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.home-notes__row {
  padding: 5px 0;
  border-bottom: 1px dashed var(--dash-border);
  font-size: 13px;
  color: var(--body-text);
}
.home-notes__row:last-child { border-bottom: none; }

.home-movers {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.home-movers__bench {
  text-align: right;
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
}

/* ── Town page ────────────────────────────────────────────────── */

/* The map fills the window under the header (--header-h is measured by
   ui/pages/home.js); a fixed height, not flex, so the map's 100% resolves. */
#page-town {
  position: relative;
  flex: none;
  max-width: none;
  padding: 0;
  height: calc(100dvh - var(--header-h, 58px));
  overflow: hidden;
}

#page-town.page--active { display: block; }

#town-map {
  width: 100%;
  height: 100%;
}

/* ── Analytics page ───────────────────────────────────────────── */

.analytics-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.analytics-head__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

/* Let a crowded controls row wrap rather than squeeze button labels. */
.analytics-head__controls .button,
.analytics-head__controls .button--ghost { white-space: nowrap; }

.chart-panel {
  height: 560px;
}

#chart-container {
  width: 100%;
  height: 100%;
}

.analytics-page--history .analytics-mode-switcher {
  display: none;
}

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

.benchmark-card__delta {
  text-align: right;
}

.benchmark-card__delta strong {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  white-space: nowrap;
}

.benchmark-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.benchmark-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

.benchmark-grid input,
.benchmark-grid select {
  padding: 7px 8px;
  border: 1px solid var(--panel-border);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 12px;
}

.benchmark-grid input { font-family: var(--font-mono); }

/* Performance card: return/risk tiles (reusing .txn-summary__tile) plus a
   dividends-per-year bar list. */
.perf-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.perf-grid .hint-text { line-height: 1.4; }

.perf-grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.perf-card[hidden] { display: none; }

.pledge-verdict { margin: 0; padding: 0 6px; line-height: 1.5; }

.perf-value--up   { color: var(--up); }
.perf-value--down { color: var(--down); }
.perf-value--flat { color: var(--ink); }

.perf-dividends__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.perf-div-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.perf-div-row {
  display: grid;
  grid-template-columns: 3.5em 1fr 8em;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.perf-div-row__bar {
  height: 12px;
  border-bottom: 1px dashed var(--panel-border);
}

.perf-div-row__bar > span {
  display: block;
  height: 100%;
  background: var(--wood);
  box-shadow: 0 2px 0 var(--wood-dark);
}

.perf-div-row__amount { text-align: right; }

.perf-empty {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Transactions page ────────────────────────────────────────── */

.txn-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.etf-date {
  width: auto;
  font-family: var(--font-mono);
}

/* Per-stock picker: a text box that filters a dropdown list as you type. */
.txn-symbol-combo {
  position: relative;
}

.txn-symbol-combo input {
  width: 15em;
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--panel-border-strong);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 0.85rem;
}

.txn-symbol-combo__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  min-width: 100%;
  max-height: 280px;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--wood);
  border-radius: var(--radius-md);
  box-shadow: 0 3px 0 var(--dropdown-shadow);
}

.txn-symbol-combo__option,
.txn-symbol-combo__empty {
  padding: 7px 12px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.txn-symbol-combo__option {
  color: var(--ink);
  cursor: pointer;
}

.txn-symbol-combo__option + .txn-symbol-combo__option { border-top: 1px solid var(--divider-strong); }
.txn-symbol-combo__option[aria-selected="true"] { font-weight: 600; }
.txn-symbol-combo__option--active { background: var(--hover-bg); }
.txn-symbol-combo__empty { color: var(--muted); }

.txn-summary {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.txn-summary__tile {
  flex: 1;
  min-width: 10rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.txn-fx-note {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.8rem;
  color: var(--muted, inherit);
  opacity: 0.85;
}

.txn-summary__tile strong {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  white-space: nowrap;
}

.stat-value--up   { color: var(--up); }
.stat-value--down { color: var(--down); }
.stat-value--flat { color: var(--muted); }
