/**
 * Ask Mikey Chatbox - Floating AI Assistant
 * Cosmetic implementation for SmplTrax v1
 */

/* ============================================
   VARIABLES
   ============================================ */
:root {
    --mikey-brand-color: #556ee6;
    --mikey-bg-white: #ffffff;
    --mikey-bg-light: #eff2f7;
    --mikey-bg-gray: #f8f9fa;
    --mikey-border-color: #e2e8f0;
    --mikey-text-dark: #495057;
    --mikey-text-muted: #74788d;
    --mikey-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --mikey-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --mikey-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* ============================================
   BRAIN BUTTON (TRIGGER)
   ============================================ */
.ask-mikey-trigger {
    cursor: pointer;
    transition: all 0.2s ease;
}

.ask-mikey-trigger:hover {
    background-color: rgba(85, 110, 230, 0.1) !important;
    color: var(--mikey-brand-color) !important;
}

.ask-mikey-trigger.active {
    background-color: rgba(85, 110, 230, 0.1) !important;
    color: var(--mikey-brand-color) !important;
}

/* ============================================
   FLOATING PANEL CONTAINER
   ============================================ */
.ask-mikey-container {
    position: fixed;
    display: none;
    z-index: 1050;
    /* Initial position set by JS */
}

.ask-mikey-container.open,
.ask-mikey-container.minimized {
    display: block;
}

/* ============================================
   CHAT PANEL (OPEN STATE)
   ============================================ */
.ask-mikey-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 384px;
    height: 540px;
    min-width: 384px;
    min-height: 400px;
    max-width: 800px;
    max-height: 700px;
    border-radius: 12px;
    border: 1px solid var(--mikey-border-color);
    background: var(--mikey-bg-white);
    box-shadow: var(--mikey-shadow);
    overflow: hidden;
    animation: fadeInZoom 300ms ease-out;
}

@keyframes fadeInZoom {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Smooth transitions when not dragging/resizing */
.ask-mikey-panel.transitioning {
    transition: left 300ms ease, top 300ms ease, width 300ms ease, height 300ms ease;
}

/* ============================================
   HEADER
   ============================================ */
.ask-mikey-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--mikey-border-color);
    background: var(--mikey-bg-white);
    cursor: grab;
    user-select: none;
}

.ask-mikey-header.dragging {
    cursor: grabbing;
}

.ask-mikey-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--mikey-brand-color);
    border-radius: 8px;
    color: white;
    font-size: 18px;
    flex-shrink: 0;
}

.ask-mikey-header-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--mikey-text-dark);
}

.ask-mikey-header-title sup {
    font-size: 9px;
    margin-left: 2px;
}

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

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

.ask-mikey-btn:hover {
    background: var(--mikey-bg-light);
    color: var(--mikey-text-dark);
}

/* ============================================
   CONTEXT BAR
   ============================================ */
.ask-mikey-context-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(85, 110, 230, 0.08);
    border-bottom: 1px solid var(--mikey-border-color);
    font-size: 12px;
}

.ask-mikey-context-bar.hidden {
    display: none;
}

.ask-mikey-context-icon {
    color: var(--mikey-brand-color);
    font-size: 14px;
}

.ask-mikey-context-text {
    flex: 1;
    color: var(--mikey-text-dark);
    font-weight: 500;
}

.ask-mikey-context-close {
    color: var(--mikey-text-muted);
    cursor: pointer;
    padding: 2px;
    transition: color 0.2s;
}

.ask-mikey-context-close:hover {
    color: var(--mikey-text-dark);
}

.ask-mikey-context-toggle {
    padding: 6px 12px;
    background: transparent;
    border: none;
    color: var(--mikey-brand-color);
    font-size: 11px;
    cursor: pointer;
    text-decoration: none;
}

.ask-mikey-context-toggle:hover {
    text-decoration: underline;
}

/* ============================================
   MESSAGES AREA
   ============================================ */
.ask-mikey-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    background: var(--mikey-bg-white);
}

.ask-mikey-messages::-webkit-scrollbar {
    width: 6px;
}

.ask-mikey-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ask-mikey-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.ask-mikey-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Empty state */
.ask-mikey-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--mikey-text-muted);
    padding: 20px;
}

.ask-mikey-empty-text {
    font-size: 14px;
    line-height: 1.6;
}

