/* =============================================
   Mudra Loan Voice Assistant — Premium Aesthetic Design System
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Poppins:wght@500;600;700&family=Noto+Sans+Devanagari:wght@400;500;600&display=swap');

/* --- CSS Custom Properties --- */
:root {
    /* Color Palette — Deep Obsidian Theme */
    --bg-primary: #09090b;
    --bg-secondary: #18181b;
    --bg-tertiary: #27272a;
    
    --bg-glass-heavy: rgba(9, 9, 11, 0.85);
    --bg-glass-light: rgba(255, 255, 255, 0.04);
    --bg-glass-hover: rgba(255, 255, 255, 0.08);

    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;

    /* Accents */
    --accent-blue: #3b82f6;
    --accent-indigo: #6366f1;
    --accent-violet: #8b5cf6;
    --accent-emerald: #10b981;
    --accent-rose: #f43f5e;

    /* Gradients */
    --gradient-user: linear-gradient(135deg, #3b82f6, #6366f1);
    --gradient-system: linear-gradient(135deg, rgba(39, 39, 42, 0.8), rgba(24, 24, 27, 0.8));
    --gradient-brand: linear-gradient(135deg, #6366f1, #8b5cf6, #d946ef);

    /* Borders & Shadows */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(255, 255, 255, 0.15);
    
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-glow-blue: 0 0 30px rgba(59, 130, 246, 0.2);
    --shadow-glow-violet: 0 0 30px rgba(139, 92, 246, 0.2);

    /* Typography */
    --font-heading: 'Poppins', sans-serif;
    --font-body: 'Inter', 'Noto Sans Devanagari', sans-serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2.5rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-full: 50%;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 300ms cubic-bezier(0.25, 1, 0.5, 1);
    --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.05), transparent 25%);
}

/* --- App Container --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 960px;
    margin: 0 auto;
    position: relative;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    background: var(--bg-primary);
}

/* --- Header --- */
.app-header {
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-glass-heavy);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 10;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass-light);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

.logo-text h1 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    background: var(--gradient-brand);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.logo-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Connection Status --- */
.connection-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    background: var(--bg-glass-light);
    border: 1px solid var(--border-subtle);
    transition: var(--transition-smooth);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--accent-rose);
    box-shadow: 0 0 8px rgba(244, 63, 94, 0.5);
}

.connection-indicator.connected .connection-dot {
    background: var(--accent-emerald);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
    animation: pulse-dot 2.5s infinite ease-in-out;
}

.connection-text {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    padding-right: var(--space-xs);
}

.connection-indicator.connected .connection-text {
    color: var(--text-secondary);
}

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

/* --- Main Content --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* --- Conversation Area --- */
.conversation-area {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.conversation-area::-webkit-scrollbar {
    width: 6px;
}
.conversation-area::-webkit-scrollbar-track {
    background: transparent;
}
.conversation-area::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

/* --- Welcome Message --- */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    animation: floatUp 0.8s ease-out forwards;
}

.welcome-message.hidden {
    display: none;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    margin-bottom: var(--space-lg);
    color: var(--accent-indigo);
    animation: breathe 4s infinite ease-in-out;
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.3));
}

.welcome-message h2 {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: var(--space-sm);
    font-weight: 600;
    letter-spacing: -0.03em;
}

.welcome-message p {
    font-size: 1.05rem;
    color: var(--text-secondary);
    max-width: 420px;
    line-height: 1.6;
}

@keyframes floatUp {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}
@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* --- Messages Container --- */
.messages-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    padding-bottom: var(--space-xl);
}

/* --- Chat Bubbles (REVERSED: User Right, Assistant Left) --- */
.message {
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    max-width: 80%;
    animation: messageEntry 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards;
    opacity: 0;
    transform: translateY(15px);
}

@keyframes messageEntry {
    to { opacity: 1; transform: translateY(0); }
}

/* User Message - Now on Right */
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Assistant Message - Now on Left */
.message.assistant {
    align-self: flex-start;
    flex-direction: row;
}

/* Avatars */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-soft);
}

.message.user .message-avatar {
    background: var(--bg-glass-light);
    border: 1px solid var(--border-subtle);
    color: var(--accent-blue);
}

.message.assistant .message-avatar {
    background: var(--gradient-system);
    border: 1px solid var(--border-highlight);
    color: var(--accent-violet);
}

