/* MetStat R5 Stage20: existing live modules, consistent desktop workspace.
   Only presentation. Never copy/replace real NWP, GIS, canvas or handlers. */
/* All widths below are logical CSS pixels. Existing viewport-fit keeps the
   identical >=960px desktop canvas on portrait/landscape devices. */
html.ms9-active {--ms-r5-control-col:328px;--ms-r5-workgap:12px}
/* Climate indices: both old ciHTML() and new cxHTML() render genuine controls
   followed by actual charts/maps. Their DOM had no sidebar/layout container. */
html.ms9-active #ciApp:not([hidden]) #ciMain {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 align-items:start;align-content:start;gap:12px;max-width:none;width:100%;min-width:0;
 direction:rtl;margin:0;padding:0;
}
html.ms9-active #ciMain > :is(.ciSel,.cxSel) {
 grid-column:1;grid-row:1 / span 12;min-width:0;max-width:100%;
 position:sticky;top:8px;max-height:calc(100dvh - 160px);
 overflow-x:hidden;overflow-y:auto;box-sizing:border-box;
}
html.ms9-active #ciMain > :not(.ciSel):not(.cxSel) {
 grid-column:2;min-width:0;max-width:100%;margin:0;box-sizing:border-box;
}
html.ms9-active #ciMain > :is(.ciFig,.civCard,#cxMap,.ciAnBox,.cxModes){direction:inherit}
/* The source already includes a native responsive grid for live satellite maps.
   Keep existing saWide behavior where it intentionally hides its map canvas. */
html.ms9-active #saApp:not([hidden]) #saMain.saGrid:not(.saWide) {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 gap:12px;align-items:start;direction:rtl;max-width:none;width:100%;min-width:0;
}
html.ms9-active #saMain.saGrid:not(.saWide) > .saTop {
 grid-column:1;grid-row:1;position:sticky;top:8px;
 max-height:calc(100dvh - 160px);overflow:auto;min-width:0;
}
html.ms9-active #saMain.saGrid:not(.saWide) > .saCard {
 grid-column:2;grid-row:1;min-width:0;width:100%;max-width:100%;
}
/* Monthly/seasonal module: do not move the genuine parameter selectors,
   precomputed maps, hindcast charts or scientific inputs. */
html.ms9-active #sfApp:not([hidden]) #sfMain .sfGrid {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 align-items:start;gap:12px;direction:rtl;min-width:0;
}
html.ms9-active #sfMain .sfGrid>.sfSide {
 grid-column:1;grid-row:1;position:sticky;top:8px;
 max-height:calc(100dvh - 160px);overflow-x:hidden;overflow-y:auto;min-width:0;
}
html.ms9-active #sfMain .sfGrid>.sfBody {grid-column:2;grid-row:1;min-width:0;max-width:100%;}
/* Mountain page: current 3 cards were blindly stacked vertically. Keep their
   entire live content, but place model+peak list on right and forecast left. */
html.ms9-active #mtApp:not([hidden]) #mtMain {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 align-items:start;align-content:start;gap:12px;direction:rtl;min-width:0;width:100%;
}
html.ms9-active #mtMain>.mtTop {grid-column:1;grid-row:1;min-width:0;max-width:100%;}
html.ms9-active #mtMain>.mtTop+section.card {grid-column:1;grid-row:2;min-width:0;max-width:100%;}
html.ms9-active #mtMain>.mtDet {grid-column:2;grid-row:1 / span 4;min-width:0;max-width:100%;}
html.ms9-active #mtMain>.mtTop .mtBar{flex-wrap:wrap}
html.ms9-active #mtMain>.mtDet :is(canvas,svg,img){max-width:100%}
/* Synergy has ONE real synCard. Reflow its direct descendants only; do NOT
   clone or reparent #synCv, layer selectors or interactive controls. */
html.ms9-active #synApp:not([hidden]) .synCard {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 gap:8px 12px;align-items:start;align-content:start;direction:rtl;
 width:100%;min-width:0;max-width:none;box-sizing:border-box;
}
html.ms9-active #synApp .synCard>h3,
html.ms9-active #synApp .synCard>p.muted {grid-column:1 / -1;min-width:0;margin:0}
html.ms9-active #synApp .synCard>.synRow:first-of-type {
 grid-column:1;grid-row:3;display:flex;flex-flow:column wrap;
 align-items:stretch;gap:6px;min-width:0;
}
html.ms9-active #synApp .synCard>details.synAdv {
 grid-column:1;grid-row:4 / span 6;min-width:0;
 max-height:calc(100dvh - 215px);overflow-y:auto;overflow-x:hidden;
 align-self:start;position:sticky;top:8px;
}
html.ms9-active #synApp .synCard>.synRow:not(:first-of-type){grid-column:2;grid-row:3;min-width:0;display:flex;flex-wrap:nowrap}
html.ms9-active #synApp .synCard>#synTime{grid-column:2;grid-row:4;min-width:0}
html.ms9-active #synApp .synCard>#synBox{grid-column:2;grid-row:5;min-width:0;width:100%;max-width:100%;}
html.ms9-active #synApp .synCard>#synMsg{grid-column:2;grid-row:6;min-width:0}
html.ms9-active #synApp .synCard>#synNote{grid-column:2;grid-row:7;min-width:0}
html.ms9-active #synApp .synCard>#synSk{grid-column:2;grid-row:8;min-width:0}
html.ms9-active #synApp .synCard>#synXs{grid-column:2;grid-row:9;min-width:0}
html.ms9-active #synApp .synCard .synRow label{min-width:0;max-width:100%}
html.ms9-active #synApp .synCard .synAdv .synRow{flex-wrap:wrap}
html.ms9-active #synApp .synCard .synAdv select{min-width:0;max-width:100%}
/* Flash-flood: the live template has flL containing one layer menu and one
   map card, not a valid right column. Preserve all lower detail/metadata. */
