/**
 * Praxis Pal — MktPraxis AI Chat Styles
 * shared/css/llm-chat.css
 *
 * Branded floating chat widget, inline panel, and streaming messages.
 * Works with shared/js/llm-chat.js
 */

/* ─── Floating Widget Container ─────────────────────────────────────────────── */

.llm-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* ─── Chat Bubble (floating trigger) ────────────────────────────────────────── */

.llm-chat-bubble {
    width: auto;
    height: auto;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.2s ease;
}

.llm-chat-bubble:hover {
    transform: scale(1.1);
}

.llm-chat-bubble-hidden {
    display: none;
}

@keyframes llm-pulse {
    0%, 100% { box-shadow: 0 4px 18px rgba(57, 83, 164, 0.45); }
    50% { box-shadow: 0 4px 28px rgba(37, 99, 235, 0.65); }
}

/* ─── Chat Panel ────────────────────────────────────────────────────────────── */

.llm-chat-panel {
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.llm-chat-widget .llm-chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
}

.llm-chat-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}

/* ─── Inline Mode ───────────────────────────────────────────────────────────── */

.llm-chat-inline {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.llm-chat-inline .llm-chat-panel {
    width: 100%;
    height: 480px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* ─── Header ────────────────────────────────────────────────────────────────── */

.llm-chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #3953a4 0%, #2563eb 100%);
    color: #fff;
    flex-shrink: 0;
}

.llm-chat-header-logo {
    width: 22px;
    height: 22px;
    margin-right: 8px;
    filter: brightness(0) invert(1);
    flex-shrink: 0;
}

.llm-chat-title {
    font-weight: 700;
    font-size: 14px;
    flex: 1;
    letter-spacing: 0.01em;
}

.llm-chat-quota {
    font-size: 12px;
    opacity: 0.85;
    margin-right: 8px;
    font-variant-numeric: tabular-nums;
}

.llm-chat-quota.llm-quota-low {
    color: #fbbf24;
    font-weight: 600;
}

.llm-chat-quota.llm-quota-empty {
    color: #f87171;
    font-weight: 700;
}

.llm-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.llm-chat-close:hover {
    opacity: 1;
}

/* ─── Messages Area ─────────────────────────────────────────────────────────── */

.llm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f9fafb;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
}

.llm-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.llm-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(57, 83, 164, 0.2);
    border-radius: 3px;
}

.llm-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(57, 83, 164, 0.35);
}

.llm-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.llm-msg-user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.llm-msg-assistant {
    align-self: flex-start;
    background: #ffffff;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    padding-left: 32px;
    position: relative;
}

.llm-msg-assistant::before {
    content: '✦';
    position: absolute;
    left: 10px;
    top: 10px;
    font-size: 14px;
    color: #3953a4;
    line-height: 1;
}

/* Welcome greeting */
.llm-msg-welcome {
    align-self: center;
    max-width: 90%;
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    font-size: 13.5px;
    text-align: center;
    padding: 10px 16px;
    line-height: 1.5;
}

.llm-upsell-link {
    display: inline-block;
    margin-top: 4px;
    color: #fff;
    background: linear-gradient(135deg, #3953a4 0%, #2563eb 100%);
    padding: 6px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    transition: filter 0.15s;
}

.llm-upsell-link:hover {
    filter: brightness(1.1);
}

.llm-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    font-size: 13px;
    text-align: center;
    border-radius: 8px;
}

/* Streaming cursor */
.llm-msg-streaming .llm-thinking-text {
    color: #9ca3af;
    font-style: italic;
    font-size: 0.85rem;
    margin-right: 4px;
}
.llm-msg-streaming .llm-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: #2563eb;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: llm-blink 0.8s infinite;
}

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

/* Code blocks in assistant messages */
.llm-code-block {
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
    margin: 8px 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.llm-inline-code {
    background: #f1f5f9;
    color: #0f172a;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
    font-size: 13px;
}

/* ─── Input Area ────────────────────────────────────────────────────────────── */

.llm-chat-input-row {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    gap: 8px;
    flex-shrink: 0;
}

.llm-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s;
}

.llm-chat-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.llm-chat-input::placeholder {
    color: #9ca3af;
}

.llm-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3953a4 0%, #2563eb 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, filter 0.15s;
}

.llm-chat-send:hover:not(:disabled) {
    filter: brightness(1.1);
}

.llm-chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    .llm-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .llm-chat-widget .llm-chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 140px);
        bottom: 68px;
        right: -8px;
    }

    .llm-chat-bubble {
        width: 48px;
        height: 48px;
    }
}

