/* ============================================================
   Fine Dashboard - Yearly Comparison ("ภาพรวมทั้งปี")
   Visual language matches the main dashboard's Apple-inspired
   soft-white theme (css/variables.css tokens, .kpi-card /
   .chart-card / .data-table conventions) — this file only
   restyles the comparison-specific classes, no logic here.
   ============================================================ */

[hidden] {
  display: none !important;
}

.comparison-switch {
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  transition: color var(--transition-fast);
}

.comparison-switch:hover {
  color: var(--color-text-primary);
}

.comparison-switch:focus-visible {
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.comparison-switch.active {
  color: var(--color-accent);
}

.comparison-switch__label {
  line-height: 1;
  white-space: nowrap;
}

.comparison-switch__track {
  width: 34px;
  height: 20px;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-full);
  background: var(--color-surface-hover);
  transition: background var(--transition-base), border-color var(--transition-base);
}

.comparison-switch__thumb {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transform: translateX(0);
  transition: transform var(--transition-base);
}

.comparison-switch.active .comparison-switch__track {
  border-color: var(--color-accent);
  background: var(--color-accent);
}

.comparison-switch.active .comparison-switch__thumb {
  transform: translateX(14px);
}

.filter-month-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}

.filter-month-label__left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.filter-month-label__right {
  margin-left: auto;
}

.comparison-month-fields {
  display: grid;
  gap: var(--space-3);
}

.comparison-month-field {
  display: grid;
  gap: 6px;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.comparison-month-field .select-input {
  min-height: 42px;
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
}

/* ── Section shell ── */
.comparison-section {
  display: grid;
  gap: var(--space-5);
  margin-bottom: var(--space-8);
}

/* ── Toolbar / page header ── */
.comparison-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-1);
}

.comparison-toolbar__title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.comparison-toolbar__period {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-tight);
  line-height: 1.25;
}

.comparison-toolbar__period span {
  margin: 0 4px;
  color: var(--color-text-muted);
  font-weight: var(--font-weight-regular);
}

.comparison-toolbar__subtitle {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.comparison-segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background: var(--color-surface-hover);
}

.comparison-segmented button {
  min-height: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.comparison-segmented button:focus-visible {
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

.comparison-segmented button.active {
  color: var(--color-accent);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}

/* Compact variant — used inside chart-card__header (e.g. the daily trend
   chart) so the toggle stays balanced against the title and doesn't
   overpower the card header. */
.comparison-segmented--compact {
  padding: 2px;
  align-self: flex-start;
  flex-shrink: 0;
}

.comparison-segmented--compact button {
  min-height: 22px;
  padding: 0 var(--space-2);
  font-size: 0.68rem;
  white-space: nowrap;
}

/* ── KPI cards — same visual language as the main dashboard's
   .kpi-card (css/components.css): gradient icon circle with glow,
   two-tone value (bold number + coloured unit), staggered fade-in. ── */
.comparison-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--space-5);
}

.comparison-kpi {
  min-width: 0;
  min-height: 158px;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  animation: fadeIn 0.5s ease forwards;
  opacity: 0;
  transition: box-shadow var(--transition-spring), transform var(--transition-spring), border-color var(--transition-base);
}

.comparison-kpi:nth-child(1) { animation-delay: 0.05s; }
.comparison-kpi:nth-child(2) { animation-delay: 0.10s; }
.comparison-kpi:nth-child(3) { animation-delay: 0.15s; }
.comparison-kpi:nth-child(4) { animation-delay: 0.20s; }
.comparison-kpi:nth-child(5) { animation-delay: 0.25s; }
.comparison-kpi:nth-child(6) { animation-delay: 0.30s; }

.comparison-kpi:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-card-hover);
}

.comparison-kpi--red { --comparison-tone: var(--color-danger); }
.comparison-kpi--blue { --comparison-tone: var(--color-accent); }
.comparison-kpi--green { --comparison-tone: var(--color-success); }
.comparison-kpi--orange { --comparison-tone: var(--color-warning); }
.comparison-kpi--purple { --comparison-tone: var(--chart-purple); }
.comparison-kpi--mint { --comparison-tone: var(--chart-mint); }

.comparison-kpi__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.comparison-kpi__label {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1.3;
}

.comparison-kpi__icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  border-radius: 50%;
  color: #FFFFFF;
  background: linear-gradient(135deg, var(--comparison-tone), color-mix(in srgb, var(--comparison-tone) 65%, white));
  box-shadow: 0 4px 16px color-mix(in srgb, var(--comparison-tone) 40%, transparent);
  transition: transform var(--transition-spring), box-shadow var(--transition-base);
}