/* Message Content */
.message-content {
    padding: 14px 20px;
    border-radius: var(--radius-xl);
    font-size: 1.05rem;
    line-height: 1.6;
    position: relative;
    box-shadow: var(--shadow-soft);
    word-wrap: break-word;
    white-space: pre-wrap;
    transition: width var(--transition-smooth), height var(--transition-smooth);
}

/* User Bubble Styling */
.message.user .message-content {
    background: var(--gradient-user);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-glow-blue);
}

/* Assistant Bubble Styling */
.message.assistant .message-content {
    background: var(--gradient-system);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* --- Typing Cursor Animation --- */
.typing-cursor {
    display: inline-block;
    width: 8px;
    height: 1.1em;
    background-color: var(--accent-indigo);
    vertical-align: middle;
    margin-left: 4px;
    animation: blink 0.8s step-end infinite;
    border-radius: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* --- Processing Indicator (Assistant side) --- */
.processing-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 16px 24px;
    background: var(--bg-glass-light);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: messageEntry 0.3s ease-out forwards;
    backdrop-filter: blur(10px);
}

.processing-dots {
    display: flex;
    gap: 6px;
}

.processing-dots span {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--accent-violet);
    animation: bounceDots 1.4s infinite ease-in-out both;
}

.processing-dots span:nth-child(1) { animation-delay: -0.32s; }
.processing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounceDots {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; box-shadow: 0 0 10px var(--accent-violet); }
}

/* --- Controls Section --- */
.controls-section {
    padding: var(--space-md) var(--space-xl) var(--space-xl);
    background: linear-gradient(to top, var(--bg-primary) 50%, transparent);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    position: relative;
    z-index: 10;
}

/* --- Audio Visualizer --- */
.visualizer-container {
    width: 100%;
    max-width: 450px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(10px);
    transition: all var(--transition-smooth);
}

.visualizer-container.active {
    opacity: 1;
    transform: translateY(0);
}

#audioVisualizer {
    width: 100%;
    height: 100%;
}

/* --- Status Text --- */
.status-text {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    min-height: 1.5em;
    transition: color var(--transition-smooth);
}

.status-text.active { color: var(--accent-blue); text-shadow: 0 0 10px rgba(59, 130, 246, 0.4); }
.status-text.processing { color: var(--accent-violet); text-shadow: 0 0 10px rgba(139, 92, 246, 0.4); }
.status-text.speaking { color: var(--accent-emerald); text-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }
.status-text.error { color: var(--accent-rose); }

/* --- Microphone Button --- */
.mic-button-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: var(--space-sm);
}

.mic-ripple {
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    border: 2px solid var(--accent-indigo);
    opacity: 0;
    pointer-events: none;
}

.mic-ripple.active {
    animation: sonarRipple 2s ease-out infinite;
}

@keyframes sonarRipple {
    0% { transform: scale(1); opacity: 0.8; border-width: 2px; }
    100% { transform: scale(2.5); opacity: 0; border-width: 0; }
}

.mic-button {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-bounce);
    box-shadow: var(--shadow-soft);
    position: relative;
    z-index: 2;
    overflow: hidden;
}

/* Subtle inner glow for idle mic */
.mic-button::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-full);
    padding: 2px;
    background: var(--gradient-brand);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0.5;
    transition: opacity var(--transition-smooth);
}

.mic-button:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    background: var(--bg-glass-hover);
}

.mic-button:hover::before { opacity: 1; }

.mic-button:active {
    transform: scale(0.95);
}

.mic-button.recording {
    background: var(--gradient-user);
    color: white;
    box-shadow: var(--shadow-glow-blue);
    animation: micFloat 3s ease-in-out infinite;
}
.mic-button.recording::before { opacity: 0; }

@keyframes micFloat {
    0%, 100% { transform: translateY(0); box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4); }
    50% { transform: translateY(-4px); box-shadow: 0 15px 40px rgba(59, 130, 246, 0.6); }
}

.mic-icon, .stop-icon {
    width: 32px;
    height: 32px;
    transition: all var(--transition-smooth);
}

.hidden {
    display: none !important;
}

/* --- Quick Actions --- */
.quick-actions {
    position: absolute;
    right: var(--space-xl);
    bottom: var(--space-xl);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--bg-glass-light);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-smooth);
    backdrop-filter: blur(10px);
}

.action-btn:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-highlight);
    transform: rotate(90deg);
}

.action-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .message { max-width: 90%; }
    .quick-actions { position: relative; right: 0; bottom: 0; margin-top: var(--space-md); }
    .app-header { padding: var(--space-md); }
    .conversation-area { padding: var(--space-md); }
}
