@import url('/assets/css/agent-controls.css');
@import url('/assets/css/agent-sidebar.css');
@import url('/assets/css/agent-items.css');
@import url('/assets/css/agent-items-reels.css');
@import url('/assets/css/archived-agents.css');
@import url('/assets/css/agent-tools.css');
@import url('/assets/css/admin-ai.css');
@import url('/assets/css/header-signals.css');

/* Remove the legacy M3-style primary links from the shared header. */
.mg-unified-header .mg-site-nav > a[href="/index.php"],
.mg-unified-header .mg-site-nav > a[href="/build.php"],
.mg-unified-header .mg-site-nav > a[href="/agent.php"]{display:none!important}

/* Header agent tool alignment */
.mg-unified-header .mg-header-agent-tools{display:flex!important;align-items:center!important;gap:8px!important;width:100%!important;min-width:0!important;flex:1 1 auto!important}
.mg-unified-header .mg-header-agent-tabs{flex:0 1 auto!important;min-width:0!important}
.mg-unified-header .mg-header-agent-tabs [data-system-tab="agent"]{display:none!important}
.mg-unified-header .mg-header-agent-search{display:none!important;visibility:hidden!important;pointer-events:none!important}
.mg-unified-header .mg-header-build-link{align-self:center!important;width:42px!important;height:42px!important;min-width:42px!important;margin-left:auto!important;border-radius:11px!important;transform:none!important;display:grid!important;place-items:center!important;line-height:1!important}

/* Account menu and header overlays must sit above page shells, cards, drawers, and profile media. */
.mg-unified-header{overflow:visible!important;position:sticky!important;z-index:10000!important;isolation:isolate!important}
.mg-unified-header .mg-header-inner,
.mg-header-actions{overflow:visible!important}
.mg-account-menu{position:relative!important;display:inline-flex!important;align-items:center!important;z-index:10030!important}
.mg-account-actions{top:calc(100% + 10px)!important;right:0!important;left:auto!important;width:min(300px,calc(100vw - 24px))!important;max-height:min(520px,calc(100vh - 88px))!important;overflow:auto!important;visibility:hidden!important;opacity:0!important;transform:translateY(-6px) scale(.985)!important;pointer-events:none!important;display:grid!important;gap:4px!important;transition:opacity .16s ease,transform .16s ease,visibility 0s linear .16s!important;z-index:10050!important}
.mg-account-menu.is-open .mg-account-actions,
.mg-account-menu:hover .mg-account-actions,
.mg-account-menu:focus-within .mg-account-actions{visibility:visible!important;opacity:1!important;transform:translateY(0) scale(1)!important;pointer-events:auto!important;transition-delay:0s!important}
.mg-account-menu:not(.is-open):not(:hover):not(:focus-within) .mg-account-actions{visibility:hidden!important;opacity:0!important;pointer-events:none!important}
.mg-account-menu-head{position:relative!important;min-width:0!important}
.mg-account-head-copy,.mg-account-head-name,.mg-account-head-email{min-width:0!important}
.mg-account-action{box-sizing:border-box!important;text-decoration:none!important;line-height:1.25!important}

