@media (max-width: 1100px) {
  header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .brand {
    width: 100%;
  }

  nav {
    width: 100%;
    justify-content: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  section[id] {
    scroll-margin-top: 160px;
  }
}

@media (max-width: 820px) {
  header {
    position: static;
    justify-content: flex-start;
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  #main {
    scroll-margin-top: 24px;
  }

  section[id] {
    scroll-margin-top: 24px;
  }

  .brand {
    justify-content: center;
  }

  nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    justify-items: stretch;
  }

  nav a {
    justify-content: center;
    text-align: center;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    align-items: center;
    justify-items: stretch;
  }

  .header-actions .cta {
    grid-column: 1 / -1;
  }

  .header-actions .cta,
  .header-actions .subtle {
    width: 100%;
  }

  body::before {
    background-size: auto, auto, auto, auto, auto, contain;
    background-position: center, 25% 15%, 75% 12%, 35% 78%, center, center;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
    align-items: stretch;
  }

  .hero-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .hero-actions > * {
    width: 100%;
    justify-content: center;
  }

  .hero-stack .metrics {
    grid-template-columns: 1fr;
  }

  .pill {
    width: 100%;
    display: flex;
    justify-content: center;
    text-align: center;
  }

  .cta-block {
    justify-items: stretch;
  }
}

@media (max-width: 720px) {
  main {
    gap: 28px;
  }

  .surface {
    padding: clamp(16px, 4vw, 24px);
  }

  footer {
    padding: 28px clamp(18px, 4vw, 28px);
  }

  :root {
    --chart-tick-max: 5;
    --chart-legend-position: bottom;
    --chart-point-radius: 2;
    --chart-point-hit-radius: 12;
    --chart-bar-thickness: 8;
    --chart-font-size: 11;
    --chart-axis-title-size: 11;
    --chart-legend-box: 10;
    --chart-legend-padding: 12;
    --chart-tick-rotation: 0;
  }

  .chart-card {
    padding: 12px;
  }

  .chart-header {
    gap: 8px;
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-header .label {
    min-width: 0;
  }

  .market-form {
    padding: 12px;
  }

  .market-form input,
  .market-form select {
    padding: 8px 10px;
  }

  #market-form .market-actions {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
  }

  .chart-header .market-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    justify-items: stretch;
  }

  .chart-header .market-actions .subtle {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  .chart-hint {
    font-size: 0.85rem;
  }
}

@media (max-width: 640px) {
  .cards,
  .metrics,
  .summary-cards,
  .grid-2,
  .bess-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  header {
    gap: 12px;
  }

  .brand {
    justify-content: center;
  }

  nav {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
  }

  nav a {
    padding: 6px 10px;
    font-size: 0.9rem;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .header-actions .cta,
  .header-actions .subtle {
    width: 100%;
    justify-content: center;
  }

  .brand-logo {
    width: 76px;
    height: 76px;
  }

  :root {
    --chart-tick-max: 4;
    --chart-font-size: 10;
    --chart-axis-title-size: 10;
    --chart-legend-box: 8;
    --chart-legend-padding: 10;
    --chart-bar-thickness: 6;
  }

  .market-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-modal__content {
    width: 100%;
  }

  .market-form input[type="datetime-local"],
  .market-form input[type="date"] {
    font-size: 1rem;
  }

}

@media (min-width: 1200px) {
  :root {
    --chart-tick-max: 12;
    --chart-font-size: 13;
    --chart-axis-title-size: 13;
    --chart-legend-box: 12;
    --chart-legend-padding: 10;
  }

  .chart-card {
    padding: 16px;
  }

  .chart-wrap {
    height: clamp(300px, 42vh, 480px);
  }
}

@media (max-width: 1200px) {
  .market-grid {
    grid-template-columns: 1fr;
  }
}
