/* Explain: Styles for the AI assistant and live chat widget. */
/* Asisten desa + live chat petugas */
.is-hidden {
    display: none !important;
}

.chat-widget {
    display: none;
}

.chat-widget.is-ready {
    display: block;
}

.chat-launcher {
    position: fixed;
    right: 1.1rem;
    bottom: 1.1rem;
    z-index: 95;
    display: inline-flex;
    height: 3.5rem;
    width: 3.5rem;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: var(--accent-color);
    color: var(--cream-color);
    font-size: 1.4rem;
    box-shadow: var(--shadow-soft);
    transition: background 300ms ease, transform 300ms ease;
}

.chat-launcher:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.chat-launcher-icon-close {
    display: none;
}

.chat-widget.is-open .chat-launcher-icon-close {
    display: inline-block;
}

.chat-widget.is-open .chat-launcher-icon-open {
    display: none;
}

.chat-panel {
    position: fixed;
    right: 1.1rem;
    bottom: 5.4rem;
    z-index: 96;
    display: none;
    flex-direction: column;
    width: min(23rem, calc(100vw - 2.2rem));
    max-height: min(33rem, calc(100vh - 8rem));
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 1.6rem;
    background: var(--surface-color);
    box-shadow: var(--shadow-soft);
}

.chat-panel.is-open {
    display: flex;
}

.chat-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: var(--cream-color);
}

.chat-avatar {
    display: inline-flex;
    height: 2.4rem;
    width: 2.4rem;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: color-mix(in srgb, var(--cream-color) 22%, transparent);
    font-size: 1.05rem;
}

.chat-head-text {
    flex: 1;
    min-width: 0;
}

.chat-head-title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 900;
    line-height: 1.2;
}

.chat-head-status {
    margin: 0.15rem 0 0;
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0.92;
}

.chat-close {
    display: inline-flex;
    height: 2rem;
    width: 2rem;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: color-mix(in srgb, var(--cream-color) 18%, transparent);
    color: var(--cream-color);
    transition: background 300ms ease;
}

.chat-close:hover {
    background: color-mix(in srgb, var(--cream-color) 32%, transparent);
}

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow-y: auto;
    padding: 1rem;
    background: color-mix(in srgb, var(--primary-color) 5%, var(--surface-color));
}

.chat-msg {
    max-width: 85%;
    border-radius: 1rem;
    padding: 0.6rem 0.8rem;
    font-size: 0.86rem;
    line-height: 1.5;
}

.chat-msg-text {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-msg-meta {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.64rem;
    font-weight: 700;
    opacity: 0.65;
}

.chat-msg-warga {
    align-self: flex-end;
    background: var(--primary-color);
    color: var(--cream-color);
    border-bottom-right-radius: 0.3rem;
}

.chat-msg-ai {
    align-self: flex-start;
    background: var(--surface-color);
    color: var(--charcoal-color);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 0.3rem;
}

.chat-msg-petugas {
    align-self: flex-start;
    background: color-mix(in srgb, var(--secondary-color) 55%, var(--surface-color));
    color: var(--charcoal-color);
    border-bottom-left-radius: 0.3rem;
}

.chat-msg-system {
    align-self: center;
    max-width: 92%;
    background: color-mix(in srgb, var(--charcoal-color) 8%, transparent);
    color: var(--text-muted);
    font-size: 0.74rem;
    text-align: center;
}

.chat-typing {
    display: inline-flex;
    gap: 0.28rem;
    align-items: center;
}

.chat-typing span {
    height: 0.45rem;
    width: 0.45rem;
    border-radius: 999px;
    background: var(--primary-hover);
    opacity: 0.4;
    animation: chatBlink 1s infinite ease-in-out;
}

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

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

@keyframes chatBlink {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.65rem 0.9rem 0;
}

.chat-chip {
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--surface-color);
    color: var(--primary-hover);
    padding: 0.32rem 0.7rem;
    font-size: 0.72rem;
    font-weight: 800;
    transition: background 300ms ease, color 300ms ease;
}

.chat-chip:hover {
    background: var(--secondary-color);
    color: var(--charcoal-color);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    min-height: 2.6rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--surface-color);
    padding: 0 1rem;
    color: var(--text-color);
    font-size: 0.86rem;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chat-send {
    display: inline-flex;
    height: 2.6rem;
    width: 2.6rem;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: var(--primary-color);
    color: var(--cream-color);
    transition: background 300ms ease;
}

.chat-send:hover {
    background: var(--primary-hover);
}

.chat-foot {
    border-top: 1px solid var(--border-color);
    padding: 0.7rem 0.9rem 0.9rem;
}

.chat-escalate {
    display: inline-flex;
    width: 100%;
    min-height: 2.7rem;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 0;
    border-radius: 999px;
    background: var(--whatsapp-color);
    color: var(--cream-color);
    font-size: 0.82rem;
    font-weight: 900;
    transition: background 300ms ease;
}

.chat-escalate:hover {
    background: var(--whatsapp-hover);
}

.chat-escalation {
    margin-top: 0.5rem;
}

.chat-escalation-text {
    margin: 0 0 0.6rem;
    font-size: 0.74rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.chat-label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.7rem;
    font-weight: 900;
    color: var(--charcoal-color);
}

.chat-escalation .chat-input {
    width: 100%;
    margin-bottom: 0.55rem;
    border-radius: 0.85rem;
}

.chat-escalation-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-wa-link {
    display: inline-flex;
    min-height: 2.4rem;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--charcoal-color);
    font-size: 0.78rem;
    font-weight: 800;
}

.admin-chat-thread {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    min-height: 12rem;
    max-height: 22rem;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: color-mix(in srgb, var(--primary-color) 5%, var(--surface-color));
}

.admin-chat-empty {
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
}

.admin-chat-item {
    display: block;
    width: 100%;
    text-align: left;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: var(--surface-color);
    padding: 0.8rem 0.9rem;
    transition: border-color 300ms ease, background 300ms ease;
}

.admin-chat-item:hover {
    border-color: color-mix(in srgb, var(--primary-color) 55%, transparent);
}

.admin-chat-item.is-active {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 8%, var(--surface-color));
}

.admin-chat-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.admin-chat-item-name {
    font-family: var(--font-heading);
    font-weight: 900;
    color: var(--charcoal-color);
}

.admin-chat-item-preview {
    display: block;
    margin-top: 0.3rem;
    overflow: hidden;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-chat-item-time {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.68rem;
    font-weight: 800;
    color: var(--text-muted);
}

.admin-chat-unread,
.admin-tab-badge {
    display: inline-flex;
    min-width: 1.2rem;
    height: 1.2rem;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--accent-color);
    color: var(--cream-color);
    font-size: 0.64rem;
    font-weight: 900;
    padding: 0 0.3rem;
}

.admin-tab-badge {
    margin-left: 0.35rem;
}

.admin-chat-reply {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.admin-chat-reply textarea {
    width: 100%;
    min-height: 4.5rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: var(--surface-color);
    padding: 0.7rem 0.9rem;
    color: var(--text-color);
    font-size: 0.86rem;
    resize: vertical;
}

.admin-chat-reply textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

@media (max-width: 480px) {
    .chat-panel {
        right: 0.7rem;
        left: 0.7rem;
        bottom: 5rem;
        width: auto;
    }

    .chat-launcher {
        right: 0.9rem;
        bottom: 0.9rem;
    }
}