:root {
    /* Palette: Electric & Immersive (TikTok Vibe) */
    --bg-app: #000000;       /* Pure Black for OLED depth */
    --bg-panel: rgba(24, 24, 27, 0.85); /* Zinc-950 */
    --bg-element: rgba(39, 39, 42, 0.6); /* Zinc-800 */
    --bg-input: rgba(255, 255, 255, 0.08);
    
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-tertiary: #52525b;
    
    /* Vibrant Accents */
    --primary-gradient: linear-gradient(135deg, #00f2ea 0%, #ff0050 100%); /* Cyan to TikTok Red/Pink */
    --accent-cyan: #00f2ea;
    --accent-pink: #ff0050;
    --accent-glow: rgba(0, 242, 234, 0.25);
    
    --border-subtle: rgba(255, 255, 255, 0.12);
    --border-focus: rgba(0, 242, 234, 0.5);
    
    --glass-blur: 20px;
    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 28px;
    --radius-full: 9999px;
    
    --font-display: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-body);
    background-color: var(--bg-app);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulseGlow { 0% { box-shadow: 0 0 0 0 var(--accent-glow); } 70% { box-shadow: 0 0 0 15px rgba(0, 242, 234, 0); } 100% { box-shadow: 0 0 0 0 rgba(0, 242, 234, 0); } }
@keyframes float { 0% { transform: translateY(0px); } 50% { transform: translateY(-8px); } 100% { transform: translateY(0px); } }

/* --- Header --- */
.main-header {
    height: 64px;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 2000; /* Higher priority */
}

.header-logo {
    position: relative;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: -0.02em;
}

.header-logo svg { color: #10b981; }

.nav-tabs {
    display: flex;
    gap: 6px;
    background: rgba(255, 255, 255, 0.03);
    padding: 4px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
}

.nav-tab {
    padding: 8px 20px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.9rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-tab.active {
    background: var(--bg-element);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.user-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-family: var(--font-display);
    cursor: pointer;
    box-shadow: 0 0 15px var(--accent-glow);
    transition: transform 0.2s;
    border: 2px solid rgba(255,255,255,0.1);
}

.user-menu-container {
    position: relative; /* This ensures the absolute dropdown stays here */
    z-index: 2001;
}
.user-icon:hover { transform: scale(1.05); }

.dropdown-menu {
    position: absolute;
    top: 100%; /* Position right below the icon */
    right: 0;
    width: 240px;
    margin-top: 10px;
    background: #18181b;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1001; /* Higher than header */
    animation: fadeIn 0.1s ease;
}
.dropdown-item {
    padding: 14px 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    transition: background 0.2s;
}
.dropdown-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.dropdown-menu.show { display: flex; }


/* --- Layout --- */
.app-container {
    display: flex;
    flex: 1;
    position: relative;
    overflow: hidden;
}

.sidebar {
    width: 280px;
    background: transparent;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    padding: 20px 0; /* Keep vertical padding but remove horizontal */
    border: none;
    opacity: 0;
    pointer-events: none;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.02);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.new-chat-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden; /* Ensure content doesn't spill during transition */
}
.new-chat-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}


#sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 4px;
}
#sidebar-toggle:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

.saved-contexts {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.context-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    transition: all 0.2s;
    text-align: left;
}
.context-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.context-item.active { background: var(--bg-element); color: var(--text-primary); }
.delete-btn { opacity: 0; color: #ef4444; background: none; border: none; cursor: pointer; transition: opacity 0.2s; }
.context-item:hover .delete-btn { opacity: 1; }

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden; /* Fix for flex child expansion */
}

/* --- Definition View --- */
#definition-view {
    display: flex; flex-direction: column;
    max-width: 700px;
    margin: 0 auto; /* Removed vertical centering to keep top aligned */
    width: 100%;
    padding: 40px;
    overflow-y: auto;
    animation: slideUp 0.6s ease;
}

#definition-view h1 {
    font-family: var(--font-display);
    font-size: 2.5rem;
    background: linear-gradient(to right, #fff, #a1a1aa);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 3rem;
    text-align: center;
}

