.ai-chat-shell {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: min(420px, calc(100vw - 32px));
    height: min(80dvh, calc(100dvh - 32px));
    max-height: 80dvh;
    min-height: min(420px, calc(100dvh - 48px));
    border-radius: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18), 0 4px 12px rgba(0,0,0,0.08);
    transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    border: 1px solid rgba(0,0,0,0.06);
    overflow: hidden;
    backdrop-filter: blur(8px);
}

.ai-chat-shell.minimized {
    height: auto;
    min-height: unset;
    max-height: none;
    width: min(340px, calc(100vw - 16px));
    transform: translateY(0);
}

/* Header children must shrink so Minimize/Close stay reachable on narrow screens.
   Without min-width:0 the title + chips push the buttons outside the clipped shell. */
.ai-header .flex-grow-1,
.ai-header .mud-typography {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-header .mud-icon-button {
    flex-shrink: 0;
}

.ai-header {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--mud-palette-primary) 0%, var(--mud-palette-secondary) 100%) !important;
    border-radius: 16px 16px 0 0;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.ai-header::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(255,255,255,0.08) 0%, transparent 50%);
    pointer-events: none;
}

.ai-header-minimized {
    border-radius: 12px;
    cursor: pointer;
}

.ai-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.ai-reconnecting-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    background: var(--mud-palette-warning);
    color: white;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.white-text { color: white !important; }
.opacity-50 { opacity: 0.5; }
.opacity-60 { opacity: 0.6; }
.opacity-40 { opacity: 0.4; }

.chat-container {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    min-height: 0;
    background: linear-gradient(to bottom, var(--mud-palette-background) 0%, var(--mud-palette-surface) 100%);
    padding-bottom: 4px;
}

.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--mud-palette-lines-inputs); border-radius: 10px; opacity: 0.5; }
.chat-container::-webkit-scrollbar-thumb:hover { background: var(--mud-palette-primary); opacity: 0.8; }

.message-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 10px;
    animation: fadeSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }

.message-bubble {
    max-width: 78%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    line-height: 1.5;
    font-size: 0.875rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

.message-bubble:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.bubble-user {
    background: linear-gradient(135deg, var(--mud-palette-primary) 0%, var(--mud-palette-primary-darken) 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.bubble-ai {
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-bottom-left-radius: 6px;
}

.streaming-bubble {
    border-left: 3px solid var(--mud-palette-primary);
}

.message-time {
    display: block;
    margin-top: 4px;
    font-size: 0.65rem;
}

.cursor-blink {
    animation: blink 0.8s step-end infinite;
    font-weight: bold;
    color: var(--mud-palette-primary);
}

@keyframes blink {
    50% { opacity: 0; }
}

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

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--mud-palette-primary);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot-2 { animation-delay: 0.2s; }
.typing-dot-3 { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

.chip-glow {
    animation: glowPulse 2s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(var(--mud-palette-secondary-rgb), 0.3); }
    50% { box-shadow: 0 0 12px rgba(var(--mud-palette-secondary-rgb), 0.6); }
}

.suggestions-section {
    border-top: 1px solid var(--mud-palette-lines-inputs);
    padding: 4px 8px;
    flex-shrink: 0;
}

.suggestions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 2px 0;
    user-select: none;
}

.suggestions-header:hover { opacity: 0.7; }

.suggestions-label {
    font-size: 0.7rem !important;
    line-height: 1.2;
    color: var(--mud-palette-text-secondary);
}

.suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    padding-top: 2px;
    max-height: 72px;
    overflow-y: auto;
    overflow-x: hidden;
    align-content: flex-start;
}

.suggestions-list::-webkit-scrollbar { width: 4px; }
.suggestions-list::-webkit-scrollbar-thumb { background: var(--mud-palette-lines-inputs); border-radius: 4px; }

.suggestion-chip {
    transition: all 0.2s ease;
    cursor: pointer;
}

.suggestion-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.input-section {
    border-top: 1px solid var(--mud-palette-lines-inputs);
    background: var(--mud-palette-surface);
    padding: 8px;
    flex-shrink: 0;
}

.message-row.tool-message {
    display: flex;
    justify-content: flex-start;
    margin: 10px 4px;
}

