#studio-view :is(.portrait-card-toolbar, .landscape-card-toolbar) {
  display: flex; align-items: start; gap: 3px;
  & button {
    display: grid; place-items: center; width: 24px; height: 24px; min-height: 24px;
    gap: 0; padding: 3px; border: 0; background: transparent; color: var(--stream-muted, var(--muted)); border-radius: 4px;
  }
  & button:hover { color: var(--blue); background: var(--blue-soft); }
  & .locate-report { font-size: 0; }
  & button::before {
    content: ''; grid-area: 1 / 1; width: 17px; height: 17px; background: currentColor;
    mask: var(--report-action-glyph) center / contain no-repeat;
  }
  & .locate-report {
    --report-action-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.65'%3E%3Cpath d='M19 10c0 5-7 10.5-7 10.5S5 15 5 10a7 7 0 1 1 14 0Z'/%3E%3Ccircle cx='12' cy='10' r='2.3'/%3E%3C/svg%3E");
  }
  & :is(.portrait-card-more, .landscape-card-more) {
    --report-action-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='4.5' cy='12' r='2'/%3E%3Ccircle cx='12' cy='12' r='2'/%3E%3Ccircle cx='19.5' cy='12' r='2'/%3E%3C/svg%3E");
  }
}
#studio-view .landscape-card-toolbar { align-self: flex-start; flex: none; margin-inline-start: auto; }
.card-heading:has(.landscape-card-toolbar) > :nth-child(2) { min-width: 0; overflow-wrap: anywhere; }
.landscape-card-details { cursor: auto; }
.report-card .report-text:has(+ .landscape-card-details[hidden]) { margin-bottom: 0; }
@media (pointer: coarse) {
  #studio-view :is(.portrait-card-toolbar, .landscape-card-toolbar) button { width: 32px; height: 32px; }
}

#layout-toggle svg { width: 20px; height: 20px; pointer-events: none; }
#studio-view:not([data-desk-layout="portrait"]) .desk-action-icon {
  flex: none; width: 16px; height: 16px; vertical-align: -.19em; pointer-events: none;
}
#studio-view:not([data-desk-layout="portrait"]) .filter-tab .desk-action-icon { margin-right: 5px; }
#studio-view:not([data-desk-layout="portrait"]) [data-filter="all"] .desk-action-icon,
#studio-view:not([data-desk-layout="portrait"]) [data-filter="radar"] .desk-action-icon { color: var(--blue); }
#studio-view:not([data-desk-layout="portrait"]) [data-filter="danger"] .desk-action-icon { color: #be4232; }
#studio-view:not([data-desk-layout="portrait"]) [data-filter="traffic"] .desk-action-icon { color: #866019; }
:root[data-theme="dark"] #studio-view:not([data-desk-layout="portrait"]) [data-filter="danger"] .desk-action-icon { color: #fa967f; }
:root[data-theme="dark"] #studio-view:not([data-desk-layout="portrait"]) [data-filter="traffic"] .desk-action-icon { color: #edb465; }

#studio-view[data-desk-layout="portrait"]:not([hidden]) {
  display: grid;
  grid-template-columns: 294px minmax(0,1fr);
  grid-template-rows: minmax(0,1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
#studio-view[data-desk-layout="portrait"] > .desk-sticky { display: none; }
#studio-view[data-desk-layout="portrait"] > .desk-content {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0; min-width: 0; width: 100%; max-width: none;
  margin: 0; padding: 0; overflow: hidden;
}
#studio-view[data-desk-layout="portrait"] #report-columns { flex: 1 1 0; min-height: 0; }
#studio-view[data-desk-layout="portrait"] #urgent-banner,
#studio-view[data-desk-layout="portrait"] #connection-warning {
  flex: 0 0 auto;
  margin: 0;
  max-height: 20dvh; overflow: auto;
}
#studio-view[data-desk-layout="portrait"] #planned-reports {
  flex: 0 0 auto; max-height: 30dvh; overflow: auto; margin: 0;
  border-width: 1px 0 0; border-radius: 0;
}
@media (max-width:760px) {
  #studio-view[data-desk-layout="portrait"]:not([hidden]) {
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: auto minmax(0,1fr);
  }
}

/* In a single category, size the card grid to the space left beside the map. */
#studio-view:not([data-desk-layout="portrait"]) .report-columns.filtered {
  max-width: none;
  & > .report-column { container: filtered-reports / inline-size; }
  & .report-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    @container filtered-reports (min-width: 40rem) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    @container filtered-reports (min-width: 60rem) {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }
  & .report-list > .empty-state { grid-column: 1 / -1; }
  @media (min-width: 900px) {
    &.with-map { grid-template-columns: minmax(0, 1fr) clamp(17rem, 27%, 26rem); }
  }
}