html.ms9-active #flApp:not([hidden]) #flMain>.flGrid {display:block;min-width:0;}
html.ms9-active #flApp:not([hidden]) #flMain>.flGrid>.flL {
 display:grid;grid-template-columns:var(--ms-r5-control-col) minmax(0,1fr);
 gap:12px;align-items:start;min-width:0;direction:rtl;
}
html.ms9-active #flMain>.flGrid>.flL>.flLayDd {
 grid-column:1;grid-row:1;position:sticky;top:8px;min-width:0;
}
html.ms9-active #flMain>.flGrid>.flL>section.card:has(#flCv){grid-column:2;grid-row:1;min-width:0;}
html.ms9-active #flMain>.flGrid>.flL>:not(.flLayDd):not(:has(#flCv)){
 grid-column:2;min-width:0;
}
/* Inputs and outputs should never dictate the width of the map column. */
html.ms9-active :is(#ciMain,#saMain,#sfMain,#mtMain,#synApp,#flMain) :is(canvas,img,svg){max-width:100%}
html.ms9-active :is(#ciMain,#saMain,#sfMain,#mtMain,#synApp,#flMain) :is(.card,section,article){box-sizing:border-box}
/* On a genuinely short viewport keep the UI scrollable; never reflow to one
   column at a mobile breakpoint. */
@media(max-height:480px){
 html.ms9-active :is(#ciMain>.ciSel,#ciMain>.cxSel,#saMain>.saTop,#sfMain .sfSide,#synApp .synAdv){max-height:calc(100dvh - 75px)}
}

/* R5 desktop layout on every device. Scoped to real toolbox converter workspaces. */
html.ms7-active #ms7Custom .ms22-workspace{display:grid;direction:rtl;grid-template-columns:328px minmax(0,1fr);gap:14px;align-items:start;min-width:0;width:100%;margin:16px 0;box-sizing:border-box}
html.ms7-active #ms7Custom .ms22-workspace>*{min-width:0;border:1px solid #c2dfed;border-radius:13px;background:#f8f9fd;padding:15px;box-sizing:border-box;color:#183b53;overflow:hidden}
html.ms7-active #ms7Custom .ms22-workspace h3{font:800 17px/1.5 Tahoma,system-ui;margin:0 0 10px;color:#17658d}
html.ms7-active #ms7Custom .ms22-workspace .ms22-note{font:500 12px/1.75 Tahoma,system-ui;color:#587183;margin:10px 0}
html.ms7-active #ms7Custom .ms22-workspace .ms22-field{display:flex;flex-direction:column;align-items:stretch;gap:5px;margin:12px 0;font:700 13px/1.6 Tahoma,system-ui}
html.ms7-active #ms7Custom .ms22-workspace input,html.ms7-active #ms7Custom .ms22-workspace select{width:100%;box-sizing:border-box;min-height:39px;max-width:100%;border:1px solid #b7d5e4;border-radius:9px;background:white;color:#183b53;padding:6px;font:600 13px Tahoma,system-ui}
html.ms7-active #ms7Custom .ms22-workspace button{width:100%;min-height:40px;border-radius:9px;margin:6px 0;font:800 13px Tahoma,system-ui;cursor:pointer}
html.ms7-active #ms7Custom .ms22-workspace .ms22-primary{background:#dc1937;color:white;border:1px solid #ba1833}
html.ms7-active #ms7Custom .ms22-workspace .ms22-secondary{background:white;color:#206c96;border:1px solid #b7d5e4}
html.ms7-active #ms7Custom .ms22-workspace button:disabled{opacity:.45;cursor:not-allowed}
html.ms7-active #ms7Custom .ms22-workspace .ms22-preview{white-space:pre-wrap;word-break:break-word;direction:ltr;text-align:left;min-height:240px;max-height:650px;overflow:auto;font:500 12px/1.6 monospace;color:#17384a;background:white;padding:14px;border-radius:9px;border:1px solid #c2dfed}
html.ms7-active #ms7Custom .ms22-workspace .ms22-status{color:#22765f;font:700 13px/1.6 Tahoma,system-ui}
html.ms7-active #ms7Custom .ms22-workspace .ms22-error{color:#c82340}
html.ms7-active #ms7Custom .ms22-workspace :focus-visible{outline:2px solid #2d91c9;outline-offset:2px}

/* Stage23: only actual archived module holders; no changes to NWP, canvas or native controls */
#ms7Custom .ms23-archive-module{width:100%;min-width:0;display:block;box-sizing:border-box;margin:10px auto}
#ms7Custom:has(.ms23-archive-module)>.ms7-description{display:none}
#ms7Custom .ms23-loading{font-size:14px;line-height:1.7;background:#f8fbff;border:1px solid #c2dfed;border-radius:12px;padding:12px;color:#176b94;margin:0 0 10px}
#ms7Custom .ms23-loading.ms23-error{color:#9d2440;background:#fff6f8;border-color:#dfacbc}
#ms7Custom .ms23-module-frame{display:block;box-sizing:border-box;width:100%;height:max(700px,calc(100vh - 245px));border:1px solid #c2dfed;border-radius:12px;background:#f5f9fd}