.tool-card {
    background: var(--mud-palette-surface) !important;
    border-radius: 14px;
    padding: 14px 16px;
    width: 100%;
    border: 1px solid var(--mud-palette-lines-inputs);
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.tool-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }

.tool-card.result-card.success { border-color: var(--mud-palette-success); background: color-mix(in srgb, var(--mud-palette-success) 4%, var(--mud-palette-surface)) !important; }
.tool-card.result-card.error { border-color: var(--mud-palette-error); background: color-mix(in srgb, var(--mud-palette-error) 4%, var(--mud-palette-surface)) !important; }

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--mud-palette-text-primary);
}

.tool-card-body {
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
    margin-bottom: 10px;
    white-space: pre-wrap;
    line-height: 1.5;
    background: var(--mud-palette-background-grey);
    padding: 10px 12px;
    border-radius: 8px;
}

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

.tool-card-footer { margin-top: 10px; }
.info-alert { font-size: 0.85rem; border-radius: 10px; }

.markdown-content h1, .markdown-content h2, .markdown-content h3 { margin: 8px 0 4px; }
.markdown-content ul, .markdown-content ol { margin: 4px 0; padding-left: 20px; }
.markdown-content code { background: var(--mud-palette-background-grey); padding: 1px 4px; border-radius: 3px; font-size: 0.85em; }
.markdown-content pre { background: var(--mud-palette-background-grey); padding: 8px; border-radius: 6px; overflow-x: auto; }
.markdown-content pre code { background: none; padding: 0; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 600px) {
    .ai-chat-shell {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        min-height: 0;
        border-radius: 0;
        box-shadow: none;
    }
    .ai-chat-shell.minimized {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        border-radius: 12px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    }
    .ai-header { border-radius: 0; padding: 12px; gap: 6px; }
    .ai-chat-shell.minimized .ai-header { border-radius: 12px; }
    .message-bubble { max-width: 85%; }
}

@media (min-width: 601px) and (max-width: 960px) {
    .ai-chat-shell { width: 380px; right: 16px; bottom: 16px; }
}

.tool-card.destructive { border-color: var(--mud-palette-error) !important; border-width: 1.5px; }
.tool-card.destructive .tool-card-header { color: var(--mud-palette-error); }

@media (prefers-reduced-motion: reduce) {
    .message-row { animation: none; }
    .typing-dot { animation: none; }
    .chip-glow { animation: none; }
    .cursor-blink { animation: none; }
    .chat-container { scroll-behavior: auto; }
}
.ai-live-dot-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-live-dot-wrapper.size-small { width: 12px; height: 12px; }
.ai-live-dot-wrapper.size-medium { width: 16px; height: 16px; }
.ai-live-dot-wrapper.size-large { width: 20px; height: 20px; }

.ai-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    position: relative;
    z-index: 2;
    animation: aiHeartbeat 1.8s ease-in-out infinite;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.size-small .ai-live-dot { width: 6px; height: 6px; }
.size-large .ai-live-dot { width: 10px; height: 10px; }

.ai-live-dot.live {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.7), 0 0 16px rgba(34, 197, 94, 0.3);
}

.ai-live-dot.configured {
    background: #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
    animation: aiPulse 2s ease-in-out infinite;
}

.ai-live-dot.offline {
    background: #94a3b8;
    box-shadow: none;
    animation: none;
    opacity: 0.7;
}

.ai-live-dot-wavery {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px solid #22c55e;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
}

.ai-live-dot-wavery.wavery-1 {
    animation: aiWavery 2s ease-out infinite;
}

.ai-live-dot-wavery.wavery-2 {
    animation: aiWavery 2s ease-out infinite 1s;
}

@keyframes aiWavery {
    0% { transform: scale(0.6); opacity: 0.7; }
    100% { transform: scale(2.4); opacity: 0; }
}

@keyframes aiHeartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.18); }
    30% { transform: scale(0.95); }
    45% { transform: scale(1.08); }
    60% { transform: scale(1); }
}

@keyframes aiPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

@media (prefers-reduced-motion: reduce) {
    .ai-live-dot, .ai-live-dot-wavery { animation: none; }
    .ai-live-dot.live { box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }
}
