/* ==========================================================================
   AI Search - Modern Minimalist Design System
   Features:
   - Ultra-clean search-first interface
   - Left corner mic button with pulse animation
   - Right corner search button
   - Seamless Light / Dark theme support
   - Modern typography, glassmorphism, responsive layout
   ========================================================================== */

:root {
    /* Light Theme */
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --bg-bubble-user: #e2e8f0;
    --bg-bubble-ai: #ffffff;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-placeholder: #94a3b8;
    
    --border-light: #e2e8f0;
    --border-subtle: #cbd5e1;
    --border-focus: #2563eb;

    --brand-primary: #2563eb;
    --brand-primary-hover: #1d4ed8;
    --brand-accent: #3b82f6;
    --brand-gradient: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%);
    
    --mic-active-bg: #ef4444;
    --mic-active-glow: rgba(239, 68, 68, 0.35);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.09);
    --shadow-search: 0 4px 20px rgba(37, 99, 235, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-search-focus: 0 6px 28px rgba(37, 99, 235, 0.16), 0 0 0 3px rgba(37, 99, 235, 0.2);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, monospace;
}

/* Dark Theme */
body.dark-theme {
    --bg-page: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-elevated: #334155;
    --bg-surface-hover: #334155;
    --bg-bubble-user: #1e293b;
    --bg-bubble-ai: #1e293b;

    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --text-placeholder: #64748b;

    --border-light: #334155;
    --border-subtle: #475569;
    --border-focus: #3b82f6;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-search: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-search-focus: 0 6px 28px rgba(59, 130, 246, 0.25), 0 0 0 3px rgba(59, 130, 246, 0.35);
}

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

html, body {
    height: 100%;
    width: 100%;
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
}

a {
    color: var(--brand-accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

.hidden {
    display: none !important;
}

/* App Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* Minimal Header */
.app-header {
    height: 60px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    z-index: 20;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--brand-gradient);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.brand-text {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    background-color: var(--bg-surface-hover);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 6px #10b981;
}

.status-badge.offline .status-dot {
    background-color: #f59e0b;
    box-shadow: 0 0 6px #f59e0b;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.header-btn:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0 20px;
}

/* Messages / Results Feed */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 16px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}
.messages-container::-webkit-scrollbar-thumb {
    background-color: var(--border-subtle);
    border-radius: 9999px;
}

/* Welcome Hero */
.welcome-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: auto 0;
    padding: 40px 20px;
    animation: fadeIn 0.4s ease;
}

.hero-icon-ring {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: var(--brand-gradient);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.25);
}

.welcome-heading {
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.welcome-subtext {
    font-size: 1.05rem;
    color: var(--text-secondary);
    max-width: 480px;
    line-height: 1.5;
}

/* Messages List */
.messages-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 24px;
}

/* Message Card */
.message-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: slideUp 0.25s ease-out;
}

.message-card.user {
    align-self: flex-end;
    max-width: 82%;
}

.message-card.assistant {
    align-self: flex-start;
    max-width: 95%;
    width: 100%;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    font-size: 1rem;
    word-break: break-word;
}

.message-card.user .message-bubble {
    background-color: var(--brand-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    font-weight: 450;
    box-shadow: var(--shadow-sm);
}

.message-card.assistant .message-bubble {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-card.assistant .message-bubble pre {
    background-color: #1e1e1e;
    color: #d4d4d4;
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
    font-family: var(--font-mono);
    font-size: 0.88rem;
}

.message-card.assistant .message-bubble code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background-color: var(--bg-surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
}

.message-card.assistant .message-bubble pre code {
    background-color: transparent;
    padding: 0;
}

.message-card.assistant .message-bubble p {
    margin-bottom: 10px;
}
.message-card.assistant .message-bubble p:last-child {
    margin-bottom: 0;
}

.message-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.action-chip-btn {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    gap: 5px;
}
.action-chip-btn:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* Live Voice Status Bar */
.voice-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    margin-bottom: 12px;
    animation: fadeIn 0.2s ease;
}

.voice-status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.status-thinking-logo {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: #ffffff;
    box-shadow: 0 0 14px rgba(124, 58, 237, 0.35);
    animation: floatPulse 1.6s ease-in-out infinite;
}

.status-pulse-ring {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ef4444;
    animation: pulseGlow 1.4s infinite;
}

.voice-status-bar.listening .status-pulse-ring {
    background-color: #ef4444;
}

.voice-status-bar.thinking .status-pulse-ring {
    background-color: #f59e0b;
}

.voice-status-bar.speaking .status-pulse-ring {
    background-color: #22c55e;
}

.voice-stop-btn {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background-color: var(--bg-surface-hover);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    gap: 5px;
}
.voice-stop-btn:hover {
    background-color: #fee2e2;
    color: #ef4444;
}

/* ==========================================================================
   SIMPLE SEARCH BAR
   Left Corner: Mic Button
   Center: Search Input
   Right Corner: Search Button
   ========================================================================== */

.search-dock-wrapper {
    padding: 16px 0 24px;
    width: 100%;
    flex-shrink: 0;
    z-index: 10;
}

.search-box {
    display: flex;
    align-items: center;
    width: 100%;
    background-color: var(--bg-surface);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-full);
    padding: 6px 8px 6px 12px;
    box-shadow: var(--shadow-search);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.search-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-search-focus);
}

