.spiritual-chat {
    --chat-ink: #32160f;
    --chat-brown: #4a241b;
    --chat-copper: #8c4a35;
    --chat-gold: #d49b35;
    --chat-paper: #fffaf4;
    --chat-line: #ead8c4;
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 110;
    color: var(--chat-ink);
    font-family: 'Inter', system-ui, sans-serif;
}

.spiritual-chat [hidden] {
    display: none !important;
}

.spiritual-chat button,
.spiritual-chat select,
.spiritual-chat textarea {
    font: inherit;
}

.spiritual-chat button:focus-visible,
.spiritual-chat select:focus-visible,
.spiritual-chat textarea:focus-visible {
    outline: 3px solid rgba(212, 155, 53, 0.7);
    outline-offset: 2px;
}

.spiritual-chat-launcher {
    display: inline-flex;
    min-height: 58px;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    padding: 0 1.15rem;
    border: 1px solid #f4c46d;
    border-radius: 999px;
    background: var(--chat-brown);
    color: #fffaf4;
    box-shadow: 0 10px 30px rgba(36, 12, 7, 0.28);
    cursor: pointer;
    font-weight: 700;
    transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.spiritual-chat-launcher:hover {
    transform: translateY(-2px);
    background: #602c1e;
    box-shadow: 0 14px 34px rgba(36, 12, 7, 0.32);
}

.chat-launcher-mark {
    color: #f4c46d;
    font-size: 1.25rem;
    line-height: 1;
}

.spiritual-chat-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    display: grid;
    width: min(430px, calc(100vw - 32px));
    height: min(700px, calc(100vh - 40px));
    height: min(700px, calc(100dvh - 40px));
    grid-template-rows: auto auto minmax(130px, 1fr) auto auto auto;
    overflow: hidden;
    border: 1px solid rgba(212, 155, 53, 0.52);
    border-radius: 18px;
    background: var(--chat-paper);
    box-shadow: 0 24px 70px rgba(36, 12, 7, 0.32);
    transform-origin: bottom right;
}

.spiritual-chat-panel.is-open {
    animation: chat-panel-arrive 180ms ease-out both;
}

@keyframes chat-panel-arrive {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.spiritual-chat-header {
    display: flex;
    min-height: 76px;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.8rem 1rem;
    background: var(--chat-brown);
    color: #fffaf4;
}

.chat-header-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.7rem;
}

.chat-brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid #e7bd70;
    border-radius: 50%;
    color: #f4c46d;
    font-family: 'Noto Serif Tamil', serif;
    font-size: 1.25rem;
}

.chat-header-brand h2 {
    margin: 0;
    color: #fffaf4;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.05;
}

.chat-header-brand p {
    margin: 0.25rem 0 0;
    color: #f1d7b9;
    font-size: 0.72rem;
    line-height: 1.3;
}

.chat-header-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 0.35rem;
}

.chat-icon-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid rgba(255, 250, 244, 0.28);
    border-radius: 50%;
    background: transparent;
    color: #fffaf4;
    cursor: pointer;
    font-size: 1.3rem;
    line-height: 1;
}

.chat-icon-button:hover {
    background: rgba(255, 250, 244, 0.14);
}

.chat-toolbar {
    display: flex;
    min-height: 48px;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.8rem;
    border-bottom: 1px solid var(--chat-line);
    background: #fbf1e6;
}

.chat-toolbar label {
    color: #6b4a3c;
    font-size: 0.75rem;
    font-weight: 600;
}

.chat-toolbar select {
    max-width: 108px;
    padding: 0.3rem 1.3rem 0.3rem 0.45rem;
    border: 1px solid #d8bea3;
    border-radius: 6px;
    background: #fffaf4;
    color: var(--chat-ink);
    font-size: 0.78rem;
}

.chat-clear-button {
    margin-left: auto;
    padding: 0.35rem 0.2rem;
    border: 0;
    background: transparent;
    color: #74402e;
    cursor: pointer;
    font-size: 0.74rem;
    font-weight: 600;
}

.chat-clear-button:hover {
    color: #a24321;
    text-decoration: underline;
}

.chat-transcript {
    display: flex;
    min-height: 0;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem 0.85rem 0.7rem;
    scroll-behavior: smooth;
}

.chat-message {
    display: flex;
    max-width: 91%;
    flex-direction: column;
    gap: 0.4rem;
    align-self: flex-start;
    animation: chat-message-arrive 160ms ease-out both;
}

.chat-message-user {
    align-self: flex-end;
}

