:root {
    --ai-chat-primary: #0d6efd;
    --ai-chat-primary-dark: #0a58ca;
    --ai-chat-bg: #f0f4f8;
    --ai-chat-surface: #ffffff;
    --ai-chat-border: #e2e8f0;
    --ai-chat-text: #1e293b;
    --ai-chat-muted: #64748b;
    --ai-chat-radius: 14px;
}

.ai-chatbot-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10050;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-dark) 100%);
    color: #fff;
    box-shadow: 0 10px 28px rgba(13, 110, 253, 0.4);
    cursor: pointer;
    font-size: 22px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chatbot-launcher:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(13, 110, 253, 0.5);
}

.ai-chatbot-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    z-index: 10051;
    width: min(420px, calc(100vw - 24px));
    height: min(560px, calc(100vh - 110px));
    background: var(--ai-chat-surface);
    border-radius: var(--ai-chat-radius);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--ai-chat-border);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

.ai-chatbot-panel.is-open {
    display: flex;
}

.ai-chatbot-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--ai-chat-primary) 0%, var(--ai-chat-primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.ai-chatbot-header h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.ai-chatbot-header small {
    display: block;
    opacity: 0.92;
    font-size: 11px;
    font-weight: 400;
    margin-top: 2px;
}

.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 12px;
    background: var(--ai-chat-bg);
    scroll-behavior: smooth;
}

.ai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ai-chatbot-msg {
    margin-bottom: 12px;
    max-width: 92%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.ai-chatbot-msg.user {
    margin-left: auto;
    background: var(--ai-chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ai-chatbot-msg.assistant {
    margin-right: auto;
    background: var(--ai-chat-surface);
    color: var(--ai-chat-text);
    border: 1px solid var(--ai-chat-border);
    border-bottom-left-radius: 4px;
    max-width: 96%;
    padding: 12px 36px 12px 14px;
    position: relative;
}

.ai-chatbot-msg.assistant.typing {
    opacity: 0.75;
    font-style: italic;
    color: var(--ai-chat-muted);
    font-size: 13px;
    box-shadow: none;
}

/* Rich markdown content */
.ai-chatbot-msg.assistant .ai-chatbot-content {
    font-size: 13.5px;
    line-height: 1.55;
}

.ai-chatbot-msg.assistant .ai-chatbot-content > *:first-child {
    margin-top: 0;
}

.ai-chatbot-msg.assistant .ai-chatbot-content > *:last-child {
    margin-bottom: 0;
}

.ai-chatbot-msg.assistant .ai-chatbot-content p {
    margin: 0 0 10px;
}

.ai-chatbot-msg.assistant .ai-chatbot-content h1,
.ai-chatbot-msg.assistant .ai-chatbot-content h2,
.ai-chatbot-msg.assistant .ai-chatbot-content h3,
.ai-chatbot-msg.assistant .ai-chatbot-content h4 {
    margin: 14px 0 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--ai-chat-text);
    line-height: 1.35;
}

.ai-chatbot-msg.assistant .ai-chatbot-content h3 {
    font-size: 13.5px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--ai-chat-border);
}

.ai-chatbot-msg.assistant .ai-chatbot-content hr {
    border: none;
    border-top: 1px solid var(--ai-chat-border);
    margin: 12px 0;
}

.ai-chatbot-msg.assistant .ai-chatbot-content strong {
    font-weight: 600;
    color: #0f172a;
}

.ai-chatbot-msg.assistant .ai-chatbot-content a {
    color: #0369a1;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chatbot-msg.assistant .ai-chatbot-content a:hover {
    color: #0c4a6e;
}

.ai-chatbot-msg.assistant .ai-chatbot-content ul,
.ai-chatbot-msg.assistant .ai-chatbot-content ol {
    margin: 8px 0 10px;
    padding-left: 1.25rem;
}

.ai-chatbot-msg.assistant .ai-chatbot-content li {
    margin-bottom: 6px;
}

.ai-chatbot-msg.assistant .ai-chatbot-content li:last-child {
    margin-bottom: 0;
}

.ai-chatbot-msg.assistant .ai-chatbot-content blockquote {
    margin: 10px 0;
    padding: 8px 12px;
    background: #fff8e6;
    border-left: 3px solid #f59e0b;
    border-radius: 0 8px 8px 0;
    font-size: 12.5px;
    color: #92400e;
}

.ai-chatbot-msg.assistant .ai-chatbot-content blockquote p {
    margin: 0;
}

.ai-chatbot-table-wrap {
    overflow-x: auto;
    margin: 10px 0 12px;
    border-radius: 8px;
    border: 1px solid var(--ai-chat-border);
    -webkit-overflow-scrolling: touch;
}

.ai-chatbot-msg.assistant .ai-chatbot-content table {
    width: 100%;
    min-width: 280px;
    border-collapse: collapse;
    font-size: 12px;
    margin: 0;
}

.ai-chatbot-msg.assistant .ai-chatbot-content th {
    background: #f1f5f9;
    color: var(--ai-chat-text);
    font-weight: 600;
    text-align: left;
    padding: 8px 10px;
    white-space: nowrap;
    border-bottom: 1px solid var(--ai-chat-border);
}

.ai-chatbot-msg.assistant .ai-chatbot-content td {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.ai-chatbot-msg.assistant .ai-chatbot-content tr:last-child td {
    border-bottom: none;
}

.ai-chatbot-msg.assistant .ai-chatbot-content tr:hover td {
    background: #f8fafc;
}

.ai-chatbot-msg.assistant .ai-chatbot-content code {
    font-size: 12px;
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 4px;
}

.ai-chatbot-footer {
    padding: 12px;
    border-top: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-surface);
    flex-shrink: 0;
}

.ai-chatbot-footer form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-chatbot-footer form.is-hidden {
    display: none;
}

.ai-chatbot-recording {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
}

.ai-chatbot-recording[hidden] {
    display: none !important;
}

.ai-chatbot-recording-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    flex-shrink: 0;
    animation: ai-chatbot-rec-pulse 1s ease-in-out infinite;
}

