/* ============================================
   MELO — SECURENCE AI Guide
   Premium Floating Assistant Styles
   Matches SECURENCE design system
   ============================================ */

/* ──────────── CSS Variables (Melo-specific) ──────────── */
:root {
    --melo-orb-size: 52px;
    --melo-gradient: linear-gradient(135deg, #d946ef, #a855f7, #3b82f6);
    --melo-gradient-hover: linear-gradient(135deg, #e879f9, #c084fc, #60a5fa);
    --melo-panel-bg: rgba(10, 10, 28, 0.88);
    --melo-panel-border: rgba(168, 85, 247, 0.12);
    --melo-panel-width: 400px;
    --melo-panel-height: 600px;
    --melo-msg-user-bg: linear-gradient(135deg, rgba(168,85,247,0.25), rgba(59,130,246,0.18));
    --melo-msg-ai-bg: rgba(255, 255, 255, 0.04);
    --melo-z-orb: 9000;
    --melo-z-panel: 9001;
}

/* ──────────── Hide during onboarding ──────────── */
body.ob-locked .melo-orb,
body.ob-locked .melo-panel { display: none !important; }

/* ──────────── Floating Orb ──────────── */
.melo-orb {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: var(--melo-orb-size);
    height: var(--melo-orb-size);
    border-radius: 50%;
    background: var(--melo-gradient);
    z-index: var(--melo-z-orb);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    outline: none;
    padding: 0;
    box-shadow:
        0 0 20px rgba(168, 85, 247, 0.35),
        0 0 60px rgba(168, 85, 247, 0.15),
        0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    will-change: transform;
}

.melo-orb::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--melo-gradient);
    opacity: 0.4;
    z-index: -1;
    animation: meloBreath 3s ease-in-out infinite;
    pointer-events: none;
}

.melo-orb:hover {
    transform: scale(1.1);
    box-shadow:
        0 0 30px rgba(168, 85, 247, 0.5),
        0 0 80px rgba(168, 85, 247, 0.2),
        0 6px 30px rgba(0, 0, 0, 0.4);
}

.melo-orb:active { transform: scale(0.95); }

.melo-orb.dragging {
    cursor: grabbing;
    transition: none;
}

.melo-orb.open .melo-orb-icon { opacity: 0; transform: scale(0.5) rotate(90deg); }
.melo-orb.open .melo-orb-close { opacity: 1; transform: scale(1) rotate(0deg); }

/* Orb Icons */
.melo-orb-icon,
.melo-orb-close {
    position: absolute;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.melo-orb-icon { opacity: 1; transform: scale(1); }
.melo-orb-close { opacity: 0; transform: scale(0.5) rotate(-90deg); }

.melo-orb-icon svg,
.melo-orb-close svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

/* Ripple on click */
.melo-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: meloRipple 0.6s ease-out forwards;
    pointer-events: none;
}

/* Notification badge */
.melo-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid var(--bg-primary, #050510);
    display: none;
}
.melo-badge.visible { display: block; }

/* ──────────── Chat Panel ──────────── */
.melo-panel {
    position: fixed;
    bottom: 92px;
    right: 28px;
    width: var(--melo-panel-width);
    height: var(--melo-panel-height);
    max-height: calc(100vh - 120px);
    z-index: var(--melo-z-panel);
    background: var(--melo-panel-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--melo-panel-border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        0 0 50px rgba(168, 85, 247, 0.08),
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    pointer-events: none;
    will-change: transform, opacity;
}

.melo-panel.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ──────────── Panel Header ──────────── */
.melo-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.08);
    background: rgba(15, 15, 35, 0.5);
    flex-shrink: 0;
}

.melo-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--melo-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.3);
}

.melo-avatar svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.melo-avatar-pulse {
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1.5px solid rgba(168, 85, 247, 0.4);
    animation: meloAvatarPulse 2s ease-in-out infinite;
}

.melo-header-info { flex: 1; min-width: 0; }

.melo-header-title {
    font-family: var(--font-display, 'Outfit', sans-serif);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-primary, #f1f5f9);
    line-height: 1.2;
}

.melo-header-subtitle {
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 0.65rem;
    color: var(--text-muted, rgba(241, 245, 249, 0.35));
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.melo-online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    animation: meloOnline 2s ease-in-out infinite;
}

