/* =========================================
   GLOBAL VARIABLES & RESET
   ========================================= */
:root {
    --background-color: #1a1a2e;
    --sidebar-bg: #16213e;
    --chat-bg: #0f3460;
    --user-bubble-bg: #5372f0;
    --ai-bubble-bg: #3a3f47;
    --text-color: #e3e3e3;
    --button-bg: #5372f0;
    --button-hover-bg: #4158b8;
    --input-bg: #16213e;
    --border-color: #5372f0;
    --card-bg: #1f2b4d;
    --selected-border: #00ff88;
    --danger-bg: #e74c3c;
    --danger-hover-bg: #c0392b;
    --magic-bg: #8e44ad;
    --magic-hover-bg: #9b59b6;
    --ready-glow-color: #00ff88;

    /* Layout Variables */
    --nav-height: 50px;
    --padding-y: 10px;
    --padding-x: 20px;
    --save-button-height: 60px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* =========================================
   BODY & WRAPPER STYLES (CORRECTED)
   ========================================= */
html {
    height: 100dvh; 
    width: 100%;
    overflow: hidden; /* Default for Chat Room (App-like feel) */
}

body {
    height: 100dvh;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Default for Chat Room */
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
}

/* --- SCROLLABLE PAGES OVERRIDE (Login, Index, Settings) --- */
/* This targets the html element ONLY when the body has class .scrollable-body */
html:has(body.scrollable-body) {
    overflow-y: auto !important;
    height: auto !important;
}

body.scrollable-body {
    overflow-y: auto !important;
    height: auto !important;
    min-height: 100dvh;
    display: block; /* Standard block layout for scrolling pages */
    padding-top: 50px; 
}

/* Main Container Wrapper */
.app-wrapper {
    display: flex;
    flex-direction: column; 
    width: 100%;
    max-width: 1200px;
    height: 100%; /* Fills 100dvh on chat page */
    background-color: var(--sidebar-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden; /* Chat room internal scrolling */
}

.app-wrapper.scrollable-wrapper {
    height: auto !important;      /* Allow wrapper to grow */
    min-height: calc(100vh - 50px);
    overflow: visible !important; /* Let content spill out */
    margin: 0 auto;
    border-radius: 15px;
}

/* =========================================
   NAVIGATION BAR
   ========================================= */
.top-nav-bar {
    width: 100%;
    height: var(--nav-height); 
    background-color: var(--sidebar-bg); 
    display: flex;
    align-items: center;
    padding: 0 10px; 
    flex-shrink: 0; 
    border-bottom: 2px solid var(--chat-bg); 
    z-index: 100;
}

/* Fixed nav for scrollable pages only */
body.scrollable-body .top-nav-bar {
    position: fixed; 
    top: 0; left: 0; right: 0;
}

.nav-left, .nav-menu-container {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.nav-menu-btn, .new-session-btn {
    width: 36px;
    height: 36px;
    background-color: transparent;
    border: 1px solid var(--text-color);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly; 
    align-items: center;
    padding: 6px; 
    transition: background-color 0.2s;
    color: var(--text-color); 
    font-size: 1.2em; 
}

.nav-menu-btn:hover, .new-session-btn:hover {
    background-color: var(--button-hover-bg);
    border-color: var(--button-hover-bg);
}

.nav-menu-btn span {
    width: 100%;
    height: 2px;
    background-color: var(--text-color);
    display: block;
    border-radius: 1px;
}

.new-session-btn:hover {
    background-color: var(--danger-bg);
    border-color: var(--danger-bg);
}

.chatting-with-title {
    font-size: 1.2em;
    margin-left: auto; 
    margin-right: 20px; 
}

/* =========================================
   DROPDOWN MENU
   ========================================= */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 45px;
    left: 0;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    min-width: 200px;
    z-index: 200;
    padding: 5px 0;
}

.dropdown-menu.visible { display: block; }

.dropdown-menu a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.9em;
    transition: background-color 0.15s;
}

.dropdown-menu a:hover { background-color: var(--chat-bg); }


/* =========================================
   LOGIN PAGE STYLES
   ========================================= */
.login-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background-color: var(--sidebar-bg);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 20px auto; 
}

