/*
 * Dex launcher — always loaded with the page: tokens, base rules, the launcher and
 * the help entries outside the widget. The chat window's styles (dex.css) load with
 * the widget on first use (assets/dex-loader.js). Keep launcher rules here, so that
 * loading dex.css never restyles or moves the launcher.
 */

/* ---------- Tokens ---------- */
#mzpc-root {
    --dex-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --dex-ink: #171717;
    --dex-text: #262626;
    --dex-secondary: #525252;
    --dex-muted: #666666;
    --dex-faint: #8a8a8a;
    --dex-accent: #dc2626;
    --dex-accent-hover: #b91c1c;
    --dex-accent-text: #b91c1c;
    --dex-accent-soft: #fef2f2;
    --dex-accent-line: #fecaca;
    --dex-success: #15803d;
    --dex-warning: #b45309;
    --dex-warning-text: #78350f;
    --dex-warning-soft: #fffbeb;
    --dex-warning-line: #fde68a;
    --dex-info-soft: #f5f5f5;
    --dex-bg: #fafafa;
    --dex-surface: #ffffff;
    --dex-surface-muted: #f5f5f5;
    --dex-line: #e5e5e5;
    --dex-line-strong: #d4d4d4;
    --dex-radius-sm: 6px;
    --dex-radius: 8px;
    --dex-radius-lg: 12px;
    --dex-pill: 999px;
    --dex-shadow-sm: 0 1px 2px rgb(23 23 23 / .05);
    --dex-shadow: 0 8px 24px rgb(23 23 23 / .08);
    --dex-shadow-window: 0 24px 64px rgb(23 23 23 / .16), 0 2px 8px rgb(23 23 23 / .06);
    --dex-ease: cubic-bezier(.16, 1, .3, 1);
    --dex-gutter: 20px;
    /* Kept for compatibility with runtime-set custom properties. */
    --pc-ease: var(--dex-ease);
    position: relative;
    z-index: 99990;
    color: var(--dex-text);
    font: 14px/1.55 var(--dex-font);
    letter-spacing: 0;
}

/* ---------- Base ---------- */
#mzpc-root *, #mzpc-root *::before, #mzpc-root *::after { box-sizing: border-box; }
#mzpc-root[hidden], #mzpc-root [hidden] { display: none !important; }
#mzpc-root :is(button, input, textarea, select) { font: inherit; letter-spacing: 0; text-transform: none; }
#mzpc-root button { margin: 0; cursor: pointer; min-height: 36px; color: inherit; }
#mzpc-root button:disabled { cursor: not-allowed; opacity: .55; }
#mzpc-root a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
#mzpc-root :is(button, a, textarea, input, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--dex-accent);
    outline-offset: 2px;
}
#mzpc-root svg { flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#mzpc-root .mzpc-sr, #mzpc-root .mzpc-usage-caption {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Launcher ---------- */
#mzpc-root .mzpc-launch {
    position: fixed; right: max(24px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 12px;
    max-width: calc(100vw - 28px); min-height: 64px; padding: 8px 12px 8px 8px;
    border: 1px solid var(--dex-line); border-radius: 16px;
    background: var(--dex-surface); color: var(--dex-ink);
    box-shadow: var(--dex-shadow), var(--dex-shadow-sm);
    text-align: left; isolation: isolate;
    /* Clears a sticky bottom bar (product buy bar, cart checkout bar). */
    translate: 0 calc(-1 * var(--mzs-floating-lift, 0px));
    transition: transform 180ms var(--dex-ease), translate 220ms var(--dex-ease), box-shadow 180ms var(--dex-ease), border-color 180ms var(--dex-ease);
}
#mzpc-root .mzpc-launch:hover { border-color: var(--dex-line-strong); box-shadow: 0 12px 32px rgb(23 23 23 / .12), var(--dex-shadow-sm); }
#mzpc-root .mzpc-launch:active { transform: scale(.98); }
#mzpc-root .mzpc-launch[aria-expanded="true"] { visibility: hidden; pointer-events: none; }
#mzpc-root .mzpc-launch[aria-busy="true"] { cursor: progress; }
#mzpc-root .mzpc-launch > .mzpc-avatar { width: 46px; height: 46px; border-radius: 14px; background: transparent; }
#mzpc-root .mzpc-launch-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#mzpc-root .mzpc-launch-title { font-size: 15px; font-weight: 700; line-height: 1.25; }
#mzpc-root .mzpc-launch-hint { font-size: 12px; line-height: 1.35; color: var(--dex-muted); }
#mzpc-root .mzpc-launch-icon {
    display: grid; place-items: center; flex: none; width: 34px; height: 34px; margin-left: 2px;
    border-radius: var(--dex-radius); background: var(--dex-accent); color: #fff;
    transition: background-color 180ms var(--dex-ease);
}
#mzpc-root .mzpc-launch-icon svg { width: 19px; height: 19px; }
#mzpc-root .mzpc-launch:hover .mzpc-launch-icon { background: var(--dex-accent-hover); }
#mzpc-root .mzpc-launch.mzpc-has-reply::after {
    content: ''; position: absolute; right: 8px; top: 8px; width: 10px; height: 10px;
    border: 2px solid #fff; border-radius: 50%; background: var(--dex-success);
}
#mzpc-root .mzpc-notification-badge {
    position: absolute; right: -4px; top: -6px; min-width: 22px; padding: 2px 6px;
    border: 2px solid #fff; border-radius: var(--dex-pill); background: var(--dex-accent); color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1.3; text-align: center;
}