.melo-header-actions {
    display: flex;
    gap: 4px;
}

.melo-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary, rgba(241, 245, 249, 0.6));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.melo-header-btn:hover {
    background: rgba(168, 85, 247, 0.1);
    color: var(--text-primary, #f1f5f9);
}

.melo-header-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ──────────── Chat Body ──────────── */
.melo-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.melo-body::-webkit-scrollbar { width: 4px; }
.melo-body::-webkit-scrollbar-track { background: transparent; }
.melo-body::-webkit-scrollbar-thumb {
    background: rgba(168, 85, 247, 0.2);
    border-radius: 4px;
}

/* ──────────── Messages ──────────── */
.melo-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: meloMsgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.melo-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.melo-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--melo-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.melo-msg-avatar svg {
    width: 14px;
    height: 14px;
    stroke: #fff;
    stroke-width: 2;
    fill: none;
}

.melo-msg.user .melo-msg-avatar {
    background: rgba(168, 85, 247, 0.2);
    border: 1px solid rgba(168, 85, 247, 0.3);
}

.melo-msg.user .melo-msg-avatar svg { stroke: #c084fc; }

.melo-msg-content {
    flex: 1;
    min-width: 0;
}

.melo-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--text-primary, #f1f5f9);
    word-break: break-word;
}

.melo-msg.assistant .melo-msg-bubble {
    background: var(--melo-msg-ai-bg);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 4px 14px 14px 14px;
}

.melo-msg.user .melo-msg-bubble {
    background: var(--melo-msg-user-bg);
    border: 1px solid rgba(168, 85, 247, 0.15);
    border-radius: 14px 4px 14px 14px;
}

/* Markdown inside messages */
.melo-msg-bubble p { margin: 0 0 8px; }
.melo-msg-bubble p:last-child { margin-bottom: 0; }
.melo-msg-bubble strong { font-weight: 600; color: #e2e8f0; }
.melo-msg-bubble em { font-style: italic; color: rgba(241, 245, 249, 0.8); }
.melo-msg-bubble code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.15);
    padding: 1px 5px;
    border-radius: 4px;
    color: #c084fc;
}
.melo-msg-bubble pre {
    margin: 8px 0;
    padding: 10px 12px;
    background: rgba(5, 5, 16, 0.6);
    border: 1px solid rgba(168, 85, 247, 0.1);
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.76rem;
}
.melo-msg-bubble pre code {
    background: none;
    border: none;
    padding: 0;
    color: var(--text-primary);
}
.melo-msg-bubble ul, .melo-msg-bubble ol {
    margin: 6px 0;
    padding-left: 18px;
}
.melo-msg-bubble li { margin-bottom: 3px; }
.melo-msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.76rem;
}
.melo-msg-bubble th, .melo-msg-bubble td {
    padding: 5px 8px;
    border: 1px solid rgba(168, 85, 247, 0.1);
    text-align: left;
}
.melo-msg-bubble th {
    background: rgba(168, 85, 247, 0.08);
    font-weight: 600;
}
.melo-msg-bubble a {
    color: #a855f7;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Message meta & actions */
.melo-msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    padding: 0 4px;
}

.melo-msg-time {
    font-size: 0.6rem;
    color: var(--text-muted, rgba(241, 245, 249, 0.3));
    font-family: var(--font-body);
}

.melo-msg-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.melo-msg:hover .melo-msg-actions { opacity: 1; }

.melo-msg-action-btn {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.2s ease;
}

.melo-msg-action-btn:hover {
    background: rgba(168, 85, 247, 0.1);
    color: var(--text-primary);
}

.melo-msg-action-btn svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* Typing indicator */
.melo-typing {
    display: flex;
    gap: 8px;
    max-width: 88%;
    padding: 0;
}

.melo-typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--melo-msg-ai-bg);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 4px 14px 14px 14px;
}

.melo-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(168, 85, 247, 0.5);
    animation: meloTypingBounce 1.2s ease-in-out infinite;
}
.melo-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.melo-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* Welcome message */
.melo-welcome {
    text-align: center;
    padding: 20px 10px 8px;
}

.melo-welcome-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--melo-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    box-shadow: 0 0 25px rgba(168, 85, 247, 0.3);
}