.input-group { margin-bottom: 24px; position: relative; }
.input-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.styled-input, .styled-textarea, select.styled-input {
    width: 100%;
    padding: 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: all 0.3s;
}
.styled-input:focus, .styled-textarea:focus {
    outline: none;
    border-color: #10b981;
    background: rgba(39, 39, 42, 0.7);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}
.styled-textarea { min-height: 150px; resize: vertical; line-height: 1.6; }

.primary-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: var(--radius-full);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.4);
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}
.primary-btn::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transform: translateX(-100%);
}
.primary-btn:hover { 
    transform: translateY(-2px) scale(1.05); 
    box-shadow: 0 0 20px var(--accent-glow);
}
.primary-btn:hover::after {
    animation: shine 1.5s infinite;
}
@keyframes shine { 100% { transform: translateX(100%); } }
.primary-btn:active { transform: translateY(0) scale(0.98); }

/* --- Chat View --- */
#chat-view { display: flex; flex-direction: column; height: 100%; }

.chat-header {
    padding: 16px;
    text-align: center;
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(9, 9, 11, 0.4);
    backdrop-filter: blur(10px);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0; /* Reduced padding as input is now relative */
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    width: 100%;
}

.message {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 24px 0;
    animation: slideUp 0.5s ease forwards;
}

.message.ai { background: rgba(255, 255, 255, 0.015); border-top: 1px solid rgba(255,255,255,0.02); border-bottom: 1px solid rgba(255,255,255,0.02); }

.message-content {
    width: 100%;
    max-width: 800px;
    padding: 0 24px;
    display: flex;
    gap: 24px;
    line-height: 1.7;
    font-size: 1.05rem;
    color: var(--text-primary);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 4px;
}
.avatar.user { background: #3f3f46; color: white; }
.avatar.ai { background: linear-gradient(135deg, #10b981, #047857); color: white; box-shadow: 0 0 15px rgba(16, 185, 129, 0.2); }

/* Bubbles/Questions */
.bubbles-container {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}

.bubble {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
}
.bubble:hover {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.05);
    color: var(--text-primary);
    transform: translateY(-2px);
}
.bubble.highlight {
    border-color: #f59e0b; /* Amber-500 */
    background: rgba(245, 158, 11, 0.05);
    color: #fcd34d;
}

/* Input Area */
.chat-input-area {
    position: relative; /* Changed from absolute to relative/static in flex */
    bottom: auto;
    left: auto; right: auto;
    display: flex;
    justify-content: center;
    padding: 20px;
    z-index: 20;
    flex-shrink: 0; /* Prevent shrinking */
    /* pointer-events: none; - Removed to ensure area is clickable if needed, though wrapper handles it */
}
.input-wrapper {
    pointer-events: auto;
    width: 100%;
    max-width: 800px;
    background: rgba(20, 20, 23, 0.7); /* Slightly darker for contrast */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2); /* More visible, elegant border */
    border-radius: 26px;
    padding: 6px 6px 6px 24px; /* Slightly more left padding */
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4); /* Deeper shadow */
    display: flex;
    align-items: flex-end;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
.input-wrapper:focus-within {
    background: rgba(20, 20, 23, 0.9);
    border-color: rgba(255, 255, 255, 0.4); /* Brighter on focus */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    transform: translateY(-1px);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px 0 12px 0; /* Vertical padding, no side padding needed directly */
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    outline: none;
    min-height: 24px; /* Ensure one line height */
}
.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-weight: 400;
}

.send-btn {
    background: rgba(0, 242, 234, 0.1); /* Subtle Cyan tint */
    color: var(--accent-cyan); /* Cyan Icon */
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 0 2px 4px;
}
.send-btn:hover { 
    background: rgba(255,255,255,0.05); /* Subtle hover bg */
    color: var(--accent-cyan); /* Glow color on hover */
    transform: none; /* No rotation */
    box-shadow: none;
}
.send-btn svg {
    transition: transform 0.3s;
    stroke-width: 2.5px; /* Thicker icon for visibility */
}
.send-btn:hover svg {
    transform: translateX(3px) scale(1.1);
    filter: drop-shadow(0 0 5px var(--accent-cyan)); /* Icon glow */
}

