/* Chat widget built by chat.js. Uses the homepage tokens from home.css. */

.chat-launcher {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1001;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.72rem 1.1rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-strong);
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    transition: border-color 0.15s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.chat-launcher:hover,
.chat-launcher[aria-expanded="true"] {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.chat-launcher svg {
    width: 19px;
    height: 19px;
    color: var(--accent-strong);
}

.chat-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 5rem;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    width: 370px;
    height: min(540px, calc(100vh - 7.5rem));
    height: min(540px, calc(100dvh - 7.5rem));
    background: var(--surface-1);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* display: flex above would otherwise override the hidden attribute */
.chat-panel[hidden] {
    display: none;
}

.chat-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem 0.8rem;
    border-bottom: 1px solid var(--border);
}

.chat-title {
    margin: 0;
    padding-left: 0.55rem;
    border-left: 3px solid var(--accent);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-strong);
}

.chat-sub {
    margin: 0.2rem 0 0;
    padding-left: calc(0.55rem + 3px);
    font-size: 0.75rem;
    color: var(--text-faint);
}

.chat-close {
    padding: 0 0.2rem;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.chat-close:hover {
    color: var(--text-strong);
}

.chat-log {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.chat-msg {
    max-width: 85%;
    padding: 0.55rem 0.8rem;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-msg-bot {
    align-self: flex-start;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text);
}

.chat-msg-user {
    align-self: flex-end;
    background: var(--accent-soft);
    border: 1px solid rgba(87, 168, 110, 0.35);
    border-bottom-right-radius: 4px;
    color: var(--text-strong);
}

.chat-msg-error {
    align-self: flex-start;
    padding: 0 0.2rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.chat-suggestions button {
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 0.78rem;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.chat-suggestions button:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.chat-typing {
    display: flex;
    gap: 0.25rem;
    padding: 0.75rem 0.8rem;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: chat-blink 1.2s infinite ease-in-out;
}

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

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

@keyframes chat-blink {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-typing span {
        animation: none;
        opacity: 0.6;
    }
}

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

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text-strong);
    font: inherit;
    font-size: 0.88rem;
}

.chat-input::placeholder {
    color: var(--text-faint);
}

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

.chat-send {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 2.4rem;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: var(--bg);
    cursor: pointer;
    transition: opacity 0.15s;
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.chat-send svg {
    width: 16px;
    height: 16px;
}

.chat-note {
    margin: 0;
    padding: 0 1rem 0.75rem;
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--text-faint);
}

@media (max-width: 520px) {
    .chat-launcher {
        right: 1rem;
        bottom: 1rem;
    }

    .chat-panel {
        left: 1rem;
        right: 1rem;
        bottom: 4.75rem;
        width: auto;
    }
}
