/* Archanis AI Chat Widget */
.chat-widget {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chat-launcher {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    border: none;
    background: var(--primary-color, #2563eb);
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 14px rgb(37 99 235 / 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-launcher:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgb(37 99 235 / 0.5);
}

.chat-launcher svg {
    width: 1.5rem;
    height: 1.5rem;
}

.chat-launcher[aria-expanded="true"] {
    display: none;
}

.chat-prompt-bubble {
    position: absolute;
    bottom: 4.25rem;
    right: 0;
    max-width: 260px;
    background: white;
    border-radius: 12px;
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-lg, 0 10px 25px rgb(0 0 0 / 0.15));
    border: 1px solid var(--border-color, #e2e8f0);
    animation: chatBubbleIn 0.35s ease;
}

.chat-prompt-bubble::after {
    content: "";
    position: absolute;
    bottom: -8px;
    right: 1.25rem;
    border: 8px solid transparent;
    border-top-color: white;
}

.chat-prompt-bubble p {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-dark, #1e293b);
}

.chat-prompt-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.chat-prompt-actions button {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 600;
}

.chat-prompt-open {
    background: var(--primary-color, #2563eb);
    color: white;
}

.chat-prompt-dismiss {
    background: var(--bg-light, #f8fafc);
    color: var(--text-light, #64748b);
}

.chat-prompt-close {
    position: absolute;
    top: 0.35rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-light, #64748b);
    cursor: pointer;
    padding: 0.25rem;
}

@keyframes chatBubbleIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-panel {
    display: none;
    flex-direction: column;
    width: min(380px, calc(100vw - 2rem));
    height: min(520px, calc(100vh - 6rem));
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgb(0 0 0 / 0.18);
    border: 1px solid var(--border-color, #e2e8f0);
    overflow: hidden;
}

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

.chat-header {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 15%;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
    border: 2px solid rgb(255 255 255 / 0.9);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-info h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chat-header-info p {
    font-size: 0.75rem;
    margin: 0.15rem 0 0;
    opacity: 0.9;
}

.chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

.chat-header-actions button {
    background: rgb(255 255 255 / 0.15);
    border: none;
    color: white;
    width: 2rem;
    height: 2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.chat-header-actions button:hover {
    background: rgb(255 255 255 / 0.25);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-light, #f8fafc);
}

.chat-message {
    max-width: 88%;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--primary-color, #2563eb);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    align-self: flex-start;
    background: white;
    color: var(--text-dark, #1e293b);
    border: 1px solid var(--border-color, #e2e8f0);
    border-bottom-left-radius: 4px;
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--text-light, #64748b);
    font-size: 0.8rem;
    text-align: center;
    padding: 0.25rem;
}

.chat-message-links {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.chat-message-links a {
    color: var(--primary-color, #2563eb);
    font-size: 0.85rem;
    font-weight: 500;
}

.chat-message.user .chat-message-links a {
    color: white;
    text-decoration: underline;
}

.chat-typing {
    align-self: flex-start;
    padding: 0.5rem 0.75rem;
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border-color, #e2e8f0);
    font-size: 0.85rem;
    color: var(--text-light, #64748b);
}

.chat-quick-actions {
    padding: 0.5rem 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
    background: white;
}

.chat-quick-actions button {
    font-size: 0.75rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border-color, #e2e8f0);
    background: var(--bg-light, #f8fafc);
    color: var(--text-dark, #1e293b);
    cursor: pointer;
    white-space: nowrap;
}

.chat-quick-actions button:hover {
    border-color: var(--primary-color, #2563eb);
    color: var(--primary-color, #2563eb);
}

.chat-human-btn {
    border-color: var(--primary-color, #2563eb) !important;
    color: var(--primary-color, #2563eb) !important;
    font-weight: 600;
}

.chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
    background: white;
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input-row textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    min-height: 2.5rem;
    max-height: 6rem;
}

.chat-input-row textarea:focus {
    outline: 2px solid var(--primary-color, #2563eb);
    outline-offset: 0;
    border-color: transparent;
}

.chat-send {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    border: none;
    background: var(--primary-color, #2563eb);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
}

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

.chat-handoff-form {
    display: none;
    flex-direction: column;
    background: var(--bg-light, #f8fafc);
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chat-handoff-form.visible {
    display: flex;
}

.chat-handoff-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-handoff-scroll h3 {
    font-size: 1rem;
    margin: 0;
    color: var(--text-dark, #1e293b);
}

.chat-handoff-scroll p {
    font-size: 0.85rem;
    color: var(--text-light, #64748b);
    margin: 0;
}

.chat-handoff-scroll label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-dark, #1e293b);
}

.chat-handoff-scroll input,
.chat-handoff-scroll textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    box-sizing: border-box;
}

.chat-handoff-scroll textarea {
    min-height: 5.5rem;
    max-height: 8rem;
    resize: vertical;
}

.chat-handoff-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
    background: white;
}

.chat-handoff-form button[type="submit"] {
    flex: 1;
    padding: 0.65rem;
    background: var(--primary-color, #2563eb);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.chat-handoff-form .chat-handoff-back {
    padding: 0.65rem 1rem;
    background: white;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    cursor: pointer;
}

.chat-body-hidden {
    display: none !important;
}

@media (max-width: 480px) {
    .chat-widget {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
    }

    .chat-panel {
        width: 100%;
        height: min(85vh, 520px);
    }

    .chat-prompt-bubble {
        right: 0;
        left: 0;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-prompt-bubble {
        animation: none;
    }
}
