/* MediFlex v3.9-RC3 — Visual elegance with ERD workspace isolation correction */
:root{
  --mf-elegant-radius-sm:8px;
  --mf-elegant-radius:12px;
  --mf-elegant-radius-lg:17px;
  --mf-elegant-shadow:0 16px 42px rgba(0,0,0,.24);
  --mf-elegant-soft-shadow:0 8px 24px rgba(0,0,0,.13);
  --mf-scroll-thumb:color-mix(in srgb,var(--muted) 48%,transparent);
  --mf-scroll-track:transparent;
}
body.light{
  color-scheme:light;
  --bg:#f2f6fb;
  --panel:#ffffff;
  --panel2:#f6f9fd;
  --line:#d4deea;
  --text:#132238;
  --muted:#61748a;
  --accent:#159a7c;
  --accent2:#376fd7;
  --warn:#b96c08;
  --danger:#c8374e;
  --shadow:0 14px 38px rgba(40,63,91,.13);
  --mf-focus:#075f83;
  --mf-contrast-muted:#52677d;
  --mf-scroll-thumb:#9dafc2;
  --mf-elegant-shadow:0 16px 44px rgba(40,63,91,.14);
  --mf-elegant-soft-shadow:0 7px 22px rgba(40,63,91,.10);
}

/* Unified page geometry */
html,body{overflow:hidden}
body.mf-usability-ready #app{min-height:0;overflow:hidden;background:var(--bg)}
body.mf-usability-ready #app>.nav,
body.mf-usability-ready #app>.story,
body.mf-usability-ready #app>.context,
body.mf-usability-ready #erdWorkspace{min-height:0;height:100%;}

/* v3.9-RC3: isolate the ERD workspace from Storybook layout overrides.
   RC2's full-height Storybook rule used display:grid!important and could
   re-expose the hidden repository over the ERD because it had higher selector
   specificity than the workspace hide rule. These guards are intentionally
   fail-closed and loaded after all shared layout rules. */
body.mf-usability-ready.workspace-erd #app>.nav,
body.mf-usability-ready.workspace-erd #app>.story,
body.mf-usability-ready.workspace-erd #app>.context{
  display:none!important;
  visibility:hidden!important;
  pointer-events:none!important;
  height:0!important;
  min-height:0!important;
  overflow:hidden!important;
}
body.mf-usability-ready.workspace-erd #erdWorkspace{
  display:block!important;
  visibility:visible!important;
  grid-column:1!important;
  grid-row:3!important;
  min-width:0!important;
  min-height:0!important;
  height:100%!important;
  overflow:hidden!important;
}

/* Full-height Storybook repository: title + filters + remaining scrollable list. */
body.mf-usability-ready #app>.nav{
  display:grid!important;
  grid-template-rows:auto auto minmax(0,1fr)!important;
  overflow:hidden!important;
  min-width:0;
  background:var(--panel);
}
body.mf-usability-ready #app>.nav .nav-head{
  position:relative!important;
  top:auto!important;
  z-index:3;
  padding:15px 16px 13px;
  background:var(--panel);
}
body.mf-usability-ready #app>.nav .filters{
  position:relative;
  z-index:2;
  padding:11px 12px 12px;
  border-bottom:1px solid var(--line);
  background:color-mix(in srgb,var(--panel) 96%,var(--accent2));
}
body.mf-usability-ready #tree,
body.mf-usability-ready #tree[data-virtualized=true]{
  min-height:0!important;
  height:100%!important;
  max-height:none!important;
  overflow-y:auto!important;
  overflow-x:hidden!important;
  overscroll-behavior:contain;
  scrollbar-gutter:stable;
  contain:layout paint style!important;
  background:var(--panel);
}
body.mf-usability-ready #tree .repo-virtual-window{right:0;min-width:0}
body.mf-usability-ready #tree .repo-virtual-row{width:100%;max-width:100%;}
body.mf-usability-ready #tree .domain-title{
  min-height:38px;
  padding:10px 14px;
  border-top:1px solid var(--line);
  background:color-mix(in srgb,var(--panel2) 86%,var(--panel));
  color:var(--muted);
  letter-spacing:.055em;
}
body.mf-usability-ready #tree .table-row{
  min-height:38px;
  padding:9px 13px 9px 20px;
  border-bottom:1px solid color-mix(in srgb,var(--line) 46%,transparent);
  transition:background-color .14s ease,border-color .14s ease;
}
body.mf-usability-ready #tree .table-row:hover{background:color-mix(in srgb,var(--accent2) 7%,var(--panel2))}
body.mf-usability-ready #tree .table-row.active{
  background:linear-gradient(90deg,color-mix(in srgb,var(--accent) 18%,var(--panel)),color-mix(in srgb,var(--accent2) 4%,var(--panel)) 82%);
  border-left-color:var(--accent);
  font-weight:720;
}
body.mf-usability-ready #tree .pill{font-size:8px;font-weight:850;letter-spacing:.03em;border:1px solid var(--line)}
body.mf-usability-ready #app>.context{overflow:hidden!important;display:grid;grid-template-rows:auto minmax(0,1fr) auto;background:var(--panel)}
body.mf-usability-ready #app>.context .context-head{position:relative!important;top:auto!important;padding:15px 16px 13px}
body.mf-usability-ready #app>.context #compass{min-height:0;overflow:auto;scrollbar-gutter:stable;padding:14px 15px 24px}
body.mf-usability-ready #app>.context .bookmarks{max-height:34%;overflow:auto}

