/* 🚨 IMPORTANT: This entire content MUST be saved as a separate file named 'style.css' */

/* --- Global Reset and Base Styles --- */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --chat-max-width: 800px; 
    --primary-color: #881475; 
    --secondary-color: #f3fdb9; 
    --background-color: #f7f7f7;
    --bubble-radius: 20px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --sidebar-width: 280px; 
    --link-color: #1977D0;
}

body {
    background-color: var(--background-color);
    display: flex;
    justify-content: center;
    /* ✅ FIX: Container செங்குத்தாக (vertically) நடுவில் வர */
    align-items: center; 
    width: 100%;
    height: 100vh; 
}

/* --- Chat Container (Desktop Size) --- */
.chat-container {
    width: 100%;
    max-width: var(--chat-max-width); 
    
    height: 100vh; 
    max-height: 100vh; 
    
    box-shadow: var(--box-shadow);
    /* ✅ FIX: இது எப்போதும் 'flex' ஆக இருக்க வேண்டும் */
    display: flex; 
    flex-direction: column; 
    background-color: white;
    
    border-radius: 15px; 
    
    overflow: hidden;
    position: relative;
    /* ✅ FIX: body-யே align-items: center-ஐப் பார்ப்பதால், இதை நீக்கிவிடலாம் */
    margin: 0; 
}

/* --- Chat Header --- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    z-index: 20;
    position: relative;
    width: 100%; 
    box-sizing: border-box;
    flex-shrink: 0; 
}

.header-info {
    flex-grow: 1;
    display: flex; 
    align-items: center;
    justify-content: center;
}

.chat-logo {
    height: 32px; 
    width: auto;
    margin-right: 5px;
    flex-shrink: 0;
}

.chat-title {
    font-size: 1.1em;
    font-weight: 600;
    color: #333;
}

.icon-button {
    background: none;
    border: none;
    color: #555;
    font-size: 1.2em;
    cursor: pointer;
    padding: 8px;
    margin: 0 4px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.icon-button:hover {
    background-color: #f0f0f0;
}

.user-profile-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    margin-left: 10px;
    cursor: pointer;
    flex-shrink: 0;
    order: 4; 
    box-shadow: 0 0 0 2px white, 0 0 0 3px var(--primary-color);
}

.upgrade-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.85em;
    font-weight: 600;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    order: 5;
}

.upgrade-button i {
    margin-right: 5px;
}

/* --- Chat Input Area --- */
.chat-input-area {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background-color: white;
    border-top: 1px solid #eee;
    z-index: 10;
    flex-shrink: 0; 
    width: 100%;
    box-sizing: border-box;
}

#user-input {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 25px; 
    font-size: 1em;
    outline: none;
    margin: 0 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#user-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(136, 20, 117, 0.2);
}