/* LEFT CORNER MIC BUTTON */
.search-mic-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--bg-surface-hover);
    color: var(--text-secondary);
    flex-shrink: 0;
    position: relative;
    transition: all 0.2s ease;
}

.search-mic-btn:hover {
    background-color: #e2e8f0;
    color: var(--text-primary);
    transform: scale(1.05);
}

body.dark-theme .search-mic-btn:hover {
    background-color: #334155;
    color: #ffffff;
}

/* When recording voice */
.search-mic-btn.recording {
    background-color: var(--mic-active-bg) !important;
    color: #ffffff !important;
    animation: pulseRecord 1.3s infinite alternate;
    box-shadow: 0 0 16px var(--mic-active-glow);
}

.search-mic-btn .recording-wave {
    display: none;
    align-items: center;
    gap: 3px;
    height: 16px;
}

.search-mic-btn.recording .mic-icon {
    display: none;
}

.search-mic-btn.recording .recording-wave {
    display: flex;
}

.recording-wave span {
    width: 3px;
    height: 100%;
    background-color: #ffffff;
    border-radius: 2px;
    animation: soundWave 0.8s infinite ease-in-out;
}
.recording-wave span:nth-child(2) { animation-delay: 0.15s; }
.recording-wave span:nth-child(3) { animation-delay: 0.3s; }

/* SEARCH INPUT */
.search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 10px 16px;
    font-size: 1.05rem;
    font-family: inherit;
    color: var(--text-primary);
    min-width: 0;
}

.search-input::placeholder {
    color: var(--text-placeholder);
    font-size: 1rem;
}

/* RIGHT CORNER SEARCH BUTTON */
.search-submit-btn {
    height: 44px;
    padding: 0 20px;
    border-radius: var(--radius-full);
    background: var(--brand-gradient);
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    gap: 8px;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-submit-btn:hover {
    opacity: 0.94;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.search-submit-btn:active {
    transform: translateY(0);
}

/* Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
    animation: scaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

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

.form-group label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.input-row {
    display: flex;
    gap: 8px;
}

.input-row input, .form-select {
    flex: 1;
    height: 42px;
    padding: 0 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}
.input-row input:focus, .form-select:focus {
    border-color: var(--border-focus);
    outline: none;
}

.btn-sm-ghost {
    padding: 0 12px;
    border-radius: var(--radius-md);
    background-color: var(--bg-surface-hover);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}
.btn-sm-ghost:hover {
    color: var(--text-primary);
}

.primary-btn {
    height: 42px;
    padding: 0 20px;
    border-radius: var(--radius-md);
    background: var(--brand-gradient);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.95rem;
}
.primary-btn:hover {
    opacity: 0.92;
}

.full-width {
    width: 100%;
}

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

.modal-divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 20px 0;
}

.alert-box {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.alert-box.success {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.alert-box.error {
    background-color: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulseRecord {
    0% { transform: scale(1); box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }
    100% { transform: scale(1.08); box-shadow: 0 0 20px rgba(239, 68, 68, 0.7); }
}

@keyframes pulseGlow {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.5; }
}

@keyframes floatPulse {
    0%, 100% { transform: translateY(0) scale(1); box-shadow: 0 0 12px rgba(124, 58, 237, 0.25); }
    50% { transform: translateY(-2px) scale(1.06); box-shadow: 0 0 20px rgba(124, 58, 237, 0.45); }
}

@keyframes soundWave {
    0%, 100% { height: 4px; }
    50% { height: 16px; }
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .app-header {
        padding: 0 16px;
    }
    .welcome-heading {
        font-size: 1.6rem;
    }
    .search-btn-label {
        display: none;
    }
    .search-submit-btn {
        width: 44px;
        padding: 0;
        justify-content: center;
    }
    .message-card.user {
        max-width: 90%;
    }
}
