/*
 * Forecast-specific landscape PC refinement.
 * Keeps VALID TIME and COLOR SCALE independent at every desktop width.
 */

@media (min-width: 981px) and (orientation: landscape) {
  :root {
    --forecast-meta-gap: 9px;
    --forecast-time-width: 180px;
    --forecast-legend-width: 196px;
    --forecast-tool-height: 29px;
    --forecast-legend-bar: 88px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage {
    isolation: isolate;
    border-color: rgba(var(--earth-accent-rgb), 0.24);
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage > .stage-title {
    display: grid !important;
    grid-template-columns: minmax(180px, 1fr) max-content !important;
    align-items: center !important;
    column-gap: clamp(12px, 1.2vw, 24px) !important;
    overflow: hidden;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage > .stage-title > div:first-child {
    min-width: 0;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage > .stage-title h2,
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage > .stage-title p {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-stage-tools {
    display: grid !important;
    grid-template-columns: var(--forecast-time-width) var(--forecast-legend-width) !important;
    align-items: stretch !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    gap: var(--forecast-meta-gap) !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-group {
    display: grid;
    grid-template-rows: auto var(--forecast-tool-height);
    min-width: 0;
    gap: 3px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    display: block;
    min-width: 0;
    color: rgba(145, 178, 195, 0.76);
    font-family: "Cascadia Mono", "Consolas", monospace;
    font-size: 6px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.11em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    display: flex !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: var(--forecast-tool-height) !important;
    height: var(--forecast-tool-height) !important;
    flex: none !important;
    justify-content: flex-start !important;
    align-items: center !important;
    padding: 0 9px !important;
    overflow: hidden;
    border: 1px solid rgba(246, 211, 101, 0.4) !important;
    border-radius: 7px !important;
    color: #ffe79b !important;
    background: linear-gradient(180deg, rgba(246, 211, 101, 0.13), rgba(246, 211, 101, 0.055)) !important;
    box-shadow: inset 3px 0 0 rgba(246, 211, 101, 0.82) !important;
    font-family: "Cascadia Mono", "Consolas", monospace;
    font-size: 9px !important;
    font-weight: 760 !important;
    line-height: 1 !important;
    letter-spacing: 0.015em !important;
    text-overflow: ellipsis;
    text-shadow: none !important;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-time-system {
    flex: 0 0 auto;
    margin-right: 6px;
    color: rgba(255, 231, 155, 0.58);
    font-size: 0.72em;
    letter-spacing: 0.08em;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeValue,
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #legendScaleText {
    min-width: 0;
    overflow: hidden;
    font: inherit;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    display: flex !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: var(--forecast-tool-height) !important;
    height: var(--forecast-tool-height) !important;
    flex: none !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 0 9px !important;
    overflow: hidden;
    border: 1px solid rgba(113, 172, 199, 0.22);
    border-radius: 7px;
    color: #c1d4de !important;
    background: rgba(5, 17, 27, 0.72);
    font-family: "Cascadia Mono", "Consolas", monospace;
    font-size: 7px !important;
    font-weight: 650;
    line-height: 1;
    letter-spacing: 0.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend::before {
    content: "";
    flex: 0 0 var(--forecast-legend-bar) !important;
    width: var(--forecast-legend-bar) !important;
    min-width: var(--forecast-legend-bar) !important;
    height: 8px !important;
    border: 1px solid rgba(224, 241, 247, 0.16);
    border-radius: 999px;
    background: linear-gradient(90deg, #2539a7 0%, #21b7d4 26%, #6dd36f 52%, #f2c14e 76%, #e64b4b 100%);
    box-shadow: none !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .geo-map-frame {
    border-top-color: rgba(var(--earth-accent-rgb), 0.1);
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .maplibregl-ctrl-group button {
    min-width: 36px;
    min-height: 36px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .geo-map-hint {
    max-width: min(72%, 520px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .profile-stage,
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .scene-stage {
    min-width: 0;
  }

  html[data-active-view="model"][data-viewport-tier] .forecast-control-panel .transport {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  html[data-active-view="model"][data-viewport-tier] .forecast-control-panel .transport .icon-button {
    width: 100%;
    min-width: 0;
    min-height: 36px;
  }

  html[data-active-view="model"][data-viewport-tier] .forecast-control-panel button:focus-visible,
  html[data-active-view="model"][data-viewport-tier] .forecast-control-panel select:focus-visible,
  html[data-active-view="model"][data-viewport-tier] .forecast-control-panel input:focus-visible,
  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .maplibregl-ctrl button:focus-visible {
    outline: 2px solid rgba(var(--earth-accent-rgb), 0.86);
    outline-offset: 2px;
  }
}

/* 1024-class landscape screens: desktop rail with an overlay control cabin. */
@media (min-width: 981px) and (max-width: 1180px) and (orientation: landscape) {
  :root {
    --pc-rail: 60px;
    --pc-panel: 0px;
    --pc-header: 68px;
    --pc-gap: 7px;
    --pc-pad: 7px;
    --pc-ribbon: 44px;
    --pc-metrics: 64px;
    --pc-stage-head: 46px;
    --forecast-meta-gap: 7px;
    --forecast-time-width: 158px;
    --forecast-legend-width: 174px;
    --forecast-tool-height: 26px;
    --forecast-legend-bar: 64px;
  }

  html[data-active-view][data-viewport-tier] .app-shell,
  html[data-panel-collapsed="true"][data-active-view][data-viewport-tier] .app-shell {
    grid-template-columns: var(--pc-rail) 0 minmax(0, 1fr) !important;
    grid-template-rows: var(--pc-header) minmax(0, 1fr) !important;
    grid-template-areas:
      "rail top top"
      "rail side work" !important;
    height: 100dvh !important;
    padding-bottom: 0 !important;
  }

  .mission-rail {
    position: relative !important;
    inset: auto !important;
    z-index: 40 !important;
    grid-area: rail !important;
    display: flex !important;
    flex-direction: column !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 8px 5px !important;
    gap: 0 !important;
    border: 0 !important;
    border-right: 1px solid var(--pc-border) !important;
    background: var(--pc-rail-bg) !important;
    box-shadow: none !important;
  }

  .mission-rail::after,
  .rail-emblem,
  .rail-footer {
    display: none !important;
  }

  .rail-nav,
  .rail-actions {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100% !important;
    gap: 5px !important;
  }

  .rail-actions {
    margin-top: auto !important;
  }

  .rail-command,
  .rail-tool {
    width: 100% !important;
    min-height: 48px !important;
    flex-direction: column !important;
  }

  html[data-active-view][data-viewport-tier] .topbar {
    grid-area: top !important;
    width: auto !important;
    height: var(--pc-header) !important;
  }

  html[data-active-view][data-viewport-tier] #modelWorkspace.workspace,
  html[data-active-view][data-viewport-tier] #wrfWorkspace.workspace,
  html[data-active-view][data-viewport-tier] #observationWorkspace.workspace,
  html[data-active-view][data-viewport-tier] #ranchWorkspace.workspace {
    grid-area: work !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  html[data-active-view][data-viewport-tier] #modelControls.control-panel,
  html[data-active-view][data-viewport-tier] #observationControls.control-panel,
  html[data-active-view][data-viewport-tier] #ranchControls.control-panel {
    position: fixed !important;
    inset: var(--pc-header) 0 0 auto !important;
    z-index: 60 !important;
    width: min(340px, 42vw) !important;
    height: auto !important;
    max-height: none !important;
    padding: 8px 8px 16px !important;
    border: 0 !important;
    border-left: 1px solid var(--pc-border) !important;
    background: rgba(7, 20, 31, 0.985) !important;
    box-shadow: -18px 0 42px rgba(0, 0, 0, 0.38) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html[data-panel-collapsed="true"][data-active-view][data-viewport-tier] #modelControls.control-panel,
  html[data-panel-collapsed="true"][data-active-view][data-viewport-tier] #observationControls.control-panel,
  html[data-panel-collapsed="true"][data-active-view][data-viewport-tier] #ranchControls.control-panel {
    transform: translateX(104%) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .map-stage > .stage-title {
    column-gap: 9px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    font-size: 5.5px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    padding-inline: 8px !important;
    font-size: 8px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    gap: 6px !important;
    padding-inline: 7px !important;
    font-size: 6.5px !important;
  }
}

/* Short laptops and compact desktop windows. */
@media (min-width: 1181px) and (max-width: 1366px) and (orientation: landscape),
       (min-width: 1181px) and (max-height: 800px) and (orientation: landscape) {
  :root {
    --forecast-meta-gap: 7px;
    --forecast-time-width: 175px;
    --forecast-legend-width: 182px;
    --forecast-tool-height: 26px;
    --forecast-legend-bar: 70px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    font-size: 5.5px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    font-size: 8px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    gap: 6px !important;
    padding-inline: 7px !important;
    font-size: 6.5px !important;
  }
}

/* FHD and roomy desktop windows. */
@media (min-width: 1600px) and (min-height: 900px) and (max-width: 2199px) and (orientation: landscape) {
  :root {
    --forecast-time-width: 202px;
    --forecast-legend-width: 224px;
    --forecast-tool-height: 31px;
    --forecast-legend-bar: 102px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    font-size: 6.5px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    padding-inline: 10px !important;
    font-size: 9.5px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    font-size: 7.5px !important;
  }
}

/* 2K productivity displays. */
@media (min-width: 2200px) and (max-width: 2999px) and (orientation: landscape) {
  :root {
    --forecast-meta-gap: 12px;
    --forecast-time-width: 250px;
    --forecast-legend-width: 280px;
    --forecast-tool-height: 35px;
    --forecast-legend-bar: 126px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    font-size: 7px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    padding-inline: 12px !important;
    font-size: 11px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    gap: 10px !important;
    padding-inline: 11px !important;
    font-size: 9px !important;
  }
}

/* 4K and large ultrawide displays. */
@media (min-width: 3000px) and (orientation: landscape) {
  :root {
    --forecast-meta-gap: 14px;
    --forecast-time-width: 310px;
    --forecast-legend-width: 350px;
    --forecast-tool-height: 42px;
    --forecast-legend-bar: 158px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-tool-label {
    font-size: 8px;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace #mitgcmTimeChip.forecast-time-chip {
    padding-inline: 14px !important;
    border-radius: 9px !important;
    font-size: 13px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend {
    gap: 12px !important;
    padding-inline: 13px !important;
    border-radius: 9px;
    font-size: 11px !important;
  }

  html[data-active-view="model"][data-viewport-tier] #modelWorkspace .forecast-legend-block .legend::before {
    height: 10px !important;
  }
}
