/* Microapp host — content-first workspace (emil-design-eng) */

:root {
  --microapp-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --microapp-ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --microapp-stage-max: 680px;
  --microapp-stage-min: min(640px, calc(100dvh - 120px));
}

body.microapp-host {
  min-height: 100dvh;
  background: var(--bg);
}

body.microapp-host::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 55% 38% at 50% -6%, var(--brand-primary-dim, rgba(124, 92, 255, 0.1)), transparent 58%);
}

body.microapp-host > * {
  position: relative;
  z-index: 1;
}

/* ── Layout: stage is the hero ── */
.microapp-host__workspace {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: calc(var(--microapp-stage-max) + 48px);
  margin: 0 auto;
  padding: 12px 16px 20px;
}

body.shell-standalone-topbar .microapp-host__workspace {
  flex: 1;
  min-height: 0;
  padding-top: 16px;
}

/* Desktop: no duplicate bento — subnav handles navigation */
@media (min-width: 1024px) {
  body.shell-standalone-topbar #app-bento-mount,
  body.shell-standalone-topbar #wallet-bento-mount {
    display: none !important;
  }
}

/* Mobile chips (replaces hero + tile grid) */
.microapp-mobile-chips {
  flex-shrink: 0;
  margin-bottom: 10px;
}

.microapp-chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 2px 0 4px;
}

.microapp-chip-row::-webkit-scrollbar { display: none; }

.microapp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--s1);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition:
    transform 140ms var(--microapp-ease-out),
    border-color 160ms var(--microapp-ease-out),
    background 160ms ease,
    color 160ms ease;
}

.microapp-chip:active {
  transform: scale(0.97);
}

.microapp-chip.is-active {
  border-color: var(--brand-primary);
  background: var(--brand-primary-dim);
  color: var(--brand-primary);
}

.microapp-chips--vela .microapp-chip.is-active {
  border-color: #C45C26;
  background: #FFF4EB;
  color: #9A4E12;
}

.microapp-chips--wallet .microapp-chip.is-active {
  border-color: #0D9488;
  background: #ECFDF5;
  color: #047857;
}

.microapp-chip-icon {
  font-size: 14px;
  line-height: 1;
}

@media (hover: hover) and (pointer: fine) {
  .microapp-chip:hover {
    border-color: var(--border-md);
    color: var(--text-1);
  }
}

/* Mobile quick tabs */
.microapp-quick-tabs {
  flex-shrink: 0;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: transparent;
  border-bottom: none;
}

.microapp-quick-tabs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.microapp-quick-tabs-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0 0 8px 2px;
}

body.shell-standalone-topbar .microapp-quick-tabs {
  display: none !important;
}

body.shell-standalone-topbar .journey-breadcrumb {
  display: none !important;
}

/* Desktop: subnav is source of truth — hide duplicate stage chrome */
@media (min-width: 1024px) {
  body.shell-standalone-topbar.microapp-host .microapp-stage-head {
    display: none !important;
  }

  body.shell-standalone-topbar.microapp-host .microapp-stage {
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  body.microapp-host--wallet .microapp-stage-body {
    background: #0c0c12;
    border-radius: var(--r-lg);
  }

  body.microapp-host--vela .microapp-stage-body {
    background: #0D1117;
    border-radius: var(--r-lg);
  }

  body.shell-standalone-topbar.microapp-host .microapp-host__workspace {
    max-width: min(920px, 100%);
  }
}

@media (max-width: 1023px) {
  body.microapp-host #app-bento-mount,
  body.microapp-host #wallet-bento-mount,
  body.microapp-host .microapp-mobile-chips,
  body.microapp-host .microapp-quick-tabs,
  body.microapp-host .journey-breadcrumb,
  body.microapp-host .microapp-stage-head {
    display: none !important;
  }
}

/* ── Shell + stage card ── */
body.microapp-host .shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.microapp-host .microapp-stage {
  flex: 1;
  min-height: var(--microapp-stage-min);
  display: flex;
  flex-direction: column;
  position: relative;
  margin: 0;
  border: 1px solid var(--border-md);
  border-radius: var(--r-lg);
  background: var(--s1);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

body.microapp-host--vela .microapp-stage {
  box-shadow:
    var(--shadow-md),
    0 24px 48px -32px rgba(196, 92, 38, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

body.microapp-host--wallet .microapp-stage {
  box-shadow:
    var(--shadow-md),
    0 24px 48px -32px rgba(13, 148, 136, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* Stage chrome — tells user where they are */
.microapp-stage-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--s1);
}

.microapp-stage-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.microapp-stage-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--s2);
}

body.microapp-host--vela .microapp-stage-icon {
  background: linear-gradient(135deg, #FFF4EB, #F0EBE3);
}

.microapp-stage-title-wrap {
  min-width: 0;
}

.microapp-stage-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.25;
  transition:
    opacity 180ms var(--microapp-ease-out),
    filter 180ms var(--microapp-ease-out);
}

.microapp-stage-sub {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  transition:
    opacity 180ms var(--microapp-ease-out),
    filter 180ms var(--microapp-ease-out);
}

.microapp-stage-title.is-swapping,
.microapp-stage-sub.is-swapping {
  opacity: 0.45;
  filter: blur(2px);
}

.microapp-stage-nudge-wrap {
  flex-shrink: 0;
}

.microapp-stage-nudge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(240px, 42vw);
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-md);
  background: var(--s2);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 140ms var(--microapp-ease-out), background 160ms ease;
}

