/* ============================================================
   CHAT MODAL - MULAI CHAT
   Diselaraskan dengan Design System Peta Wisata
   Palet: var(--primary-bg), --tooltip-bg, --tooltip-text,
          --tooltip-icon-bg, --hotspot-hover (orange accent)
   Efek: Glassmorphism untuk overlay & container (lihat AGENTS.md 2c)
   ============================================================ */

/* Overlay - glassmorphism dark */
.intro-modal-overlay#chatModal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: rgba(26, 26, 26, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.intro-modal-overlay#chatModal.show {
    display: flex;
    opacity: 1;
}

/* Container - glassmorphism card */
.chat-modal-content {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
    width: 90%;
    max-width: 460px;
    height: min(82vh, 680px);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.96) translateY(8px);
    opacity: 0;
    transition: transform 0.32s cubic-bezier(0.175, 0.885, 0.32, 1.28), opacity 0.28s ease;
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#chatModal.show .chat-modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Header - selaras Legend/Kalender (hijau perkebunan) */
.chat-header {
    background: linear-gradient(180deg, #558b2f 0%, #33691e 100%);
    border-bottom: 1px solid rgba(255,255,255,0.18);
    color: var(--text-color);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.chat-close-btn {
    background: rgba(255,255,255,0.14);
    border: 1px solid rgba(255,255,255,0.2);
    color: #ffffff;
    font-size: 1.35rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-close-btn:hover {
    background: rgba(255,255,255,0.24);
    transform: rotate(90deg);
}

.chat-close-btn:focus-visible {
    outline: 2px solid var(--hotspot-hover);
    outline-offset: 2px;
}

/* Body - warm cream agar kontras tetap 4.5:1 di atas glass */
.chat-body {
    padding: 18px;
    flex: 1;
    min-height: 320px;
    overflow-y: auto;
    background: var(--tooltip-bg);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.chat-message.bot .chat-bubble {
    background: #ffffff;
    border: 1px solid #e2d2ba;
    border-radius: 16px 16px 16px 4px;
    padding: 12px 14px;
    font-size: 0.88rem;
    color: var(--tooltip-text);
    box-shadow: 0 2px 8px rgba(78, 52, 46, 0.08);
    max-width: 84%;
    line-height: 1.5;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.user .chat-bubble {
    background: linear-gradient(180deg, #558b2f 0%, #33691e 100%);
    border: 1px solid #1b5e20;
    color: #ffffff;
    border-radius: 16px 16px 4px 16px;
    padding: 11px 14px;
    font-size: 0.88rem;
    max-width: 78%;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(51, 105, 30, 0.3);
}

/* Typing indicator - 3 dots */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e2d2ba;
    border-radius: 16px 16px 16px 4px;
    width: fit-content;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    background: var(--tooltip-icon-bg);
    border-radius: 50%;
    display: inline-block;
    animation: chatBounce 1.1s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

.chat-error {
    background: #fce8e6;
    border: 1px solid #f5c6c2;
    color: #8d1a13;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 0.82rem;
    line-height: 1.4;
    max-width: 90%;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-retry-btn {
    background: var(--tooltip-icon-bg);
    color: #ffffff;
    border: 1px solid #3d7a1f;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(90, 158, 51, 0.25);
    transition: background 0.2s ease, transform 0.15s ease;
    white-space: nowrap;
}

.chat-retry-btn:hover {
    background: #4a821e;
    transform: translateY(-1px);
}

.chat-retry-btn:focus-visible {
    outline: 2px solid var(--hotspot-hover);
    outline-offset: 2px;
}

/* Bubble info/disabled - tetap cream tapi italic */
.chat-bubble--muted {
    background-color: #fdf8f0 !important;
    font-style: italic;
    color: #6d4c41 !important;
    border-style: dashed !important;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--tooltip-bg);
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

/* Footer - glass subtle + input cream */
.chat-footer {
    padding: 14px 16px;
    background: rgba(246, 235, 216, 0.92);
    border-top: 1px solid #e3b586;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-footer input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid #d7c4a8;
    border-radius: 999px;
    outline: none;
    font-family: inherit;
    font-size: 0.88rem;
    background: #ffffff;
    color: var(--tooltip-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-footer input::placeholder {
    color: #8d6e63;
    opacity: 0.7;
}

.chat-footer input:focus {
    border-color: var(--tooltip-icon-bg);
    box-shadow: 0 0 0 3px rgba(90, 158, 51, 0.18);
}

.chat-footer input:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    background: #fdf8f0;
}

.chat-footer .send-btn {
    background: var(--tooltip-icon-bg);
    color: #ffffff;
    border: 1px solid #3d7a1f;
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(90, 158, 51, 0.3), inset 0 1px 0 rgba(255,255,255,0.2);
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    white-space: nowrap;
}

.chat-footer .send-btn:hover:not(:disabled) {
    background: #4a821e;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(90, 158, 51, 0.36);
}

.chat-footer .send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.chat-footer .send-btn:focus-visible {
    outline: 2px solid var(--hotspot-hover);
    outline-offset: 2px;
}

.chat-footer .send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    transform: none;
    box-shadow: none;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-modal-content {
        width: 96%;
        height: 88vh;
        max-height: 88vh;
        border-radius: 14px;
    }
    .chat-body {
        padding: 14px;
        min-height: 240px;
    }
}
@media (max-height: 600px) {
    .chat-modal-content {
        height: 90vh;
        max-height: 90vh;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chat-modal-content,
    .intro-modal-overlay#chatModal,
    .chat-close-btn,
    .chat-footer .send-btn {
        transition: none !important;
        animation: none !important;
    }
}