@keyframes chat-message-arrive {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message-label {
    padding: 0 0.55rem;
    color: #765646;
    font-size: 0.67rem;
    font-weight: 700;
}

.chat-message-user .chat-message-label {
    text-align: right;
}

.chat-message-body {
    padding: 0.7rem 0.8rem;
    border: 1px solid #ead8c4;
    border-radius: 4px 14px 14px 14px;
    background: #fff;
    color: #32160f;
    font-size: 0.88rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-message-user .chat-message-body {
    border-color: #8c4a35;
    border-radius: 14px 4px 14px 14px;
    background: #8c4a35;
    color: #fff;
}

.chat-message-error .chat-message-body {
    border-color: #c8654b;
    background: #fff0eb;
    color: #642b1b;
}

.chat-source-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0 0.4rem;
}

.chat-source-links a {
    color: #71402e;
    font-size: 0.72rem;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-followups {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.1rem 0.4rem 0;
}

.chat-followups button,
.chat-retry-button {
    min-height: 32px;
    padding: 0.35rem 0.55rem;
    border: 1px solid #d9b878;
    border-radius: 6px;
    background: #fff9ed;
    color: #57301f;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 600;
}

.chat-followups button:hover,
.chat-retry-button:hover {
    background: #f7e5c8;
}

.chat-typing {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 0.3rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid #ead8c4;
    border-radius: 4px 14px 14px 14px;
    background: #fff;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8c4a35;
    animation: chat-typing-bounce 850ms ease-in-out infinite alternate;
}

.chat-typing span:nth-child(2) { animation-delay: 160ms; }
.chat-typing span:nth-child(3) { animation-delay: 320ms; }

@keyframes chat-typing-bounce {
    to { opacity: 0.35; transform: translateY(-3px); }
}

.chat-suggestions {
    display: flex;
    max-height: 92px;
    flex-wrap: wrap;
    gap: 0.4rem;
    overflow-y: auto;
    padding: 0.55rem 0.8rem;
    border-top: 1px solid #f0e2d2;
}

.chat-suggestions button {
    min-height: 30px;
    padding: 0.3rem 0.55rem;
    border: 1px solid #ddc9af;
    border-radius: 999px;
    background: #fff;
    color: #5e3728;
    cursor: pointer;
    font-size: 0.7rem;
    line-height: 1.2;
}

.chat-suggestions button:hover {
    border-color: #bd8c3e;
    background: #fff4df;
}

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border-top: 1px solid var(--chat-line);
    background: #fffdf9;
}

.chat-composer textarea {
    width: 100%;
    max-height: 110px;
    min-height: 42px;
    resize: none;
    padding: 0.65rem 0.7rem;
    border: 1px solid #d9c5ae;
    border-radius: 8px;
    background: #fff;
    color: var(--chat-ink);
    font-size: 0.86rem;
    line-height: 1.4;
}

.chat-composer textarea::placeholder {
    color: #816b5c;
}

.chat-send-button {
    display: grid;
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid #f4c46d;
    border-radius: 8px;
    background: #4a241b;
    color: #fffaf4;
    cursor: pointer;
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
}

.chat-send-button:hover:not(:disabled) {
    background: #713822;
}

.chat-send-button:disabled {
    cursor: wait;
    opacity: 0.58;
}

.chat-privacy-note {
    margin: 0;
    padding: 0 0.7rem 0.55rem;
    background: #fffdf9;
    color: #755f50;
    font-size: 0.65rem;
    text-align: center;
}

.spiritual-chat-minimized {
    display: flex;
    min-width: 220px;
    min-height: 50px;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0.55rem 0.35rem 0.9rem;
    border: 1px solid #f4c46d;
    border-radius: 12px;
    background: var(--chat-brown);
    color: #fffaf4;
    box-shadow: 0 10px 30px rgba(36, 12, 7, 0.28);
    font-weight: 700;
}

.spiritual-chat-minimized .chat-icon-button {
    transform: rotate(180deg);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    clip-path: inset(50%);
}

@media (max-width: 560px) {
    .spiritual-chat {
        right: 0.5rem;
        bottom: 6.75rem;
        z-index: 130;
    }

    .spiritual-chat-panel {
        position: fixed;
        right: 0.5rem;
        bottom: 0.5rem;
        left: 0.5rem;
        width: auto;
        height: min(760px, calc(100vh - 16px));
        height: min(760px, calc(100dvh - 16px));
        grid-template-rows: auto auto minmax(100px, 1fr) auto auto auto;
        border-radius: 14px;
        transform-origin: bottom center;
    }

    .spiritual-chat-launcher {
        min-height: 52px;
        padding: 0 0.9rem;
        font-size: 0.88rem;
    }

    .chat-suggestions {
        max-height: 82px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .spiritual-chat *,
    .spiritual-chat *::before,
    .spiritual-chat *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}