.melo-welcome-avatar svg {
    width: 24px;
    height: 24px;
    stroke: #fff;
    stroke-width: 2;
    fill: none;
}

.melo-welcome-title {
    font-family: var(--font-display, 'Outfit');
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.melo-welcome-text {
    font-size: 0.78rem;
    color: var(--text-secondary, rgba(241, 245, 249, 0.6));
    line-height: 1.5;
}

/* ──────────── Suggestion Chips ──────────── */
.melo-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px 4px;
    flex-shrink: 0;
}

.melo-chip {
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid rgba(168, 85, 247, 0.15);
    background: rgba(168, 85, 247, 0.06);
    color: var(--text-secondary, rgba(241, 245, 249, 0.6));
    font-family: var(--font-body);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.melo-chip:hover {
    background: rgba(168, 85, 247, 0.12);
    border-color: rgba(168, 85, 247, 0.3);
    color: var(--text-primary);
    transform: translateY(-1px);
}

/* ──────────── Input Area ──────────── */
.melo-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(168, 85, 247, 0.08);
    background: rgba(15, 15, 35, 0.4);
    flex-shrink: 0;
}

.melo-input-wrap {
    flex: 1;
    position: relative;
}

.melo-input {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 9px 14px;
    background: rgba(15, 15, 35, 0.6);
    border: 1px solid rgba(168, 85, 247, 0.1);
    border-radius: 12px;
    color: var(--text-primary, #f1f5f9);
    font-family: var(--font-body, 'Inter');
    font-size: 0.82rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    overflow-y: auto;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.melo-input::placeholder {
    color: var(--text-muted, rgba(241, 245, 249, 0.3));
}

.melo-input:focus {
    border-color: rgba(168, 85, 247, 0.3);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.08);
}

.melo-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: var(--melo-gradient);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: all 0.25s ease;
    box-shadow: 0 2px 12px rgba(168, 85, 247, 0.3);
}

.melo-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
}

.melo-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.melo-send-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ──────────── Settings Panel (placeholder) ──────────── */
.melo-settings {
    position: absolute;
    inset: 0;
    background: var(--melo-panel-bg);
    backdrop-filter: blur(24px);
    z-index: 5;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.melo-settings.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* ──────────── Keyframe Animations ──────────── */
@keyframes meloBreath {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50% { transform: scale(1.35); opacity: 0.15; }
}

@keyframes meloRipple {
    to { transform: scale(3); opacity: 0; }
}

@keyframes meloAvatarPulse {
    0%, 100% { transform: scale(1); opacity: 0.4; }
    50% { transform: scale(1.15); opacity: 0.1; }
}

@keyframes meloOnline {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes meloTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes meloMsgIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes meloFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ──────────── Responsive ──────────── */
@media (max-width: 480px) {
    .melo-orb {
        bottom: 18px;
        right: 18px;
        width: 48px;
        height: 48px;
    }
    .melo-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        transform-origin: bottom center;
    }
    .melo-panel.open { border-radius: 0; }
    .melo-header { padding: 14px 16px; }
    .melo-body { padding: 12px; }
    .melo-suggestions { padding: 6px 12px 2px; }
    .melo-input-area { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

@media (min-width: 481px) and (max-width: 768px) {
    .melo-panel {
        width: calc(100vw - 40px);
        right: 20px;
        bottom: 84px;
        max-height: calc(100vh - 110px);
    }
}

/* ──────────── Reduced Motion ──────────── */
@media (prefers-reduced-motion: reduce) {
    .melo-orb::before { animation: none; opacity: 0.2; }
    .melo-orb { transition-duration: 0.001ms; }
    .melo-panel { transition-duration: 0.001ms; }
    .melo-msg { animation: none; }
    .melo-typing-dot { animation: none; opacity: 0.5; }
    .melo-avatar-pulse { animation: none; }
    .melo-online-dot { animation: none; }
    .melo-chip { transition-duration: 0.001ms; }
}

/* ──────────── Accessibility ──────────── */
.melo-orb:focus-visible {
    outline: 2px solid #a855f7;
    outline-offset: 3px;
}
.melo-header-btn:focus-visible,
.melo-chip:focus-visible,
.melo-send-btn:focus-visible,
.melo-msg-action-btn:focus-visible {
    outline: 2px solid #a855f7;
    outline-offset: 2px;
}
