/**
 * Help System Styles — AI Help Bot (Premium)
 * @feature: ui, help
 * @domain: css
 *
 * Full redesign: replaces static bubble system with a modern glassmorphic
 * AI chat panel. Inherits design tokens from magenta-design-tokens.css.
 */

/* ==========================================================================
   BOT PANEL — Glassmorphic Chat Window
   ========================================================================== */

.mg-helpbot {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 340px;
    max-height: 520px;
    display: flex;
    flex-direction: column;
    z-index: 9999999; /* Super high z-index to be above all other components */

    /* Liquid Glass surface */
    background: var(--mg-glass-radial, rgba(255,255,255,0.98));
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--mg-panel-border-glow, rgba(255,255,255,0.5));
    border-radius: var(--mg-radius-xl, 24px);
    box-shadow: var(--mg-panel-shadow-deep, 0 20px 50px rgba(0,0,0,0.18)),
                var(--mg-glass-inset-glow, inset 1px 1px 0 rgba(255,255,255,0.6));
    overflow: hidden;

    /* Hidden by default → slides up on open */
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 280ms cubic-bezier(0.4,0,0.2,1),
                visibility 280ms,
                transform 320ms cubic-bezier(0.32,0.72,0,1);
}

.mg-helpbot--open {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
}

/* Dark Mode */
[data-theme="dark"] .mg-helpbot {
    background: var(--mg-glass-radial, linear-gradient(135deg, rgba(30,41,59,0.9) 0%, rgba(15,23,42,0.95) 100%));
    border-color: var(--mg-glass-border, rgba(255,255,255,0.08));
}

/* ==========================================================================
   HEADER
   ========================================================================== */

.mg-helpbot__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 13px;
    background: linear-gradient(160deg, var(--mg-color-primary-light, #e74c3c) 0%, var(--mg-color-primary, #c0392b) 100%);
    flex-shrink: 0;
}

.mg-helpbot__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mg-helpbot__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.4);
    animation: mg-helpbot-float 3s ease-in-out infinite;
}

.mg-helpbot__avatar svg {
    display: block;
    width: 100%;
    height: 100%;
}

@keyframes mg-helpbot-float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-3px); }
}

.mg-helpbot__header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mg-helpbot__name {
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
}

.mg-helpbot__status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    font-size: 11px;
    color: rgba(255,255,255,0.8);
}

.mg-helpbot__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74,222,128,0.6);
    animation: mg-helpbot-pulse 2s infinite;
}

@keyframes mg-helpbot-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(74,222,128,0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(74,222,128,0); }
    100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

.mg-helpbot__close {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background var(--mg-transition-fast, 150ms);
    flex-shrink: 0;
}

.mg-helpbot__close:hover {
    background: rgba(255,255,255,0.28);
}

.mg-helpbot__close svg {
    width: 15px;
    height: 15px;
}

/* ==========================================================================
   MESSAGES AREA
   ========================================================================== */

.mg-helpbot__messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    min-height: 0;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--mg-gray-300, #d1d5db) transparent;
}