/* Format 1 shares the space below the actual header between lists and map. */
#studio-view:not([data-desk-layout="portrait"]):not([hidden]) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: clip;

  & > .desk-sticky { display: block; max-height: 64dvh; overflow-y: auto; }
  & .desk-controls, & .desk-controls .desk-intro { display: block; overflow: visible; }
  & > .desk-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    min-width: 0;
    margin-block: 0;
    padding-block: 10px;
  }
  & #report-columns {
    flex: 1 1 0;
    width: 100%;
    min-height: 0;
    align-items: stretch;
    grid-auto-rows: minmax(8rem, 1fr);
    container: landscape-board / size;
    overflow: auto;
    overscroll-behavior: contain;
  }
  & .report-column {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    margin-block: 0;
  }
  & .report-column :is(.report-list, .danger-lists) {
    min-height: 0;
    max-block-size: none;
  }
  & .danger-lists:not(.has-dangers):not(.has-mowas) {
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  & #traffic-map-panel {
    display: grid;
    grid-template-rows: auto auto auto minmax(6rem, 1fr) auto;
    min-height: 0;
    overflow: auto;
  }
  & #traffic-map-panel #map-frame {
    min-height: 0;
    min-width: 0;
    aspect-ratio: auto;
  }
  & #map-frame iframe { height: 100%; aspect-ratio: auto; }
  & #urgent-banner, & #planned-reports {
    flex: none;
    max-height: min(20dvh, 24%);
    overflow: auto;
    margin-block: 0 6px;
  }
  & .statusbar { flex: none; margin-top: 8px; padding-top: 5px; }

  @container landscape-board (max-height: 24rem) {
    & .column-sign { width: 30px; height: 30px; }
    & .column-caption { min-height: 0; margin-block: 2px 6px; }
    & .mowas-heading { padding-block: 2px; margin-top: 2px; }
    & #traffic-map-panel {
      grid-template-columns: auto minmax(0, 1fr);
      grid-template-rows: auto auto minmax(3.5rem, 1fr) auto;
      column-gap: 8px;
    }
    & #traffic-map-panel .column-heading { min-height: 0; }
    & #map-focus { align-self: center; max-height: 3em; overflow: auto; }
    & #traffic-map-panel :is(#map-area-button, #map-frame, #radar-legend) { grid-column: 1 / -1; }
    & #traffic-map-panel #map-area-button { min-height: 30px; padding-block: 3px; margin-bottom: 4px; }
    & #radar-legend { row-gap: 2px; margin-top: 4px; padding-top: 4px; }
    & #radar-legend img { width: 20px; height: 20px; }
  }
  @container landscape-board (max-height: 16rem) {
    & #radar-legend {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(min(5.5rem, 100%), 1fr));
      gap: 2px 4px;
      font-size: 12px;
      line-height: 1.15;
    }
    & #radar-legend li { gap: 3px; overflow-wrap: anywhere; hyphens: auto; }
    & #radar-legend img { width: 16px; height: 16px; }
    & #radar-legend .legend-dot { flex: none; width: 7px; height: 7px; }
  }
  @media (min-width: 900px) and (max-height: 800px) {
    & .topbar { min-height: 56px; gap: 14px; padding-block: 5px; }
    & .brand-logo { width: 88px; height: 64px; }
    & .header-actions .button { min-height: 34px; padding: 5px 8px; }
    & .desk-controls { padding-top: 6px; }
    & .page-heading { margin-bottom: 6px; }
    & .page-heading h1 { font-size: 24px; }
    & .page-heading p { margin-top: 3px; }
    & .page-actions { flex: none; gap: 6px; max-inline-size: none; }
    & .page-actions > .button { inline-size: 11rem; min-height: 36px; padding-block: 5px; }
    & .toolbar { padding-bottom: 5px; }
    & .toolbar :is(select, input) { min-height: 34px; padding-block: 4px; }
    & #urgent-banner { padding: 5px 10px; }
    & #urgent-banner .sign { width: 34px; height: 34px; flex-basis: 34px; }
    /* Keep the warning, the open schedule and the map usable together. */
    &:has(#urgent-banner:not([hidden])):has(#planned-reports[open]:not([hidden])) > .desk-sticky {
      max-height: min(64dvh, max(10rem, calc(100dvh - 26rem)));
    }
  }
  @media (900px <= width <= 1150px) and (max-height: 800px), (min-width: 900px) and (max-height: 600px) {
    & .topbar { row-gap: 3px; }
    & .brand-logo { width: 68px; height: 50px; }
    & .page-heading { display: block; }
    & .page-heading > div:first-child { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 12px; }
    & .page-heading .eyebrow { flex-basis: 100%; margin-bottom: 0; }
    & .page-actions { margin-top: 4px; }
    & #urgent-banner > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
    & #urgent-text { margin: 0; }
  }
  @media (max-width: 899px) {
    /* Stacked rows remain reachable inside the report area on small screens. */
    & > .desk-sticky { max-height: 50dvh; }
    & #report-columns { grid-auto-rows: minmax(19rem, 1fr); }
  }
}
