/* ==========================================
   1. CSS VARIABLES (Premium Glass Theme)
   ========================================== */
:root {
    /* Light Theme - High Translucency */
    --bg-color: #f5f5f7;
    --text-primary: #000000;
    --text-secondary: #6e6e73;
    --accent-color: #0071e3; 
    --accent-glow: rgba(0, 113, 227, 0.4);
    --error-color: #ff3b30; 
    --success-color: #10b981; 
    
    /* Global Glass Effects */
    --glass-bg: rgba(255, 255, 255, 0.45); /* Highly translucent */
    --glass-border: rgba(255, 255, 255, 0.5); /* Shiny edge */
    --liquid-blur: blur(25px);
    
    /* Modals & Surfaces (Now Glassy too) */
    --surface-solid: rgba(255, 255, 255, 0.35);
    --modal-bg: rgba(255, 255, 255, 0.65);
}

body.dark-mode {
    /* Dark Theme - High Translucency */
    --bg-color: #000000;
    --text-primary: #ffffff;
    --text-secondary: #a1a1a6;
    --accent-color: #2997ff;
    --accent-glow: rgba(41, 151, 255, 0.4);
    --error-color: #ff453a;
    --success-color: #34d399;
    
    --glass-bg: rgba(28, 28, 30, 0.45);
    --glass-border: rgba(255, 255, 255, 0.15);
    
    --surface-solid: rgba(28, 28, 30, 0.4);
    --modal-bg: rgba(28, 28, 30, 0.65);
}

/* ==========================================
   2. GLOBAL RESETS & BODY
   ========================================== */
* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Inter', 'Noto Sans Devanagari', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color); color: var(--text-primary);
    transition: background-color 0.5s ease, color 0.5s ease;
    overflow: hidden; height: 100vh; height: 100dvh;
    position: relative;
}

.hidden { opacity: 0; visibility: hidden; pointer-events: none; display: none !important; }
.scroll-hidden::-webkit-scrollbar { display: none; }
.scroll-hidden { -ms-overflow-style: none; scrollbar-width: none; }

.glass-morph {
    background: var(--glass-bg); backdrop-filter: var(--liquid-blur);
    -webkit-backdrop-filter: var(--liquid-blur); border: 1px solid var(--glass-border);
}

/* Background Logo Watermark */
.bg-logo-wrapper {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 0; /* Kept lowest to ensure chips and UI stay on top */
    pointer-events: none;
}

.bg-logo-watermark {
    width: 350px;
    height: auto;
    max-width: 80vw;
    opacity: 0.5; /* Colorful with 50% opacity */
}

/* ==========================================
   3. OFFLINE BANNER & TOAST ALERTS
   ========================================== */
.offline-banner {
    position: fixed; top: 0; left: 0; width: 100%; background: var(--error-color);
    color: #fff; padding: 10px; text-align: center; font-size: 0.9rem; font-weight: 500;
    display: flex; justify-content: center; align-items: center; gap: 8px; z-index: 40;
}
.offline-banner:not(.hidden) { display: flex !important; }

