/* Global layout structure — equal grids, toolbars, page rhythm */

:root {
  --page-gap: 1.5rem;
  --panel-pad: 1.25rem 1.35rem;
}

/* Page content stack: even vertical rhythm */
.container.section {
  display: flex;
  flex-direction: column;
  gap: var(--page-gap);
  padding-top: 1.75rem;
  padding-bottom: 2.5rem;
}
.container.section > .section-head {
  margin-bottom: 0;
}
.container.section > .ad-slot {
  margin: 0;
}

/* Panels / cards share one structure */
.result-card,
.filter-panel,
.panel {
  padding: var(--panel-pad);
}
.result-card > :last-child,
.panel > :last-child {
  margin-bottom: 0;
}

/* Filter / settings toolbars — fill width, action beside fields */
.form-toolbar {
  display: grid;
  gap: 1rem;
  align-items: end;
}
@media (min-width: 720px) {
  .form-toolbar.cols-3-action {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  }
  .form-toolbar.cols-2-action {
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  }
  .form-toolbar.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.form-toolbar .form-group {
  margin-bottom: 0;
}
.form-toolbar .form-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}
@media (min-width: 720px) {
  .form-toolbar .form-actions {
    padding-bottom: 2px;
  }
}
.form-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--outline, var(--brand-line));
}

/* Grid stretch — equal card heights in a row */
.grid,
.cw-charts-row,
.car-card-grid,
.cw-charts-grid {
  align-items: stretch;
}
.grid > .card,
.grid > .result-card,
.grid > a.card,
.grid > a.result-card,
.car-card-grid > .car-card,
.car-card-grid > a {
  height: 100%;
}
.grid > a.card,
.grid > a.result-card {
  display: flex;
  flex-direction: column;
  color: inherit;
}
.grid > a.card .card-body {
  flex: 1;
}

/* Charts: consistent tiles */
.cw-charts-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 860px) {
  .cw-charts-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.cw-charts-row {
  align-items: stretch !important;
  margin: 0 !important;
}
.cw-chart-card {
  display: flex;
  flex-direction: column;
  min-height: 280px;
  height: 100%;
  box-sizing: border-box;
  padding: 1.15rem 1.2rem 1.2rem;
}
.cw-chart-card .cw-chart-title {
  flex: 0 0 auto;
}
.cw-chart-card .cw-donut-wrap,
.cw-chart-card .cw-bars {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 140px;
}
.cw-chart-card .cw-donut-legend {
  flex: 0 0 auto;
  margin-top: auto;
}
@media (min-width: 520px) {
  .cw-chart-card[data-cw-donut] {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(140px, 1.1fr);
    grid-template-rows: auto 1fr;
    column-gap: 1rem;
    align-items: center;
    min-height: 260px;
  }
  .cw-chart-card[data-cw-donut] .cw-chart-title {
    grid-column: 1 / -1;
  }
  .cw-chart-card[data-cw-donut] .cw-donut-wrap {
    min-height: 0;
  }
  .cw-chart-card[data-cw-donut] .cw-donut-legend {
    margin-top: 0;
    align-self: center;
  }
}
.cw-donut-svg {
  width: min(100%, 200px);
  margin-inline: auto;
}

/* Tables — readable density */
table.data {
  font-size: 0.9rem;
}
table.data th,
table.data td {
  padding: 0.95rem 1.1rem;
  line-height: 1.45;
}
table.data tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--brand-mist) 55%, #fff);
}
table.data th:first-child,
table.data td:first-child {
  width: 28%;
  font-weight: 650;
  color: var(--brand-navy);
}
[data-theme="dark"] table.data tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}
[data-theme="dark"] table.data th:first-child,
[data-theme="dark"] table.data td:first-child {
  color: var(--on-surface);
}

/* Outline CTA — readable on light panels */
.btn-outline {
  background: var(--surface, #fff);
  border-color: var(--outline-strong, #8a9bab);
  color: var(--on-surface, var(--brand-ink));
  font-weight: 700;
}
.btn-outline:hover {
  background: var(--surface-3, var(--brand-mist));
  border-color: var(--brand-steel);
  color: var(--on-surface, var(--brand-navy));
}

/* Choice cards (compare / FMC radios) */
.choice-card {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.95rem 1.05rem;
  cursor: pointer;
  border: 1px solid var(--outline, var(--brand-line));
  border-radius: var(--radius);
  background: var(--surface, #fff);
  color: var(--on-surface, var(--brand-ink));
  transition: border-color .15s, box-shadow .15s, background .15s;
  min-height: var(--touch-min, 48px);
}
.choice-card:hover,
.choice-card:has(input:checked) {
  border-color: color-mix(in srgb, var(--brand-accent) 55%, var(--outline, var(--brand-line)));
  box-shadow: 0 0 0 2px rgba(232, 93, 4, 0.12);
  background: var(--choice-hover, #fffaf6);
}
.choice-card input {
  margin-top: 0.3rem;
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--brand-accent);
  flex-shrink: 0;
}

/* Compact results meta */
.results-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0;
}
.results-meta strong {
  color: var(--brand-ink);
}

/* Hero actions cluster */
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

/* Nested margin cleanup inside flex section stacks */
.container.section .faq,
.container.section .prose,
.container.section .notice {
  margin-top: 0;
  margin-bottom: 0;
}
.container.section .table-wrap + .notice,
.container.section .notice + .hero-actions {
  margin-top: 0;
}

/* Ads when enabled — less jarring */
.ad-slot {
  margin: 0;
  min-height: 0;
}
.ad-top, .ad-header, .ad-footer {
  min-height: 0;
}
.ad-top .ad-frame,
.ad-header .ad-frame,
.ad-footer .ad-frame {
  min-height: 72px;
}
.ad-in-content .ad-frame,
.ad-article .ad-frame {
  min-height: 180px;
}

/* Calculator two-column balance */
.calc-layout {
  display: grid;
  gap: 1.25rem;
  align-items: start;
}
@media (min-width: 900px) {
  .calc-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* Nested form rows inside panels — tighter last row */
.filter-panel .form-row {
  margin-bottom: 0.85rem;
}
.filter-panel .form-row:last-of-type {
  margin-bottom: 0;
}
.filter-panel .form-group {
  margin-bottom: 0;
}

/* Prevent section flex from stretching tables oddly */
.container.section > .table-wrap,
.container.section > .cw-charts-grid,
.container.section > .grid {
  width: 100%;
}

/* Pair section-head with following grid visually */
.container.section > .section-head + .grid,
.container.section > .section-head + .cw-charts-grid,
.container.section > .section-head + .table-wrap,
.container.section > .section-head + .car-card-grid {
  margin-top: -0.5rem;
}