/* --- Desktop/Web Mode (Default) --- */
/* User requested "4 posts at once", implying a Grid layout */
/* --- Desktop/Web Mode (Default) --- */
/* User requested "4 posts at once", implying a Grid layout */
#feed-view {
    max-width: 100%; /* Full width */
    margin: 0; 
    padding: 20px 40px;
    width: 100%;
    flex: 1; 
    min-height: 0; 
    overflow-y: auto; /* Standard scroll for grid */
    animation: fadeIn 0.5s;
    display: flex; flex-direction: column;
    scrollbar-width: thin; /* Thin scrollbar for desktop */
}
#feed-view::-webkit-scrollbar { display: block; width: 6px; }

.feed-grid { 
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); /* Denser grid */
    gap: 24px; 
    padding-bottom: 80px;
}

.feed-card {
    background: linear-gradient(160deg, #18181b 0%, #121214 100%);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    height: 450px; /* Fixed height for grid consistency */
    position: relative;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.7);
    cursor: pointer;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* Overlay for text readability when image is present */
.feed-card.has-image::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(0deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.4) 50%, rgba(0,0,0,0.1) 100%);
    z-index: 3; /* Above both images */
}

.card-image-blur {
    position: absolute;
    top: -10%; left: -10%; width: 120%; height: 120%; /* Bleed for blur */
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(0.5);
    z-index: 1;
    opacity: 0.6;
}

.card-image-foreground {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    object-fit: contain;
    object-position: top; /* Keep main content at top, usually better for news */
    z-index: 2;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.feed-card:hover .card-image-foreground {
    transform: scale(1.02); /* Very subtle to avoid cutting */
}

.card-content {
    position: relative;
    z-index: 4; /* Above the gradients and images */
    height: 100%;
    width: 100%;
    padding: 32px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: none; /* Allow clicks to pass to card if needed, though they click content too */
}

/* Ensure children have pointer events for interactions if any */
.card-content > * {
    pointer-events: auto;
}

/* Dynamic background gradient for visual interest since we might lack images */
.feed-card:not(.has-image)::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(0, 242, 234, 0.05) 0%, transparent 60%);
    opacity: 0.6;
    transform: rotate(30deg);
    pointer-events: none;
    z-index: 0;
}

.feed-card:hover {
    border-color: var(--accent-cyan);
    transform: scale(0.98); /* Slight press effect */
}

.feed-card::after {
    content:''; position: absolute; bottom:0; left:0; right:0; height: 6px;
    background: var(--primary-gradient); opacity: 0.8;
}

.feed-meta { 
    font-size: 0.85rem; 
    color: var(--accent-cyan); 
    margin-bottom: 8px; 
    display: flex; 
    justify-content: space-between; 
    font-weight: 600; 
    letter-spacing: 0.5px;
    text-transform: uppercase;
    z-index: 2;
}