/* ─── Dark Mode Support ─────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
    .llm-chat-panel {
        background: #1f2937;
    }

    .llm-chat-header {
        background: linear-gradient(135deg, #1e293b 0%, #3953a4 100%);
    }

    .llm-chat-messages {
        background: #111827;
        box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
    }

    .llm-msg-assistant {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }

    .llm-msg-assistant::before {
        color: #93c5fd;
    }

    .llm-msg-welcome {
        background: #1e3a5f;
        color: #93c5fd;
        border-color: #2563eb;
    }

    .llm-msg-error {
        background: #451a1a;
        border-color: #7f1d1d;
    }

    .llm-chat-input-row {
        background: #1f2937;
        border-top-color: #374151;
    }

    .llm-chat-input {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .llm-chat-input:focus {
        border-color: #3b82f6;
    }

    .llm-inline-code {
        background: #374151;
        color: #e2e8f0;
    }

    .llm-chat-messages::-webkit-scrollbar-thumb {
        background: rgba(147, 197, 253, 0.2);
    }

    .llm-chat-messages::-webkit-scrollbar-thumb:hover {
        background: rgba(147, 197, 253, 0.35);
    }
}

/* ─── Praxis Pal Animated Pixel Head ────────────────────────────────────────── */
/*
 * Sprite: shared/img/baker_sprite.png — 1700×900
 *   Row 0 (top):    [Rest1] [Rest2] [Rest3] [Rest4]   y = 0%
 *   Row 1 (bottom): [Enth1] [Enth2] [Enth3] [Enth4]  y = 100%
 * background-size: 400% 200%  (4 cols × 2 rows)
 * To swap visuals later: just replace baker_sprite.png (same grid layout)
 */

.praxis-pal-head {
    display: inline-block;
    background: url('../img/baker_sprite.png') 0% 0% / 400% 200% no-repeat;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    animation:
        pal-rest-frames 8s steps(1) infinite,
        pal-bob 3s ease-in-out infinite;
    vertical-align: middle;
}

/* Size variants */
.praxis-pal-head--bubble { width: 48px; height: 51px; }
.praxis-pal-head--header { width: 24px; height: 25px; }
.praxis-pal-head--msg    { width: 18px; height: 19px; }

/* Rest animation (top row, y=0%) — slow idle cycle */
@keyframes pal-rest-frames {
    0%      { background-position: 0%      0%; }
    18.75%  { background-position: 33.333% 0%; }
    22.5%   { background-position: 0%      0%; }
    26.25%  { background-position: 66.667% 0%; }
    30%     { background-position: 0%      0%; }
    50%     { background-position: 33.333% 0%; }
    53.75%  { background-position: 66.667% 0%; }
    57.5%   { background-position: 100%    0%; }
    61.25%  { background-position: 0%      0%; }
    77.5%   { background-position: 100%    0%; }
    81.25%  { background-position: 33.333% 0%; }
    85%     { background-position: 0%      0%; }
    100%    { background-position: 0%      0%; }
}

/* Enthused animation (bottom row, y=100%) — faster excited cycle */
@keyframes pal-enthused-frames {
    0%      { background-position: 0%      100%; }
    12.5%   { background-position: 33.333% 100%; }
    20%     { background-position: 0%      100%; }
    30%     { background-position: 66.667% 100%; }
    37.5%   { background-position: 100%    100%; }
    45%     { background-position: 33.333% 100%; }
    55%     { background-position: 0%      100%; }
    62.5%   { background-position: 100%    100%; }
    70%     { background-position: 66.667% 100%; }
    80%     { background-position: 33.333% 100%; }
    90%     { background-position: 0%      100%; }
    100%    { background-position: 0%      100%; }
}

/* Gentle float (rest) */
@keyframes pal-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}

/* Bouncier bob (enthused) */
@keyframes pal-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25%      { transform: translateY(-4px) rotate(-2deg); }
    50%      { transform: translateY(-1px) rotate(0deg); }
    75%      { transform: translateY(-5px) rotate(2deg); }
}

/* Hover → enthused */
.llm-chat-bubble:hover .praxis-pal-head,
.llm-chat-header:hover .praxis-pal-head {
    animation:
        pal-enthused-frames 4s steps(1) infinite,
        pal-bounce 1.5s ease-in-out infinite;
}

/* Generating state → enthused (toggled via JS) */
.llm-chat-generating .praxis-pal-head {
    animation:
        pal-enthused-frames 4s steps(1) infinite,
        pal-bounce 1.5s ease-in-out infinite;
}

/* Green pulse dot during generation */
.llm-chat-generating .llm-chat-bubble::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    background: #34d399;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: pal-gen-pulse 1s ease-in-out infinite;
}

@keyframes pal-gen-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .5; transform: scale(.7); }
}