/* Message bubbles */
.ask-mikey-message {
    display: flex;
    flex-direction: column;
    max-width: 83%;
    animation: fadeIn 300ms ease-out;
}

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

.ask-mikey-message.user {
    align-self: flex-end;
    margin-left: auto;
}

.ask-mikey-message.bot {
    align-self: flex-start;
    margin-right: auto;
}

.ask-mikey-message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    word-wrap: break-word;
}

.ask-mikey-message.user .ask-mikey-message-bubble {
    background: var(--mikey-brand-color);
    color: white;
}

.ask-mikey-message.bot .ask-mikey-message-bubble {
    background: var(--mikey-bg-light);
    color: var(--mikey-text-dark);
}

.ask-mikey-message-time {
    font-size: 10px;
    color: var(--mikey-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.ask-mikey-message.user .ask-mikey-message-time {
    text-align: right;
}

/* Typing indicator */
.ask-mikey-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--mikey-bg-light);
    border-radius: 12px;
    margin-right: auto;
    max-width: fit-content;
}

.ask-mikey-typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: bounce 1s infinite;
}

.ask-mikey-typing-dot:nth-child(2) {
    animation-delay: 150ms;
}

.ask-mikey-typing-dot:nth-child(3) {
    animation-delay: 300ms;
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* ============================================
   INPUT AREA
   ============================================ */
.ask-mikey-input-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--mikey-border-color);
    background: var(--mikey-bg-white);
}

.ask-mikey-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.ask-mikey-textarea {
    flex: 1;
    min-height: 38px;
    max-height: 80px;
    padding: 8px 12px;
    border: 1px solid var(--mikey-border-color);
    border-radius: 8px;
    background: var(--mikey-bg-white);
    color: var(--mikey-text-dark);
    font-size: 13px;
    font-family: inherit;
    resize: none;
    overflow-y: auto;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ask-mikey-textarea:focus {
    outline: none;
    border-color: var(--mikey-brand-color);
    box-shadow: 0 0 0 3px rgba(85, 110, 230, 0.1);
}

.ask-mikey-textarea::placeholder {
    color: var(--mikey-text-muted);
}

.ask-mikey-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--mikey-brand-color);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ask-mikey-send-btn:hover {
    background: #4055c5;
}

.ask-mikey-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ask-mikey-hints {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--mikey-text-muted);
    padding: 0 2px;
}

/* ============================================
   MINIMIZED BUBBLE
   ============================================ */
.ask-mikey-bubble {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 48px;
    padding: 0 16px;
    background: var(--mikey-brand-color);
    border-radius: 24px;
    box-shadow: var(--mikey-shadow-md);
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
    white-space: nowrap;
}

.ask-mikey-bubble:hover {
    box-shadow: var(--mikey-shadow-lg);
    padding-right: 36px; /* Make room for close badge */
}

.ask-mikey-bubble-icon {
    font-size: 20px;
    color: white;
    flex-shrink: 0;
}

.ask-mikey-bubble-text {
    font-size: 13px;
    font-weight: 600;
    color: white;
    max-width: 0;
    opacity: 0;
    transition: max-width 0.3s ease, opacity 0.3s ease;
}

.ask-mikey-bubble:hover .ask-mikey-bubble-text {
    max-width: 128px;
    opacity: 1;
}

.ask-mikey-bubble-close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    font-size: 12px;
    color: white;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ask-mikey-bubble:hover .ask-mikey-bubble-close {
    opacity: 1;
}

/* ============================================
   RESIZE HANDLES
   ============================================ */
.ask-mikey-resize-handle {
    position: absolute;
    z-index: 10;
}

/* Edge handles */
.ask-mikey-resize-n {
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
}

.ask-mikey-resize-s {
    bottom: 0;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
}

.ask-mikey-resize-e {
    top: 0;
    right: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
}

.ask-mikey-resize-w {
    top: 0;
    left: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
}

/* Corner handles */
.ask-mikey-resize-ne {
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

.ask-mikey-resize-nw {
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

.ask-mikey-resize-se {
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

.ask-mikey-resize-sw {
    bottom: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .ask-mikey-panel {
        width: calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
    }
}

/* ============================================
   UTILITY
   ============================================ */
.ask-mikey-hidden {
    display: none !important;
}