/* Scrollbar treatment */
:where(.nav,.context,.story,#tree,.stats-content,.mf-command-results,.mf-drill-list,.ai2-drawer-content,.right-panel-scroll,.panel-scroll){
  scrollbar-width:thin;
  scrollbar-color:var(--mf-scroll-thumb) var(--mf-scroll-track);
}
:where(.nav,.context,.story,#tree,.stats-content,.mf-command-results,.mf-drill-list,.ai2-drawer-content,.right-panel-scroll,.panel-scroll)::-webkit-scrollbar{width:9px;height:9px}
:where(.nav,.context,.story,#tree,.stats-content,.mf-command-results,.mf-drill-list,.ai2-drawer-content,.right-panel-scroll,.panel-scroll)::-webkit-scrollbar-track{background:transparent}
:where(.nav,.context,.story,#tree,.stats-content,.mf-command-results,.mf-drill-list,.ai2-drawer-content,.right-panel-scroll,.panel-scroll)::-webkit-scrollbar-thumb{background:var(--mf-scroll-thumb);border:2px solid transparent;background-clip:padding-box;border-radius:999px}

/* Guided narration: compact dock at the lower-left of the working canvas. */
#ai2NarrationBar,
#ai2NarrationBar.minimized{
  left:calc(var(--nav-width,300px) + 18px)!important;
  right:auto!important;
  bottom:16px!important;
  width:min(520px,calc(100vw - var(--nav-width,300px) - 38px))!important;
  max-width:calc(100vw - 36px)!important;
  border-radius:15px!important;
  border:1px solid color-mix(in srgb,var(--accent2) 38%,var(--line))!important;
  background:color-mix(in srgb,var(--panel) 96%,transparent)!important;
  color:var(--text)!important;
  box-shadow:var(--mf-elegant-shadow)!important;
  backdrop-filter:blur(18px) saturate(1.18)!important;
}
#ai2NarrationBar:not(.minimized){
  width:min(760px,calc(100vw - var(--nav-width,300px) - var(--context-width,330px) - 42px))!important;
  grid-template-columns:160px minmax(220px,1fr) auto!important;
}
body.left-panel-collapsed #ai2NarrationBar,
body.story-focus #ai2NarrationBar{left:18px!important}
#ai2NarrationBar .ai2-narration-meta b{color:var(--text)}
#ai2NarrationBar .ai2-narration-meta span{color:var(--muted)}
#ai2NarrationBar .ai2-narration-meta em{
  display:inline-flex;margin-top:4px;padding:2px 7px;border-radius:999px;
  background:color-mix(in srgb,var(--accent) 13%,var(--panel2));
  color:var(--accent);font-size:8px;font-style:normal;font-weight:850;
}
#ai2NarrationBar .ai2-transcript>span{color:var(--muted);background:transparent}
#ai2NarrationBar .ai2-transcript>span.active{background:color-mix(in srgb,var(--accent2) 10%,var(--panel2));color:var(--text)}
#ai2NarrationBar .ai2-transcript b{color:var(--accent)}
#ai2NarrationBar .ai2-narration-controls button{background:var(--panel2);border-color:var(--line);box-shadow:none}
#ai2LiveStatus{left:auto;right:18px;bottom:18px;background:color-mix(in srgb,var(--panel) 96%,transparent);color:var(--text);backdrop-filter:blur(12px)}