.comparison-kpi:hover .comparison-kpi__icon {
  transform: scale(1.10) rotate(-5deg);
}

.comparison-kpi__icon svg {
  width: 18px;
  height: 18px;
}

.comparison-kpi__value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.28rem;
  color: var(--color-text-primary);
  font-size: 1.7rem;
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--letter-spacing-tight);
  line-height: 1.1;
  white-space: nowrap;
}

.comparison-kpi__value-main {
  display: inline-block;
  line-height: 1;
}

.comparison-kpi__value-suffix {
  display: inline-block;
  font-size: 0.72em;
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  color: var(--comparison-tone);
  transform: translateY(-0.06em);
}

.comparison-kpi__value-suffix--word {
  font-size: 0.5em;
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
}

.comparison-kpi__footer {
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}

.comparison-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
}

.comparison-trend svg {
  width: 12px;
  height: 12px;
}

.comparison-trend--positive,
.comparison-summary__value--positive,
.comparison-delta--positive { color: var(--color-success); }

.comparison-trend--negative,
.comparison-summary__value--negative,
.comparison-delta--negative { color: var(--color-danger); }

.comparison-trend--neutral,
.comparison-summary__value--neutral,
.comparison-delta--neutral { color: var(--color-text-muted); }

.comparison-kpi__baseline {
  min-width: 0;
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: 0.68rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comparison-analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(250px, 1fr);
  gap: var(--space-4);
  align-items: stretch;
}

.comparison-trend-card,
.comparison-summary-card {
  min-height: 430px;
}

.comparison-chart-legend {
  padding: var(--space-3) var(--space-5) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
}

.comparison-chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.comparison-chart-legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.comparison-chart-legend__dot--primary { background: rgba(0, 113, 227, 0.78); }
.comparison-chart-legend__dot--comparison { background: rgba(174, 174, 178, 0.72); }
.comparison-chart-legend__dot--cumulative { background: #AF52DE; border-radius: var(--radius-full); }

.comparison-daily-chart {
  width: 100%;
  height: 330px;
  padding: 0 var(--space-2) var(--space-2);
}

.comparison-summary-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
}

.comparison-summary-card__header {
  padding: var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
}

.comparison-summary {
  padding: var(--space-3) var(--space-5);
}

.comparison-summary__row {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
}

.comparison-summary__row:last-child {
  border-bottom: none;
}

.comparison-summary__value {
  text-align: right;
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.comparison-summary__value small {
  margin-left: 4px;
  font-size: 0.625rem;
  font-weight: var(--font-weight-medium);
}

.comparison-summary__counts {
  margin-top: auto;
  padding: var(--space-4) var(--space-5);
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--color-border-light);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}

.comparison-breakdown-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: var(--space-4);
  align-items: stretch;
}

.comparison-table-wrap {
  margin-top: var(--space-4);
  overflow-x: auto;
}

.comparison-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  table-layout: fixed;
}

.comparison-table th,
.comparison-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  text-align: right;
  vertical-align: middle;
}

.comparison-table th {
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  font-weight: var(--font-weight-semibold);
  white-space: normal;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  width: 32%;
  text-align: left;
}

.comparison-table tbody tr:last-child td {
  border-bottom: none;
}

.comparison-customer-name {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
  overflow-wrap: anywhere;
}

.comparison-delta {
  font-weight: var(--font-weight-semibold);
}

.comparison-empty-cell {
  padding: var(--space-8) !important;
  color: var(--color-text-muted);
  text-align: center !important;
}

/* ── Customer doughnut card ── */
.comparison-customer-chart-layout {
  min-height: 300px;
  padding: var(--space-4) var(--space-5) var(--space-5);
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(160px, 1.1fr);
  align-items: center;
  gap: var(--space-5);
}

.comparison-doughnut-wrap {
  width: 100%;
  max-width: 210px;
  aspect-ratio: 1;
  position: relative;
  margin: 0 auto;
}

.comparison-doughnut-center {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 62%;
  display: grid;
  justify-items: center;
  gap: 2px;
  pointer-events: none;
  text-align: center;
}

.comparison-doughnut-center strong {
  max-width: 100%;
  color: var(--color-text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--letter-spacing-tight);
  overflow-wrap: anywhere;
}

.comparison-doughnut-center span {
  color: var(--color-text-muted);
  font-size: 0.625rem;
  font-weight: var(--font-weight-medium);
}

.comparison-customer-legend {
  display: grid;
  align-content: center;
  gap: var(--space-3);
}

