/* MediFlex v4.0-RC4 — clean UI recovery built on v4.0-RC1 */
:root{
  --mf-business:#1dbb98;
  --mf-business-deep:#0d856d;
  --mf-technical:#6f8ff7;
  --mf-technical-deep:#4d69c7;
  --mf-steward:#f1aa48;
  --mf-steward-deep:#c97719;
  --mf-rc4-radius:10px;
  --mf-rc4-control:36px;
}
body.mf-v40-rc4{--context-width:360px}
/* Storybook repository is intentionally untouched: no selector in this file targets
   .mf-story-advanced-filters, .mf-advanced-filter-grid, .mf-advanced-scope,
   .mf-story-quick-jump or repository row sizing. */
body.mf-v40-rc4:not(.workspace-erd):not(.left-panel-collapsed):not(.right-panel-collapsed):not(.story-focus) #app{
  grid-template-columns:300px minmax(560px,1fr) 360px;
}
body.mf-v40-rc4 .context{min-width:300px;max-width:480px}

/* Coordinated top layers without affecting the repository. */
body.mf-v40-rc4 #app>.topbar{min-height:64px;height:64px;padding:7px 14px;gap:10px;border-top:3px solid color-mix(in srgb,var(--accent2) 65%,var(--accent));}
body.mf-v40-rc4 #mfUsabilityBar{min-height:38px;height:38px;padding:4px 14px;}
body.mf-v40-rc4 .story-toolbar{min-height:52px;height:52px;padding:7px 16px;gap:8px}
body.mf-v40-rc4 .topbar button,body.mf-v40-rc4 #mfUsabilityBar button,body.mf-v40-rc4 .story-toolbar button{border-radius:var(--mf-rc4-radius)}

