:root {
    /* Backgrounds - warm cream/beige tones for luxury home décor */
    --bg-primary: #FAF9F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F5F3EF;
    --bg-hover: #EDE9E3;
    --bg-active: #E5DFD6;
    
    /* Text - elegant dark tones */
    --text-primary: #2C2825;
    --text-secondary: #5C5651;
    --text-tertiary: #8A847D;
    --text-inverse: #FFFFFF;
    
    /* Borders - soft warm gray */
    --border-color: #E8E4DD;
    --border-hover: #D4CEC4;
    
    /* Accent - dusty rose tones to match logo */
    --accent-primary: #C4A4A0;
    --accent-secondary: #B09490;
    --accent-gradient: linear-gradient(135deg, #D4B4B0 0%, #C4A4A0 100%);
    --accent-gradient-hover: linear-gradient(135deg, #DCC4C0 0%, #D4B4B0 100%);
    
    /* Status colors */
    --success-color: #6B8E6B;
    --error-color: #C75050;
    --warning-color: #D4A855;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.15);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    /* Backgrounds - deep warm tones */
    --bg-primary: #1C1A18;
    --bg-secondary: #262320;
    --bg-tertiary: #322E2A;
    --bg-hover: #3D3833;
    --bg-active: #48423C;
    
    /* Text */
    --text-primary: #F5F3EF;
    --text-secondary: #C8C4BC;
    --text-tertiary: #9A958D;
    --text-inverse: #1C1A18;
    
    /* Borders */
    --border-color: #3D3833;
    --border-hover: #4A443D;
    
    /* Accent - dusty rose tones for dark mode */
    --accent-primary: #D9B4B0;
    --accent-secondary: #C9A4A0;
    --accent-gradient: linear-gradient(135deg, #D9B4B0 0%, #C9A4A0 100%);
    --accent-gradient-hover: linear-gradient(135deg, #E5C4C0 0%, #D9B4B0 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.7);
    --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    transition: background var(--transition-normal), color var(--transition-normal);
}

/* Brand styling for Castania */
.brand-icon {
    font-size: 28px;
    line-height: 1;
}

.brand-icon-large {
    font-size: 72px;
    line-height: 1;
}

.brand-name {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.brand-name-small {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.app-container {
    display: flex;
    height: 100dvh;
    height: 100vh; /* Fallback for older browsers */
    overflow: hidden;
}

@supports (height: 100dvh) {
    .app-container {
        height: 100dvh;
    }
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal), background var(--transition-normal);
    z-index: 100;
}

.sidebar-header {
    padding: 8.5px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    max-height: 60px;
    position: relative;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
}

.logo-container .logo-image {
    max-height: 50px;
    object-fit: contain;
}

/* Theme-specific logo visibility */
html .logo-light,
html[data-theme="light"] .logo-light {
    display: block !important;
}

html .logo-dark,
html[data-theme="light"] .logo-dark {
    display: none !important;
}

html[data-theme="dark"] .logo-light {
    display: none !important;
}

html[data-theme="dark"] .logo-dark {
    display: block !important;
}

.logo-placeholder {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.logo-svg {
    width: 100%;
    height: 100%;
    display: block;
}

.app-title {
    font-size: 20px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: none;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.sidebar-header .sidebar-toggle {
    position: absolute;
    right: 20px;
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.new-chat-btn {
    width: 100%;
    padding: 14px 16px;
    background: var(--accent-gradient);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
    background: var(--accent-gradient-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.new-chat-btn:active {
    transform: translateY(0);
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
}

.chat-history {
    margin-top: 24px;
    padding-bottom: 8px;
}

.history-section {
    margin-bottom: 20px;
}

.history-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    padding: 0 8px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 14px;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    position: relative;
    min-height: 48px;
    margin-bottom: 6px;
}

.history-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.history-item.active {
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-color: var(--accent-primary);
    font-weight: 500;
}

.history-item.active .history-item-title,
.history-item.active .history-item-date {
    color: var(--text-inverse);
}

.history-item.active .history-action-btn {
    color: var(--text-inverse);
    opacity: 0.8;
}

.history-item.active .history-action-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.history-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    cursor: pointer;
}

.history-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
    color: inherit;
}

.history-item-date {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-actions {
    display: none;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.history-item:hover .history-item-actions {
    display: flex;
}

.history-action-btn {
    width: 24px;
    height: 24px;
    padding: 4px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: var(--text-tertiary);
}

.history-action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.history-action-delete:hover {
    background: var(--error-color);
    color: white;
}

.history-title-edit {
    flex: 1;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 14px;
    color: var(--text-primary);
    font-family: inherit;
    outline: none;
}

.sidebar-footer {
    padding: 0 20px 4px;
    border-top: 1px solid var(--border-color);
}

.chat-management {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 16px;
    margin-bottom: 0;
}

.manage-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

.manage-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.manage-btn.delete-all-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.manage-btn svg {
    width: 16px;
    height: 16px;
}

.selection-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 16px;
    margin-bottom: 0;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
    font-weight: 500;
}

.delete-selected-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

.delete-selected-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

.delete-selected-btn svg {
    width: 16px;
    height: 16px;
}

.cancel-selection-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.cancel-selection-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.history-item.selection-mode {
    position: relative;
    cursor: pointer;
}

.history-item.selection-mode:hover {
    background: var(--bg-hover);
}

.history-item.selection-mode .history-item-actions {
    display: none !important;
}

.history-item-checkbox {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    display: none;
    background: var(--bg-primary);
    transition: all var(--transition-fast);
}

.history-item.selection-mode .history-item-checkbox {
    display: block;
}

.history-item-checkbox.checked {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.history-item-checkbox.checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.history-item.selection-mode .history-item-content {
    padding-left: 30px;
}

.theme-toggle-btn {
    position: relative;
}

.theme-toggle-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    position: absolute;
    transition: all var(--transition-fast);
}

.sun-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.moon-icon {
    opacity: 0;
    transform: rotate(180deg);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(180deg);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
    position: relative;
}

.top-nav {
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    transition: background var(--transition-normal);
}

.nav-title {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.nav-chat-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.nav-chat-date {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-actions {
    display: flex;
    gap: 8px;
}

.nav-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
}

.nav-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.nav-btn.active-mode {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.nav-btn.active-mode:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.nav-btn svg {
    width: 18px;
    height: 18px;
}

.user-menu {
    position: relative;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast);
    z-index: 1000;
}

.user-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.user-dropdown-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-dropdown-item {
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.user-dropdown-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-dropdown-item svg {
    width: 16px;
    height: 16px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background: var(--bg-primary);
    scroll-behavior: smooth;
}

.scroll-to-bottom {
    position: absolute;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: none !important;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: opacity 0.2s ease, transform var(--transition-fast);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
}

.scroll-to-bottom.visible {
    opacity: 1;
    pointer-events: all;
    display: flex !important;
}

.scroll-to-bottom:hover {
    background: var(--accent-secondary);
    transform: translateX(-50%) translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.scroll-to-bottom svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 768px) {
    .scroll-to-bottom {
        bottom: 140px;
        width: 44px;
        height: 44px;
    }
}

.chat-container::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb:hover,
.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: var(--border-hover);
}

.welcome-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    background: var(--bg-primary);
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.welcome-screen:not(.hidden) {
    pointer-events: auto;
}

.welcome-content {
    max-width: 800px;
    text-align: center;
    overflow: visible;
    transform: scale(0.75);
    transform-origin: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.welcome-icon {
    width: 120px;
    height: 120px;
    margin: 0 auto 32px;
    animation: float 3s ease-in-out infinite;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-icon img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.welcome-title {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 12px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 48px;
}

.feature-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    margin-top: 40px;
}

.feature-card {
    background: var(--bg-secondary);
    padding: 32px 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
}

.feature-card:nth-child(3) {
    grid-column: 1 / -1;
    max-width: 50%;
    margin: 0 auto;
    width: 100%;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.feature-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.feature-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.feature-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.messages-wrapper {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--bg-primary);
}

.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlide 0.3s ease-out;
}

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

@keyframes messageSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(20px);
    }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent-gradient);
    color: var(--text-inverse);
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.message-content {
    flex: 1;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.message.user .message-bubble {
    background: var(--accent-gradient);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
    border: 1px solid transparent;
}

.message.assistant .message-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.25em; }
.message-bubble h3 { font-size: 1.1em; }
.message-bubble h4 { font-size: 1em; }

.message-bubble p {
    margin: 8px 0;
    line-height: 1.6;
}

.message-bubble ul,
.message-bubble ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin: 4px 0;
    line-height: 1.5;
}

.message-bubble strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-bubble em {
    font-style: italic;
}

.message-bubble code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-bubble pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    max-width: 100%;
    margin: 8px 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent-primary);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* LaTeX equation styles */
.message-bubble .katex {
    font-size: 1.1em;
}

.message-bubble .katex-display {
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.message-bubble .katex-display > .katex {
    display: inline-block;
    text-align: left;
    max-width: 100%;
}

/* Ensure LaTeX equations don't break layout */
.message-bubble .katex-display {
    display: block;
    text-align: center;
}

.message-bubble .katex-display .katex {
    text-align: left;
}

.message-bubble a {
    color: var(--accent-primary);
    text-decoration: underline;
}

.message-bubble a:hover {
    opacity: 0.8;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 12px 0;
}

.message-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    width: auto;
    min-width: 100%;
    font-size: 0.9em;
    display: table;
    table-layout: auto;
}

.message-bubble .table-wrapper {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
}

.message-bubble .table-wrapper table {
    margin: 0;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
    white-space: nowrap;
}

.message-bubble th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.message-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity var(--transition-fast);
    flex-wrap: wrap;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 5px;
}

.message-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.message-action-btn:active {
    transform: translateY(0);
}

.message-action-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.message-action-btn .action-label {
    white-space: nowrap;
}

.message-edit-input {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    margin-bottom: 8px;
}

.message-edit-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(138, 180, 248, 0.2);
}

.message-edit-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.message-edit-save,
.message-edit-cancel {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
    border: none;
}

.message-edit-save {
    background: var(--success-color);
    color: white;
}

.message-edit-save:hover {
    background: #059669;
    transform: translateY(-1px);
}

.message-edit-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.message-edit-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.message-edit-save svg,
.message-edit-cancel svg {
    width: 16px;
    height: 16px;
}

.message-file {
    margin-top: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.message-file img {
    max-width: 200px;
    border-radius: var(--radius-sm);
}

.message-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.message-files img {
    max-width: 150px;
    max-height: 150px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.message-files img:hover {
    transform: scale(1.05);
}

.message-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    max-width: 200px;
}

.file-item-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.file-item-name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 20px 24px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    transition: background var(--transition-normal);
}

.input-container {
    max-width: 1000px;
    margin: 0 auto;
}

.file-preview {
    margin-bottom: 12px;
    display: none;
}

.file-preview.active {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.file-preview-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    position: relative;
    min-width: 120px;
    max-width: 150px;
}

.file-preview-image {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.file-preview-icon {
    font-size: 48px;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-preview-info {
    width: 100%;
    text-align: center;
}

.file-preview-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-size: 11px;
    color: var(--text-tertiary);
}

.file-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--error-color);
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0.9;
}

.file-preview-remove:hover {
    opacity: 1;
    transform: scale(1.1);
}

.file-preview-remove svg {
    width: 14px;
    height: 14px;
}

.file-preview-loading {
    opacity: 0.7;
}

.file-preview-spinner {
    width: 40px;
    height: 40px;
    position: relative;
    flex-shrink: 0;
    margin: 30px 0;
}

.file-preview-spinner .spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.file-preview-spinner .spinner-ring:nth-child(1) {
    animation-delay: -0.45s;
}

.file-preview-spinner .spinner-ring:nth-child(2) {
    animation-delay: -0.3s;
}

.file-preview-spinner .spinner-ring:nth-child(3) {
    animation-delay: -0.15s;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: all var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.input-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.input-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.input-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.voice-btn.active {
    background: var(--error-color);
    color: white;
    animation: pulse 1.5s ease-in-out infinite;
}

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

.voice-btn .mic-icon {
    display: block;
}

.voice-btn .mic-active-icon {
    display: none;
}

.voice-btn.active .mic-icon {
    display: none;
}

.voice-btn.active .mic-active-icon {
    display: block;
}

.graph-btn {
    color: var(--accent-primary);
}

.graph-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    color: var(--accent-primary);
}

/* ========== Graph Display ========== */

.graph-container {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.generated-graph {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.graph-metadata {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.graph-metadata p {
    margin: 4px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.graph-metadata strong {
    color: var(--text-primary);
    font-weight: 600;
}

.graph-insights {
    padding: 12px;
    background: rgba(102, 126, 234, 0.1);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

.graph-insights strong {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Mobile responsiveness for graphs */
@media (max-width: 768px) {
    .graph-container {
        padding: 12px;
        margin: 12px 0;
    }
    
    .graph-metadata {
        padding: 10px;
    }
    
    .graph-metadata p,
    .graph-insights {
        font-size: 13px;
    }
}

/* ========== Voice Recording Indicator ========== */

.voice-recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.3s ease;
}

.voice-recording-indicator.active {
    opacity: 1;
    transform: scale(1);
}

.recording-waveform {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

#waveformCanvas {
    display: block;
    width: 100%;
    height: 40px;
}

.recording-timer {
    color: var(--accent-primary);
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 45px;
    text-align: right;
    flex-shrink: 0;
}

/* Mobile responsiveness for recording indicator */
@media (max-width: 768px) {
    .voice-recording-indicator {
        gap: 8px;
    }
    
    #waveformCanvas {
        height: 35px;
    }
    
    .recording-timer {
        font-size: 14px;
        min-width: 40px;
    }
}

@media (max-width: 480px) {
    .voice-recording-indicator {
        gap: 6px;
    }
    
    #waveformCanvas {
        height: 30px;
    }
    
    .recording-timer {
        font-size: 13px;
        min-width: 35px;
    }
}


#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    padding: 10px 4px;
    line-height: 1.5;
}

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

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    color: white;
    flex-shrink: 0;
}

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

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.send-btn.stop-btn {
    background: #ef4444;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.send-btn.stop-btn:hover {
    background: #dc2626;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
}

.send-btn.stop-btn svg {
    width: 14px;
    height: 14px;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    position: relative;
    width: 80px;
    height: 80px;
}

.spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid transparent;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.spinner-ring:nth-child(1) {
    animation-delay: -0.45s;
}

.spinner-ring:nth-child(2) {
    animation-delay: -0.3s;
}

.spinner-ring:nth-child(3) {
    animation-delay: -0.15s;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.thinking-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.thinking-text {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typingAnimation 1.4s infinite;
}

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

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-10px); }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-toggle.mobile-only {
        display: flex;
    }
    
    .top-nav {
        padding: 0 20px;
        height: 56px;
    }
    
    .sidebar-content {
        padding: 16px 20px;
    }
    
    .messages-wrapper {
        padding: 16px;
    }
    
    .welcome-screen {
        padding: 70px 20px 100px;
    }
    
    .welcome-content {
        margin-top: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .welcome-icon {
        width: 100px;
        height: 80px;
        margin: 0 auto 16px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .input-area {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    
    .welcome-title {
        font-size: 22px;
        margin-bottom: 8px;
    }
    
    .welcome-subtitle {
        font-size: 13px;
        margin-bottom: 20px;
    }
    
    .feature-cards {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-top: 16px;
    }
    
    .feature-card {
        padding: 10px 14px;
    }
    
    .feature-card:nth-child(3) {
        grid-column: auto;
        max-width: none;
        margin: 0;
    }
    
    .feature-icon {
        font-size: 18px;
        margin-bottom: 2px;
    }
    
    .feature-card h3 {
        font-size: 12px;
        margin-bottom: 2px;
    }
    
    .feature-card p {
        font-size: 10px;
        line-height: 1.3;
    }
    
    .nav-chat-title {
        font-size: 14px;
    }
    
    .nav-chat-date {
        font-size: 10px;
    }
    
    
    .manage-btn span {
        display: none;
    }
    
    .manage-btn {
        padding: 10px;
    }
    
    
    .history-item-actions {
        display: flex !important;
    }
    
    
    .history-item:has(.history-title-edit) .history-item-actions {
        display: none !important;
    }
    
    
    .message-actions {
        opacity: 1;
    }
    
    .message-action-btn .action-label {
        display: none;
    }
    
    .message-action-btn {
        padding: 6px 8px;
    }
}

@media (max-width: 480px) {
    .app-title {
        font-size: 18px;
    }
    
    .logo-placeholder {
        width: 36px;
        height: 36px;
    }
    
    .sidebar-header {
        padding: 16px 20px;
    }
    
    .sidebar-footer {
        padding: 0 20px 20px;
    }
    
    .chat-management {
        padding-top: 16px;
    }
    
    .selection-actions {
        padding-top: 16px;
    }
    
    .message-bubble {
        font-size: 14px;
        padding: 12px 14px;
    }
    
    .welcome-content {
        margin-top: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .welcome-icon {
        width: 80px;
        height: 60px;
        margin: 0 auto 10px;
    }
    
    .welcome-title {
        font-size: 18px;
        margin-bottom: 6px;
    }
    
    .welcome-subtitle {
        font-size: 11px;
        margin-bottom: 14px;
    }
    
    .feature-cards {
        gap: 6px;
    }
    
    .feature-card {
        padding: 8px 12px;
    }
    
    .feature-icon {
        font-size: 16px;
        margin-bottom: 2px;
    }
    
    .feature-card h3 {
        font-size: 11px;
        margin-bottom: 2px;
    }
    
    .feature-card p {
        font-size: 9px;
        line-height: 1.2;
    }
    
    .toast-container {
        top: 70px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
    }
    
    .modal-container {
        max-width: 340px;
    }
    
    .modal-title {
        font-size: 16px;
    }
    
    .modal-message {
        font-size: 13px;
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.active {
    display: flex;
}

.modal-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s ease-out;
    border: 1px solid var(--border-color);
}

.modal-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 24px;
}

.modal-icon.warning {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.modal-icon.info {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.modal-title {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-message {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-btn {
    flex: 1;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid var(--border-color);
}

.modal-btn-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.modal-btn-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-btn-confirm {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.modal-btn-confirm:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.modal-btn-confirm.primary {
    background: var(--accent-gradient);
    border-color: transparent;
}

.modal-btn-confirm.primary:hover {
    background: var(--accent-gradient-hover);
}

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

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 350px;
}

.toast {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toastSlideIn 0.3s ease-out;
    border: 1px solid;
    min-width: 280px;
}

.toast.success {
    border-left-color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
    background: var(--bg-secondary);
}

.toast.error {
    border-left-color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    background: var(--bg-secondary);
}

.toast.info {
    border-left-color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.3);
    background: var(--bg-secondary);
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: #10b981;
}

.toast.error .toast-icon {
    color: #ef4444;
}

.toast.info .toast-icon {
    color: #3b82f6;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.4;
}

.toast-close {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.toast-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toast.removing {
    animation: toastSlideOut 0.3s ease-out forwards;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.hidden {
    display: none !important;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

button:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 48px 40px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.login-card .logo-container {
    text-align: center;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.login-card .logo-icon {
    width: 100px;
    height: 100px;
    display: block;
}

.login-card .app-title {
    font-size: 32px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.login-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all var(--transition-normal);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.login-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    color: white;
    background: var(--accent-gradient);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-normal);
    margin-top: 8px;
}

.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.error-message {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    display: none;
}

.error-message.show {
    display: block;
}

.login-page .theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.login-page .theme-toggle:hover {
    background: var(--bg-primary);
}

.login-page .theme-toggle svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

.login-page .theme-toggle .sun-icon {
    display: block;
}

.login-page .theme-toggle .moon-icon {
    display: none;
}

[data-theme="dark"] .login-page .theme-toggle .sun-icon {
    display: none;
}

[data-theme="dark"] .login-page .theme-toggle .moon-icon {
    display: block;
}

@media (max-width: 768px) {
    .login-card {
        padding: 32px 24px;
    }

    .login-page .theme-toggle {
        top: 12px;
        right: 12px;
    }
}

.analyzer-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

.analyzer-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.analyzer-modal-content {
    background: var(--bg-primary);
    width: 90%;
    max-width: 1200px;
    height: 85vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

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

.analyzer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: var(--accent-gradient);
    color: var(--text-inverse);
    border-bottom: 1px solid var(--border-color);
}

.analyzer-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
}

.analyzer-icon-large {
    width: 24px;
    height: 24px;
}

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

.analyzer-action-btn,
.analyzer-close-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    color: var(--text-inverse);
}

.analyzer-action-btn:hover,
.analyzer-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

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

.analyzer-chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-primary);
}

.analyzer-messages {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.analyzer-input-area {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.analyzer-input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.analyzer-textarea {
    flex: 1;
    min-height: 50px;
    max-height: 200px;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    outline: none;
    transition: var(--transition-fast);
}

.analyzer-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(71, 85, 105, 0.1);
}

.analyzer-send-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    color: var(--text-inverse);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.analyzer-send-btn:hover:not(:disabled) {
    background: var(--accent-gradient-hover);
    transform: scale(1.05);
}

.analyzer-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

/* Analyzer message styles (reuse main chat styles) */
.analyzer-messages .message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: messageSlide 0.3s ease-out;
}

.analyzer-messages .message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.analyzer-messages .message.assistant {
    margin-right: auto;
}

.analyzer-messages .message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.analyzer-messages .message.user .message-bubble {
    background: var(--accent-gradient);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
}

.analyzer-messages .message.assistant .message-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

@media (max-width: 768px) {
    .analyzer-modal-content {
        width: 95%;
        height: 90vh;
    }
    
    .analyzer-header {
        padding: 16px 20px;
    }
    
    .analyzer-title {
        font-size: 16px;
    }
}

/* ========== Media Gallery ========== */

.gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.gallery-modal.active {
    display: flex;
}

.gallery-container {
    background: var(--bg-secondary);
    width: 90%;
    max-width: 1200px;
    height: 85vh;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
}

.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.gallery-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.gallery-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.gallery-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

.gallery-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
}

.gallery-empty svg {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.gallery-empty p {
    font-size: 16px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 12px;
}

.gallery-item:hover .gallery-item-overlay {
    opacity: 1;
}

.gallery-item-info {
    color: white;
    margin-bottom: 8px;
}

.gallery-item-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item-date {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 2px;
}

.gallery-item-actions {
    display: flex;
    gap: 8px;
}

.gallery-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.gallery-action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.8);
}

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

/* Image Viewer (Full Screen) */
.image-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.image-viewer.active {
    opacity: 1;
}

.image-viewer-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-viewer-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.image-viewer-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-viewer-close svg {
    width: 24px;
    height: 24px;
}

.image-viewer-content img {
    max-width: 100%;
    max-height: calc(90vh - 100px);
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.image-viewer-info {
    margin-top: 20px;
    color: white;
    font-size: 14px;
    text-align: center;
}

@media (max-width: 768px) {
    .gallery-container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }
}

/* ==================== VISUALIZATION / CHART STYLES ==================== */

/* Chart wrapper - container for the entire chart component */
.chart-wrapper {
    background: var(--bg-primary);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    padding: 24px 28px;
    margin: 20px 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s ease;
}

.chart-wrapper:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* Chart header with title and subtitle */
.chart-header {
    margin-bottom: 20px;
    text-align: left;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.chart-title {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.chart-subtitle {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    margin: 0;
    font-weight: 400;
}

/* Chart container - holds the canvas */
.chart-container {
    position: relative;
    width: 100%;
    height: 320px;
    min-height: 280px;
}

/* Pie chart specific adjustments */
.chart-container canvas {
    max-height: 100%;
}

/* Insight box below chart */
.chart-insight {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 20px;
    padding: 14px 18px;
    background: rgba(74, 111, 165, 0.04);
    border-radius: 8px;
    border-left: 3px solid #4A6FA5;
}

.insight-icon {
    font-size: 1rem;
    flex-shrink: 0;
    opacity: 0.8;
}

.insight-text {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.6;
    font-weight: 400;
}

/* Message content with charts */
.message-text-content {
    margin-bottom: 8px;
}

.message-chart-content {
    margin: 16px 0;
}

/* Chart error state */
.chart-error {
    padding: 24px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.875rem;
}

/* Responsive chart adjustments */
@media (max-width: 768px) {
    .chart-wrapper {
        padding: 16px;
        margin: 12px 0;
    }
    
    .chart-title {
        font-size: 1.15rem;
    }
    
    .chart-container {
        height: 280px;
        min-height: 240px;
    }
    
    .chart-insight {
        padding: 10px 12px;
    }
    
    .insight-text {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .chart-wrapper {
        padding: 12px;
        border-radius: var(--radius-md);
    }
    
    .chart-title {
        font-size: 1.05rem;
    }
    
    .chart-subtitle {
        font-size: 0.75rem;
    }
    
    .chart-container {
        height: 240px;
        min-height: 200px;
    }
    
    .chart-insight {
        flex-direction: column;
        gap: 6px;
    }
}

/* Dark mode chart adjustments */
[data-theme="dark"] .chart-wrapper {
    background: var(--bg-secondary);
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .chart-wrapper:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .chart-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .chart-insight {
    background: rgba(74, 111, 165, 0.08);
    border-left-color: #6B8E8D;
}


/* Print styles for charts */
@media print {
    .chart-wrapper {
        break-inside: avoid;
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .chart-container {
        height: 250px;
    }
}