.login-container h1 {
    margin-bottom: 15px;
    color: var(--text-color);
    font-size: 2em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
}

.login-divider {
    width: 100%;
    height: 2px;
    background-color: var(--button-bg);
    border: none;
    margin-bottom: 20px;
}

.login-image-placeholder {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #0f3460;
    margin-bottom: 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid var(--border-color);
}

.login-image-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.login-container h2 { 
    margin-bottom: 15px; 
    color: #aaa; 
    font-size: 1.2em; 
    font-weight: normal;
}

.login-container input {
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 16px;
    transition: border-color 0.3s;
}

.login-container input:focus {
    outline: none;
    border-color: var(--button-hover-bg);
    box-shadow: 0 0 8px rgba(83, 114, 240, 0.3);
}

.login-container button {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 8px;
    background-color: var(--button-bg);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    margin-top: 10px;
}

.login-container button:hover { background-color: var(--button-hover-bg); }
.login-container button:active { transform: scale(0.98); }

.error-message { 
    color: #ff4d4d; 
    margin-top: 15px; 
    font-weight: bold;
    background-color: rgba(255, 77, 77, 0.1);
    padding: 10px;
    border-radius: 5px;
    width: 100%;
}


/* =========================================
   INDEX PAGE (CARD SELECTION)
   ========================================= */
.selection-container {
    flex-grow: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    background-color: var(--background-color); 
}

.section-header {
    font-size: 1.5em;
    margin-bottom: 15px;
    color: var(--text-color);
    border-left: 4px solid var(--button-bg);
    padding-left: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.horizontal-scroll-wrapper {
    display: flex;
    overflow-x: auto;
    gap: 20px;
    padding-top: 15px;
    padding-bottom: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--button-bg) var(--chat-bg);
}

.horizontal-scroll-wrapper::-webkit-scrollbar { height: 8px; }
.horizontal-scroll-wrapper::-webkit-scrollbar-track { background: var(--chat-bg); border-radius: 4px; }
.horizontal-scroll-wrapper::-webkit-scrollbar-thumb { background: var(--button-bg); border-radius: 4px; }
.horizontal-scroll-wrapper::-webkit-scrollbar-thumb:hover { background: var(--button-hover-bg); }

.card {
    flex: 0 0 auto;
    width: 200px;
    height: 280px;
    background-color: var(--card-bg);
    border-radius: 12px;
    border: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
    position: relative;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.card.selected {
    border-color: var(--selected-border);
    box-shadow: 0 0 15px var(--selected-border);
}

.card-image {
    width: 100%;
    height: 200px;
    flex-shrink: 0;
    background-color: #000;
    object-fit: cover;
}
.card-image img { width: 100%; height: 100%; object-fit: cover; }

.card-content {
    padding: 10px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.card-title {
    font-weight: bold;
    font-size: 1.1em;
    color: var(--text-color);
    margin-bottom: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-subtitle {
    font-size: 0.8em;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.info-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--text-color);
    color: var(--text-color);
    border-radius: 50%;
    font-family: serif; 
    font-style: italic;
    font-weight: bold;
    cursor: pointer;
    z-index: 10; 
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
}
.info-btn:hover { background-color: var(--button-bg); border-color: var(--button-bg); }

.action-bar {
    padding: 20px;
    border-top: 2px solid var(--chat-bg);
    background-color: var(--sidebar-bg);
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-shrink: 0;
}

.action-btn {
    padding: 15px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
    color: white;
    width: 100%;
    max-width: 300px;
}

.btn-join { background-color: var(--button-bg); }
.btn-join:hover { background-color: var(--button-hover-bg); }
.action-btn:disabled {
    background-color: #3a3f47;
    cursor: not-allowed;
    opacity: 0.5;
}


/* =========================================
   CHAT ROOM STYLES (MOBILE OPTIMIZED)
   ========================================= */
.app-wrapper-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex-grow: 1; 
    /* This ensures it fills the space between Nav and Input */
    overflow: hidden; 
    background-color: var(--sidebar-bg);
    min-height: 0; /* Crucial for nested flexbox scrolling */
}

.chat-container {
    display: flex;
    width: 100%;
    height: 100%; 
    flex-grow: 1; 
    overflow: hidden; 
    background-color: var(--sidebar-bg);
}

.main-chat {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
    width: 100%; 
    height: 100%; 
    position: relative;
    overflow: hidden; /* Ensure only chat-window scrolls */
}

.chat-window {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto; 
    display: flex;
    flex-direction: column;
    gap: 20px;
    -webkit-overflow-scrolling: touch; 
    overscroll-behavior: contain; 
}

/* Message Bubbles */
.message-bubble {
    max-width: 75%;
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    display: flex;
    flex-direction: column; 
}

.msg-content {
    font-weight: bold; 
    font-style: normal; 
}
.msg-content .italic-text {
    font-style: italic;
    font-weight: normal; 
}

.msg-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background-color: #000;
}

