/**
 * Semarang Next - Chat Widget Styles
 * Matches existing template design system
 */

/* ============================================
   CSS Variables (inherited from template)
   ============================================ */
:root {
    --chat-primary: linear-gradient(115deg, #168bff, #6a52ff 52%, #b542ff);
    --chat-primary-solid: #168bff;
    --chat-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
    --chat-radius: 14px;
    --chat-radius-lg: 20px;
}

/* ============================================
   Chat Widget Wrapper (Fixed Position)
   ============================================ */
.chat-widget {
    position: fixed;
    z-index: 9999;
    bottom: 32px;
    right: 32px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 16px;
}

@media (max-width: 1024px) {
    .chat-widget {
        bottom: 24px;
        right: 24px;
    }
}

@media (max-width: 640px) {
    .chat-widget {
        bottom: 20px;
        right: 20px;
    }
}

/* ============================================
   Floating Chat Button (Fixed at Bottom)
   ============================================ */
.chat-float-btn {
    position: relative;
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 999px;
    background: var(--chat-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 18px 36px rgba(94, 82, 255, 0.35),
                0 0 28px rgba(199, 70, 255, 0.2);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
    flex-shrink: 0;
}

.chat-float-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 26px 48px rgba(94, 82, 255, 0.45),
                0 0 36px rgba(199, 70, 255, 0.3);
}

.chat-float-btn:active {
    transform: scale(0.95);
}

.chat-float-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
}

.chat-float-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 999px;
    border: 3px solid transparent;
    background: var(--chat-primary) border-box;
    -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: chat-pulse 2s ease-in-out infinite;
    opacity: 0;
}

@keyframes chat-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.6;
    }
}

@media (max-width: 1024px) {
    .chat-float-btn {
        width: 56px;
        height: 56px;
    }
    .chat-float-icon {
        font-size: 22px;
    }
}

@media (max-width: 640px) {
    .chat-float-btn {
        width: 52px;
        height: 52px;
    }
    .chat-float-icon {
        font-size: 20px;
    }
}

/* ============================================
   Chat Window (Positioned Above Button)
   ============================================ */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    height: 620px;
    background: var(--panel, rgba(5, 22, 50, 0.92));
    border: 1px solid var(--line, rgba(116, 190, 255, 0.2));
    border-radius: var(--chat-radius-lg);
    box-shadow: var(--chat-shadow), var(--shadow-lg, 0 24px 80px rgba(0, 0, 0, 0.42));
    backdrop-filter: blur(24px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-window.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

@media (max-width: 1024px) {
    .chat-window {
        width: 360px;
        height: 560px;
    }
}

@media (max-width: 640px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        align-items: center;
        padding: 0 20px 20px;
        flex-direction: column-reverse;
    }

    .chat-window {
        position: fixed;
        width: 100%;
        max-width: 100%;
        height: 85vh;
        bottom: 80px;
        left: 0;
        right: 0;
        border-radius: var(--chat-radius-lg) var(--chat-radius-lg) 0 0;
        z-index: 10000;
    }

    .chat-float-btn {
        width: 52px;
        height: 52px;
    }

    .chat-float-icon {
        font-size: 20px;
    }
}

/* ============================================
   Chat Header
   ============================================ */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--panel-strong, rgba(6, 24, 56, 0.92));
    border-bottom: 1px solid var(--line, rgba(116, 190, 255, 0.15));
    flex-shrink: 0;
}

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

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    box-shadow: 0 8px 20px rgba(94, 82, 255, 0.35);
}

.chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text, #f5f9ff);
    margin: 0;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted, #a9b8d4);
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--green, #15e59a);
    box-shadow: 0 0 8px var(--green, #15e59a);
    animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-close-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--muted, #a9b8d4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 16px;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text, #f5f9ff);
}

.chat-header-actions{display:flex;align-items:center;gap:6px}.chat-end-session-btn{display:grid;width:36px;height:36px;place-items:center;border:1px solid rgba(255,255,255,.14);border-radius:10px;color:rgba(255,255,255,.78);background:rgba(255,255,255,.07);cursor:pointer;transition:.2s}.chat-end-session-btn:hover{color:#fff;background:rgba(255,255,255,.16);transform:rotate(-18deg)}.chat-end-session-btn:focus-visible{outline:2px solid #fff;outline-offset:2px}

/* ============================================
   Chat Body
   ============================================ */
.chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    scroll-behavior: smooth;
}

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

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

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(116, 190, 255, 0.3);
    border-radius: 999px;
}

