/* AI Studio Chat Widget — ported from POS AI Slice design */
/* GPU-only animations: transform + opacity only */

#ai-studio-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Trigger button ─────────────────────────────────────────── */

.ai-studio-trigger {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ai-studio-trigger:hover {
    transform: scale(1.1) translate3d(0, -2px, 0);
    box-shadow: 0 6px 24px rgba(108, 92, 231, 0.6);
}

/* ── Chat panel ─────────────────────────────────────────────── */

.ai-studio-panel {
    display: none;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: 70px;
    right: 0;
    animation: aiSlideIn 0.25s ease-out;
}
.ai-studio-panel.open {
    display: flex;
}

/* Knight rider border glow (from POS AI Slice) */
.ai-studio-panel::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    padding: 2px;
    background: linear-gradient(90deg, transparent 30%, rgba(108,92,231,0.9) 45%, rgba(168,85,247,0.8) 50%, rgba(108,92,231,0.9) 55%, transparent 70%);
    background-size: 200% 100%;
    animation: knightRider 2.5s linear infinite;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    z-index: 1;
}

@keyframes knightRider {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes aiSlideIn {
    from { transform: translate3d(0, 20px, 0); opacity: 0; }
    to   { transform: translate3d(0, 0, 0); opacity: 1; }
}

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

.ai-studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    flex-shrink: 0;
}
.ai-studio-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.01em;
}
.ai-studio-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-studio-close,
.ai-studio-clear-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}
.ai-studio-close:hover,
.ai-studio-clear-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ── Messages area ──────────────────────────────────────────── */

.ai-studio-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
}

/* ── Message bubbles ────────────────────────────────────────── */

.ai-studio-msg {
    max-width: 88%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}
.ai-studio-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}
.ai-studio-msg.assistant {
    align-self: flex-start;
    background: #f5f5fa;
    color: #1a1a2e;
    border-radius: 4px 14px 14px 14px;
    border: 1px solid #e8e8f0;
    white-space: pre-wrap;
}
.ai-studio-msg.assistant strong { color: #6c5ce7; }
.ai-studio-msg.assistant code {
    background: #e8e8f0;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
}
.ai-studio-msg.error {
    align-self: center;
    background: #fff0f0;
    color: #c53030;
    border: 1px solid #fed7d7;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* Provider tag on assistant messages */
.ai-studio-provider-tag {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    color: #999;
    letter-spacing: 0.02em;
}

/* ── Typing indicator (from POS AI Slice) ───────────────────── */

.ai-studio-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f5f5fa;
    border: 1px solid #e8e8f0;
    border-radius: 4px 14px 14px 14px;
}
.ai-studio-typing span {
    display: inline-block;
    animation: typingBounce 1.2s infinite ease-in-out;
    color: #999;
    font-size: 1.3rem;
    line-height: 1;
}
.ai-studio-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-studio-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translate3d(0, 0, 0); opacity: 0.35; }
    30% { transform: translate3d(0, -5px, 0); opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────────── */

.ai-studio-input-wrap {
    display: flex;
    padding: 12px 14px;
    border-top: 1px solid #eee;
    gap: 8px;
    flex-shrink: 0;
    background: #fafafa;
}
#ai-studio-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
}
#ai-studio-input:focus {
    border-color: #6c5ce7;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}
#ai-studio-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-studio-send {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    white-space: nowrap;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
}
.ai-studio-send:hover:not(:disabled) {
    transform: translate3d(0, -1px, 0);
    opacity: 0.9;
}
.ai-studio-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Action messages & buttons ──────────────────────────────── */

.ai-studio-msg.action {
    align-self: center;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    padding: 8px 14px;
}

.ai-studio-action-btn-wrap {
    display: flex;
    justify-content: center;
    padding: 4px 0;
}

.ai-studio-action-btn {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.ai-studio-action-btn:hover {
    transform: translate3d(0, -1px, 0);
    opacity: 0.9;
    color: #fff;
}

/* ── Mobile responsive ──────────────────────────────────────── */

@media (max-width: 480px) {
    .ai-studio-panel {
        width: calc(100vw - 20px);
        right: -10px;
        bottom: 65px;
        height: 60vh;
        border-radius: 16px 16px 0 0;
    }
    .ai-studio-trigger {
        width: 48px;
        height: 48px;
    }
}
