/* ==========================================================================
   Ask Ellie Chat Interface
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Theme Integration)
   -------------------------------------------------------------------------- */
:root {
    --ellie-primary: #4589AF;
    --ellie-primary-dark: #3A7799;
    --ellie-fab-size: 56px;
    --ellie-window-width: 380px;
    --ellie-window-height: 500px;
    --ellie-border-radius: 12px;
    --ellie-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --ellie-shadow-dark: 0 4px 20px rgba(0, 0, 0, 0.4);
    --ellie-transition: 200ms ease-out;
}

/* Light mode */
[data-md-color-scheme="default"] {
    --ellie-bg: #ffffff;
    --ellie-bg-secondary: #f5f5f5;
    --ellie-text: #333333;
    --ellie-text-muted: #666666;
    --ellie-border: #e0e0e0;
    --ellie-user-bubble: var(--ellie-primary);
    --ellie-user-text: #ffffff;
    --ellie-assistant-bubble: #f0f0f0;
    --ellie-assistant-text: #333333;
}

/* Dark mode */
[data-md-color-scheme="slate"] {
    --ellie-bg: #1e1e1e;
    --ellie-bg-secondary: #2d2d2d;
    --ellie-text: #e0e0e0;
    --ellie-text-muted: #a0a0a0;
    --ellie-border: #404040;
    --ellie-user-bubble: var(--ellie-primary);
    --ellie-user-text: #ffffff;
    --ellie-assistant-bubble: #2d2d2d;
    --ellie-assistant-text: #e0e0e0;
}

/* --------------------------------------------------------------------------
   FAB (Floating Action Button)
   -------------------------------------------------------------------------- */
.ellie-fab {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: var(--ellie-fab-size);
    height: var(--ellie-fab-size);
    border-radius: 50%;
    border: none;
    background: var(--ellie-primary);
    color: white;
    cursor: pointer;
    box-shadow: var(--ellie-shadow);
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
    transition: transform var(--ellie-transition),
                box-shadow var(--ellie-transition),
                opacity var(--ellie-transition);
}

.ellie-fab--visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.ellie-fab--visible:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.ellie-fab--visible:active {
    transform: scale(0.95);
}

.ellie-fab:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.ellie-fab svg {
    width: 24px;
    height: 24px;
}

/* --------------------------------------------------------------------------
   Chat Window
   -------------------------------------------------------------------------- */
.ellie-window {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: var(--ellie-window-width);
    height: var(--ellie-window-height);
    max-height: calc(100vh - 120px);
    background: var(--ellie-bg);
    border-radius: var(--ellie-border-radius);
    box-shadow: var(--ellie-shadow);
    z-index: 951;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity var(--ellie-transition),
                transform var(--ellie-transition);
}

[data-md-color-scheme="slate"] .ellie-window {
    box-shadow: var(--ellie-shadow-dark);
}

.ellie-window--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* --------------------------------------------------------------------------
   Resize Handle (top-left corner)
   -------------------------------------------------------------------------- */
.ellie-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    z-index: 10;
}

.ellie-resize-handle::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 8px;
    height: 8px;
    border-left: 2px solid rgba(255, 255, 255, 0.5);
    border-top: 2px solid rgba(255, 255, 255, 0.5);
    opacity: 0;
    transition: opacity var(--ellie-transition);
}

.ellie-window:hover .ellie-resize-handle::before {
    opacity: 1;
}

.ellie-window--resizing {
    transition: none;
    user-select: none;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.ellie-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--ellie-primary);
    color: white;
    flex-shrink: 0;
}

.ellie-header__info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ellie-header__avatar {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ellie-header__avatar svg {
    width: 100%;
    height: 100%;
}

.ellie-header__title {
    font-size: 16px;
    font-weight: 600;
}

.ellie-header__actions {
    display: flex;
    gap: 8px;
}

.ellie-header__btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: white;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--ellie-transition);
}

.ellie-header__btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.ellie-header__btn:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.ellie-header__btn svg {
    width: 18px;
    height: 18px;
}

/* --------------------------------------------------------------------------
   Messages Area
   -------------------------------------------------------------------------- */
.ellie-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ellie-message {
    display: flex;
    max-width: 85%;
}

