/* --- Chat Widget --- */
.chat-widget {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 60;
    display: grid;
    justify-items: end;
    gap: 0.75rem;
}

.chat-launcher {
    min-width: 13rem;
    min-height: 3.75rem;
    padding: 0.95rem 1.2rem;
    border-radius: 999px;
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: var(--shadow);
}

.chat-launcher-copy {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-panel {
    width: min(24rem, calc(100vw - 1.5rem));
    max-height: min(42rem, calc(100vh - 6rem));
    display: grid;
    gap: 0.9rem;
    padding: 1rem;
    border-radius: 24px;
    background: rgba(255, 252, 246, 0.98);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.chat-panel-header,
.chat-field,
.chat-form,
.chat-messages,
.chat-message {
    display: grid;
    gap: 0.75rem;
}

.chat-panel-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
}

.chat-panel-header h2 {
    margin: 0;
}

.chat-messages {
    min-height: 10rem;
    max-height: 18rem;
    overflow: auto;
    align-content: start;
}

.chat-message {
    padding: 0.85rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--line);
}

.chat-message.is-customer {
    justify-self: start;
}

.chat-message.is-admin {
    justify-self: end;
    background: rgba(15, 118, 110, 0.12);
    border-color: rgba(15, 118, 110, 0.22);
}

.chat-message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    justify-content: space-between;
}

.chat-message-meta {
    color: var(--muted);
    font-size: 0.88rem;
}

.chat-field input,
.chat-field textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.7rem 0.9rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface-strong);
    color: var(--ink);
    font: inherit;
}

.chat-field textarea {
    min-height: 6rem;
    resize: vertical;
}

.chat-status {
    min-height: 1.25rem;
    margin: 0;
    color: var(--muted);
}

.chat-status.is-error {
    color: #9a3412;
}

.chat-panel-body {
    display: grid;
    grid-template-rows: 1fr auto;
    gap: 0.75rem;
    min-height: 12rem;
    overflow: hidden;
}

.chat-init-fields {
    margin: 0;
    padding: 0;
    border: 0;
    display: grid;
    gap: 0.75rem;
}

.chat-message-field {
    margin: 0;
}

.chat-field textarea {
    min-height: 5rem;
    resize: vertical;
}

.chat-actions {
    display: grid;
    gap: 0.5rem;
}

.chat-actions .button {
    width: 100%;
}

.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.chat-typing-indicator[hidden] {
    display: none !important;
}

.chat-typing-indicator span {
    display: inline-block;
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--muted);
    animation: chat-typing-bounce 1.4s infinite ease-in-out both;
}

.chat-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@media (max-width: 640px) {
    .hero h1,
    .catalog-header h1,
    .about-page h1,
    .not-found h1 {
        font-size: 2.4rem;
    }

    .chat-widget {
        right: 0.75rem;
        left: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        justify-items: stretch;
    }

    .chat-launcher {
        width: 100%;
        min-height: 4.25rem;
        padding: 1rem 1.1rem;
        font-size: 1rem;
        touch-action: manipulation;
    }

    .chat-panel {
        width: 100%;
        max-height: min(36rem, calc(100vh - 6.25rem));
        padding: 1rem;
        border-radius: 24px 24px 20px 20px;
    }

    .chat-panel-body {
        min-height: 10rem;
    }

    .chat-panel-header {
        gap: 0.65rem;
    }

    .chat-messages {
        max-height: min(14rem, calc(100vh - 18rem));
    }

    .chat-field input,
    .chat-field textarea,
    .chat-form .button {
        font-size: 16px;
    }

    .chat-field textarea {
        min-height: 4rem;
    }
}