.mg-helpbot__messages::-webkit-scrollbar       { width: 4px; }
.mg-helpbot__messages::-webkit-scrollbar-track  { background: transparent; }
.mg-helpbot__messages::-webkit-scrollbar-thumb  {
    background: var(--mg-gray-300, #d1d5db);
    border-radius: 4px;
}

/* Individual message row */
.mg-helpbot__message {
    display: flex;
    gap: 8px;
    animation: mg-helpbot-msg-in 220ms cubic-bezier(0.32,0.72,0,1) both;
}

@keyframes mg-helpbot-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* User message — right aligned */
.mg-helpbot__message--user {
    flex-direction: row-reverse;
}

.mg-helpbot__message--user .mg-helpbot__bubble {
    background: var(--mg-color-primary, #c0392b);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    box-shadow: var(--mg-glow-primary, 0 4px 14px rgba(192,57,43,0.25));
}

/* Bot message — left aligned */
.mg-helpbot__message--bot {
    align-items: flex-start;
}

.mg-helpbot__bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.mg-helpbot__avatar-mini {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 50%;
    margin-top: 2px;
}

.mg-helpbot__bubble {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 18px 18px 18px 4px;
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    font-size: 13px;
    line-height: 1.55;
    max-width: 100%;
    word-break: break-word;

    background: var(--mg-overlay-subtle, rgba(255,255,255,0.95));
    color: var(--mg-text-main, #1f2937);
    border: 1px solid var(--mg-panel-border-glow, rgba(0,0,0,0.06));
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

[data-theme="dark"] .mg-helpbot__bubble {
    background: rgba(30,41,59,0.85);
    color: var(--mg-text-main, #f9fafb);
    border-color: rgba(255,255,255,0.08);
}

/* "Show me" tool highlight buttons */
.mg-helpbot__tools {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.mg-helpbot__show-tool {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 30px;
    border: 1px solid var(--mg-color-primary, #c0392b);
    background: transparent;
    color: var(--mg-color-primary, #c0392b);
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--mg-transition-fast, 150ms), color var(--mg-transition-fast, 150ms);
    width: fit-content;
}

.mg-helpbot__show-tool:hover {
    background: var(--mg-color-primary, #c0392b);
    color: #fff;
}

/* ==========================================================================
   TYPING INDICATOR
   ========================================================================== */

.mg-helpbot__bubble--typing {
    padding: 12px 16px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.mg-helpbot__bubble--typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mg-text-muted, #9ca3af);
    animation: mg-helpbot-typing 1.2s ease-in-out infinite;
}

.mg-helpbot__bubble--typing span:nth-child(2) { animation-delay: 0.2s; }
.mg-helpbot__bubble--typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mg-helpbot-typing {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

/* ==========================================================================
   COMPOSER (Input + Send)
   ========================================================================== */

.mg-helpbot__composer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--mg-panel-border-glow, rgba(0,0,0,0.06));
    background: var(--mg-overlay-subtle, rgba(255,255,255,0.8));
    flex-shrink: 0;
}

[data-theme="dark"] .mg-helpbot__composer {
    background: rgba(15,23,42,0.6);
    border-top-color: rgba(255,255,255,0.07);
}

.mg-helpbot__input {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 14px;
    border-radius: 30px;
    border: 1.5px solid var(--mg-gray-200, #e5e7eb);
    background: var(--mg-glass-bg-solid, #fff);
    color: var(--mg-text-main, #1f2937);
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    font-size: 13px;
    outline: none;
    transition: border-color var(--mg-transition-fast, 150ms),
                box-shadow var(--mg-transition-fast, 150ms);
}

[data-theme="dark"] .mg-helpbot__input {
    background: rgba(30,41,59,0.8);
    border-color: rgba(255,255,255,0.12);
    color: var(--mg-text-main, #f9fafb);
}

.mg-helpbot__input:focus {
    border-color: var(--mg-color-primary, #c0392b);
    box-shadow: 0 0 0 3px var(--mg-primary-overlay-light, rgba(192,57,43,0.12));
}

.mg-helpbot__input::placeholder {
    color: var(--mg-text-muted, #9ca3af);
    font-size: 12px;
}

.mg-helpbot__send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--mg-btn-primary-bg, linear-gradient(160deg, #e74c3c 0%, #c0392b 100%));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform var(--mg-transition-elastic-fast, 400ms),
                box-shadow var(--mg-transition-smooth, 300ms);
    box-shadow: var(--mg-btn-primary-shadow, 0 4px 14px rgba(192,57,43,0.3));
}

.mg-helpbot__send:hover {
    transform: scale(1.08);
    box-shadow: var(--mg-btn-primary-shadow-hover, 0 8px 22px rgba(192,57,43,0.45));
}

.mg-helpbot__send:active {
    transform: scale(0.95);
}

.mg-helpbot__send svg {
    width: 16px;
    height: 16px;
    margin-left: 1px; /* optical centering for send icon */
}

/* ==========================================================================
   mg-help-toggle button  — Existing toggle augmented for bot
   ========================================================================== */

.mg-help-toggle.active {
    background: var(--mg-color-primary, #c0392b) !important;
    color: #fff !important;
    box-shadow: var(--mg-glow-primary, 0 4px 14px rgba(192,57,43,0.35)) !important;
}

/* Pulsing ring when bot is open to draw attention */
.mg-help-toggle.active::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: inherit;
    border: 2px solid var(--mg-color-primary, #c0392b);
    animation: mg-helpbot-ring 1.5s ease-out infinite;
    pointer-events: none;
}

@keyframes mg-helpbot-ring {
    0%   { opacity: 0.8; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.6); }
}

/* ==========================================================================
   TEMPORARY HIGHLIGHT (no Driver.js fallback)
   ========================================================================== */

@keyframes mg-helpbot-highlight-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.5); }
    50%       { box-shadow: 0 0 0 10px rgba(192,57,43,0); }
}

.mg-helpbot-highlight {
    outline: 2px solid var(--mg-color-primary, #c0392b) !important;
    outline-offset: 3px !important;
    animation: mg-helpbot-highlight-pulse 0.7s ease 3 !important;
    border-radius: var(--mg-radius-sm, 6px) !important;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 480px) {
    .mg-helpbot {
        bottom: 80px;
        right: 8px;
        left: 8px;
        width: auto;
        max-height: 60vh;
    }
}

/* ============================================================================
   LEGACY BUBBLE STYLES — kept minimal for potential Driver.js overlap
   (These are only used if the admin manually calls the old HelpManager methods)
   ========================================================================== */

/* Driver.js Theme Overrides — shared with both systems */
.driver-popover {
    border-radius: var(--mg-radius-md, 12px);
    box-shadow: var(--mg-panel-shadow-deep, 0 20px 50px rgba(0,0,0,0.15));
    background: var(--mg-glass-bg-solid, #fff);
    color: var(--mg-text-main, #1f2937);
    font-family: var(--mg-font-family, 'Inter', sans-serif);
    border: 1px solid var(--mg-panel-border-glow, rgba(0,0,0,0.06));
}

[data-theme="dark"] .driver-popover {
    background: var(--mg-glass-bg-solid, #111827);
    border-color: rgba(255,255,255,0.1);
}

.driver-popover-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--mg-text-main, #1f2937);
    margin-bottom: 6px;
}

.driver-popover-description {
    font-size: 13px;
    line-height: 1.6;
    color: var(--mg-text-muted, #6b7280);
}

.driver-popover-next-btn,
.driver-popover-close-btn {
    background: var(--mg-color-primary, #c0392b);
    color: white;
    border: none;
    padding: 7px 16px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--mg-transition-fast, 150ms);
}

.driver-popover-next-btn:hover {
    background: var(--mg-color-primary-hover, #96281b);
}

.driver-popover-prev-btn.driver-popover-btn-disabled {
    display: none !important;
}
