@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* --- THEME COLORS --- */
    /* Primary Color (Blue for Light Theme) */
    --primary-color-light: #3b82f6;
    --primary-dark-light: #2563eb;
    --primary-glow-light: rgba(59, 130, 246, 0.25);

    /* Accent Color (Cyan for Dark Theme) */
    --primary-color-dark: #0891b2;
    --primary-dark-dark: #0e7490;
    --primary-glow-dark: rgba(8, 145, 178, 0.25);
    
    /* Light Theme: "Fresh Lime" */
    --text-primary-light: #18181b;
    --text-secondary-light: #71717a;
    --bg-light: #f0fdf4; /* Light Lime */
    --header-bg-light: rgba(240, 253, 244, 0.8);
    --bubble-bg-light: #ffffff;
    --border-light: #dcfce7; /* Lime Border */
    
    /* Dark Theme: "Vivid Cyan" */
    --text-primary-dark: #fafafa;
    --text-secondary-dark: #a1a1aa;
    --bg-dark: #121212;
    --header-bg-dark: rgba(18, 18, 18, 0.8);
    --bubble-bg-dark: #27272a; 
    --border-dark: #3f3f46;

    /* --- UI STYLES --- */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100%;
    height: 100vh;
    background: var(--bg-light);
    color: var(--text-primary-light);
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

body.dark {
    background: var(--bg-dark);
    color: var(--text-primary-dark);
}

/* --- REFINED SCROLLBAR --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(120, 120, 120, 0.3);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(120, 120, 120, 0.5); }


.app-container { width: 100%; height: 100vh; display: flex; flex-direction: column; }

/* --- HEADER --- */
.header {
    background: var(--header-bg-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-light);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    transition: background 0.3s ease, border-color 0.3s ease;
}
body.dark .header { background: var(--header-bg-dark); border-bottom-color: var(--border-dark); }
.header h1 { font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 0.75rem; }

/* --- REFINED HEADER ICON & TITLE --- */
.header-icon {
    color: var(--primary-color-light);
}
body.dark .header-icon { color: var(--primary-color-dark); }

/* New Blinking Animation */
.icon-eye-open, .icon-eye-closed {
    animation-duration: 3s; /* Slower, more natural blink */
    animation-iteration-count: infinite;
    animation-timing-function: ease-in-out;
}
.icon-eye-open {
    animation-name: blink-open;
}
.icon-eye-closed {
    animation-name: blink-closed;
    font-size: 12px; /* Make degree symbol larger */
    font-weight: bold;
    fill: currentColor;
}

@keyframes blink-open {
    0%, 95%, 100% { opacity: 1; }
    96%, 99% { opacity: 0; }
}

@keyframes blink-closed {
    0%, 95%, 100% { opacity: 0; }
    96%, 99% { opacity: 1; }
}

.header-title {
    background: linear-gradient(45deg, var(--primary-color-light), var(--primary-dark-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(0,0,0,0.1);
}
body.dark .header-title {
    background: none;
    -webkit-text-fill-color: initial;
    color: var(--text-primary-dark);
}

.header-actions { display: flex; align-items: center; gap: 1rem; }

/* --- NEW THEME TILE STYLES --- */
.theme-tile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(255, 255, 255, 0.5);
    padding: 0.25rem 0.25rem 0.25rem 0.75rem;
    border-radius: 999px; /* Pill shape */
    border: 1px solid var(--border-light);
    transition: all 0.3s ease;
}
body.dark .theme-tile {
    background-color: rgba(0, 0, 0, 0.2);
    border-color: var(--border-dark);
}
.theme-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary-light);
}
body.dark .theme-label {
    color: var(--text-secondary-dark);
}
#theme-toggle {
    background-color: white;
}
body.dark #theme-toggle {
    background-color: var(--bubble-bg-dark);
}
#theme-toggle:hover {
    background-color: #f0f0f0;
}
body.dark #theme-toggle:hover {
    background-color: #3f3f46;
}

/* --- ICON VISIBILITY LOGIC --- */
.icon-moon { display: none; }
.icon-sun { display: block; }

body.dark .icon-moon { display: block; }
body.dark .icon-sun { display: none; }


.status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; color: var(--text-secondary-light); }
body.dark .status { color: var(--text-secondary-dark); }
.status-dot { width: 8px; height: 8px; background: #10b981; border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* --- CHAT CONTAINER --- */
.chat-container { flex: 1; padding: 1.5rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; }
.message-wrapper { display: flex; align-items: flex-end; gap: 0.75rem; max-width: 85%; animation: slideIn 0.5s cubic-bezier(0.25, 1, 0.5, 1); }

/* --- UPDATED USER MESSAGE WRAPPER --- */
.message-wrapper.user {
    flex-direction: column; /* Stack bubble and label vertically */
    align-items: flex-end; /* Keep everything to the right */
    gap: 0.25rem; /* Small gap between bubble and label */
}
@keyframes slideIn { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* --- AVATAR STYLES (NOW ONLY FOR AI) --- */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 0.875rem;
    flex-shrink: 0;
    color: white;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 0 0 3px var(--bg-light);
}
body.dark .avatar { box-shadow: 0 0 0 3px var(--bg-dark); }
.avatar.ai { background: #4ade80; }
body.dark .avatar.ai { background: var(--primary-color-dark); } 

/* --- NEW USER LABEL STYLES --- */
.user-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary-light); /* Dark grey for light mode */
    padding-right: 0.75rem; /* Align it nicely with the bubble */
}
body.dark .user-label {
    color: var(--text-primary-dark); /* White for dark mode */
}


