.filter-grid { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
.filter-grid > * { min-width: 0; }
.filter-grid select { max-width: 100%; min-width: 0; }
.table-card { overflow: hidden; }
.content > .table-card + .table-card { margin-top: 14px; }
.metric-strip.three { grid-template-columns: repeat(3, 1fr); }
.download-menu { position: relative; }
.title-area { display: flex; align-items: center; gap: 16px; min-width: 0; }
.back-btn { flex: 0 0 auto; border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; color: var(--ink); padding: 10px 14px; font-size: 16px; font-weight: 750; cursor: pointer; box-shadow: 0 4px 14px rgba(24,39,75,.08); }
.back-btn:hover:not(:disabled) { border-color: #174f84; background: #f3f7fb; color: #174f84; }
.back-btn:focus-visible { outline: 3px solid rgba(35,100,170,.28); outline-offset: 2px; }
.back-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.download-options { position: absolute; right: 0; top: calc(100% + 7px); min-width: 168px; padding: 6px; border: 1px solid #e4e9f0; border-radius: 9px; background: #fff; box-shadow: 0 12px 30px rgba(24,39,75,.16); z-index: 12; }
.download-options button { width: 100%; border: 0; border-radius: 6px; background: transparent; color: #152237; padding: 9px 10px; text-align: left; cursor: pointer; }
.download-options button:hover { background: #f3f6fa; }
.assistant-actions { display: flex; align-items: center; gap: 8px; }
.assistant-panel header .assistant-actions button:first-child { color: #2364aa; font-size: 12px; font-weight: 700; padding: 6px 8px; border: 1px solid #c9d8e8; border-radius: 7px; }
.method-note { margin-bottom: 14px; padding: 16px 18px; border: 1px solid #c9d8e8; border-left: 4px solid #2364aa; border-radius: 12px; background: #f7fbff; color: #344054; }
.method-note h2 { margin: 0 0 8px; color: #152237; font-size: 16px; }
.method-note p, .method-note ul { margin: 0; line-height: 1.65; font-size: 14px; }
.method-note ul { padding-left: 20px; }

@media (max-width: 850px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
  .app-shell { grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 100vw; overflow: hidden; }
  main, .topbar, .filter-panel, .content { min-width: 0; max-width: 100%; }
  .filter-grid { min-width: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: flex-start; gap: 12px; }
  .title-area { align-items: flex-start; gap: 10px; }
  .back-btn { padding: 9px 11px; font-size: 15px; }
}

@media (max-width: 520px) {
  .filter-grid, .metric-strip.three { grid-template-columns: minmax(0, 1fr); }
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; flex-wrap: wrap; }
}

@media print {
  .sidebar, .top-actions, .filter-panel, .assistant-fab, .assistant-panel { display: none !important; }
  .app-shell { display: block; }
  body { background: #fff; }
  .topbar, .content { padding-left: 0; padding-right: 0; }
  .card, .chart-card, .table-card, .hero-card { box-shadow: none; break-inside: avoid; }
  .table-wrap { max-height: none; overflow: visible; }
}

/* 高齡友善閱讀：放大介面文字並提高深灰色對比 */
:root { --ink: #30343b; --muted: #4b5563; --blue: #174f84; --red: #b4232d; }
body { color: var(--ink); font-size: 18px; line-height: 1.6; }
button, select, input { color: var(--ink); font-size: 16px; }
.brand strong { font-size: 21px; }
.brand small, .source-status small { font-size: 14px; }
.nav-btn { font-size: 17px; padding: 13px 12px; }
.topbar h1 { font-size: 32px; color: var(--ink); }
.eyebrow { font-size: 13px; }
.ghost-btn, .primary-btn, .text-btn { font-size: 16px; padding: 11px 15px; }
.filter-head span { color: var(--muted); font-size: 16px; }
.filter-grid label, .field-label { color: var(--ink); font-size: 16px; }
.filter-grid select { font-size: 16px; padding: 10px; }
.month-chip span { color: var(--ink); font-size: 16px; padding: 8px 12px; }
.card-label { color: var(--ink); font-size: 16px; font-weight: 650; }
.formula { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; font-weight: 650; line-height: 1.35; white-space: normal; }
.hero-card .formula { color: #dce8f4; }
.card-value { color: var(--ink); font-size: 30px; }
.card-meta { color: var(--muted); font-size: 15px; }
.card-head h2, .method-note h2 { color: var(--ink); font-size: 20px; }
.card-head p, .legend, .section-note, .breadcrumbs { color: var(--muted); font-size: 15px; }
.chart text { fill: #3f4650; font-size: 14px; font-weight: 600; }
.chart.chart-tall { height: 360px; }
.chart.chart-ranking { height: 420px; overflow-x: auto; }
.chart.chart-ranking svg { min-width: 720px; }
.ranking-card .card-head { align-items: center; }
.ranking-card .legend { flex-wrap: wrap; justify-content: flex-end; }
.chart-tooltip { max-width: min(420px, calc(100vw - 24px)); padding: 12px 16px; border: 2px solid #fff; border-radius: 10px; background: #20242b; color: #fff; font-size: 19px; font-weight: 750; line-height: 1.5; letter-spacing: .01em; box-shadow: 0 12px 34px rgba(16,24,40,.3); white-space: normal; }
.chart svg rect[tabindex], .chart svg circle[tabindex] { cursor: help; outline: none; }
.chart svg rect[tabindex]:focus, .chart svg circle[tabindex]:focus { stroke: #20242b; stroke-width: 3; }
.data-table { color: var(--ink); font-size: 16px; }
.data-table th { color: #3f4650; padding: 12px 10px; }
.data-table td { padding: 11px 10px; }
.pill { color: #3f4650; font-size: 14px; padding: 5px 9px; }
.btn-small, .search-input { font-size: 16px; }
.mini-metric { color: var(--ink); }
.mini-metric b { font-size: 21px; }
.assistant-panel header small, .assistant-answer, .assistant-panel input { color: var(--ink); font-size: 16px; }
.quick-questions button, .assistant-panel header .assistant-actions button:first-child { font-size: 15px; }
.method-note { color: var(--ink); }
.method-note p, .method-note ul { font-size: 16px; }
.download-options button { color: var(--ink); font-size: 16px; }
.pie-chart path { cursor: pointer; transition: opacity .12s ease; }
.pie-chart path:hover, .pie-chart path:focus { opacity: .82; outline: none; }
.chart .pie-label { fill: #344054; font-size: 15px; font-weight: 700; }
.chart.chart-pie { height: 340px; }
.pie-legend-row { cursor: pointer; }
.kpi-grid.kpi-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 850px) {
  .kpi-grid.kpi-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar h1 { font-size: 28px; }
  .chart { height: 270px; }
  .chart.chart-tall { height: 330px; }
  .chart.chart-ranking { height: 420px; }
}

@media (max-width: 520px) {
  .kpi-grid.kpi-grid-4 { grid-template-columns: 1fr; }
  body { font-size: 17px; }
  .primary-btn { font-size: 15px; }
  .card-value { font-size: 27px; }
  .data-table { font-size: 15px; }
  .chart text { font-size: 13px; }
  .chart-tooltip { font-size: 17px; padding: 11px 14px; }
}
.sort-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.sortable-table th:first-child .sort-btn,
.sortable-table th:nth-child(2) .sort-btn {
  justify-content: flex-start;
}

.sort-btn:hover,
.sort-btn:focus-visible,
.sort-btn.active {
  color: #174f79;
}

.sort-btn:focus-visible {
  outline: 3px solid rgba(35, 100, 170, 0.28);
  outline-offset: 4px;
  border-radius: 4px;
}

.sort-icon {
  min-width: 1em;
  font-size: 15px;
  line-height: 1;
}

.expense-structure-pie .pie-label {
  font-size: 17px;
  font-weight: 700;
  fill: #344054;
}

.structure-trend-grid {
  margin-top: 14px;
}

.structure-trend-grid .chart-card {
  min-height: 350px;
}

.drill-kpi {
  position: relative;
  width: 100%;
  min-height: 150px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.drill-kpi:hover,
.drill-kpi:focus-visible,
.drill-kpi.selected {
  border-color: #2364aa;
  box-shadow: 0 0 0 3px rgba(35, 100, 170, 0.16), var(--shadow);
}

.drill-kpi:focus-visible {
  outline: none;
}

.drill-hint {
  display: block;
  margin-top: 10px;
  color: #2364aa;
  font-size: 13px;
  font-weight: 700;
}

.variance-detail-card {
  scroll-margin-top: 18px;
}

.detail-filter-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 0 20px 18px;
}

.detail-filter-dropdown {
  position: relative;
  min-width: 0;
  margin: 0;
}

.detail-filter-dropdown summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: #374151;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.detail-filter-dropdown summary::-webkit-details-marker {
  display: none;
}

.detail-filter-dropdown summary::after {
  content: "▼";
  margin-left: 12px;
  color: #2364aa;
  font-size: 13px;
}

.detail-filter-dropdown[open] summary::after {
  content: "▲";
}

.detail-filter-dropdown summary strong {
  margin-left: auto;
  color: #2364aa;
  font-size: 16px;
}

.detail-dropdown-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(15, 35, 60, .18);
}

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

.multi-check span {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #374151;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.multi-check input:checked + span {
  border-color: #2364aa;
  background: #e8f1fb;
  color: #174f89;
  box-shadow: inset 0 0 0 1px #2364aa;
}

.multi-check input:focus-visible + span {
  outline: 3px solid rgba(35, 100, 170, .25);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .detail-filter-panel {
    grid-template-columns: 1fr;
    padding-inline: 14px;
  }

  .detail-dropdown-menu {
    position: static;
    margin-top: 6px;
  }
}

.pareto-top-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.pareto-top-card .table-wrap {
  max-height: none;
  overflow: visible;
}

.pareto-top-card .data-table {
  table-layout: fixed;
  white-space: normal;
}

.pareto-top-card .data-table th:first-child,
.pareto-top-card .data-table td:first-child {
  width: 36%;
}

.pareto-top-card .data-table th,
.pareto-top-card .data-table td {
  padding: 12px 14px;
}