.toast-container {
    position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
    display: flex; flex-direction: column; gap: 10px; z-index: 150; pointer-events: none;
}
.premium-toast {
    background: var(--text-primary); color: var(--bg-color);
    padding: 12px 24px; font-size: 0.95rem; font-weight: 500;
    display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border-radius: 16px; /* Native Roundness */
    animation: toastSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes toastSlideUp { from { opacity: 0; transform: translateY(20px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
.toast-fade-out { animation: toastFadeOut 0.4s ease forwards !important; }
@keyframes toastFadeOut { to { opacity: 0; transform: translateY(10px) scale(0.95); } }

/* ==========================================
   4. HEADER & HERO LOGO
   ========================================== */
#app-container { display: flex; flex-direction: column; height: 100%; position: relative; z-index: 10; }
.glass-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; z-index: 20; background: transparent; }
.brand-area { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.brand-text { font-family: 'Geist Mono', monospace; font-size: 1.25rem; font-weight: 700; letter-spacing: 2px; }

.icon-btn {
    background: transparent; border: none; color: var(--text-primary);
    width: 44px; height: 44px; border-radius: 50%; /* Native Roundness */
    display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn:hover { background: var(--glass-bg); } /* Updated to use glass */

#chat-canvas { flex: 1; overflow-y: auto; padding: 0 24px 90px 24px; display: flex; flex-direction: column; scroll-behavior: smooth; position: relative; }
#hero-section { 
    width: 100%; 
    max-width: 600px; 
    margin: 5px auto; /* Reduced margin to maximize vertical space */
    position: relative; 
    z-index: 5; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center;
    flex: 1; /* Allows vertical centering naturally */
}

/* AI Chips - No Background, 10 Rows Compact Layout */
.ai-chips-container {
    display: flex; 
    flex-direction: column; /* 10 Rows guaranteed */
    gap: 6px; /* Extremely tight gap so 10 rows fit without scroll */
    width: 100%;
    max-width: 350px; /* Keep them neat and centered */
}
.ai-chip {
    width: 100%;
    padding: 6px 16px; /* Reduced padding for extreme compactness */
    min-height: 34px; /* Tiny height */
    background: transparent; /* NO background, purely floating text/border */
    border: 1px solid rgba(150, 150, 150, 0.25);
    border-radius: 100px; /* Native Roundness */
    color: var(--text-primary);
    font-size: 0.88rem; /* Scaled down to fit perfectly */
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    box-shadow: none; /* Removed shadow to keep it clean over logo */
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.ai-chip:hover {
    background: rgba(150, 150, 150, 0.1); /* Subtle highlight only on hover */
    border-color: var(--accent-color);
    transform: scale(1.02); /* Pop out slightly instead of sliding */
}
.ai-chip i { color: var(--accent-color); font-size: 1rem; }

/* ==========================================
   5. SINGLE CHAT & MARKDOWN
   ========================================== */
#messages-container { display: flex; flex-direction: column; gap: 40px; margin-top: 10px; width: 100%; max-width: 850px; margin-left: auto; margin-right: auto; z-index: 2; padding-bottom: 20px;}
#messages-container:not(.hidden) { display: flex !important; }

.user-msg-block { animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.user-text { font-size: 1.6rem; font-weight: 600; line-height: 1.4; color: var(--text-primary); }
.ai-msg-block { animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards; padding-left: 20px; border-left: 3px solid var(--accent-color); }
.ai-text { font-size: 1.15rem; line-height: 1.8; color: var(--text-primary); }

.ai-text p { margin-bottom: 16px; }
.ai-text strong { color: var(--text-primary); font-weight: 700; }
.ai-text ul, .ai-text ol { margin: 10px 0 16px 24px; }
.ai-text li { margin-bottom: 8px; }
.ai-text code { background: var(--glass-border); padding: 3px 6px; border-radius: 4px; font-family: 'Geist Mono', monospace; font-size: 0.9em; color: var(--accent-color); }
.ai-text pre { background: var(--surface-solid); padding: 16px; overflow-x: auto; margin: 16px 0; border: 1px solid var(--glass-border); border-radius: 12px; }
.ai-text pre code { background: transparent; padding: 0; color: var(--text-primary); }

@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.action-bar { display: flex; gap: 20px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--glass-border); flex-wrap: wrap; }
.action-bar button { background: transparent; border: none; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; transition: 0.2s; border-radius: 50%; }
.action-bar button:hover { color: var(--text-primary); }

.loading-container { display: flex; align-items: center; gap: 16px; margin-top: 40px; padding-left: 20px; border-left: 3px solid var(--glass-border); }
.loading-container:not(.hidden) { display: flex !important; }
.liquid-loader { display: flex; gap: 4px; }
.loader-bar { width: 4px; height: 16px; background: var(--accent-color); animation: liquidBar 1s ease-in-out infinite; }
.loader-bar:nth-child(2) { animation-delay: 0.15s; }
.loader-bar:nth-child(3) { animation-delay: 0.3s; }
@keyframes liquidBar { 0%, 100% { transform: scaleY(0.5); opacity: 0.5; } 50% { transform: scaleY(1.5); opacity: 1; } }
.loading-text { color: var(--text-secondary); font-size: 0.95rem; }

/* ==========================================
   6. BOTTOM DOCK (Search Bar) - GLASS UI
   ========================================== */
#bottom-dock { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); width: calc(100% - 40px); max-width: 650px; z-index: 30; }
.glass-search-bar { 
    position: relative; display: flex; align-items: center; justify-content: space-between; 
    background: var(--glass-bg); /* Glass UI */
    backdrop-filter: var(--liquid-blur); -webkit-backdrop-filter: var(--liquid-blur); 
    border: 1px solid var(--glass-border); padding: 8px 16px; 
    border-radius: 100px; /* Native Roundness */
    box-shadow: 0 10px 30px rgba(0,0,0,0.08); cursor: pointer; transition: transform 0.2s; 
}
.glass-search-bar:active { transform: scale(0.98); }
.search-content { display: flex; align-items: center; flex: 1; pointer-events: none; }
.search-icon { color: var(--text-primary); margin-right: 12px; }
.placeholder-text { font-size: 1.05rem; font-weight: 500; color: var(--text-primary); }
.cursor { color: var(--text-secondary); animation: blink 1s infinite; margin-left: 2px;}
.search-actions { display: flex; gap: 8px; pointer-events: auto; }
.action-btn { background: transparent; border: none; color: var(--text-primary); width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s; border-radius: 50%; }
.action-btn:hover { background: rgba(150,150,150,0.15); }
.active-mode { color: var(--accent-color); }

/* ==========================================
   7. MODAL SHEET & PREVIEW - GLASS UI
   ========================================== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); z-index: 100; display: flex; align-items: flex-end; justify-content: center; transition: opacity 0.3s ease, visibility 0.3s; }
.apple-sheet { 
    width: 100%; max-width: 800px; 
    background: var(--modal-bg); /* Glass UI */
    backdrop-filter: var(--liquid-blur); -webkit-backdrop-filter: var(--liquid-blur);
    border-radius: 32px 32px 0 0; /* Native Roundness */
    display: flex; flex-direction: column; height: auto; min-height: 45vh; max-height: 90dvh; 
    transform: translateY(100%); transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1); 
    box-shadow: 0 -20px 60px rgba(0,0,0,0.15); border: 1px solid var(--glass-border); border-bottom: none;
}
#input-popup-backdrop:not(.hidden) .apple-sheet { transform: translateY(0); }

.sheet-header { padding: 16px 24px; display: flex; flex-direction: column; align-items: center; border-bottom: 1px solid rgba(150,150,150,0.15); }
.drag-handle { width: 40px; height: 5px; background: var(--text-secondary); opacity: 0.3; margin-bottom: 16px; border-radius: 10px; }
.sheet-controls { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.mode-badge {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 16px;
    background: rgba(150,150,150,0.1); border: 1px solid var(--glass-border);
    color: var(--text-primary); font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: 0.3s;
}
.mode-badge.active-mode { color: var(--accent-color); border-color: var(--accent-glow); }
.mode-badge.active-search { color: var(--success-color); border-color: rgba(16, 185, 129, 0.4); }

.icon-btn-glass-sm { background: rgba(150,150,150,0.15); border: 1px solid var(--glass-border); color: var(--text-primary); width: 36px; height: 36px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; }

.sheet-body { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; }

.preview-container {
    position: relative; align-self: flex-start; margin-bottom: 16px;
    border-radius: 16px; border: 1px solid var(--glass-border);
    padding: 6px; background: rgba(150,150,150,0.1);
}
.preview-container:not(.hidden) { display: inline-block !important; }
.preview-container img { max-height: 120px; max-width: 200px; object-fit: cover; display: block; border-radius: 10px; }
.remove-btn {
    position: absolute; top: -10px; right: -10px; width: 28px; height: 28px;
    background: var(--error-color); color: #fff; border-radius: 50%; border: none;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); transition: transform 0.2s;
}
.remove-btn:hover { transform: scale(1.1); }

#main-textarea { width: 100%; flex: 1; min-height: 120px; background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 1.3rem; line-height: 1.5; resize: none; }

.sheet-footer { padding: 16px 24px 32px 24px; display: flex; justify-content: space-between; align-items: center; }
.footer-left-actions { display: flex; align-items: center; gap: 12px; }
.icon-btn-solid { background: transparent; border: none; color: var(--text-secondary); width: 44px; height: 44px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: 0.2s; }
.icon-btn-solid:hover { background: rgba(150,150,150,0.15); color: var(--text-primary); }
.icon-btn-solid.active-attachment { color: var(--accent-color); }

.char-count-text { font-size: 0.85rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.char-count-text.limit-reached { color: var(--error-color); font-weight: 600; }

.send-btn { background: var(--text-primary); color: var(--bg-color); border: none; width: 50px; height: 50px; border-radius: 50%; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.2s; }
.send-btn:active { transform: scale(0.9); }

/* ==========================================
   8. SIDEBAR (HISTORY) - GLASS UI
   ========================================== */
#sidebar-backdrop { z-index: 50; }
.liquid-sidebar { 
    position: fixed; top: 0; left: -100%; width: 85vw; max-width: 360px; height: 100%; 
    background: var(--glass-bg); /* Glass UI Enabled here */
    backdrop-filter: var(--liquid-blur); -webkit-backdrop-filter: var(--liquid-blur);
    z-index: 60; transition: left 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); 
    border-right: 1px solid var(--glass-border); display: flex; flex-direction: column; 
}
.liquid-sidebar.active { left: 0; }
#sidebar-backdrop.active { opacity: 1; visibility: visible; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 24px; border-bottom: 1px solid rgba(150,150,150,0.15); }
.sidebar-title { display: flex; align-items: center; gap: 10px; font-weight: 600; }
#history-list { flex: 1; overflow-y: auto; padding: 12px; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-radius: 16px; cursor: pointer; color: var(--text-primary); transition: 0.2s; margin-bottom: 4px; background: transparent; }
.history-item:hover { background: rgba(150,150,150,0.15); }
.hist-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.hist-actions { display: flex; gap: 12px; color: var(--text-secondary); }
.hist-actions i:hover { color: var(--accent-color); }