/* Complete persona identity across switch, tabs, lens banners, cards and narration. */
body.mf-v40-rc4[data-story-persona="business"]{--persona:var(--mf-business);--persona2:var(--mf-business-deep);--persona-soft:color-mix(in srgb,var(--mf-business) 11%,transparent);--persona-line:color-mix(in srgb,var(--mf-business) 43%,transparent)}
body.mf-v40-rc4[data-story-persona="technical"]{--persona:var(--mf-technical);--persona2:var(--mf-technical-deep);--persona-soft:color-mix(in srgb,var(--mf-technical) 11%,transparent);--persona-line:color-mix(in srgb,var(--mf-technical) 43%,transparent)}
body.mf-v40-rc4[data-story-persona="steward"]{--persona:var(--mf-steward);--persona2:var(--mf-steward-deep);--persona-soft:color-mix(in srgb,var(--mf-steward) 12%,transparent);--persona-line:color-mix(in srgb,var(--mf-steward) 46%,transparent)}
body.mf-v40-rc4 .view-switch button[data-view="business"]{border-color:color-mix(in srgb,var(--mf-business) 35%,var(--line));background:color-mix(in srgb,var(--mf-business) 8%,var(--panel2))}
body.mf-v40-rc4 .view-switch button[data-view="technical"]{border-color:color-mix(in srgb,var(--mf-technical) 35%,var(--line));background:color-mix(in srgb,var(--mf-technical) 8%,var(--panel2))}
body.mf-v40-rc4 .view-switch button[data-view="steward"]{border-color:color-mix(in srgb,var(--mf-steward) 38%,var(--line));background:color-mix(in srgb,var(--mf-steward) 9%,var(--panel2))}
body.mf-v40-rc4 .view-switch button[data-view="business"].active{background:var(--mf-business)!important;border-color:var(--mf-business)!important;color:#04251d!important;box-shadow:0 6px 16px color-mix(in srgb,var(--mf-business) 25%,transparent)!important}
body.mf-v40-rc4 .view-switch button[data-view="technical"].active{background:var(--mf-technical)!important;border-color:var(--mf-technical)!important;color:#071326!important;box-shadow:0 6px 16px color-mix(in srgb,var(--mf-technical) 25%,transparent)!important}
body.mf-v40-rc4 .view-switch button[data-view="steward"].active{background:var(--mf-steward)!important;border-color:var(--mf-steward)!important;color:#271703!important;box-shadow:0 6px 16px color-mix(in srgb,var(--mf-steward) 25%,transparent)!important}
body.mf-v40-rc4 .view-switch button.active small{color:rgba(5,17,28,.72)!important}
body.mf-v40-rc4[data-story-persona] .story>.tabs button.active,
body.mf-v40-rc4[data-story-persona] .story .tabs button.active{background:var(--persona)!important;border-color:var(--persona)!important;color:#07131f!important;box-shadow:inset 0 -2px 0 var(--persona2)!important}
body.mf-v40-rc4[data-story-persona] .story .callout{border-left-color:var(--persona)!important}
body.mf-v40-rc4[data-story-persona] .story .card{border-color:color-mix(in srgb,var(--persona) 24%,var(--line))}
body.mf-v40-rc4[data-story-persona] .story .card h3,
body.mf-v40-rc4[data-story-persona] .story .content strong{color:color-mix(in srgb,var(--persona) 82%,var(--text))}
body.mf-v40-rc4[data-story-persona] .story [class*="lens"],
body.mf-v40-rc4[data-story-persona] .story [class*="persona"]{--accent:var(--persona);--accent2:var(--persona2)}

/* One controlled narration component. */
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration{
  position:fixed;left:318px;right:auto;bottom:18px;top:auto;
  width:380px;max-width:calc(100vw - 338px);max-height:280px;
  display:grid;grid-template-rows:44px minmax(0,1fr) 48px;gap:0;padding:0;
  overflow:visible;border:1px solid color-mix(in srgb,var(--persona) 54%,var(--line));
  border-radius:14px;background:var(--panel);color:var(--text);box-shadow:0 18px 55px rgba(0,0,0,.30);backdrop-filter:none;z-index:120;
}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.hidden{display:none!important}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-meta{display:grid;grid-template-columns:minmax(0,1fr) auto auto;align-items:center;gap:8px;margin:0;padding:0 12px;border-bottom:1px solid var(--line);background:color-mix(in srgb,var(--persona) 10%,var(--panel2));cursor:move}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-meta b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-meta em{order:2;margin:0;padding:3px 7px;border:1px solid color-mix(in srgb,var(--persona) 42%,var(--line));border-radius:999px;background:color-mix(in srgb,var(--persona) 12%,var(--panel));color:var(--persona);font-size:8px;font-style:normal;font-weight:850}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-meta span{order:3;font-size:9px;font-weight:850;color:var(--muted)}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-transcript{min-height:0;max-height:188px;overflow:auto;display:grid;gap:6px;padding:9px;background:var(--bg)}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-transcript>span{display:block;width:100%;padding:8px 9px;border-radius:9px;border-left:3px solid color-mix(in srgb,var(--persona) 55%,var(--line));background:var(--panel2);color:var(--muted);font-size:10px;line-height:1.4}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-transcript>span.active{outline:1px solid color-mix(in srgb,var(--persona) 45%,var(--line));background:color-mix(in srgb,var(--persona) 11%,var(--panel2));color:var(--text)}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-controls{position:relative;display:flex;align-items:center;justify-content:flex-end;gap:5px;padding:6px 8px;border-top:1px solid var(--line);background:var(--panel)}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .ai2-narration-controls>button{display:grid;place-items:center;width:34px;height:34px;min-height:34px;padding:0;border-radius:8px;font-size:12px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .mf-rc4-narration-more{position:absolute;right:8px;bottom:44px;width:210px;display:grid;grid-template-columns:1fr 1fr;gap:6px;padding:8px;border:1px solid var(--line);border-radius:11px;background:var(--panel);box-shadow:0 14px 38px rgba(0,0,0,.30)}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .mf-rc4-narration-more.hidden{display:none!important}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration .mf-rc4-narration-more button{height:32px;padding:0 7px;border-radius:7px;font-size:9px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.mf-rc4-transcript-hidden{grid-template-rows:44px 48px;max-height:92px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.mf-rc4-transcript-hidden .ai2-transcript{display:none}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized{width:420px;max-width:calc(100vw - 338px);height:48px;max-height:48px;display:block;overflow:hidden}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized .ai2-transcript{display:none!important}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized .ai2-narration-meta{height:48px;border:0;grid-template-columns:minmax(0,1fr) auto auto;padding:0 200px 0 12px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized .ai2-narration-controls{position:absolute;right:7px;top:7px;height:34px;display:flex!important;padding:0;border:0;background:transparent}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized .ai2-narration-controls>button{width:30px;height:30px;min-height:30px}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized #mfRc4NarrationMore{display:none!important}
body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration.minimized .mf-rc4-narration-more{display:none!important}
body.mf-v40-rc4.workspace-erd #ai2NarrationBar,body.mf-v40-rc4:has(.stats-workspace:not(.hidden)) #ai2NarrationBar{display:none!important}

/* Statistics: stable header hierarchy and one content scroll owner. */
body.mf-v40-rc4 .stats-workspace{grid-template-rows:auto auto auto auto minmax(0,1fr) auto!important;overflow:hidden!important;min-height:0!important}
body.mf-v40-rc4 .stats-filterbar{position:relative!important;display:grid!important;grid-template-columns:minmax(145px,.8fr) repeat(4,minmax(130px,1fr)) minmax(220px,1.5fr) auto!important;gap:8px!important;padding:9px 14px!important;align-items:end!important;overflow:visible!important;min-height:58px!important}
body.mf-v40-rc4 .stats-filterbar label{min-width:0!important;gap:3px!important;font-size:9px!important}
body.mf-v40-rc4 .stats-filterbar select,body.mf-v40-rc4 .stats-filterbar input,body.mf-v40-rc4 .stats-filterbar>button{height:36px!important;min-height:36px!important;border-radius:9px!important}
body.mf-v40-rc4 .stats-search{grid-column:auto!important}
body.mf-v40-rc4 .stats-operational-bar{min-height:42px!important;padding:5px 14px!important;display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;gap:8px!important;overflow:hidden!important;align-items:center!important}
body.mf-v40-rc4 .stats-operational-presets,body.mf-v40-rc4 .stats-operational-actions{flex-wrap:nowrap!important;min-width:0!important;overflow:hidden!important}
body.mf-v40-rc4 .stats-tabs{position:relative!important;z-index:3!important;min-height:42px!important;height:42px!important;padding:5px 14px!important;overflow-x:auto!important;overflow-y:hidden!important;align-items:center!important;background:var(--panel)!important;border-bottom:1px solid var(--line)!important}
body.mf-v40-rc4 .stats-tabs button{height:32px!important;min-height:32px!important;padding:0 11px!important}
body.mf-v40-rc4 .stats-content{min-height:0!important;overflow-y:auto!important;overflow-x:hidden!important;padding:16px 18px 24px!important}
body.mf-v40-rc4 .stats-header,body.mf-v40-rc4 .stats-filterbar,body.mf-v40-rc4 .stats-operational-bar,body.mf-v40-rc4 .stats-tabs{overflow-y:visible!important}
body.mf-v40-rc4 .stats-layer-field{position:relative!important}
body.mf-v40-rc4 .mf-stats-layer-trigger{height:36px;width:100%;display:flex;align-items:center;justify-content:space-between;padding:0 9px;border:1px solid var(--line);border-radius:9px;background:var(--panel2);color:var(--text);font-size:11px}
body.mf-v40-rc4 #statsLayerPicker.mf-stats-layer-popover{position:absolute!important;left:0!important;top:calc(100% + 5px)!important;z-index:50!important;width:230px!important;display:grid!important;grid-template-columns:1fr!important;gap:4px!important;padding:8px!important;background:var(--panel)!important;border:1px solid var(--line)!important;border-radius:11px!important;box-shadow:0 18px 48px rgba(0,0,0,.32)!important}
body.mf-v40-rc4 #statsLayerPicker.mf-stats-layer-popover.hidden{display:none!important}
body.mf-v40-rc4 #statsLayerPicker.mf-stats-layer-popover button{height:30px!important;min-height:30px!important;justify-content:flex-start!important;text-align:left!important;padding:0 9px!important;border-radius:7px!important;background:var(--panel2)!important}
body.mf-v40-rc4 #statsLayerPicker.mf-stats-layer-popover button:before{content:'□';width:16px;color:var(--muted)}
body.mf-v40-rc4 #statsLayerPicker.mf-stats-layer-popover button.active:before{content:'☑';color:var(--accent)}
@media(max-width:1500px){body.mf-v40-rc4 .stats-filterbar{grid-template-columns:repeat(4,minmax(150px,1fr))!important}body.mf-v40-rc4 .stats-search{grid-column:span 2!important}}
@media(max-width:980px){body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration{left:10px;right:10px;width:auto;max-width:none;bottom:10px}body.mf-v40-rc4 .stats-filterbar{grid-template-columns:repeat(2,minmax(0,1fr))!important}body.mf-v40-rc4 .stats-search{grid-column:1/-1!important}body.mf-v40-rc4 .stats-operational-bar{grid-template-columns:1fr!important}}
@media(max-width:700px){body.mf-v40-rc4 .stats-filterbar{display:none!important}body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration{left:8px;right:8px;bottom:8px;width:auto;max-width:none}body.mf-v40-rc4 #ai2NarrationBar.mf-rc4-narration:not(.minimized){height:min(72vh,420px);max-height:none;grid-template-rows:44px minmax(0,1fr) 48px}}
@media print{body.mf-v40-rc4 #ai2NarrationBar{display:none!important}body.mf-v40-rc4 .stats-workspace{grid-template-rows:auto 1fr!important}}