.comparison-customer-legend__item {
  display: grid;
  grid-template-columns: 8px minmax(70px, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 0.68rem;
  transition: background var(--transition-fast);
}

.comparison-customer-legend__item:hover {
  background: var(--color-surface-hover);
}

.comparison-customer-legend__item strong {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
}

.comparison-customer-legend__item > span:last-child {
  grid-column: 2 / -1;
  color: var(--color-text-muted);
  text-align: right;
}

.comparison-customer-legend__dot {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-full);
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent);
}

.comparison-customer-legend__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--font-weight-medium);
}

.comparison-empty {
  padding: var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  text-align: center;
}

/* ── Yearly Mode Banner (sidebar) ── */
.yearly-mode-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(135deg, rgba(74, 159, 219, 0.10) 0%, rgba(90, 200, 250, 0.08) 100%);
  border: 1px solid rgba(74, 159, 219, 0.18);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.yearly-mode-banner::before {
  content: '';
  position: absolute;
  top: -30%;
  right: -20%;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, rgba(74, 159, 219, 0.14) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.yearly-mode-banner__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.yearly-mode-banner__label {
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1.3;
}

.yearly-mode-banner__year {
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
  line-height: 1.3;
}

.yearly-mode-banner__badge {
  margin-left: auto;
  padding: 3px 9px;
  background: var(--color-accent);
  color: #FFFFFF;
  font-size: 0.625rem;
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(74, 159, 219, 0.35);
}

/* ── Yearly Table ── */
.comparison-yearly-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  min-width: 0 !important;
}

/* ตารางภาพรวมรายเดือนมี 7 คอลัมน์ที่ชื่อหัวยาวไม่เท่ากัน — บังคับความกว้างต่อคอลัมน์
   ให้รวมกันพอดี 100% ของการ์ด ไม่ล้นจนเกิด horizontal scroll และหัวข้อไม่ถูกตัด */
.comparison-yearly-table--monthly {
  table-layout: fixed;
}

.comparison-yearly-table--monthly th:nth-child(1),
.comparison-yearly-table--monthly td:nth-child(1) { width: 11%; }
.comparison-yearly-table--monthly th:nth-child(2),
.comparison-yearly-table--monthly td:nth-child(2) { width: 13%; }
.comparison-yearly-table--monthly th:nth-child(3),
.comparison-yearly-table--monthly td:nth-child(3) { width: 14%; }
.comparison-yearly-table--monthly th:nth-child(4),
.comparison-yearly-table--monthly td:nth-child(4) { width: 15%; }
.comparison-yearly-table--monthly th:nth-child(5),
.comparison-yearly-table--monthly td:nth-child(5) { width: 14%; }
.comparison-yearly-table--monthly th:nth-child(6),
.comparison-yearly-table--monthly td:nth-child(6) { width: 19%; }
.comparison-yearly-table--monthly th:nth-child(7),
.comparison-yearly-table--monthly td:nth-child(7) { width: 14%; }

.comparison-yearly-table th,
.comparison-yearly-table td {
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
}

.comparison-yearly-table th {
  color: var(--color-text-muted);
  background: var(--color-bg);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: normal;
  line-height: 1.35;
}

.comparison-yearly-table--monthly th:first-child {
  white-space: nowrap;
}

.comparison-yearly-table td {
  color: var(--color-text-secondary);
  transition: background var(--transition-fast);
}

/* .comparison-yearly-table td (2 classes) would otherwise out-specificity the
   shared .cell-amount--positive/--negative color rules (css/tables.css, also
   2 classes but declared earlier) — restate them here so paid/overpaid amounts
   still show green/red instead of falling back to plain gray text. */
.comparison-yearly-table td.cell-amount--positive { color: var(--color-success); }
.comparison-yearly-table td.cell-amount--negative { color: var(--color-danger); }

.comparison-yearly-table tbody tr:not(.row-total):nth-child(even) td {
  background: var(--color-surface-alt);
}

.comparison-yearly-table tbody tr:not(.row-total):hover td {
  background: var(--color-surface-hover);
}

.comparison-yearly-table td:first-child {
  white-space: nowrap;
}

.comparison-yearly-table--monthly td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* เดือนที่ยังไม่มีข้อมูล (count 0) — ลดน้ำหนักสายตาลง ไม่ให้แถวว่างเด่นพอๆ กับ
   เดือนที่มีข้อมูลจริง ช่วยให้กวาดตาหาเดือนที่ต้องดูได้เร็วขึ้น */
.comparison-yearly-table tr.row--empty td {
  color: var(--color-text-muted);
}

.comparison-yearly-table tr.row--empty .cell-month-name {
  color: var(--color-text-muted);
  font-weight: var(--font-weight-regular);
}