.chat-body::-webkit-scrollbar-thumb:hover {
    background: rgba(116, 190, 255, 0.5);
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ============================================
   Chat Messages
   ============================================ */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

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

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

.chat-bubble {
    padding: 14px 18px;
    border-radius: var(--chat-radius);
    line-height: 1.5;
    font-size: 14px;
}

.chat-message-user .chat-bubble {
    background: var(--chat-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message-assistant .chat-bubble {
    background: var(--panel-strong, rgba(6, 24, 56, 0.92));
    border: 1px solid var(--line, rgba(116, 190, 255, 0.15));
    color: var(--text, #f5f9ff);
    border-bottom-left-radius: 4px;
}

.chat-time {
    font-size: 11px;
    color: var(--muted, #a9b8d4);
    margin-top: 4px;
    padding: 0 4px;
}

/* Welcome Message Styles */
.chat-welcome-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 8px 0;
}

.chat-welcome-text {
    margin: 0 0 6px 0;
}

.chat-welcome-list {
    margin: 8px 0;
    padding-left: 8px;
}

.chat-welcome-list li {
    margin-bottom: 4px;
}

.chat-welcome-prompt {
    margin: 12px 0 0 0;
    font-weight: 500;
}

/* ============================================
   Quick Suggestions
   ============================================ */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line, rgba(116, 190, 255, 0.1));
    background: rgba(5, 22, 50, 0.5);
    flex-shrink: 0;
}

.chat-suggestion-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--line, rgba(116, 190, 255, 0.2));
    border-radius: 999px;
    background: var(--panel, rgba(5, 22, 50, 0.76));
    color: var(--text, #f5f9ff);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-suggestion-chip:hover {
    background: rgba(22, 139, 255, 0.2);
    border-color: rgba(22, 139, 255, 0.4);
    transform: translateY(-2px);
}

.chat-suggestion-chip i {
    font-size: 14px;
    color: var(--cyan, #18d9ff);
}

/* ============================================
   Chat Input Area
   ============================================ */
.chat-input-area {
    padding: 12px 16px 16px;
    background: var(--panel-strong, rgba(6, 24, 56, 0.92));
    border-top: 1px solid var(--line, rgba(116, 190, 255, 0.15));
    flex-shrink: 0;
}

.chat-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 6px 6px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line, rgba(116, 190, 255, 0.15));
    border-radius: 999px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-container:focus-within {
    border-color: rgba(22, 139, 255, 0.5);
    box-shadow: 0 0 0 3px rgba(22, 139, 255, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text, #f5f9ff);
    font-size: 14px;
    outline: none;
}

.chat-input::placeholder {
    color: var(--muted, #a9b8d4);
}

.chat-emoji-btn,
.chat-send-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 18px;
}

.chat-emoji-btn {
    background: transparent;
    color: var(--muted, #a9b8d4);
}

.chat-emoji-btn:hover {
    color: var(--cyan, #18d9ff);
    background: rgba(24, 217, 255, 0.1);
}

.chat-send-btn {
    background: var(--chat-primary);
    color: white;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(94, 82, 255, 0.35);
}

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

/* ============================================
   Typing Indicator
   ============================================ */
.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px 12px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--cyan, #18d9ff);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ============================================
   Animations
   ============================================ */
.chat-enter { transition: all 0.3s ease; }
.chat-enter-start { opacity: 0; transform: scale(0.8); }
.chat-enter-end { opacity: 1; transform: scale(1); }

.chat-leave { transition: all 0.2s ease; }
.chat-leave-start { opacity: 1; transform: scale(1); }
.chat-leave-end { opacity: 0; transform: scale(0.8); }

.chat-window-enter { transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
.chat-window-enter-start { opacity: 0; transform: translateY(20px) scale(0.95); }
.chat-window-enter-end { opacity: 1; transform: translateY(0) scale(1); }

.chat-window-leave { transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.chat-window-leave-start { opacity: 1; transform: translateY(0) scale(1); }
.chat-window-leave-end { opacity: 0; transform: translateY(10px) scale(0.98); }

/* ============================================
   Dark Mode Styles (already inherited from template)
   ============================================ */
[data-theme="dark"] .chat-window {
    background: var(--panel, rgba(5, 22, 50, 0.92));
}

[data-theme="light"] .chat-window {
    background: var(--panel, rgba(255, 255, 255, 0.92));
}

[data-theme="light"] .chat-header {
    background: var(--panel-strong, rgba(255, 255, 255, 0.95));
}

[data-theme="light"] .chat-header-text .chat-title {
    color: var(--text, #071831);
}

[data-theme="light"] .chat-input-container {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .chat-input {
    color: var(--text, #071831);
}

[data-theme="light"] .chat-message-assistant .chat-bubble {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(16, 85, 150, 0.1);
}

/* ============================================
   Accessibility
   ============================================ */
[x-cloak] {
    display: none !important;
}

.chat-suggestion-chip:focus-visible,
.chat-send-btn:focus-visible,
.chat-close-btn:focus-visible,
.chat-float-btn:focus-visible {
    outline: 2px solid var(--cyan, #18d9ff);
    outline-offset: 2px;
}

/* ============================================
   Mobile Bottom Sheet Handle
   ============================================ */
@media (max-width: 640px) {
    .chat-window::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.3);
    }
}