.microapp-stage-nudge:active {
  transform: scale(0.97);
}

.microapp-stage-nudge-kicker {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand-primary);
}

body.microapp-host--vela .microapp-stage-nudge-kicker {
  color: #C45C26;
}

.microapp-stage-nudge-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.microapp-stage-nudge-arrow {
  opacity: 0.5;
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .microapp-stage-nudge:hover {
    background: var(--brand-primary-dim);
  }
}

@media (max-width: 640px) {
  .microapp-stage-nudge-kicker { display: none; }
  .microapp-stage-nudge { max-width: 160px; }
}

/* Stage body + iframe */
.microapp-stage-body {
  flex: 1;
  min-height: min(480px, calc(100dvh - 240px));
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.microapp-host .microapp-stage .frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex: none;
  border: 0;
  background: var(--bg);
  opacity: 1;
  transition:
    opacity 200ms var(--microapp-ease-out),
    filter 200ms var(--microapp-ease-out);
}

body.microapp-host .microapp-stage.is-loading:not(.is-intent-swapping) .frame {
  opacity: 0.4;
  filter: blur(2px);
}

body.microapp-host .microapp-stage.is-intent-swapping .frame {
  opacity: 0.92;
  filter: none;
  transition: opacity 150ms var(--microapp-ease-out);
}

body.microapp-host .microapp-stage.is-swapping .frame {
  opacity: 0.35;
  filter: blur(2px);
}

body.microapp-host--wallet .microapp-stage .loading {
  border-radius: 0;
  background: #0c0c12;
  color: rgba(226, 232, 240, 0.72);
}

body.microapp-host--vela .microapp-stage .loading {
  border-radius: 0;
  background: #0D1117;
  color: rgba(237, 232, 227, 0.65);
}

body.microapp-host .microapp-stage .loading {
  border-radius: 0;
  background: var(--s1);
}

body.microapp-host .microapp-stage .loading .dot {
  background: var(--brand-primary);
  animation: microappLoadPulse 720ms var(--microapp-ease-out) infinite;
}

@keyframes microappLoadPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1); }
}

body.microapp-host .hd-context-strip.visible {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

body.microapp-host .error-panel {
  border-radius: var(--r-md);
  margin: 10px;
  inset: auto;
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 4;
}

.microapp-quick-tabs .tab-btn,
.error-btn {
  transition:
    transform 140ms var(--microapp-ease-out),
    box-shadow 160ms var(--microapp-ease-out),
    border-color 160ms var(--microapp-ease-out),
    background 160ms ease;
}

.microapp-quick-tabs .tab-btn:active,
.error-btn:active {
  transform: scale(0.97);
}

/* Primary story tabs — first item reads as "start here" on mobile */
.microapp-quick-tabs-row .tab-btn:first-child {
  font-weight: 700;
}

body.microapp-host--vela .microapp-quick-tabs-row .tab-btn[data-intent="checkin"].active,
body.microapp-host--wallet .microapp-quick-tabs-row .tab-btn[data-intent="dashboard"].active {
  box-shadow: inset 0 0 0 1px currentColor;
}

/* First paint only — not on every intent switch (seen 100+/day) */
@keyframes microappWorkspaceIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

body.microapp-host.is-ready .microapp-stage {
  animation: microappWorkspaceIn 240ms var(--microapp-ease-out) forwards;
}

@media (max-width: 1023px) {
  :root {
    --microapp-stage-min: min(520px, calc(100dvh - 220px));
  }

  .microapp-host__workspace {
    max-width: none;
    padding: 0 12px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.microapp-host.is-ready .microapp-stage {
    animation: none;
  }

  body.microapp-host .microapp-stage .frame,
  body.microapp-host .microapp-stage.is-swapping .frame,
  body.microapp-host .microapp-stage.is-intent-swapping .frame,
  body.microapp-host .microapp-stage.is-loading .frame {
    opacity: 1;
    filter: none;
    transition: opacity 0.15s ease;
  }

  .microapp-stage-title.is-swapping,
  .microapp-stage-sub.is-swapping {
    opacity: 0.7;
    filter: none;
  }

  .microapp-chip,
  .microapp-quick-tabs .tab-btn,
  .microapp-stage-nudge,
  .error-btn {
    transition: none;
  }

  body.microapp-host .microapp-stage .loading .dot {
    animation: none;
    opacity: 0.65;
  }
}