.ai-chatbot-recording.is-transcribing .ai-chatbot-recording-pulse {
    background: var(--ai-chat-primary);
    animation: ai-chatbot-rec-pulse 0.7s ease-in-out infinite;
}

.ai-chatbot-recording.is-transcribing {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.ai-chatbot-recording-label {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: #991b1b;
}

.ai-chatbot-recording.is-transcribing .ai-chatbot-recording-label {
    color: #1e40af;
}

.ai-chatbot-stop-record {
    border: none;
    background: #ef4444;
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.ai-chatbot-stop-record:hover:not(:disabled) {
    background: #dc2626;
}

.ai-chatbot-stop-record:disabled {
    opacity: 0.55;
    cursor: default;
}

@keyframes ai-chatbot-rec-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.65; }
}

.ai-chatbot-footer input[type="text"] {
    flex: 1;
    border: 1px solid var(--ai-chat-border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-chatbot-footer input[type="text"]:focus {
    border-color: var(--ai-chat-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.ai-chatbot-footer button[type="submit"] {
    border: none;
    background: var(--ai-chat-primary);
    color: #fff;
    border-radius: 10px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.ai-chatbot-footer button[type="submit"]:hover {
    background: var(--ai-chat-primary-dark);
}

.ai-chatbot-actions button {
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.ai-chatbot-actions button:hover {
    background: rgba(255, 255, 255, 0.28);
}

.ai-chatbot-actions .ai-chatbot-speak-toggle.is-active {
    background: rgba(255, 255, 255, 0.35);
}

.ai-chatbot-actions .ai-chatbot-reset {
    color: #fca5a5;
    background: rgba(220, 38, 38, 0.35);
}

.ai-chatbot-actions .ai-chatbot-reset:hover {
    color: #fff;
    background: #dc2626;
}

.ai-chatbot-msg-speak {
    position: absolute;
    top: 8px;
    right: 6px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 6px;
    background: #f1f5f9;
    color: var(--ai-chat-muted);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-chatbot-msg-speak:hover {
    background: #e2e8f0;
    color: var(--ai-chat-primary);
}

.ai-chatbot-mic {
    border: 1px solid var(--ai-chat-border);
    background: var(--ai-chat-surface);
    color: var(--ai-chat-muted);
    border-radius: 10px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ai-chatbot-mic:hover {
    color: var(--ai-chat-primary);
    border-color: var(--ai-chat-primary);
}

.ai-chatbot-mic.is-listening {
    background: #fee2e2;
    border-color: #ef4444;
    color: #dc2626;
    animation: ai-chatbot-pulse 1.2s ease-in-out infinite;
}

@keyframes ai-chatbot-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

@media (max-width: 576px) {
    .ai-chatbot-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: min(85vh, 100%);
        border-radius: var(--ai-chat-radius) var(--ai-chat-radius) 0 0;
    }

    .ai-chatbot-launcher {
        right: 16px;
        bottom: 16px;
    }

    .ai-chatbot-msg.assistant {
        max-width: 98%;
    }
}