.add-button, .mic-button, .send-button {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 1.2em;
    cursor: pointer;
    padding: 8px;
    margin: 0 2px;
    border-radius: 50%;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.send-button {
    color: white; 
    background-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.send-button:hover {
    background-color: #721162;
}

/* 🖼️ Image Preview Styles (BEFORE sending - next to input box) - புதுப்பிக்கப்பட்டது */
.image-preview-area {
    display: none; /* JS-ஆல் மாற்றப்படும் */
    align-items: center;
    gap: 8px;
    margin-right: 10px; /* input-உக்கு முன் இடைவெளி */
    position: relative;
    /* இமேஜ் ப்ரிவியூவை சரியான இடத்தில் காட்ட */
    flex-shrink: 0; 
    order: -1; 
}

/* ✅ FIX: அனுப்பும் முன் உள்ள படத்தின் ப்ரிவியூ-வை நீங்கள் கேட்ட சிறிய அளவில் (60x60px) காட்ட */
.input-preview-img {
    width: 60px; 
    height: 60px; 
    object-fit: cover; /* படத்தை சிதைக்காமல் சிறிய இடத்தில் நிரப்ப */
    border-radius: 8px;
    border: 1px solid #ddd;
}

.clear-image-btn {
    position: absolute;
    top: -5px; /* மேலே தூக்க */
    right: -5px; /* வலது ஓரத்தில் வைக்க */
    color: #888;
    font-size: 1em;
    padding: 3px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    border: 1px solid #ddd;
}

/* --- Messages Area (Scrolling) --- */
.chat-messages {
    flex-grow: 1; 
    padding: 0; 
    background-color: var(--background-color);
    display: flex;
    flex-direction: column; 
    overflow-y: auto; 
    position: relative;
}

/* Tools block */
.tools-block {
    padding: 20px 15px;
    text-align: center;
    background-color: white;
    border-radius: 12px;
    /* ✅ FIX: Tools Block-ஐ நடுவில் வைக்க */
    margin: auto; 
    width: 90%;
    max-width: 350px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.tools-title {
    font-size: 1.3em;
    font-weight: 700;
    color: #333;
    margin-bottom: 20px;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.tool-button {
    background-color: var(--background-color);
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 15px 10px;
    font-size: 0.9em;
    font-weight: 500;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.tool-button:hover {
    background-color: #eee;
    border-color: var(--primary-color);
}

.tool-button i {
    font-size: 1.5em;
    color: var(--primary-color);
    margin-bottom: 8px;
}

/* --- Message List (Inner container for messages) --- */
.message-list {
    flex-grow: 1; 
    padding: 15px; 
    display: flex;
    flex-direction: column; 
}

/* --- Message Bubbles --- */
.message {
    max-width: 85%;
    padding: 10px 15px;
    word-wrap: break-word;
    word-break: break-word;
    position: relative; 
    font-size: 0.95em;
    user-select: text; 
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
    margin: 0 0 15px 0; 
    box-sizing: border-box; 
    height: auto; 
}

.message.sent {
    background-color: var(--secondary-color);
    margin-left: auto; 
    border-radius: var(--bubble-radius) var(--bubble-radius) 4px var(--bubble-radius);
}

.message.received {
    background-color: white;
    margin-right: auto; 
    border-radius: var(--bubble-radius) var(--bubble-radius) var(--bubble-radius) 4px;
    padding: 10px 15px 10px 45px;
}

/* 🖼️ Message Bubble-க்குள் உள்ள படத்திற்கான CSS - புதுப்பிக்கப்பட்டது */
.message-image {
    /* ✅ FIX: மெசேஜ் பப்பில் உள்ள படத்தை நீங்கள் கேட்ட சிறிய அளவில் காட்ட */
    max-width: 180px; /* அகலத்தைக் குறைக்கவும் */
    max-height: 140px; /* உயரத்தைக் குறைக்கவும் */
    width: auto;
    height: auto;
    display: block; 
    margin: 5px 0; 
    border-radius: 8px;
    object-fit: contain; /* படத்தைத் சிதைக்காமல் (stretch) வைக்க */
    border: 1px solid #eee;
}

/* 💡 குறிப்பு: உங்கள் HTML-லில் படம் இவ்வாறு இருக்க வேண்டும்:
    <div class="message sent">
     <p>இமேஜ் இதோ:</p>
     <img class="message-image" src="your_image_url.jpg" alt="அனுப்பிய படம்">
    </div>
*/


.tts-control {
    position: absolute;
    top: 5px;
    left: 8px;
    z-index: 10;
    cursor: pointer;
    background-color: var(--background-color);
    border-radius: 50%;
    width: 28px; 
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s;
}

.voice-creation-view {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--background-color);
    display: none; /* JS-ஆல் மாற்றப்படும் */
}

/* --- Splash Screen (For Logo Animation) --- */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background-color: white; 
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}

/* Splash Logo Image Style */
.splash-logo {
    width: 250px; 
    height: auto;
    animation: scale-in 1.5s ease-out forwards;
    transform: scale(0.1); 
}

/* Animation Definition: Small to Big */
@keyframes scale-in {
    0% {
        transform: scale(0.1); 
        opacity: 0;
    }
    100% {
        transform: scale(1); 
        opacity: 1;
    }
}

/* Splash Screen மறைதல் */
.splash-screen.hidden {
    opacity: 0;
    pointer-events: none; 
}

/* --- History Sidebar Styles --- */
.history-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100dvh;
    background-color: #333; 
    color: white;
    z-index: 99;
    transform: translateX(-100%); 
    transition: transform 0.3s ease-in-out;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.history-sidebar.open {
    transform: translateX(0); 
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 98;
    display: none; 
}

.sidebar-overlay.active {
    display: block;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #444;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.3em;
}

.close-sidebar-btn {
    color: white;
    margin: 0;
}

.history-list {
    list-style: none;
    padding: 10px 0;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
}

.history-item {
    padding: 12px 15px;
    font-size: 0.95em;
    color: #ccc;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
}

.history-item i {
    margin-right: 10px;
    color: #aaa;
}

.history-item:hover, .history-item.active {
    background-color: #444;
    color: white;
}

.new-chat-btn {
    background-color: #555;
    color: white !important;
    font-weight: 600;
    margin: 10px 15px;
    border-radius: 8px;
    text-align: center;
    padding: 15px;
}
/* --- Media Query: Mobile Size Optimization --- */
@media (max-width: 768px) {
    
    .chat-container {
        width: 100%;
        max-width: 100%; 
        height: 100dvh; 
        max-height: 100dvh; 
        border-radius: 0; 
        box-shadow: none; 
        margin: 0 auto;
    }

    body {
        align-items: flex-start;
        background-color: white; 
    }
    
    .chat-header {
        padding: 10px 15px;
    }
}