/* Elegant shared surfaces */
.topbar{box-shadow:0 5px 18px rgba(0,0,0,.12)}
.header-action-group,.workspace-switch,.search,.mf-usability-bar{border-color:color-mix(in srgb,var(--line) 88%,transparent)!important}
.story{background:
  radial-gradient(circle at 82% 0,color-mix(in srgb,var(--accent2) 8%,transparent),transparent 36%),
  linear-gradient(180deg,color-mix(in srgb,var(--bg) 97%,var(--panel)),var(--bg));
}
.story-toolbar{padding:9px 17px;box-shadow:0 3px 12px rgba(0,0,0,.06)}
.hero{border-radius:var(--mf-elegant-radius-lg);box-shadow:var(--mf-elegant-soft-shadow);background:linear-gradient(145deg,color-mix(in srgb,var(--panel) 98%,var(--accent2)),color-mix(in srgb,var(--panel2) 95%,var(--accent)))}
.card,.callout,.provenance,.persona-context-strip,.persona-boundary,.columns-shell,.rel-card,.compass-center,.compass-link{
  box-shadow:0 4px 15px rgba(0,0,0,.055);
}
.card,.rel-card,.provenance,.persona-context-strip,.persona-boundary{border-radius:var(--mf-elegant-radius)}
.tabs{scrollbar-width:none}.tabs::-webkit-scrollbar{display:none}
.mf-story-identity{box-shadow:0 4px 16px rgba(0,0,0,.07)}
.mf-command-panel,.mf-drill-dialog,.stats-workspace,.ai2-drawer,.ai2-guide-modal,.fk-record-modal{box-shadow:var(--mf-elegant-shadow)}

