* {
    box-sizing: border-box;
}

:root {
    --bg: #f2f4f7;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --primary: #78003f;
    --primary-text: #ffffff;
    --assistant-bubble: #eef1f6;
    --shadow: rgba(15, 23, 42, 0.08);
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
}

.chat-app {
    position: relative;
    width: 100%;
    max-width: 720px;
    height: min(85vh, 860px);
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header-title h1 {
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}

.chat-header-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clear-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.clear-btn:hover {
    background: #f3f4f6;
    color: var(--text);
}

.contact-btn {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: var(--primary-text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.contact-btn:hover {
    opacity: 0.9;
}

/* --- Contact form overlay --- */
.contact-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10;
}

.contact-overlay.hidden {
    display: none;
}

.contact-panel {
    background: var(--surface);
    border-radius: 14px;
    padding: 20px;
    width: 100%;
    max-width: 420px;
    max-height: 100%;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
}

.contact-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.contact-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.contact-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}

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

.contact-intro {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0 0 14px;
}

.contact-field {
    display: block;
    margin-bottom: 12px;
}

.contact-field span {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.contact-field input,
.contact-field textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 12px;
    /* 16px minimum stops iOS Safari from auto-zooming when the field is focused. */
    font-size: 16px;
    font-family: inherit;
    outline: none;
    resize: vertical;
    transition: border-color 0.15s ease;
}

.contact-field input:focus,
.contact-field textarea:focus {
    border-color: var(--primary);
}

.contact-consent {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 12px;
    cursor: pointer;
}

.contact-consent input {
    margin-top: 2px;
    flex: 0 0 auto;
    accent-color: var(--primary);
}

.contact-status {
    font-size: 13px;
    color: var(--text-muted);
    min-height: 18px;
    margin-bottom: 10px;
}

.contact-status.success {
    color: #16a34a;
    font-weight: 600;
}

.contact-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.contact-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
}

.contact-cancel:hover {
    background: #f3f4f6;
    color: var(--text);
}

.contact-submit {
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    border-radius: 10px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.contact-submit:hover {
    opacity: 0.9;
}

.contact-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    max-width: 100%;
}

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

.message.assistant {
    justify-content: flex-start;
}

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.45;
    font-size: 14.5px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.user .bubble {
    background: var(--primary);
    color: var(--primary-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--assistant-bubble);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message.error .bubble {
    background: #fee2e2;
    color: #991b1b;
}

.bubble a {
    color: var(--primary);
    text-decoration: underline;
    word-break: break-word;
}

.message.user .bubble a {
    color: var(--primary-text);
}

.loading-indicator {
    display: flex;
    gap: 4px;
    padding: 0 20px 10px;
}

.loading-indicator.hidden {
    display: none;
}

.loading-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.message-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    /* 16px minimum stops iOS Safari from auto-zooming when the field is focused. */
    font-size: 16px;
    font-family: inherit;
    min-height: 60px;
    max-height: 140px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease;
}

.message-input:focus {
    border-color: var(--primary);
}

.send-btn {
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    border-radius: 12px;
    padding: 10px 18px;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.send-btn:hover {
    opacity: 0.9;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .chat-app {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
        border: none;
    }

    .bubble {
        max-width: 88%;
    }
}