/* Shared avatar frame (launcher, header, replies, compact bar). */
#mzpc-root .mzpc-avatar {
    display: inline-block; flex: none; width: 48px; height: 48px; overflow: hidden;
    border-radius: 28%; background: var(--dex-surface); vertical-align: middle;
}
#mzpc-root .mzpc-avatar img { display: block; width: 100%; height: 100%; max-width: none; object-fit: contain; }

/* ---------- Outside the widget ---------- */
/* Account page: help entry next to the account navigation. */
.mzpc-account-help {
    display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 0 24px; padding: 18px 22px;
    border: 1px solid #fecaca; border-radius: 12px; background: #fef2f2; color: #262626;
    font: 14px/1.6 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.mzpc-account-help p { margin: 4px 0 0; font-size: 14px; }
.mzpc-account-help button {
    flex: none; min-height: 44px; padding: 10px 16px; border: 0; border-radius: 8px; background: #dc2626; color: #fff;
    font: 600 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: normal; text-transform: none; cursor: pointer;
}
.mzpc-account-help button:hover { background: #b91c1c; }
.mzpc-account-help button:focus-visible { outline: 2px solid #dc2626; outline-offset: 2px; }
@media (max-width: 600px) { .mzpc-account-help { flex-direction: column; align-items: flex-start; gap: 12px; } }

/* Keep the shop's own cart/wishlist/quickview drawers unobstructed. */
body:has(#cart-sidebar.nasa-active) #mzpc-root .mzpc-launch,
body:has(#nasa-wishlist-sidebar.nasa-active) #mzpc-root .mzpc-launch,
body:has(#nasa-quickview-sidebar.nasa-active) #mzpc-root .mzpc-launch { display: none; }
/* Reserve the launcher corner; hide storefront shortcuts while the chat is open. */
body:has(#mzpc-root:not([hidden])) .msec-public-admin-entry { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
body:has(#mzpc-root:not([hidden])) .nasa-static-group-btn { bottom: calc(81px + env(safe-area-inset-bottom, 0px)); }
body:has(#mzpc-root:not([hidden])) #mzs-back-to-top { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
body:has(#mzpc-root:not([hidden])):has(.msec-public-admin-entry) .nasa-static-group-btn { bottom: calc(131px + env(safe-area-inset-bottom, 0px)); }
body:has(#mzpc-root:not([hidden])):has(.msec-public-admin-entry) #mzs-back-to-top { bottom: calc(146px + env(safe-area-inset-bottom, 0px)); }
body:has(#mzpc-root:not([hidden]) #mzpc-panel[open]) :is(.msec-public-admin-entry, .nasa-static-group-btn, #mzs-back-to-top) { display: none !important; }

/* ---------- Phones ---------- */
@media (max-width: 520px) {
    #mzpc-root .mzpc-launch { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); min-height: 60px; gap: 10px; padding: 7px 10px 7px 7px; }
    #mzpc-root .mzpc-launch > .mzpc-avatar { width: 44px; height: 44px; }
    #mzpc-root .mzpc-launch-icon { width: 32px; height: 32px; }
}
@media (max-width: 520px), (pointer: coarse) {
    #mzpc-root :is(button, a, summary) { touch-action: manipulation; }
}

/* ---------- Motion and accessibility ---------- */
@media (hover: hover) {
    #mzpc-root .mzpc-launch:hover:not(:active) { transform: translateY(-2px); }
}
@media (prefers-reduced-motion: reduce) {
    #mzpc-root *, #mzpc-root *::before, #mzpc-root *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
    #mzpc-root :is(button, a, textarea, input, summary):focus-visible { outline: 2px solid CanvasText; }
}
