:root {
    --bg-color: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --user-msg-bg: #6366f1;
    --ai-msg-bg: rgba(30, 41, 59, 0.8);
    --danger-color: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-color);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(168, 85, 247, 0.15), transparent 25%);
    background-size: 150% 150%;
    animation: ambientBg 12s ease-in-out infinite alternate;
    color: var(--text-primary);
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

@keyframes ambientBg {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 900px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

@media (min-width: 768px) {
    .app-container {
        height: 90vh;
        border-radius: 24px;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        overflow: hidden;
    }
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    gap: 16px;
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.avatar-container {
    position: relative;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #6366f1, #a855f7);
}

.avatar.ai-avatar span {
    color: white;
    font-size: 28px;
}

.avatar.ai-avatar {
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.4);
    animation: avatarPulse 3s infinite alternate ease-in-out;
}

@keyframes avatarPulse {
    0% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.3); }
    100% { box-shadow: 0 0 25px rgba(99, 102, 241, 0.6); }
}

.status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background-color: #22c55e;
    border-radius: 50%;
    border: 2px solid var(--bg-color);
    box-shadow: 0 0 8px #22c55e;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.header-info {
    flex-grow: 1;
}

.header-info h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.status-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Area */
.chat-box {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar {
    width: 6px;
}

.chat-box::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

/* Messages */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease-out forwards;
}

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

.ai-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.ai-message .message-bubble {
    background: var(--ai-msg-bg);
    border-top-left-radius: 4px;
    border: 1px solid var(--glass-border);
}

.user-message .message-bubble {
    background: var(--user-msg-bg);
    color: white;
    border-top-right-radius: 4px;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-left: 4px;
    margin-right: 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
    background: var(--ai-msg-bg);
    border-radius: 18px;
    border-top-left-radius: 4px;
    width: fit-content;
    border: 1px solid var(--glass-border);
}

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

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Footer / Input Area */
.chat-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--glass-border);
    position: relative;
    z-index: 10;
}

.input-area {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 6px 12px;
    transition: all 0.3s ease;
}

.input-area:focus-within {
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(15, 23, 42, 0.8);
}

.input-wrapper {
    flex-grow: 1;
}

#messageInput {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 10px 0;
    outline: none;
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

.mic-btn {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

.mic-btn.recording {
    color: var(--danger-color);
    animation: pulseMic 1.5s infinite;
}

@keyframes pulseMic {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.send-btn {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--glass-bg);
    color: var(--text-secondary);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Recording Indicator Overlay */
.recording-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    z-index: 20;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

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

@keyframes slideUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.pulse-ring {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--danger-color);
    animation: ringPulse 1.5s infinite;
}

@keyframes ringPulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

#recordingTimer {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.icon-btn.danger {
    color: var(--danger-color);
}

.icon-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    width: 90%;
    max-width: 450px;
    padding: 32px;
    border-radius: 20px;
    text-align: center;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-content h2 {
    margin-bottom: 12px;
    color: white;
}

.modal-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
    line-height: 1.5;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

#apiKeyInput {
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease;
}

#apiKeyInput:focus {
    border-color: var(--primary-color);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: color 0.2s ease;
}

.btn-text:hover {
    color: var(--text-primary);
}

/* Markdown & Adaptive Cards Styling */
.markdown-body p {
    margin: 0 0 0.5rem 0;
}
.markdown-body p:last-child {
    margin: 0;
}
.markdown-body a {
    color: #a855f7;
    text-decoration: underline;
}
.markdown-body ul, .markdown-body ol {
    margin: 0 0 0.5rem 1.2rem;
    padding: 0;
}
.markdown-body strong {
    font-weight: 600;
    color: white;
}
.adaptive-card-wrapper .message-bubble {
    padding: 0;
    overflow: hidden;
    background: transparent !important;
    border: none !important;
}
.adaptive-card-wrapper .ac-container {
    padding: 1rem;
    background: var(--ai-msg-bg) !important;
    border-radius: 18px;
    border: 1px solid var(--glass-border);
    color: var(--text-primary) !important;
}
.ac-textBlock {
    color: var(--text-primary) !important;
}