.feed-title { 
    font-family: var(--font-display); 
    font-size: 2.5rem; /* Big Bold Title */
    font-weight: 800; 
    margin-bottom: 16px; 
    line-height: 1.1; 
    color: #ffffff; /* Fallback for mobile/unsupported */
    background: linear-gradient(to right, #fff, #d4d4d8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    z-index: 2;
    text-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* Elegant Gradients for No-Image Mode */
/* Using a refined pastel/neon mix that isn't too overpowering but looks premium */
.gradient-1 { background: linear-gradient(135deg, #2A1B3D 0%, #44318D 50%, #E98074 100%) !important; }
.gradient-2 { background: linear-gradient(135deg, #1A2980 0%, #26D0CE 100%) !important; }
.gradient-3 { background: linear-gradient(135deg, #134E5E 0%, #71B280 100%) !important; }
.gradient-4 { background: linear-gradient(135deg, #FF4B1F 0%, #1FDDFF 100%) !important; }
.gradient-5 { background: linear-gradient(135deg, #2C3E50 0%, #FD746C 100%) !important; }
.gradient-6 { background: linear-gradient(135deg, #093028 0%, #237A57 100%) !important; }

/* When using gradients, text shadow helps readability against varied backgrounds */
.feed-card[class*="gradient-"] .feed-title {
    text-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
.feed-card[class*="gradient-"] .feed-meta {
    color: rgba(255,255,255,0.9);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.feed-card[class*="gradient-"] .feed-desc {
    color: rgba(255,255,255,0.85);
}

/* Ensure overlay is lighter or removed for gradients to pop, or keep it subtle? */
/* Let's remove the default dark overlay for gradient cards to let colors shine */
.feed-card[class*="gradient-"]::before {
    background: linear-gradient(0deg, rgba(0,0,0,0.6) 0%, transparent 100%);
    opacity: 0.5;
}

.feed-desc { 
    font-size: 1.1rem; 
    color: var(--text-secondary); 
    line-height: 1.6; 
    overflow: hidden; 
    display: -webkit-box; 
    -webkit-line-clamp: 4; 
    line-clamp: 4; 
    -webkit-box-orient: vertical; 
    z-index: 2;
    margin-bottom: 24px;
}

/* Filter Bar */
.filter-bar {
    display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap;
}
.filter-chip {
    padding: 6px 16px; border-radius: 99px; font-size: 0.85rem;
    background: rgba(255,255,255,0.05); border: 1px solid var(--border-subtle);
    color: var(--text-secondary); cursor: pointer; transition: all 0.2s;
}
.filter-chip:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.filter-chip.active { background: var(--bg-element); color: #10b981; border-color: #10b981; }

.load-more-btn {
    background: rgba(255,255,255,0.05); border: 1px solid var(--border-subtle);
    width: 200px; padding: 12px; margin: 30px auto; display: block;
    border-radius: var(--radius-full); color: var(--text-secondary); cursor: pointer;
    transition: all 0.2s; text-align: center;
}
.load-more-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

/* --- Loading --- */
.typing-indicator span {
    width: 6px; height: 6px; background: #10b981; border-radius: 50%;
    display: inline-block; animation: typing 1.4s infinite ease-in-out both; margin: 0 2px;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8); backdrop-filter: blur(8px);
    display: none; align-items: center; justify-content: center;
    z-index: 3000; opacity: 0; transition: opacity 0.3s;
}
.modal-overlay.open { display: flex; opacity: 1; }

.preview-modal {
    background: #18181b; border: 1px solid var(--border-subtle);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 800px; max-width: 90%; height: 85vh;
    border-radius: var(--radius-lg);
    display: flex; flex-direction: column; position: relative;
    transform: scale(0.95); transition: transform 0.3s;
    overflow: hidden;
}
.modal-overlay.open .preview-modal { transform: scale(1); }

.close-modal {
    background: rgba(255,255,255,0.1); border: 1px solid var(--border-subtle);
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; cursor: pointer;
    color: var(--text-secondary); transition: all 0.2s;
}
.close-modal:hover { background: rgba(255,255,255,0.2); color: white; transform: rotate(90deg); }

/* Skeleton Loading */
.skeleton-container { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.skeleton-card {
    height: 36px; width: 140px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    position: relative; overflow: hidden;
}

.skeleton-feed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 24px;
    width: 100%;
}

.skeleton-feed-card {
    height: 450px;
    background: rgba(24, 24, 27, 0.8);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 16px;
    position: relative;
    overflow: hidden;
}

/* --- Styled Markdown Content (Preview Modal) --- */
#pv-body {
    line-height: 1.8;
    color: #e4e4e7; /* Zinc-200 */
    font-size: 1.05rem;
}

#pv-body p { margin-bottom: 1.5rem; }

#pv-body h1, #pv-body h2, #pv-body h3, #pv-body h4, #pv-body h5, #pv-body h6 {
    color: var(--text-primary);
    font-family: var(--font-display);
    margin-top: 2rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}
#pv-body h1 { font-size: 2rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.5rem; }
#pv-body h2 { font-size: 1.75rem; }
#pv-body h3 { font-size: 1.5rem; color: var(--accent-cyan); }

/* Links */
#pv-body a {
    color: var(--accent-cyan);
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 242, 234, 0.3);
    transition: all 0.2s;
}
#pv-body a:hover {
    color: #fff;
    border-bottom-color: var(--accent-cyan);
    background: rgba(0, 242, 234, 0.1);
}

/* Lists */
#pv-body ul, #pv-body ol {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}
#pv-body li { margin-bottom: 0.5rem; }
#pv-body ul li::marker { color: var(--accent-pink); }
#pv-body ol li::marker { color: var(--accent-cyan); font-weight: 600; }

/* Images */
#pv-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 1.5rem 0;
    display: block;
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}
.preview-main-image {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    margin-top: 0 !important;
}

/* Blockquotes */
#pv-body blockquote {
    border-left: 4px solid var(--accent-pink);
    margin: 1.5rem 0;
    padding: 0.5rem 0 0.5rem 1.5rem;
    background: rgba(255, 0, 80, 0.05);
    font-style: italic;
    color: #e4e4e7;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Code */
#pv-body code {
    background: rgba(255,255,255,0.1);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    color: #fca5a5;
}
#pv-body pre {
    background: #111;
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    margin-bottom: 1.5rem;
}
#pv-body pre code {
    background: transparent;
    padding: 0;
    color: #fff;
}



.skeleton-rect, .skeleton-text {
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

.skeleton-rect::after, .skeleton-text::after, .skeleton-feed-card::after {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
    animation: skeleton-loading 1.5s infinite;
}

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

@keyframes skeleton-loading {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Preview Content Refinement */
.preview-content { padding: 40px; overflow-y: auto; flex: 1; }
.preview-title {
    font-family: var(--font-display); font-size: 2.2rem; font-weight: 700;
    margin-bottom: 16px; line-height: 1.2;
    color: var(--text-primary);
}
#pv-meta {
    font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 30px;
    display: flex; gap: 16px; align-items: center; border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 24px;
}
#pv-body {
    font-size: 1.1rem; line-height: 1.8; color: #d4d4d8; font-family: var(--font-body);
}
#pv-body p { margin-bottom: 24px; }
#pv-body img { max-width: 100%; border-radius: var(--radius-md); margin: 20px 0; }

.preview-main-image {
    width: 100%;
    height: auto;
    max-height: 400px;
    object-fit: cover;
    object-position: center;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    display: block;
}

.fab-btn {
    position: absolute; bottom: 30px; right: 30px;
    background: var(--primary-gradient); color: white;
    border: none; padding: 14px 24px; border-radius: var(--radius-full);
    font-family: var(--font-display); font-weight: 600; cursor: pointer;
    box-shadow: 0 10px 25px -5px rgba(16, 185, 129, 0.4);
    display: flex; align-items: center; gap: 8px;
    transition: all 0.2s; z-index: 10;
}
.fab-btn:hover { transform: translateY(-2px); box-shadow: 0 15px 35px -5px rgba(16, 185, 129, 0.5); }

#preview-actions .fab-btn {
    position: static; margin: 0; transform: none;
}
#preview-actions .fab-btn:hover {
    transform: translateY(-2px);
}

/* --- AI Config Header & Menu --- */
.ai-config-container {
    position: relative;
    display: flex;
    align-items: center;
}

.ai-config-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.03); 
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.ai-config-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.05);
}

.ai-config-btn.active {
    background: var(--bg-element);
    color: #10b981;
    border-color: #10b981;
}

.ai-config-btn .status-dot {
    position: absolute;
    top: 0px;
    right: 0px;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid #09090b; /* Match header bg */
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-menu {
    width: 320px;
    background: #18181b;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px 0;
    box-shadow: 0 15px 40px -10px rgba(0, 0, 0, 0.6);
}

.menu-section-label {
    padding: 16px 20px 8px 20px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 700;
    color: var(--text-tertiary); /* Darker, subtle label */
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-section-label::after {
    content:''; flex:1; height: 1px; background: var(--border-subtle); margin-left:8px;
}

.menu-options {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 8px 20px;
    opacity: 0.5;
}

/* Override dropdown-item for this menu for tighter control */
.ai-menu .dropdown-item {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.ai-menu .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.ai-menu .dropdown-item.active {
    background: rgba(16, 185, 129, 0.08); /* Very subtle green tint */
    color: #10b981; /* Green text */
    border-color: rgba(16, 185, 129, 0.15);
    font-weight: 500;
}

/* --- Preview Footer (Fix Overlap) --- */
.preview-footer {
    padding: 24px 40px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-panel); /* Consistent background */
    backdrop-filter: blur(10px);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    flex-shrink: 0; /* Prevent shrinking */
}

/* --- Preview Header --- */
.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 40px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-panel);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

/* --- Mobile / Responsive Styles --- */
@media (max-width: 768px) {
    /* Layout */
    .app-container {
        flex-direction: column;
        position: relative;
    }

    /* Sidebar - Mobile Overlay */
    .sidebar {
        position: fixed;
        top: 64px; /* Header height */
        bottom: 0;
        left: 0;
        width: 100%; /* Full width on mobile */
        z-index: 90;
        background: #09090b; /* Solid background */
        border-right: none;
        transform: translateX(0);
        padding-bottom: 80px; /* Space for bottom content if needed */
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 100%;
        opacity: 1; /* Keep opacity 1 for smooth slide */
        pointer-events: none;
    }

    /* Main Content */
    .main-content {
        width: 100%;
    }

    /* Definition View */
    #definition-view {
        padding: 20px;
    }
    #definition-view h1 {
        font-size: 2rem;
        margin-bottom: 2rem;
    }

    /* Input Groups */
    .input-group label {
        font-size: 0.8rem;
    }
    .styled-textarea {
        min-height: 120px;
    }

    /* Chat View */
    .chat-history {
        padding: 20px 0 140px 0; /* More bottom padding for input area */
    }
    .message {
        padding: 16px 0;
    }
    .message-content {
        padding: 0 16px;
        gap: 12px;
        font-size: 0.95rem;
    }
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }
    
    /* Chat Input Area */
    .chat-input-area {
        bottom: 10px;
        padding: 0 10px;
    }
    .input-wrapper {
        border-radius: 20px;
        padding: 6px;
    }
    .chat-input {
        padding: 10px 14px;
        font-size: 0.95rem;
    }
    .send-btn {
        width: 36px;
        height: 36px;
    }

    /* Feed View - Mobile (Keep immersive) */
    #feed-view {
        padding: 0; /* Full width/height */
    }
    .feed-grid {
        gap: 0; /* Seamless transition or small gap */
    }
    .feed-card {
        height: 100vh; /* Full screen per item */
        border-radius: 0; /* Square corners for full immersion */
        border-left: none;
        border-right: none;
        scroll-snap-align: start; /* Snap to top */
    }

    /* Modals */
    .preview-modal {
        width: 100%;
        height: 100%;
        border-radius: 0;
        max-width: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }
    .preview-header {
        padding: 16px 20px;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-panel);
        border-radius: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--border-subtle);
    }
    .preview-content {
        flex: 1;
        overflow-y: auto;
        padding: 20px;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }
    .preview-footer {
        padding: 16px 20px;
        flex-shrink: 0;
    }
    .preview-title {
        font-size: 1.5rem;
    }
    
    /* Header Adjustments */
    .main-header {
        padding: 0 16px;
    }
    .header-logo span {
        display: none; /* Hide 'Deep Dive AI' text if needed, or keep it */
    }
    .nav-tab {
        padding: 6px 14px;
        font-size: 0.85rem;
    }
    
    /* Mobile Text Fix: Disable gradient text for better compatibility/readability */
    .feed-title {
        background: none;
        -webkit-background-clip: initial;
        background-clip: initial;
        -webkit-text-fill-color: initial;
        color: #ffffff;
        text-shadow: 0 2px 10px rgba(0,0,0,0.8); /* Strong shadow for contrast */
    }

    /* RSS Modal */
    #rss-modal .preview-modal {
        width: 100%; 
        height: 100%;
        border-radius: 0;
    }
    #new-rss-url {
        margin-bottom: 8px; /* Stack on mobile if flex wraps */
    }
    .input-group > div { 
         flex-direction: column; 
    }
    #extract-btn, #add-rss-btn { /* Assuming buttons need full width */
        width: 100%;
        align-self: stretch !important;
    }
}

/* --- Login View --- */
#login-view {
    display: none; /* Toggled by JS */
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-app);
    align-items: center; justify-content: center;
    z-index: 2000;
}
.login-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    backdrop-filter: blur(20px);
    text-align: center;
}
.login-title {
    font-family: var(--font-display);
    font-size: 2rem;
    margin-bottom: 30px;
    background: var(--primary-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: none;
}

/* --- Admin Modal --- */
#admin-user-list {
    max-height: 400px;
    overflow-y: auto;
}
.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.user-row:last-child { border-bottom: none; }
.admin-toolbar {
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex; justify-content: space-between; align-items: center;
}
.tag {
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.icon-btn {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 4px; border-radius: 4px; transition: all 0.2s;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