/* --- REFINED MESSAGE BUBBLES --- */
.message-bubble {
    padding: 0.75rem 1.25rem;
    border-radius: 1.25rem;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.message-bubble:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.message-bubble.user { background: var(--primary-color-light); color: white; border-bottom-right-radius: 0.25rem; }
.message-bubble.ai { background: var(--bubble-bg-light); color: var(--text-primary-light); border: 1px solid var(--border-light); border-bottom-left-radius: 0.25rem; }
body.dark .message-bubble.user { background: var(--primary-color-dark); }
body.dark .message-bubble.ai {
    background: var(--bubble-bg-dark);
    color: var(--text-primary-dark);
    border-color: var(--border-dark);
}
.message-bubble p { margin-bottom: 0.5em; } .message-bubble p:last-child { margin-bottom: 0; }
.message-image { max-width: 100%; border-radius: 0.75rem; margin-top: 0.5rem; }

/* --- REFINED CODE BLOCKS --- */
pre[class*="language-"] {
    position: relative;
    margin: 1em 0;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border-light);
}
body.dark pre[class*="language-"] { border-color: var(--border-dark); }
.copy-code-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
}
pre[class*="language-"]:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover { background: rgba(255, 255, 255, 0.2); }

/* Typing Indicator */
.typing-indicator { display: flex; align-items: center; gap: 0.25rem; }
.typing-dot { width: 6px; height: 6px; background: var(--text-secondary-light); border-radius: 50%; animation: typing 1.4s infinite ease-in-out; }
body.dark .typing-dot { background: var(--text-secondary-dark); }
.typing-dot:nth-child(1) { animation-delay: -0.32s; } .typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* --- INPUT AREA --- */
.input-area { padding: 1rem 1.5rem; border-top: 1px solid var(--border-light); background: transparent; }
body.dark .input-area { border-top-color: var(--border-dark); }

.input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--bubble-bg-light);
    border: 1px solid var(--border-light);
    border-radius: 1.5rem;
    padding: 0.5rem;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
body.dark .input-wrapper { background: var(--bubble-bg-dark); border-color: var(--border-dark); }
.input-wrapper:focus-within { border-color: var(--primary-color-light); box-shadow: 0 0 0 4px var(--primary-glow-light); }
body.dark .input-wrapper:focus-within { border-color: var(--primary-color-dark); box-shadow: 0 0 0 4px var(--primary-glow-dark); }

textarea#messageInput { flex: 1; border: none; outline: none; background: transparent; font-size: 1rem; color: var(--text-primary-light); padding: 0.5rem; resize: none; max-height: 150px; line-height: 1.5; }
body.dark textarea#messageInput { color: var(--text-primary-dark); }

.action-buttons { display: flex; gap: 0.5rem; align-items: center; }
.action-btn { width: 44px; height: 44px; border-radius: 50%; background: transparent; color: var(--text-secondary-light); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; border: 1px solid transparent; }
body.dark .action-btn { color: var(--text-secondary-dark); }
.action-btn:hover { color: var(--primary-color-light); background-color: rgba(59, 130, 246, 0.1); }
body.dark .action-btn:hover { color: var(--primary-color-dark); background-color: rgba(8, 145, 178, 0.1); }

.action-btn.primary { background: var(--primary-color-light); color: white; box-shadow: var(--shadow-md); }
.action-btn.primary:hover { background: var(--primary-dark-light); transform: scale(1.05); }
body.dark .action-btn.primary { background: var(--primary-color-dark); }
body.dark .action-btn.primary:hover { background: var(--primary-dark-dark); transform: scale(1.05); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
body.light .action-btn:disabled { background: var(--primary-color-light) !important; }
body.dark .action-btn:disabled { background: var(--primary-color-dark) !important; }

/* Image Preview */
.image-preview { position: absolute; bottom: calc(100% + 0.5rem); left: 0; background: var(--bubble-bg-light); border: 1px solid var(--border-light); border-radius: 0.75rem; padding: 0.5rem; display: none; box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease; }
body.dark .image-preview { background: var(--bubble-bg-dark); border-color: var(--border-dark); }
.image-preview.show { display: block; }
.image-preview img { max-height: 100px; border-radius: 0.5rem; }
.remove-btn { position: absolute; top: -0.5rem; right: -0.5rem; width: 20px; height: 20px; background: #ef4444; color: white; border: none; border-radius: 50%; cursor: pointer; }