:root {
    --bg-color: #0d0e12;
    --surface-color: #1a1c23;
    --primary-gradient: linear-gradient(135deg, #4285f4, #d96570);
    --text-primary: #ffffff;
    --text-secondary: #9aa0a6;
    --accent-blue: #a8c7fa;
    --user-bubble: #2b2f3a;
    --ai-bubble: #004a77;
    --radius-lg: 16px;
    --radius-md: 12px;
    --font-family: 'Outfit', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

.app-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% -20%, #1c2235 0%, #0d0e12 60%);
    z-index: -1;
}

.app-container {
    width: 100%;
    max-width: 800px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 1rem;
}

/* Header */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 1rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.icon-sparkle {
    -webkit-text-fill-color: initial;
}

.status-group {
    display: flex;
    align-items: center;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #f44336;
    /* Red for disconnected */
}

.status-badge.connected .dot {
    background-color: #4caf50;
    /* Green for connected */
    box-shadow: 0 0 8px #4caf50;
}

.status-badge.connected .text {
    color: #a8dba9;
}

/* Chat Area */
.chat-viewport {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    margin-top: 30%;
    opacity: 0.7;
}

.empty-state h1 {
    font-size: 1.8rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: var(--user-bubble);
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 4px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Indicators */
.indicators-area {
    min-height: 30px;
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 10px;
}

.indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 5px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    animation: slideUp 0.3s ease;
}

.hidden {
    display: none !important;
}

.spinner-search {
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-secondary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.thought-animation span {
    display: inline-block;
    width: 4px;
    height: 4px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.thought-animation span:nth-child(1) {
    animation-delay: -0.32s;
}

.thought-animation span:nth-child(2) {
    animation-delay: -0.16s;
}

/* Visualizer (Background) */
.visualizer-wrapper {
    position: fixed;
    top: 50%;
    left: 0;
    width: 100%;
    height: 300px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: -1;
    opacity: 0.4;
    pointer-events: none;
}

canvas#audio-visualizer {
    width: 100%;
    height: 100%;
}

/* Controls */
.control-bar {
    background: var(--surface-color);
    padding: 10px 16px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.icon-button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: color 0.2s;
}

.icon-button:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.input-field-container {
    flex: 1;
    display: flex;
    align-items: center;
    position: relative;
}

#message-input {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
}

.send-btn {
    background: none;
    border: none;
    color: var(--accent-blue);
    cursor: pointer;
    padding: 4px;
}

.mic-container {
    position: relative;
}

.mic-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--text-primary);
    color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.mic-button.active {
    background: #f44336;
    color: white;
}

.mic-button:hover {
    transform: scale(1.05);
}

.media-preview {
    position: absolute;
    bottom: 70px;
    left: 20px;
    background: var(--surface-color);
    padding: 5px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.media-preview img {
    height: 80px;
    border-radius: 4px;
}

.close-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Animations */
@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Transcription Container to hold button and display */
.transcription-container {
    position: relative;
    width: 100%;
    max-width: 94%;
    margin: 0 auto 2rem auto;
}

@keyframes fadeOutTranscription {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

.transcription-display.fade-out {
    animation: fadeOutTranscription 0.5s ease forwards;
}

.log-btn {
    position: absolute;
    top: -25px;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    padding: 2px 8px;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    z-index: 10;
}

.log-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.transcription-display {
    text-align: left;
    /* User requested Left alignment */
    min-height: 1.5em;
    width: 100%;
    /* Fixed width relative to container */
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    padding: 15px 20px;
    /* adjusted padding */
    border-radius: 12px;
    margin-bottom: -20px;
    opacity: 0.9;
}

.transcription-display:empty {
    display: none;
}

.transcription-display.user {
    color: var(--accent-blue);
    /* For user, maybe we don't want the full glass bg? Or keep it consistent? */
}

.transcription-display.ai {
    color: var(--text-primary);
}

/* History Sidebar */
.history-sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    /* Hidden by default */
    width: 300px;
    height: 100vh;
    background: rgba(20, 20, 25, 0.98);
    backdrop-filter: blur(15px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 3000;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
}

.history-sidebar.active {
    right: 0;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn-sidebar {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.history-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: none;
    /* Firefox */
}

.history-content::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.history-item {
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-name {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.history-item.user {
    background: rgba(66, 133, 244, 0.15);
    color: #d0e0fd;
    align-self: flex-end;
    max-width: 85%;
    border-bottom-right-radius: 2px;
}

.history-item.user .history-name {
    color: #4caf50;
    /* Green for "You" */
}

.history-item.ai {
    background: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    align-self: flex-start;
    max-width: 85%;
    border-bottom-left-radius: 2px;
}

.history-item.ai .history-name {
    background: var(--primary-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    width: fit-content;
}

/* Audio Player Styling */
.history-audio {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.03);
    /* Brighter glass */
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Subtle border */
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(6px);
    width: 100%;
}

.history-audio audio {
    width: 100%;
    height: 32px;
    outline: none;
    filter: invert(0.9) hue-rotate(180deg) opacity(0.85);
    /* Dark mode adjustment */
    border-radius: 20px;
    transition: filter 0.2s;
}

.history-audio audio:hover {
    filter: invert(0.9) hue-rotate(180deg) opacity(1);
}

/* Hide native download button in some browsers if redundant */
audio::-webkit-media-controls-enclosure {
    background: transparent;
}

.audio-download-link {
    align-self: flex-end;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.3px;
}

.audio-download-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}


/* Settings Button */
.settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.3s ease;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
    transform: rotate(30deg);
}

/* Settings Popup */
.settings-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 800px;
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.settings-popup.hidden {
    display: none;
    opacity: 0;
    transform: translate(-50%, -45%);
}

.popup-header {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}

.popup-line {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 20px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    justify-items: center;
}

.card-f {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 284px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.number-display {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 4px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
    margin-bottom: 12px;
}

.popup-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
    font-style: italic;
}

.reset-btn {
    width: 100%;
    padding: 10px;
    background: rgba(244, 67, 54, 0.15);
    border: 1px solid rgba(244, 67, 54, 0.4);
    color: #f44336;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-btn:hover {
    background: rgba(244, 67, 54, 0.3);
    border-color: #f44336;
}