/* Package limit usage cards */
.mg-package-limits-panel{margin:18px 0!important}
.mg-package-limit-grid{display:grid!important;grid-template-columns:repeat(auto-fit,minmax(180px,1fr))!important;gap:12px!important;width:100%!important}
.mg-package-limit-card{display:grid!important;gap:9px!important;padding:14px!important;border:1px solid rgba(148,163,184,.24)!important;border-radius:16px!important;background:linear-gradient(180deg,#fff,rgba(248,250,252,.94))!important;box-shadow:0 12px 30px rgba(15,23,42,.06)!important;min-width:0!important}
.mg-package-limit-card>div:first-child{display:flex!important;justify-content:space-between!important;align-items:flex-start!important;gap:10px!important;min-width:0!important}
.mg-package-limit-card span{font-size:12px!important;font-weight:800!important;text-transform:uppercase!important;letter-spacing:.08em!important;color:#64748b!important}
.mg-package-limit-card strong{font-size:18px!important;color:#0f172a!important;text-align:right!important;white-space:nowrap!important}
.mg-package-limit-card small{color:#64748b!important;font-size:12px!important;line-height:1.35!important}
.mg-package-limit-card a{justify-self:start!important;font-size:12px!important;font-weight:800!important;color:#2563eb!important;text-decoration:none!important}
.mg-package-limit-meter{height:7px!important;border-radius:999px!important;background:#e2e8f0!important;overflow:hidden!important}
.mg-package-limit-meter b{display:block!important;height:100%!important;border-radius:999px!important;background:#2563eb!important}
.mg-package-limit-card.is-limit-hit{border-color:rgba(220,38,38,.35)!important;background:linear-gradient(180deg,#fff,rgba(254,242,242,.9))!important}
.mg-package-limit-card.is-limit-hit .mg-package-limit-meter b{background:#dc2626!important}
.is-package-locked{opacity:.58!important;cursor:not-allowed!important;filter:grayscale(.12)!important}
button.is-package-locked{pointer-events:auto!important}

/* Modal z-index contract: modals/drawers must sit above the app header, not below it. */
body.mg-cart-open .mg-unified-header,
body.mg-item-modal-open .mg-unified-header,
body.mg-action-modal-open .mg-unified-header,
body.mg-modal-lock .mg-unified-header,
body:has(.mg-action-modal[aria-hidden="false"]) .mg-unified-header,
body:has(.mg-create-menu:not([hidden])) .mg-unified-header,
body:has(.mg-cart-drawer.is-open) .mg-unified-header,
body.mg-crm-modal-open .mg-unified-header,
body.mg-crm-drawer-open .mg-unified-header{z-index:500!important}

/* Loaded item drawer */
.mg-gift-preview{position:absolute!important;z-index:650!important}
.mg-gift-preview-close-floating{position:fixed!important;top:80px!important;right:14px!important;z-index:760!important;display:grid!important;visibility:visible!important;opacity:1!important;pointer-events:auto!important}

/* Gift action modal */
.mg-action-modal-backdrop{position:fixed!important;inset:0!important;z-index:40000!important;background:rgba(7,18,37,.42)!important;backdrop-filter:blur(3px)!important}
.mg-action-modal{position:fixed!important;inset:auto 0 0 0!important;z-index:40010!important;background:#fff!important;border-radius:18px 18px 0 0!important;box-shadow:0 -24px 70px rgba(15,23,42,.24)!important}
.mg-action-modal[aria-hidden="true"]{display:none!important}
.mg-action-modal[aria-hidden="false"]{display:block!important}
body:has(.mg-action-modal[aria-hidden="false"]){overflow:hidden!important}

/* Create menu/modal layering only. Component layout lives in create-menu.css. */
.mg-create-menu{z-index:70000!important}
.mg-create-menu-backdrop{z-index:0!important}
.mg-create-menu-dialog{z-index:1!important}

/* Cart drawer */
.mg-cart-drawer{overflow:hidden!important;z-index:60000!important}
.mg-cart-drawer.is-contained{position:fixed!important;inset:0!important;z-index:60000!important}
.mg-cart-drawer.is-contained .mg-cart-backdrop,.mg-cart-drawer .mg-cart-backdrop{position:fixed!important;inset:0!important;background:rgba(15,23,42,.42)!important;backdrop-filter:blur(3px)!important;z-index:60010!important}
.mg-cart-drawer-panel{position:fixed!important;top:0!important;right:0!important;bottom:0!important;height:100vh!important;max-height:100vh!important;will-change:transform!important;backface-visibility:hidden!important;contain:layout paint!important;z-index:60020!important}
.mg-cart-drawer:not(.is-open) .mg-cart-drawer-panel{visibility:hidden!important;transition:transform .24s ease,visibility 0s linear .24s!important}
.mg-cart-drawer.is-open .mg-cart-drawer-panel{visibility:visible!important;transition:transform .24s ease!important}
body.mg-cart-open .mg-account-menu.is-open .mg-account-actions{visibility:hidden!important;opacity:0!important;pointer-events:none!important}
body:has(.mg-cart-drawer.is-contained).mg-cart-open,body.mg-cart-open{overflow:hidden!important}
body.mg-item-modal-open{overflow:hidden!important}
body.mg-cart-open .mg-unified-header,
body.mg-cart-open .mg-site-header.mg-unified-header,
body:has(.mg-cart-drawer.is-open) .mg-unified-header,
body:has(.mg-cart-drawer.is-open) .mg-site-header.mg-unified-header{z-index:100!important;pointer-events:none!important}

/* Shared mobile overflow contract for app/workspace pages. */
html,body{max-width:100%!important;overflow-x:hidden!important}
*,*::before,*::after{box-sizing:border-box}
img,svg,video,canvas,iframe{max-width:100%;height:auto}
.mg-main,.mg-page,.mg-content,.mg-container,.mg-app-shell,.mg-app-workspace,.mg-app-panel,.mg-panel,.mg-card,.mg-section-agent,.mg-section-merchant,.mg-dashboard-shell,.mg-dashboard-main,.mg-dashboard-panel,.mg-gift-center-page,.mg-gift-center-workspace,.mg-gift-center-main,.mg-gift-feed-column,.mg-gift-list{max-width:100%!important;min-width:0!important}
.mg-app-shell,.mg-app-workspace,.mg-gift-center-page,.mg-gift-center-workspace,.mg-gift-center-main{width:100%!important;overflow-x:hidden!important}
input,select,textarea,button{max-width:100%;min-width:0}
.mg-btn,.mg-pill,.mg-chip,.mg-filter-chip,.mg-tab,.mg-action-card,.mg-quick-action{max-width:100%;min-width:0}
.mg-card-grid,.mg-kpi-grid,.mg-stats-grid,.mg-merchant-kpis,.mg-dashboard-grid,.mg-panel-grid{min-width:0;max-width:100%}
.mg-table-wrap,.mg-scroll-wrap,.mg-overflow-x{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
table{max-width:100%}

@media(max-width:980px){
  .mg-unified-header .mg-header-agent-tools{display:grid!important;grid-template-columns:minmax(0,1fr) 48px!important;align-items:center!important;gap:10px!important;width:100%!important;flex:1 1 auto!important}
  .mg-unified-header .mg-header-agent-search{display:none!important;visibility:hidden!important;pointer-events:none!important}
  .mg-unified-header .mg-header-build-link{grid-column:2!important;justify-self:center!important;align-self:center!important;width:42px!important;height:42px!important;min-width:42px!important;margin:0!important;display:grid!important;place-items:center!important;line-height:1!important}
  .mg-gift-preview-close-floating{top:calc(14px + env(safe-area-inset-top))!important;right:14px!important;z-index:2200!important}
  .mg-account-actions{position:fixed!important;top:68px!important;right:12px!important;left:12px!important;width:auto!important;z-index:30050!important}
  .mg-action-modal-backdrop{z-index:40000!important}
  .mg-action-modal{z-index:40010!important}
  .mg-cart-drawer.is-contained,.mg-cart-drawer{position:fixed!important;inset:0!important;z-index:60000!important}
  .mg-cart-drawer.is-contained .mg-cart-backdrop,.mg-cart-drawer .mg-cart-backdrop{position:fixed!important;inset:0!important;background:rgba(7,18,37,.42)!important;backdrop-filter:blur(3px)!important;z-index:60010!important}
  .mg-cart-drawer-panel{position:fixed!important;top:0!important;right:0!important;bottom:0!important;height:100vh!important;max-height:100vh!important;z-index:60020!important}
  body:has(.mg-cart-drawer.is-contained).mg-cart-open,body.mg-cart-open{overflow:hidden!important}
}

@media(max-width:760px){
  .mg-app-shell,.mg-app-workspace,.mg-dashboard-shell,.mg-dashboard-main,.mg-content,.mg-main{padding-left:min(12px,3vw)!important;padding-right:min(12px,3vw)!important}
  .mg-app-workspace,.mg-gift-center-workspace{padding-left:10px!important;padding-right:10px!important}
  .mg-card-grid,.mg-kpi-grid,.mg-stats-grid,.mg-merchant-kpis,.mg-dashboard-grid,.mg-panel-grid,.mg-package-limit-grid{grid-template-columns:1fr!important;width:100%!important}
  .mg-toolbar,.mg-filter-row,.mg-action-row,.mg-button-row,.mg-form-row{flex-wrap:wrap!important;max-width:100%;min-width:0}
  .mg-toolbar>*,.mg-filter-row>*,.mg-action-row>*,.mg-button-row>*,.mg-form-row>*{min-width:0;max-width:100%}
  .mg-btn,.mg-action-card,.mg-quick-action{white-space:normal!important}
  h1,h2,h3,h4,p,span,a,button,label{overflow-wrap:anywhere}
}

@media(max-width:640px){
  .mg-gift-item-meta{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px 12px!important}
  .mg-gift-item-meta div{min-width:0!important}
  .mg-gift-item-meta dd{white-space:normal!important;overflow:visible!important;text-overflow:clip!important;line-height:1.35!important}
}
