/**
 * AAIS Casey Engine CSS Styling
 * Sovereign Chat Widget for Asheville AI Solutions
 */

:root {
    --casey-primary: #0055FF;
    --casey-primary-hover: #0044CC;
    --casey-primary-glow: rgba(0, 85, 255, 0.35);
    --casey-bg-dark: #0f172a;
    --casey-bg-card: #1e293b;
    --casey-bg-chat: #0b0f19;
    --casey-text-main: #f8fafc;
    --casey-text-muted: #94a3b8;
    --casey-text-dark: #1e293b;
    --casey-border: rgba(255, 255, 255, 0.1);
    --casey-bot-bubble: #1e293b;
    --casey-user-bubble: linear-gradient(135deg, #0055FF 0%, #003db3 100%);
    --casey-radius-lg: 16px;
    --casey-radius-md: 12px;
    --casey-radius-sm: 8px;
    --casey-font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --casey-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 20px rgba(0, 85, 255, 0.15);
    --casey-z-index: 999999;
}

#aais-casey-root {
    font-family: var(--casey-font-family);
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--casey-z-index);
    line-height: 1.5;
    box-sizing: border-box;
}

#aais-casey-root[data-aais-position="left"] {
    right: auto;
    left: 24px;
}

#aais-casey-root * {
    box-sizing: border-box;
}

/* Launcher Button */
.casey-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--casey-primary);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px var(--casey-primary-glow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    outline: none;
}

.casey-launcher:hover {
    transform: scale(1.08) translateY(-2px);
    background: var(--casey-primary-hover);
    box-shadow: 0 12px 30px var(--casey-primary-glow);
}

.casey-launcher:active {
    transform: scale(0.95);
}

.casey-launcher-pulse {
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 2px solid var(--casey-primary);
    opacity: 0.8;
    animation: casey-pulse 2.5s infinite ease-in-out;
    pointer-events: none;
}

@keyframes casey-pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.25);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

.casey-launcher svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: transform 0.3s ease;
}

/* Photo launcher variant — Casey's headshot instead of a generic chat icon */
.casey-launcher-photo {
    padding: 0;
    overflow: hidden;
    background: var(--casey-bg-card);
}

.casey-launcher-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.casey-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background-color: #10b981;
    border: 2px solid #ffffff;
    border-radius: 50%;
}

/* Chat Window Wrapper */
.casey-chat-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 120px);
    background: var(--casey-bg-chat);
    border: 1px solid var(--casey-border);
    border-radius: var(--casey-radius-lg);
    box-shadow: var(--casey-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#aais-casey-root[data-aais-position="left"] .casey-chat-window {
    right: auto;
    left: 0;
}

.casey-chat-window.casey-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.casey-header {
    background: var(--casey-bg-card);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--casey-border);
}

.casey-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.casey-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0055FF, #00d2ff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0, 85, 255, 0.4);
    overflow: hidden;
    flex-shrink: 0;
}

.casey-avatar-has-photo {
    background: var(--casey-bg-card);
}

.casey-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.casey-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--casey-text-main);
    display: flex;
    align-items: center;
    gap: 6px;
}

.casey-status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--casey-text-muted);
}

.casey-status-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px #10b981;
}

.casey-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.casey-icon-btn:hover {
    color: var(--casey-text-main);
    background: rgba(255, 255, 255, 0.1);
}

.casey-icon-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Chat Body / Messages Area */
.casey-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.casey-body::-webkit-scrollbar {
    width: 6px;
}

.casey-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* Message Item */
.casey-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: casey-fade-in 0.25s ease-out forwards;
}

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

.casey-msg-bot {
    align-self: flex-start;
}

.casey-msg-user {
    align-self: flex-end;
}

.casey-msg-content {
    padding: 12px 16px;
    border-radius: var(--casey-radius-md);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.casey-msg-bot .casey-msg-content {
    background: var(--casey-bot-bubble);
    color: var(--casey-text-main);
    border: 1px solid var(--casey-border);
    border-bottom-left-radius: 4px;
}

.casey-msg-user .casey-msg-content {
    background: var(--casey-user-bubble);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.casey-msg-content p {
    margin: 0 0 8px 0;
}

.casey-msg-content p:last-child {
    margin-bottom: 0;
}

.casey-msg-content ul, .casey-msg-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.casey-msg-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.casey-msg-content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.casey-msg-content a {
    color: #38bdf8;
    text-decoration: underline;
}

.casey-msg-time {
    font-size: 11px;
    color: var(--casey-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.casey-msg-user .casey-msg-time {
    text-align: right;
}

/* Live Booking Card — embeds the real Google Calendar scheduling page */
.casey-booking-card {
    width: 100%;
    max-width: 100%;
    border-radius: var(--casey-radius-md);
    overflow: hidden;
    border: 1px solid var(--casey-border);
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.casey-booking-frame {
    width: 100%;
    height: 420px;
    border: none;
    display: block;
    background: #ffffff;
}

.casey-booking-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--casey-bg-card);
    color: var(--casey-text-muted);
    font-size: 12px;
    text-decoration: none;
    border-top: 1px solid var(--casey-border);
    transition: color 0.2s ease;
}

.casey-booking-fallback:hover {
    color: var(--casey-primary);
}

.casey-booking-fallback svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Quick Suggestion Chips */
.casey-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.casey-chip {
    background: rgba(0, 85, 255, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(0, 85, 255, 0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.casey-chip:hover {
    background: var(--casey-primary);
    color: #ffffff;
    border-color: var(--casey-primary);
}

/* Typing Indicator */
.casey-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--casey-bot-bubble);
    border: 1px solid var(--casey-border);
    border-radius: var(--casey-radius-md);
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.casey-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--casey-text-muted);
    border-radius: 50%;
    animation: casey-bounce 1.4s infinite ease-in-out both;
}

.casey-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.casey-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes casey-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Footer / Input Area */
.casey-footer {
    padding: 12px 16px;
    background: var(--casey-bg-card);
    border-top: 1px solid var(--casey-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.casey-input-form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--casey-bg-chat);
    border: 1px solid var(--casey-border);
    border-radius: 24px;
    padding: 4px 6px 4px 16px;
    transition: border-color 0.2s ease;
}

.casey-input-form:focus-within {
    border-color: var(--casey-primary);
    box-shadow: 0 0 0 2px var(--casey-primary-glow);
}

.casey-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--casey-text-main);
    font-size: 14px;
    padding: 8px 0;
    font-family: inherit;
}

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

.casey-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--casey-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.casey-send-btn:hover {
    background: var(--casey-primary-hover);
    transform: scale(1.05);
}

.casey-send-btn:disabled {
    background: var(--casey-border);
    cursor: not-allowed;
    transform: none;
}

.casey-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    margin-left: 2px;
}

.casey-powered {
    text-align: center;
    font-size: 10px;
    color: var(--casey-text-muted);
    margin: 0;
}

.casey-powered a {
    color: var(--casey-text-muted);
    text-decoration: none;
    font-weight: 500;
}

.casey-powered a:hover {
    color: var(--casey-primary);
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    #aais-casey-root {
        bottom: 16px;
        right: 16px;
    }
    
    #aais-casey-root[data-aais-position="left"] {
        left: 16px;
    }

    .casey-chat-window {
        position: fixed;
        top: 0;
        left: 0 !important;
        right: 0 !important;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .casey-booking-frame {
        height: 340px;
    }
}