.ellie-message--user {
    align-self: flex-end;
}

.ellie-message--assistant {
    align-self: flex-start;
}

.ellie-message__content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.ellie-message--user .ellie-message__content {
    background: var(--ellie-user-bubble);
    color: var(--ellie-user-text);
    border-bottom-right-radius: 4px;
}

.ellie-message--assistant .ellie-message__content {
    background: var(--ellie-assistant-bubble);
    color: var(--ellie-assistant-text);
    border-bottom-left-radius: 4px;
}

/* Streaming indicator */
.ellie-message--streaming .ellie-message__content::after {
    content: '\25FC';
    margin-left: 2px;
    animation: ellie-blink 1s infinite;
}

@keyframes ellie-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Busy status indicator */
.ellie-busy-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--ellie-text-muted);
    font-size: 13px;
    font-style: italic;
    animation: ellie-fade-in 0.3s ease-out;
}

.ellie-busy-status::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid var(--ellie-border);
    border-top-color: var(--ellie-primary);
    border-radius: 50%;
    animation: ellie-spin 0.8s linear infinite;
}

@keyframes ellie-spin {
    to { transform: rotate(360deg); }
}

@keyframes ellie-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Code formatting in messages */
.ellie-message__content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
}

[data-md-color-scheme="slate"] .ellie-message__content code {
    background: rgba(255, 255, 255, 0.1);
}

.ellie-message__content pre {
    margin: 8px 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    overflow-x: auto;
}

[data-md-color-scheme="slate"] .ellie-message__content pre {
    background: rgba(0, 0, 0, 0.3);
}

.ellie-message__content pre code,
[data-md-color-scheme="slate"] .ellie-message__content pre code {
    background: transparent !important;
    background-color: transparent !important;
    padding: 0;
}

/* Ensure all elements inside code blocks have transparent backgrounds */
.ellie-message__content pre code *,
.ellie-message__content pre span,
[data-md-color-scheme="slate"] .ellie-message__content pre code *,
[data-md-color-scheme="slate"] .ellie-message__content pre span {
    background: transparent !important;
    background-color: transparent !important;
}

.ellie-message__content a {
    color: var(--ellie-primary);
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Input Area
   -------------------------------------------------------------------------- */
.ellie-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: var(--ellie-bg-secondary);
    border-top: 1px solid var(--ellie-border);
    flex-shrink: 0;
}

.ellie-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--ellie-border);
    border-radius: 20px;
    background: var(--ellie-bg);
    color: var(--ellie-text);
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color var(--ellie-transition);
    font-family: inherit;
}

.ellie-input::placeholder {
    color: var(--ellie-text-muted);
}

.ellie-input:focus {
    border-color: var(--ellie-primary);
}

.ellie-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--ellie-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--ellie-transition),
                transform var(--ellie-transition);
}

.ellie-send-btn:hover {
    background: var(--ellie-primary-dark);
}

.ellie-send-btn:active {
    transform: scale(0.95);
}

.ellie-send-btn:focus-visible {
    outline: 2px solid var(--ellie-primary);
    outline-offset: 2px;
}

.ellie-send-btn svg {
    width: 18px;
    height: 18px;
}

.ellie-send-btn--stop {
    background: #f44336;
}

.ellie-send-btn--stop:hover {
    background: #d32f2f;
}

/* --------------------------------------------------------------------------
   Responsive Adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .ellie-window {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 16px;
        height: calc(100vh - 100px);
        max-height: none;
    }

    .ellie-fab {
        right: 16px;
        bottom: 16px;
    }
}

/* --------------------------------------------------------------------------
   Scrollbar Styling
   -------------------------------------------------------------------------- */
.ellie-messages::-webkit-scrollbar {
    width: 6px;
}

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

.ellie-messages::-webkit-scrollbar-thumb {
    background: var(--ellie-border);
    border-radius: 3px;
}

.ellie-messages::-webkit-scrollbar-thumb:hover {
    background: var(--ellie-text-muted);
}

/* Input textarea scrollbar - hide by default, show on hover/focus */
.ellie-input {
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
}

.ellie-input::-webkit-scrollbar {
    width: 0;
    display: none;
}
