/* Dashboard summaries use normal layout flow so amounts and metrics cannot overlap. */
.dailyOverview > .reportBlock { min-width: 0; }
.dailyOverview > .profitBlock {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  grid-template-rows: auto auto 1fr;
  align-content: start;
  align-items: start;
  gap: 10px 12px;
  padding-bottom: 100px;
}
.profitBlock > h2 { grid-column: 1; grid-row: 1; }
.profitBlock > .reportValue { grid-column: 1; grid-row: 2; margin-top: 0; }
.profitBlock > .profitValueComparison { grid-column: 1; grid-row: 3; margin-top: 0; max-width: 100%; }
.profitBlock > .profitRows {
  position: static;
  grid-column: 2;
  grid-row: 1 / 4;
  width: auto;
  min-width: 0;
}
.profitRows > div { grid-template-columns: minmax(0, 1fr) max-content max-content; min-width: 0; }
.profitRows > div > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.profitRows strong { min-width: 0; }

/* The date form must fit both its original panel and its pinned hosts. */
#dashboardView > .dailyControls,
.dashboardSummaryPinnedPortal > .dailyControls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(0, 1260px);
  gap: 16px 24px;
}
#summaryForm, #summaryForm > *, #summaryForm .comparisonGroup > label { min-width: 0; max-width: 100%; }
#summaryForm input[type="date"], #summaryForm .periodPicker { width: 100%; min-width: 0; }

@media (max-width: 1450px) {
  .dailyOverview { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .dailyOverview > .reportBlock { grid-column: span 2; }
  .dailyOverview > .profitBlock { grid-column: span 3; }
}
@media (max-width: 1700px) {
  #dashboardView > .dailyControls,
  .dashboardSummaryPinnedPortal > .dailyControls { grid-template-columns: minmax(0, 1fr); }
  #summaryForm { width: 100%; }
}
@media (max-width: 1300px) {
  #summaryForm {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    gap: 10px 12px;
  }
  #summaryForm > label,
  #summaryForm > .periodField,
  #summaryForm > .comparisonToggle { width: auto; }
  #summaryForm .comparisonGroup {
    display: grid;
    grid-column: span 3;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
  }
  #summaryForm button[type="submit"] { width: 100%; min-width: 0; }
  .dashboardProfitPinned { grid-template-columns: minmax(0, 1fr) !important; }
  .dashboardProfitPinnedTitle { grid-column: 1 !important; grid-row: 1 !important; }
  .dashboardProfitPinnedDates { grid-column: 1 !important; grid-row: 2 !important; }
  .dashboardProfitPinnedClip { grid-column: 1 !important; grid-row: 3 !important; }
  .dailyCards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .dailyOverview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dailyOverview > .reportBlock { grid-column: auto; }
  .dailyOverview > .profitBlock { grid-column: 1 / -1; }
  .dailyCardsControl .costTemplateActions { flex-wrap: wrap; min-width: 0; max-width: 100%; }
  .toolbarControls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #adsView .adsBlockHeader { flex-wrap: wrap; }
  #adsView .adsBlockHeader > * { min-width: 0; max-width: 100%; }
}
@media (max-width: 760px) {
  body .appHeader:has(#abTestTab), body.dashboardActive .appHeader {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 10px 16px;
  }
  body .appHeader:has(#abTestTab) .appBrand { grid-column: 1; grid-row: 1; }
  body .appHeader:has(#abTestTab) .accountArea { grid-column: 1; grid-row: 2; width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  body .appHeader .accountSwitcher { flex: 1 1 100px; min-width: 0; }
  body .appHeader .accountButton { min-width: 0; max-width: 100%; }
  body .appHeader #accountLabel { max-width: 100%; }
  body .appHeader:has(#abTestTab) .tabs { grid-column: 1; grid-row: 3; flex-wrap: wrap; width: 100%; gap: 2px; }
  body .appHeader .tabButton { padding: 8px; font-size: 13px; min-height: 34px; height: auto; }
  .dailyCards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboardProfitPinnedTitle { grid-template-columns: minmax(0, 1fr) !important; gap: 6px !important; }
  .dashboardProfitPinnedTitle > .profitToolbar { flex-wrap: wrap; justify-content: flex-start; white-space: normal; }
  .dashboardSummaryPinnedPortal > .dailyControls { max-height: 60svh; overflow: auto; }
  #summaryForm { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #summaryForm .comparisonGroup { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #summaryForm .comparisonTitle { grid-column: 1 / -1; min-height: 0; line-height: normal; }
  #summaryForm .comparisonToggle { white-space: normal; }
  #adsView #ads-section-active > .adsBlockHeader .adsHeaderPeriodControls { flex-wrap: wrap; margin-left: 0; flex: 1 1 100%; }
}
@media (max-width: 620px) {
  body .appHeader { margin-right: -14px; margin-left: -14px; }
  .dailyOverview { grid-template-columns: minmax(0, 1fr); }
  .dailyOverview > .profitBlock { grid-column: auto; grid-template-columns: minmax(0, 1fr); }
  .profitBlock > .profitRows { grid-column: 1; grid-row: 4; }
  .dailyCards, .toolbarControls { grid-template-columns: minmax(0, 1fr); }
  .dailyCardsControl > *, .dailyCardsControl .costTemplateActions { max-width: 100%; min-width: 0; }
  .dailyCardsControl .costTemplateActions { margin: 0; width: 100%; }
  .dailyCardsControl .costTemplateActions > button { white-space: normal; height: auto; min-height: 42px; }
  #seoView .seoHeader { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  #seoView .seoHeader > * { min-width: 0; max-width: 100%; }
  #seoView .seoHeader button { white-space: normal; height: auto; min-height: 42px; }
}

/* Keep the desktop arrangement while the navigation and summaries can fit. */
@media (min-width: 1451px) and (max-width: 1899px) {
  body.dashboardActive .appHeader {
    column-gap: clamp(8px, calc(5vw - 77px), 18px);
    padding-inline: clamp(14px, calc(5vw - 71px), 24px);
  }
  body.dashboardActive .appHeader .tabs > .tabButton,
  body.dashboardActive .appHeader .tabs > :not(.tabButton) > .tabButton {
    padding-inline: clamp(4px, calc(6vw - 102px), 12px);
    white-space: nowrap;
  }
  body.dashboardActive .appHeader .tabs .tabButton.active::after {
    inset-inline: clamp(6px, calc(7vw - 114px), 18px);
  }
  #dashboardView .dailyOverview > .reportBlock {
    padding-inline: clamp(12px, calc(3vw - 32px), 22px);
  }
  #dashboardView .dailyOverview > .netProfitBlock {
    grid-template-columns: minmax(0, 1fr) clamp(196px, calc(13vw - 22px), 250px);
  }
  #dashboardView .dailyOverview > .profitBlock:not(.netProfitBlock) {
    grid-template-columns: minmax(0, 1fr) max-content;
  }
}