/* ── Collection-rate pill (โทนเดียวกับ .status-badge ของตารางหลัก) ── */
.rate-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 22px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: var(--font-weight-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rate-pill--good  { background: var(--color-success-light); color: var(--color-success); }
.rate-pill--warn  { background: var(--color-warning-light); color: var(--color-warning); }
.rate-pill--bad   { background: var(--color-danger-light);  color: var(--color-danger); }
.rate-pill--muted { background: var(--color-surface-hover); color: var(--color-text-muted); }

/* ── Table-card header icon — same gradient-circle badge language as the
   KPI cards' icons (.comparison-kpi__icon), scoped to this section only so
   the plain global .table-card__title-area icon used elsewhere is untouched. ── */
.comparison-section .table-card__title-area > svg {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 8px;
  box-sizing: border-box;
  border-radius: 50%;
  color: #FFFFFF;
}

.comparison-section .table-card__title-area--blue > svg {
  background: linear-gradient(135deg, var(--color-accent), color-mix(in srgb, var(--color-accent) 65%, white));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--color-accent) 35%, transparent);
}

.comparison-section .table-card__title-area--purple > svg {
  background: linear-gradient(135deg, var(--chart-purple), color-mix(in srgb, var(--chart-purple) 65%, white));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--chart-purple) 35%, transparent);
}

.comparison-section .table-card__title-area--mint > svg {
  background: linear-gradient(135deg, var(--chart-mint), color-mix(in srgb, var(--chart-mint) 65%, white));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--chart-mint) 35%, transparent);
}

.cell-month-name {
  text-align: left;
  color: var(--color-text-primary);
  font-weight: var(--font-weight-medium);
}

.cell-right {
  text-align: right;
}

.cell-customer-name {
  text-align: left;
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
}

.row-total td {
  border-top: 2px solid var(--color-border);
  border-bottom: none !important;
  background: var(--color-surface-alt);
  color: var(--color-text-primary);
}

.row--current-month td {
  background: var(--color-accent-surface);
}

.row--current-month .cell-month-name {
  color: var(--color-accent);
  font-weight: var(--font-weight-bold);
}

.row--current-month .cell-month-name::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--color-accent);
  vertical-align: middle;
}

.comparison-yearly-table-card {
  min-height: 0;
  overflow: visible;
}

.comparison-customer-chart-card {
  min-height: 0;
}

.comparison-yearly-chart-card {
  margin-bottom: 0;
}

@media (max-width: 1280px) {
  .comparison-kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .comparison-breakdown-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1050px) {
  .comparison-analysis-grid {
    grid-template-columns: 1fr;
  }

  .comparison-summary-card {
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .comparison-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  /* Full-width segmented controls only apply to the toolbar variant.
     The compact variant (in the daily-trend card header) must stay
     inline-sized so it doesn't stretch over the chart title on mobile. */
  .comparison-segmented:not(.comparison-segmented--compact) {
    width: 100%;
  }

  .comparison-segmented:not(.comparison-segmented--compact) button {
    flex: 1;
  }

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

  .comparison-daily-chart {
    height: 285px;
  }

  .comparison-trend-card {
    min-height: 390px;
  }

  .comparison-customer-chart-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .comparison-kpi-grid {
    grid-template-columns: 1fr;
  }

  .comparison-kpi {
    min-height: 132px;
  }

  .comparison-kpi__value {
    font-size: 1.55rem;
  }

  .comparison-chart-legend {
    gap: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .comparison-switch,
  .comparison-kpi,
  .comparison-section .chart-card {
    transition: none;
    animation: none;
    opacity: 1;
  }

  .comparison-switch__track,
  .comparison-switch__thumb {
    transition: none;
  }

  .comparison-section .chart-card {
    opacity: 1;
  }
}

/* ── Trend chart metric toggle — สลับกราฟแนวโน้มรายเดือนดูทีละตัวชี้วัด ── */
.chart-card__header--stack {
  flex-wrap: wrap;
  align-items: center;
}

.chart-metric-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.chart-metric-toggle__btn {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: var(--font-weight-medium);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), box-shadow var(--transition-fast);
}

.chart-metric-toggle__btn:hover {
  border-color: var(--metric-color);
  color: var(--metric-color);
}

.chart-metric-toggle__btn.is-active {
  background: var(--metric-color);
  border-color: var(--metric-color);
  color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--metric-color) 40%, transparent);
}

@media (max-width: 640px) {
  .chart-metric-toggle {
    margin-left: 0;
    width: 100%;
  }

  .chart-metric-toggle__btn {
    flex: 1 1 auto;
    text-align: center;
  }
}