.msg-name {
    font-weight: bold;
    font-size: 0.9em;
    color: #fff;
    flex-grow: 1; 
}

.edit-msg-btn, .delete-msg-btn {
    background: transparent;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 5px;
    transition: color 0.2s;
}
.edit-msg-btn:hover { color: #fff; }

.delete-msg-btn { color: #e74c3c; margin-left: 5px; }
.delete-msg-btn:hover { color: #c0392b; }


/* Editable Text Area inside bubble */
.edit-container textarea {
    min-height: 60px;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 8px;
    padding: 8px;
    resize: vertical;
    font-size: 1em;
    margin-bottom: 8px;
    font-family: inherit;
    line-height: 1.5;
}
.edit-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.edit-actions button {
    padding: 5px 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: bold;
}
.btn-save-edit { background-color: var(--button-bg); color: white; }
.btn-cancel-edit { background-color: #555; color: white; }

/* Message Types */
.ai-message {
    background-color: var(--ai-bubble-bg);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}
.user-message {
    background-color: var(--user-bubble-bg);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.system-message {
    align-self: center;
    background-color: rgba(0,0,0,0.3);
    border-radius: 10px;
    text-align: center;
    font-style: italic;
    color: #aaa;
    max-width: 90%;
    border: 1px dashed var(--border-color);
    font-weight: normal; 
}
.system-message .msg-header { display: none; } 
.system-message .msg-content { font-weight: normal; }
.system-message .msg-timestamp { display: none; }

.msg-timestamp {
    font-size: 0.7em;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 4px;
    align-self: flex-end;
}

/* Editing Indicator */
.editing-indicator {
    font-size: 0.8em;
    color: #ffd700; 
    font-style: italic;
    margin-bottom: 5px;
    display: none; 
}
.editing-indicator.visible { display: block; animation: pulse 1.5s infinite; }

/* Typing Indicator */
.typing-indicator-bubble {
    background-color: var(--ai-bubble-bg);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    padding: 15px;
    display: none; 
    width: 60px;
    border-radius: 18px;
}
.typing-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: #ccc;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Chat Input Area */
.input-area {
    width: 100%;
    z-index: 100;
    display: flex;
    padding: 10px 20px; 
    border-top: 2px solid var(--sidebar-bg);
    background-color: var(--chat-bg);
    flex-shrink: 0; 
    /* Safe area inset for modern mobile devices (iPhone X+) */
    padding-bottom: calc(10px + env(safe-area-inset-bottom)); 
}

.input-area textarea {
    flex-grow: 1;
    min-height: 50px;
    max-height: 150px;
    height: 50px; 
    padding: 15px;
    border: none;
    border-radius: 25px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 16px;
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
}
.input-area textarea.loading-state {
    background-color: #2c2c44; 
    color: #aaa;
    cursor: wait;
}
.input-area textarea:focus {
    outline: none;
    box-shadow: 0 0 10px var(--border-color);
}
.input-area button {
    width: 80px;
    margin-left: 10px;
    border: none;
    border-radius: 25px;
    background-color: var(--button-bg);
    color: white;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    height: 50px; /* Align with input */
}

/* AI Assist Button */
.ai-assist-btn {
    width: 50px !important;
    background-color: var(--magic-bg) !important;
    font-size: 1.2em !important;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: box-shadow 0.3s ease;
}
.ai-assist-btn:hover { background-color: var(--magic-hover-bg) !important; }

.magic-pulse { animation: magic-glow 1.5s infinite alternate; }
@keyframes magic-glow {
    from { box-shadow: 0 0 5px var(--magic-bg); }
    to { box-shadow: 0 0 15px var(--magic-bg); }
}

.ai-ready-glow {
    box-shadow: 0 0 10px 2px var(--ready-glow-color);
    animation: ready-pulse 2s infinite alternate;
}
@keyframes ready-pulse {
    from { box-shadow: 0 0 5px var(--ready-glow-color); }
    to { box-shadow: 0 0 15px var(--ready-glow-color); }
}


/* =========================================
   FORMS (Create/Edit/Delete Pages)
   ========================================= */
.main-content {
    padding-top: var(--nav-height); 
    padding-bottom: 0px; 
    flex-grow: 1;
    width: 100%;
    overflow-y: auto;
    background-color: var(--chat-bg);
    -webkit-overflow-scrolling: touch; 
}

.form-container, .app-wrapper.form-wrapper {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px 20px 150px 20px;
    background-color: var(--sidebar-bg);
    border-radius: 10px;
}

/* For delete page which uses a slightly different structure */
.delete-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    margin-top: 50px;
    padding: 30px;
    border-radius: 15px;
    background-color: var(--sidebar-bg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    gap: 25px;
}

.page-header {
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Common Input Styles */
input[type="text"], textarea, select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 16px;
    resize: vertical;
    line-height: 1.4;
}

select {
    appearance: none; 
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%23e3e3e3" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-down"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 10px top 50%;
}

.save-area {
    position: fixed; 
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--save-button-height);
    background-color: var(--sidebar-bg);
    border-top: 2px solid var(--chat-bg);
}

#save-button {
    padding: 12px 30px;
    border: none;
    border-radius: 30px;
    background-color: var(--button-bg);
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
#save-button:hover { background-color: var(--button-hover-bg); }

/* Delete Button Specifics */
.delete-btn {
    background-color: var(--danger-bg);
    color: white;
    padding: 15px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 10px;
}
.delete-btn:hover { background-color: var(--danger-hover-bg); }
.delete-btn:disabled { background-color: #555; cursor: not-allowed; opacity: 0.6; }

/* Status Messages */
#message-box, #status-message {
    position: fixed;
    top: 60px;
    right: 20px;
    padding: 10px 20px;
    background-color: #28a745;
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 200;
}
#status-message { display: block; position: static; text-align: center; min-height: 20px; background: none; box-shadow: none; }
.success { color: #2ecc71; }
.error { color: #e74c3c; }


/* =========================================
   IMAGE GENERATION UI (Common to Create Image & Edit)
   ========================================= */
.image-display-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--background-color);
    position: relative;
    padding: 20px;
    overflow: hidden;
    padding-bottom: 150px;
}

.image-gen-container {
    margin-bottom: 20px;
    padding: 15px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: center;
}

.img-preview, .generated-image {
    width: 100%;
    max-width: 300px; 
    height: 300px;
    background-color: #000;
    object-fit: cover;
    border-radius: 8px;
    margin: 0 auto 10px auto;
    display: block;
}

/* Create Image Page specific overrides */
.image-display-area .generated-image {
    max-width: 100%;
    max-height: 60vh; 
    height: auto;
    width: auto;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

.placeholder-text {
    color: #555;
    font-size: 1.5em;
    text-align: center;
    width: 100%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.control-overlay {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    display: none; 
    z-index: 50;
}

.icon-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: var(--chat-bg);
    border: 2px solid var(--border-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2em;
}
.icon-btn:hover { background-color: var(--button-bg); transform: scale(1.1); }

.loader {
    border: 4px solid var(--chat-bg);
    border-top: 4px solid var(--border-color);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
    display: none;
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
}
@keyframes spin { 0% { transform: translate(-50%, -50%) rotate(0deg); } 100% { transform: translate(-50%, -50%) rotate(360deg); } }

.use-img-btn {
    background-color: #28a745;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    display: none; 
}
.use-img-btn:hover { background-color: #218838; }

/* --- FIXED INPUT AREA ALIGNMENT --- */
.image-gen-input-area {
    position: fixed; 
    bottom: 0; left: 0; width: 100%; z-index: 90; 
    padding: 20px; 
    background-color: var(--sidebar-bg);
    border-top: 2px solid var(--chat-bg);
    /* Remove flex-direction column to prevent stacking issues */
    display: flex; 
    justify-content: center; /* Center the container horizontally */
    align-items: center;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5); 
}

.prompt-container {
    display: flex; 
    width: 100%; 
    max-width: 1000px; 
    gap: 10px; 
    margin: 0 auto;
    align-items: center; /* Vertically align text area and button */
}

/* Ensure textarea has specific height for this page */
.image-gen-input-area textarea {
    flex-grow: 1;
    height: 50px; /* Explicit height */
    min-height: 50px;
    padding: 12px 15px;
    resize: none;
    margin: 0; /* Remove any default margins */
}

/* Ensure button matches textarea height */
/* Ensure button matches textarea height */
.btn-generate {
    background-color: var(--button-bg);
    color: white; 
    border: none; 
    border-radius: 25px; /* Enforces the pill shape */
    padding: 0 30px; 
    font-weight: bold; 
    font-size: 1em;
    cursor: pointer; 
    transition: background-color 0.2s;
    height: 50px; /* Match textarea height exactly */
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0; /* Remove margins */
    white-space: nowrap; /* Prevent text wrapping */
    flex-shrink: 0; /* CRITICAL: Prevents the button from being squashed */
    min-width: 150px; /* CRITICAL: Reserves space for "Generating..." text */
}
.btn-generate:hover { background-color: var(--button-hover-bg); }
.btn-generate:disabled { background-color: #555; cursor: not-allowed; }

/* =========================================
   LIVE PRESENCE INDICATOR
   ========================================= */
.header-title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-left: auto; 
    margin-right: 20px;
}

.status-dot {
    width: 12px;
    height: 12px;
    background-color: #555; /* Default Grey (Offline) */
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 2px rgba(0,0,0,0.5);
}

.status-dot.online {
    background-color: #00ff88;
    box-shadow: 0 0 8px #00ff88, 0 0 15px #00ff88; /* Green Glow */
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.7); }
    70% { box-shadow: 0 0 10px 5px rgba(0, 255, 136, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 255, 136, 0); }
}

/* Ensure typing bubble animation looks good */
.typing-indicator-bubble {
    /* Existing style is okay, just ensuring margins are good for 'live' feel */
    margin-bottom: 20px;
    margin-left: 10px;
    opacity: 0;
    transform: translateY(10px);
    animation: fade-in-up 0.3s forwards;
}

@keyframes fade-in-up {
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   SETTINGS PAGE
   ========================================= */
.settings-description {
    text-align: center;
    color: #aaa;
    margin-bottom: 30px;
    font-size: 0.9em;
    line-height: 1.5;
}

.settings-group {
    background-color: var(--input-bg);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.settings-label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-color);
    font-weight: bold;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
/* =========================================
   MODALS
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal-box {
    background-color: var(--sidebar-bg);
    padding: 25px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    text-align: center;
}

.modal-close {
    position: absolute; top: 10px; right: 15px;
    font-size: 1.5em; cursor: pointer; color: #aaa;
}
.modal-close:hover { color: white; }

.modal-text {
    line-height: 1.6;
    white-space: pre-wrap; 
    text-align: left; 
}

.modal-actions {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: bold;
    cursor: pointer;
}
.btn-yes { background-color: var(--danger-bg); color: white; }
.btn-yes:hover { background-color: var(--danger-hover-bg); }
.btn-no { background-color: #555; color: white; }
.btn-no:hover { background-color: #777; }

/* =========================================
   MEDIA QUERIES
   ========================================= */
@media (max-width: 800px) {
    body { padding: 0; padding-top: 50px; }
    
    /* Wrapper Adjustments */
    .app-wrapper { border-radius: 0; min-height: 100vh; height: 100dvh; margin: 0; }
    .app-wrapper.scrollable-wrapper { min-height: calc(100vh - 50px); }
    
    /* Login Page */
    .login-container { width: 90%; margin: 20px; padding: 30px 20px; }
    .login-container h1 { font-size: 1.6em; }
    
    /* Index Page */
    .action-bar { flex-direction: column; }
    .card { width: 160px; height: 230px; }
    .card-image { height: 160px; }
    
    /* Chat Room */
    .chat-container { flex-direction: column; }
    .chat-window { padding: 10px; }
    
    /* Forms */
    .top-nav-bar, .save-area { width: 100vw; }
    .main-content { padding-left: 10px; padding-right: 10px; }
    .form-container { margin: 10px 0; padding: 15px 15px 150px 15px; }
}

/* =========================================
   THEME: DARK MODE (Black & Purple)
   ========================================= */
body.dark-theme {
    /* Backgrounds: Deep Black & Dark Greys */
    --background-color: #050505;
    --sidebar-bg: #0a0a0a;
    --chat-bg: #000000;
    --card-bg: #121212;
    --input-bg: #141414;

    /* Text: Off-white for comfort */
    --text-color: #e6e6e6;

    /* Primary Accents: Purple */
    --border-color: #5e35b1;        /* Visible Purple for structural lines */
    --button-bg: #6200ea;           /* Deep Purple buttons */
    --button-hover-bg: #7c4dff;     /* Brighter Purple on hover */

    /* Chat Bubbles */
    --user-bubble-bg: #4527a0;      /* Rich Purple for user messages */
    --ai-bubble-bg: #1f1f1f;        /* Neutral Dark Grey for AI */

    /* Highlights & Glows */
    --selected-border: #d500f9;     /* Neon Purple for selected items */
    --ready-glow-color: #d500f9;    /* Matches the neon accent */
    
    /* Magic/AI Assist */
    --magic-bg: #651fff;
    --magic-hover-bg: #7c4dff;

    /* Danger Actions (Darkened Red to fit theme) */
    --danger-bg: #b71c1c;
    --danger-hover-bg: #d32f2f;
}
/* =========================================
   MESSAGE MENU (Three Dots)
   ========================================= */

.msg-actions-container {
    position: relative;
    display: flex;
    align-items: center;
}

.msg-kebab-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 8px;
    line-height: 1;
    transition: color 0.2s;
    border-radius: 4px;
}

.msg-kebab-btn:hover, .msg-kebab-btn.active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

.msg-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    width: 120px;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow: hidden;
    flex-direction: column;
}

.msg-dropdown.visible {
    display: flex;
    animation: fade-in-menu 0.2s ease-out;
}

@keyframes fade-in-menu {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-dropdown button {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 10px 15px;
    text-align: left;
    cursor: pointer;
    font-size: 0.9em;
    width: 100%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.msg-dropdown button:hover {
    background-color: var(--chat-bg);
}

.msg-dropdown button.delete-opt {
    color: #ff6b6b;
}
.msg-dropdown button.delete-opt:hover {
    background-color: rgba(231, 76, 60, 0.2);
}
/* =========================================
   AI REGENERATE BUTTON
   ========================================= */

.ai-assist-btn.regenerate {
    background-color: var(--button-bg) !important;
    color: white;
    font-size: 1.5em !important;
    animation: none !important; /* Stop magic pulse in regen mode */
    box-shadow: none !important;
}

.ai-assist-btn.regenerate:hover {
    background-color: var(--button-hover-bg) !important;
    transform: rotate(180deg);
    transition: transform 0.4s ease, background-color 0.2s;
}