/* Complete daylight theme — application shell and Storybook. */
body.light{background:#f2f6fb}
body.light .topbar{
  background:rgba(255,255,255,.96)!important;
  border-bottom-color:#d5dfeb!important;
  border-top-color:#6c4ad1!important;
  box-shadow:0 5px 18px rgba(42,64,91,.10)!important;
}
body.light .header-brand strong,body.light .workspace-switch button,body.light .header-icon-button,body.light .header-control-button{color:#14243a!important}
body.light .workspace-switch,body.light .header-action-group,body.light .search{background:#f6f9fd!important}
body.light .workspace-switch button.active{background:#6ee0c2!important;color:#073b31!important;box-shadow:0 4px 12px rgba(21,154,124,.20)}
body.light .search input{color:#132238!important}
body.light .mf-usability-bar{background:rgba(248,251,255,.97)!important;box-shadow:0 4px 14px rgba(42,64,91,.06)!important}
body.light #app>.nav,body.light #app>.context{background:#fff!important}
body.light .nav-head,body.light .context-head{background:#fff!important}
body.light .filters{background:#f8fbff!important}
body.light .filters select,body.light button,body.light input,body.light select,body.light textarea{color:#14243a}
body.light .filters select,body.light .header-icon-button,body.light .header-control-button,body.light .panel-collapse,
body.light .story-toolbar button,body.light .mf-story-identity button{background:#f7faff;border-color:#cfdae7}
body.light .story{background:
  radial-gradient(circle at 74% 0,rgba(55,111,215,.08),transparent 35%),
  linear-gradient(180deg,#f7faff 0,#f2f6fb 52%,#eef3f8 100%)!important;
}
body.light .story-toolbar{background:rgba(255,255,255,.92)!important;border-color:#d6e0eb!important}
body.light .mf-story-identity{background:rgba(255,255,255,.94)!important;border-color:#d6e0eb!important}
body.light .hero{
  background:linear-gradient(145deg,#fff 0,#f8fbff 60%,#f2faf7 100%)!important;
  border-color:#ccd9e6!important;
  box-shadow:0 13px 34px rgba(42,64,91,.10)!important;
}
body.light .metric{background:#f8fbff!important;border-color:#d5dfeb!important}
body.light .tabs{border-color:#d6e0eb!important}
body.light .tabs button{color:#5c7087!important}
body.light .tabs button.active,body.light .view-switch button.active{background:#f3b85d!important;color:#382300!important;border-color:#e5a840!important}
body.light .card,body.light .callout,body.light .provenance,body.light .persona-context-strip,body.light .persona-boundary,
body.light .columns,body.light .columns-shell,body.light .rel-card,body.light .flow-center,body.light .compass-center,body.light .compass-link,
body.light .definition-list dd,body.light .fk-record-modal,body.light .ai2-drawer,body.light .ai2-guide-modal{
  background:#fff!important;border-color:#d5dfeb!important;color:#14243a!important;
}
body.light .definition-list dt,body.light .columns th,body.light .column-validation,body.light .column-lineage{background:#f6f9fd!important;color:#5c7087!important}
body.light .columns td{border-color:#e0e7ef!important}
body.light .card p,body.light .callout p,body.light .provenance p,body.light .qualified,body.light .empty,
body.light .persona-context-strip p,body.light .persona-boundary,body.light .compass-link small{color:#5c7087!important}
body.light .table-row:hover,body.light .compass-link:hover,body.light .rel-card:hover{background:#f4f8fd!important}
body.light .table-row.active{background:linear-gradient(90deg,#dff7ef,#f6fbff 82%)!important}
body.light .pill{background:#eef3f8!important;color:#566b82!important}
body.light .source-badge{background:#e5f7f1!important;color:#08745d!important;border-color:#a9dfd1!important}
body.light .toast,body.light .ai2-toast{background:#fff!important;color:#14243a!important;border-color:#ced9e5!important}
body.light .results,body.light .mf-recent-menu{background:#fff!important;border-color:#d5dfeb!important}

/* Complete daylight theme — Statistics and overlays. */
body.light .stats-workspace{background:#f3f7fb!important;border-color:#cbd7e4!important}
body.light .stats-header{background:linear-gradient(110deg,#fff,#f4f8fd)!important;border-color:#d5dfeb!important}
body.light .stats-filterbar,body.light .stats-tabs{background:#fff!important;border-color:#d5dfeb!important}
body.light .stats-filterbar select,body.light .stats-filterbar input{background:#f7faff!important;border-color:#cfdae7!important}
body.light .stats-content{background:radial-gradient(circle at 70% 0,rgba(55,111,215,.08),transparent 38%),#f3f7fb!important}
body.light .stats-card,body.light .stats-kpi,body.light .stats-chart-card,body.light .stats-table-wrap,
body.light .mf-command-panel,body.light .mf-drill-dialog{background:#fff!important;border-color:#d4deea!important;color:#14243a!important}
body.light .stats-tabs button.active{background:#62d8ba!important;color:#083e33!important;border-color:#43bca0!important}
body.light .mf-command-backdrop,body.light .mf-drill-backdrop,body.light .ai2-backdrop,body.light .fk-record-backdrop{background:rgba(36,52,72,.42)!important}
body.light .mf-command-head,body.light .mf-command-scope,body.light .mf-command-foot,
body.light .mf-drill-dialog header,body.light .mf-drill-dialog footer{background:#f8fbff!important;border-color:#d5dfeb!important}
body.light .mf-command-item:hover,body.light .mf-command-item.active{background:#edf4fd!important}
body.light .ai2-drawer-head{background:linear-gradient(135deg,#effaf7,#f0f5ff)!important}

/* Identity and governed-review surfaces in daylight mode. */
body.light .identity-gate{background:rgba(232,239,247,.82)!important}
body.light .identity-card{background:#fff!important;color:#14243a!important;border-color:#cbd7e4!important;box-shadow:0 28px 80px rgba(42,64,91,.20)!important}
body.light .identity-card input,body.light .identity-card select{background:#f7faff!important;border-color:#cfdae7!important;color:#14243a!important}
body.light .mfgr-root,body.light .mfgr-panel,body.light .mfgr-card,body.light .mfgr-dialog{background:#fff!important;color:#14243a!important;border-color:#d4deea!important}
body.light .mfgr-header,body.light .mfgr-toolbar,body.light .mfgr-table th{background:#f7faff!important}

/* More stable content density and spacing. */
.content{padding-bottom:110px}
.card-grid{gap:14px}.card{padding:17px}.hero-grid{gap:9px}
.context .compass-link{padding:10px 11px}
.filters select{height:40px}
.panel-head-row h2{letter-spacing:-.01em}

/* Shadow-DOM ERD refinements are injected by visual-elegance.js. */

@media(max-width:1200px){
  #ai2NarrationBar,#ai2NarrationBar.minimized{left:16px!important;width:min(520px,calc(100vw - 32px))!important}
  #ai2NarrationBar:not(.minimized){width:min(690px,calc(100vw - 32px))!important}
}
@media(max-width:800px){
  html,body{overflow:auto}
  body.mf-usability-ready #app>.nav{height:min(44vh,430px)!important;grid-template-rows:auto auto minmax(180px,1fr)!important}
  #ai2NarrationBar,#ai2NarrationBar.minimized,#ai2NarrationBar:not(.minimized){left:10px!important;right:10px!important;width:auto!important;bottom:10px!important}
}
@media(prefers-reduced-motion:reduce){#ai2NarrationBar{backdrop-filter:none!important}}
@media print{#ai2NarrationBar,#ai2LiveStatus{display:none!important}}
