/* ============================================
   MELO — SECURENCE AI Guide
   SpaceX / OpenAI / Anthropic Dark Aesthetic
   ============================================ */

:root {
    --melo-orb-size: 50px;
    --melo-gradient: linear-gradient(135deg, #ffffff, #d4d4d8);
    --melo-gradient-hover: linear-gradient(135deg, #ffffff, #e4e4e7);
    --melo-panel-bg: rgba(9, 9, 12, 0.96);
    --melo-panel-border: rgba(255, 255, 255, 0.16);
    --melo-panel-width: 400px;
    --melo-panel-height: 580px;
    --melo-msg-user-bg: rgba(255, 255, 255, 0.12);
    --melo-msg-ai-bg: rgba(255, 255, 255, 0.04);
    --melo-z-orb: 9000;
    --melo-z-panel: 9001;
}

body.ob-locked .melo-orb,
body.ob-locked .melo-panel { display: none !important; }

/* ──────────── Floating Orb ──────────── */
.melo-orb {
    position: fixed;
    bottom: 26px;
    right: 26px;
    width: var(--melo-orb-size);
    height: var(--melo-orb-size);
    border-radius: 50%;
    background: #ffffff;
    color: #000000;
    z-index: var(--melo-z-orb);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.3);
    outline: none;
    padding: 0;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.65);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    user-select: none;
    will-change: transform;
}

.melo-orb::before {
    display: none;
}

.melo-orb:hover {
    transform: scale(1.06);
    background: #e4e4e7;
}

.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); }

.melo-orb-icon,
.melo-orb-close {
    position: absolute;
    transition: all 0.25s 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: 22px;
    height: 22px;
    fill: none;
    stroke: #000000;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.melo-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.16);
    transform: scale(0);
    animation: meloRipple 0.5s ease-out forwards;
    pointer-events: none;
}

.melo-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid #000000;
    display: none;
}
.melo-badge.visible { display: block; }

/* ──────────── Chat Panel ──────────── */
.melo-panel {
    position: fixed;
    bottom: 88px;
    right: 26px;
    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(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--melo-panel-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.85);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}

.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: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
    background: #060608;
    flex-shrink: 0;
}

.melo-avatar {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

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

.melo-avatar-pulse {
    display: none;
}

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

.melo-header-title {
    font-family: var(--font-display, 'Plus Jakarta Sans', sans-serif);
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text-primary, #fafafa);
    line-height: 1.2;
}

.melo-header-subtitle {
    font-family: var(--font-display, 'Inter', sans-serif);
    font-size: 0.62rem;
    color: var(--text-muted, #71717a);
    display: flex;
    align-items: center;
    gap: 5px;
}

.melo-online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
}

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

.melo-header-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #a1a1aa);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
    padding: 0;
}

.melo-header-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.melo-header-btn svg {
    width: 15px;
    height: 15px;
    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(255, 255, 255, 0.16);
    border-radius: 4px;
}

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

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

.melo-msg-avatar {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

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

.melo-msg.user .melo-msg-avatar {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

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

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

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

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

.melo-msg.user .melo-msg-bubble {
    background: var(--melo-msg-user-bg);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.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: #ffffff; }
.melo-msg-bubble em { font-style: italic; color: var(--text-secondary); }
.melo-msg-bubble code {
    font-family: var(--font-display, 'Inter', sans-serif);
    font-size: 0.78rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 1px 5px;
    border-radius: 4px;
    color: #ffffff;
}
.melo-msg-bubble pre {
    margin: 8px 0;
    padding: 10px 12px;
    background: #040406;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    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(255, 255, 255, 0.12);
    text-align: left;
}
.melo-msg-bubble th {
    background: rgba(255, 255, 255, 0.06);
    font-weight: 600;
}
.melo-msg-bubble a {
    color: #ffffff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

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

.melo-msg-time {
    font-family: var(--font-display, 'Inter', sans-serif);
    font-size: 0.6rem;
    color: var(--text-muted, #71717a);
}

.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: background 0.2s ease, color 0.2s ease;
}

.melo-msg-action-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.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%;
}

.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.08);
    border-radius: 10px;
}

.melo-typing-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    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: 18px 10px 8px;
}

.melo-welcome-avatar {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
}

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

.melo-welcome-title {
    font-family: var(--font-display, 'Plus Jakarta Sans', sans-serif);
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.melo-welcome-text {
    font-size: 0.8rem;
    color: var(--text-secondary, #a1a1aa);
    line-height: 1.5;
}

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

.melo-chip {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary, #a1a1aa);
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.melo-chip:hover {
    background: #ffffff;
    border-color: #ffffff;
    color: #000000;
}

/* ──────────── Input Area ──────────── */
.melo-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    background: #060608;
    flex-shrink: 0;
}

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

.melo-input {
    width: 100%;
    min-height: 38px;
    max-height: 120px;
    padding: 9px 12px;
    background: #0a0a0d;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    color: var(--text-primary, #fafafa);
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 0.84rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    overflow-y: auto;
    transition: border-color 0.2s ease;
}

.melo-input::placeholder {
    color: var(--text-muted, #71717a);
}

.melo-input:focus {
    border-color: #ffffff;
}

.melo-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: none;
    background: #ffffff;
    color: #000000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.2s ease;
}

.melo-send-btn:hover {
    background: #e4e4e7;
    transform: scale(1.04);
}

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

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

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

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

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

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

@media (max-width: 480px) {
    .melo-orb {
        bottom: 18px;
        right: 18px;
        width: 46px;
        height: 46px;
    }
    .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);
    }
}

@media (prefers-reduced-motion: reduce) {
    .melo-msg { animation: none; }
    .melo-typing-dot { animation: none; opacity: 0.5; }
}

.melo-orb:focus-visible,
.melo-header-btn:focus-visible,
.melo-chip:focus-visible,
.melo-send-btn:focus-visible,
.melo-msg-action-btn:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}
