* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
    background: #ffffff;
}

/* Mobile-specific body adjustments */
@media (max-width: 767px) {
    body {
        height: 100dvh; /* Dynamic viewport height for mobile */
        overflow: hidden;
    }
}

.app-container {
    display: flex;
    height: 100vh;
    position: relative;
}

/* Mobile app container adjustments */
@media (max-width: 767px) {
    .app-container {
        height: 100dvh; /* Dynamic viewport height */
        flex-direction: column;
    }
}

.sidebar {
    width: 280px;
    background: #f8f9fa;
    color: #333;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    border-right: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
}

/* Mobile sidebar improvements */
@media (max-width: 767px) {
    .sidebar {
        width: 100vw;
        height: 100dvh; /* Dynamic viewport height for mobile */
        z-index: 1050;
        background: #f8f9fa;
    }
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 20px;
    background: #f8f9fa;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
}

.sidebar-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
}

.sidebar-close {
    background: none;
    border: none;
    color: #666;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
    display: none;
}

.sidebar-close:hover {
    background: #f0f0f0;
}

.sidebar-title {
    font-size: 20px;
    font-weight: 700;
    color: #2B5AA0;
    margin: 0;
}

.sidebar-subtitle {
    font-size: 12px;
    color: #95a5a6;
}

.sidebar-menu {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    min-height: 0; /* Important for flex overflow */
}

/* Mobile sidebar menu adjustments */
@media (max-width: 767px) {
    .sidebar-menu {
        padding: 12px 16px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        min-height: 0;
        /* Ensure space for profile section */
        margin-bottom: 0;
    }
}

.menu-section {
    margin-bottom: 20px;
}

.menu-button {
    width: 100%;
    padding: 12px 16px;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
}

.menu-button:hover {
    background: #f0f0f0;
    border-color: #d0d0d0;
}

.menu-button.primary {
    background: linear-gradient(135deg, #cdffd8 0%, #94b9ff 100%);
    color: #333;
    border: none;
    box-shadow: 0 4px 8px rgba(148, 185, 255, 0.3);
    justify-content: center;
}

.menu-button.primary .menu-icon {
    color: #333;
}

.menu-button.primary:hover {
    background: linear-gradient(135deg, #b8ffcc 0%, #7da7ff 100%);
    box-shadow: 0 6px 12px rgba(148, 185, 255, 0.4);
    transform: translateY(-1px);
}

.menu-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 8px;
    font-size: 14px;
    color: #666;
    margin: 2px 0;
}

.menu-item:hover {
    background: #f0f0f0;
}

.conversation-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px;
    font-size: 14px;
    color: #666;
    margin: 2px 0;
}

.conversation-item:hover {
    background: #f0f0f0;
}

.conversation-item.active {
    background: #e3f2fd;
    color: #4A90E2;
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
}

.conversation-edit,
.conversation-copy,
.conversation-delete {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.2s;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-edit:hover {
    background: #f3e5f5;
    color: #9c27b0;
}

.conversation-copy:hover {
    background: #e3f2fd;
    color: #4A90E2;
}

.conversation-delete:hover {
    background: #ffebee;
    color: #ff6b6b;
}

.conversation-edit:disabled,
.conversation-copy:disabled,
.conversation-delete:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.conversation-title-input {
    background: white;
    border: 1px solid #4A90E2;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    color: #333;
    flex: 1;
    min-width: 0;
    font-family: inherit;
}

.conversation-title-input:focus {
    outline: none;
    border-color: #357ABD;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.menu-icon {
    font-size: 16px;
    width: 20px;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

/* Mobile main content adjustments */
@media (max-width: 767px) {
    .main-content {
        height: 100dvh; /* Dynamic viewport height */
        width: 100%;
        position: relative;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Prevent body scroll */
    }
}

.chat-header {
    background: #ffffff;
    color: #333;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 70px;
    box-sizing: border-box;
    border-bottom: 1px solid #e5e5e5;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

/* Mobile header improvements */
@media (max-width: 767px) {
    .chat-header {
        padding: 12px 16px;
        height: 60px;
        position: sticky;
        top: 0;
        background: #ffffff;
        border-bottom: 1px solid #e5e5e5;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}

.menu-toggle {
    background: none;
    border: none;
    color: #666;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
    display: block;
}

.menu-toggle:hover {
    background: #f0f0f0;
}

.character-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.character-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #4A90E2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.character-details h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: #2B5AA0;
}

.character-details p {
    font-size: 13px;
    color: #666;
    margin: 2px 0 0 0;
}

.conversation-characters {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Remove margin-left: auto since we're using justify-content: space-between */
}

.characters-list {
    display: flex;
    gap: 4px;
}

.conversation-character {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4A90E2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    font-weight: 500;
    position: relative;
    cursor: pointer;
}

.conversation-character .remove-btn {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background: #ff6b6b;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 10px;
    cursor: pointer;
    display: none;
}

.conversation-character:hover .remove-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-character.main-character {
    border: 2px solid #4A90E2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}

.conversation-character.main-character:hover .remove-btn {
    display: none;
}


.add-character-to-chat-btn-header {
    background: linear-gradient(135deg, #f8fbff 0%, #e8f4ff 100%);
    border: 2px solid #e1f0ff;
    border-radius: 12px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #4A90E2;
    flex-shrink: 0;
    outline: none;
    white-space: nowrap;
    margin-left: 8px;
}

.add-character-to-chat-btn-header:hover {
    background: linear-gradient(135deg, #e8f4ff 0%, #d6ebff 100%);
    border-color: #4A90E2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

.add-character-to-chat-btn-header:focus {
    border-color: #357ABD;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2), 0 4px 12px rgba(74, 144, 226, 0.15);
}

.warning-message {
    display: flex;
    justify-content: center;
    margin: 16px 0;
    padding: 0 20px;
}


/* Message Actions - Replay and Remove Buttons */
.message-actions {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 8px;
    padding-left: 0;
    align-self: flex-start;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.remove-message-btn,
.replay-btn,
.edit-message-btn,
.remember-message-btn,
.picture-message-btn {
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    font-family: 'Raleway', sans-serif;
    transition: all 0.2s ease;
    border: none;
    min-width: auto;
    height: auto;
}

.remove-message-btn {
    background: rgba(74, 144, 226, 0.1);
    color: #4A90E2;
    border: 1px solid rgba(74, 144, 226, 0.3);
}

.remove-message-btn:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    transform: translateY(-1px);
}

.edit-message-btn {
    background: rgba(74, 144, 226, 0.1);
    color: #4A90E2;
    border: 1px solid rgba(74, 144, 226, 0.3);
}

.edit-message-btn:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    transform: translateY(-1px);
}

.replay-btn {
    background: rgba(74, 144, 226, 0.1);
    color: #4A90E2;
    border: 1px solid rgba(74, 144, 226, 0.3);
    display: none; /* Hidden by default, shown only on last AI message */
}

.replay-btn:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    transform: translateY(-1px);
}

.remember-message-btn {
    background: rgba(74, 144, 226, 0.1);
    color: #4A90E2;
    border: 1px solid rgba(74, 144, 226, 0.3);
}

.remember-message-btn:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    transform: translateY(-1px);
}

.remember-message-btn.remembered {
    background: rgba(74, 144, 226, 0.3);
    color: #357ABD;
    border-color: rgba(74, 144, 226, 0.6);
    font-weight: 600;
}

.picture-message-btn {
    background: rgba(74, 144, 226, 0.1);
    color: #4A90E2;
    border: 1px solid rgba(74, 144, 226, 0.3);
    display: none; /* Hidden by default, shown only when character has gallery images */
}

.picture-message-btn:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    transform: translateY(-1px);
}

.remove-message-btn:active,
.replay-btn:active,
.edit-message-btn:active,
.remember-message-btn:active,
.picture-message-btn:active {
    transform: translateY(0);
}

.remove-message-btn:disabled,
.replay-btn:disabled,
.edit-message-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Edit message interface */
.edit-textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid rgba(74, 144, 226, 0.3);
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    background: #fff;
    margin-bottom: 8px;
}

.edit-textarea:focus {
    outline: none;
    border-color: #4A90E2;
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.edit-controls {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.save-edit-btn,
.cancel-edit-btn {
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    font-family: 'Raleway', sans-serif;
    transition: all 0.2s ease;
    border: none;
    min-width: auto;
    height: auto;
}

.save-edit-btn {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.save-edit-btn:hover:not(:disabled) {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.5);
    transform: translateY(-1px);
}

.cancel-edit-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.cancel-edit-btn:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    transform: translateY(-1px);
}

.save-edit-btn:disabled,
.cancel-edit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.warning-content {
    background: linear-gradient(135deg, #fef5f5 0%, #fdf2f2 100%);
    color: #dc2626;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    max-width: 600px;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.05);
    line-height: 1.4;
}

/* Image upload styling */
.image-upload-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.profile-image-preview {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 2px dashed #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f9f9f9;
    position: relative;
}

.profile-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.no-image-placeholder {
    color: #999;
    font-size: 12px;
    text-align: center;
    line-height: 1.3;
}

.image-upload-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
}

.form-help {
    color: #666;
    font-size: 12px;
    margin-top: 4px;
    display: block;
}

/* Profile image styling for avatars */
.character-avatar img,
.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.character-avatar {
    position: relative;
    overflow: hidden;
}

.message-avatar {
    position: relative;
    overflow: hidden;
}

/* Gallery styling */
.gallery-upload-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gallery-upload-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.gallery-count {
    color: #666;
    font-size: 12px;
    margin-left: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid #eee;
    border-radius: 8px;
    background: #fafafa;
}

.gallery-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #ddd;
    background: #f9f9f9;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-overlay {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    border-bottom-left-radius: 4px;
}

.gallery-item-overlay:hover {
    background: rgba(220, 38, 38, 0.9);
}

/* Gallery button in chat header */
.gallery-btn {
    background: linear-gradient(135deg, #f8fbff 0%, #e8f4ff 100%);
    border: 2px solid #e1f0ff;
    border-radius: 12px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #4A90E2;
    flex-shrink: 0;
    outline: none;
    white-space: nowrap;
}

.gallery-btn:hover {
    background: linear-gradient(135deg, #e8f4ff 0%, #d6ebff 100%);
    border-color: #4A90E2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

.gallery-btn:focus {
    border-color: #357ABD;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2), 0 4px 12px rgba(74, 144, 226, 0.15);
}

/* Gallery modal styling */
.gallery-modal {
    width: 95%;
    max-width: 1200px;
    max-height: 90vh;
}

.gallery-viewer {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.gallery-viewer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
    border-radius: 12px;
    border: 1px solid #eee;
    box-sizing: border-box;
}

.gallery-viewer-item {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 100%; /* Creates a 1:1 aspect ratio */
    border-radius: 16px;
    overflow: hidden;
    border: 3px solid #fff;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.gallery-viewer-item:hover {
    border-color: #4A90E2;
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(74, 144, 226, 0.25);
}

.gallery-viewer-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-actions {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85), transparent);
    padding: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-viewer-item:hover .gallery-item-actions {
    opacity: 1;
}

.gallery-action-btn {
    background: rgba(255, 255, 255, 0.95);
    border: none;
    color: #333;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Raleway', sans-serif;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.gallery-action-btn:hover {
    background: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.send-to-chat-btn {
    background: rgba(74, 144, 226, 0.95);
    color: white;
}

.send-to-chat-btn:hover {
    background: rgba(74, 144, 226, 1);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

.gallery-empty {
    text-align: center;
    color: #999;
    padding: 60px 40px;
    font-style: italic;
    font-size: 16px;
    background: #fafafa;
    border-radius: 12px;
    border: 1px solid #eee;
}

/* Pure Image Viewer */
.image-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.image-viewer-overlay.show {
    display: flex;
}

.image-viewer-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.8);
    color: white;
    font-size: 18px;
    font-weight: 300;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    z-index: 10001;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.image-viewer-close:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: white;
    transform: scale(1.1);
}

.image-viewer-overlay img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    cursor: default;
}

/* Picture Quote Modal */
.picture-quote-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
}

.picture-quote-overlay.show {
    display: flex;
}

.picture-quote-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, rgba(43, 90, 160, 0.8), rgba(74, 144, 226, 0.9));
    border: none;
    color: white;
    font-size: 18px;
    font-weight: 300;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10001;
    box-shadow: 0 4px 16px rgba(43, 90, 160, 0.3);
    backdrop-filter: blur(10px);
}

.picture-quote-close:hover {
    background: linear-gradient(135deg, rgba(53, 122, 189, 0.9), rgba(74, 144, 226, 1));
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(43, 90, 160, 0.4);
}

.picture-quote-container {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.picture-quote-container img {
    min-width: 70vw;
    min-height: 70vh;
    max-width: 95vw;
    max-height: 95vh;
    width: auto;
    height: auto;
    object-fit: cover;
    border-radius: 8px;
}

.picture-quote-text {
    position: absolute;
    bottom: 40px;
    left: 40px;
    right: 40px;
    background: linear-gradient(135deg, rgba(43, 90, 160, 0.4), rgba(74, 144, 226, 0.7));
    color: white;
    padding: 25px 35px;
    border-radius: 20px;
    font-size: 20px;
    line-height: 1.5;
    font-style: normal;
    font-weight: 400;
    backdrop-filter: blur(15px);
    border: none;
    box-shadow: 0 12px 48px rgba(43, 90, 160, 0.3), 0 4px 16px rgba(74, 144, 226, 0.2);
    max-height: 250px;
    overflow: hidden;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    transition: all 0.3s ease;
}

/* Responsive font sizing based on text length */
.picture-quote-text.long-text {
    font-size: 16px;
    line-height: 1.4;
}

.picture-quote-text.very-long-text {
    font-size: 14px;
    line-height: 1.3;
    padding: 20px 30px;
}

.picture-quote-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, rgba(43, 90, 160, 0.8), rgba(74, 144, 226, 0.9));
    border: none;
    color: white;
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    padding: 12px 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10001;
    user-select: none;
    width: 60px;
    height: 60px;
    box-shadow: 0 4px 16px rgba(43, 90, 160, 0.3);
    backdrop-filter: blur(10px);
}

.picture-quote-nav:hover {
    background: linear-gradient(135deg, rgba(53, 122, 189, 0.9), rgba(74, 144, 226, 1));
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(43, 90, 160, 0.4);
}

.picture-quote-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: translateY(-50%) scale(0.9);
}

.picture-quote-prev {
    left: 20px;
}

.picture-quote-next {
    right: 20px;
}

.picture-quote-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 10001;
}

.picture-quote-title {
    background: linear-gradient(135deg, rgba(43, 90, 160, 0.8), rgba(74, 144, 226, 0.9));
    color: white;
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(10px);
    border: none;
    box-shadow: 0 4px 16px rgba(43, 90, 160, 0.3);
    letter-spacing: 0.5px;
}

.picture-quote-counter {
    background: linear-gradient(135deg, rgba(43, 90, 160, 0.7), rgba(74, 144, 226, 0.8));
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    border: none;
    box-shadow: 0 3px 12px rgba(43, 90, 160, 0.25);
}

.picture-quote-branding {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10001;
}

.aymi-logo {
    height: 16px;
    width: auto;
    opacity: 0.4;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
    transition: opacity 0.3s ease;
}

.aymi-logo:hover {
    opacity: 1;
}

/* Chat image styling */
.chat-image {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 300px;
}

.chat-image img,
.chat-image-element {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    border: 1px solid #ddd;
    transition: all 0.2s;
    cursor: pointer;
    display: block;
}

.chat-image img:hover,
.chat-image-element:hover {
    border-color: #4A90E2;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.2);
}

.image-caption {
    font-size: 11px;
    color: #666;
    font-style: italic;
    padding: 0 4px;
}

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #ffffff;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 0; /* Important for flex overflow */
}

/* Mobile chat messages improvements - CRITICAL FIX */
@media (max-width: 767px) {
    .chat-messages {
        flex: 1 1 auto;
        padding: 16px 12px;
        overflow-y: scroll !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        min-height: 0;
        height: 0; /* Force flex item to be scrollable */
        /* Remove transforms that might interfere */
        position: relative;
        z-index: 1;
        /* Ensure touch events work */
        touch-action: pan-y;
        /* Better scroll performance */
        will-change: scroll-position;
    }
    
    /* Hide scrollbars but keep functionality */
    .chat-messages::-webkit-scrollbar {
        display: none;
        width: 0;
    }
    
    .chat-messages {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

.message {
    margin: 24px 0;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    max-width: 900px;
}

.message.user-message {
    flex-direction: row-reverse;
}

.message-sender {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    width: 60px;
    min-width: 60px;
    max-width: 60px;
}

.user-message .message-sender {
    align-items: center;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.message-name {
    font-size: 12px;
    font-weight: 500;
    color: #666;
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-message .message-avatar {
    background: #4A90E2;
    color: white;
}

.user-message .message-avatar {
    background: #e5e5e5;
    color: #666;
}

.message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 85%;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    word-wrap: break-word;
    line-height: 1.0;
    font-size: 15px;
    width: fit-content;
    max-width: 100%;
}

.user-message .message-content {
    align-items: flex-end;
}

.user-message .message-bubble {
    background: #f0f0f0;
    color: #333;
    border-radius: 16px 16px 4px 16px;
}

.ai-message .message-bubble {
    background: #f8f9fa;
    color: #333;
    border-radius: 16px 16px 16px 4px;
}

.chat-input-container {
    padding: 20px 24px;
    background: white;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

/* Mobile input container improvements - CRITICAL for mobile usability */
@media (max-width: 767px) {
    .chat-input-container {
        padding: 12px 16px;
        background: white;
        border-top: 1px solid #e5e5e5;
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        max-width: none;
        width: 100%;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        /* Ensure it stays above keyboard */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}



.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.settings-btn {
    background: linear-gradient(135deg, #f8fbff 0%, #e8f4ff 100%);
    border: 2px solid #e1f0ff;
    border-radius: 12px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #4A90E2;
    flex-shrink: 0;
    outline: none;
    white-space: nowrap;
}

.settings-btn:hover {
    background: linear-gradient(135deg, #e8f4ff 0%, #d6ebff 100%);
    border-color: #4A90E2;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
}

.settings-btn:focus {
    border-color: #357ABD;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2), 0 4px 12px rgba(74, 144, 226, 0.15);
}

/* Settings Modal Styles */
.settings-section {
    margin-bottom: 24px;
}

.settings-section-title {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.settings-description {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: #666;
    margin-bottom: 16px;
    line-height: 1.4;
}

.model-selection-grid {
    display: grid;
    gap: 12px;
}

.model-option {
    border: 2px solid #e5e5e5;
    border-radius: 12px;
    padding: 16px;
    transition: all 0.2s;
    cursor: pointer;
}

.model-option:hover {
    border-color: #4A90E2;
    background: #f8fbff;
}

.model-option-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.model-option input[type="radio"] {
    margin-top: 2px;
    accent-color: #4A90E2;
}

.model-option-label {
    flex: 1;
    cursor: pointer;
}

.model-name {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.model-description {
    font-family: 'Raleway', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.model-option:has(input:checked) {
    border-color: #4A90E2;
    background: linear-gradient(135deg, #f8fbff 0%, #f0f7ff 100%);
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.1);
}

#messageInput {
    flex: 1;
    padding: 14px 18px;
    border: 1px solid #e5e5e5;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
    resize: none;
    min-height: 48px;
    max-height: 120px;
    font-family: inherit;
    background: #fafafa;
    line-height: 1.5;
    overflow-y: hidden;
}

/* Mobile input improvements */
@media (max-width: 767px) {
    #messageInput {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
        min-height: 44px; /* iOS touch target minimum */
        border-radius: 22px;
        -webkit-appearance: none;
        appearance: none;
        /* Prevent scrolling issues on focus */
        position: relative;
        z-index: 1;
    }
    
    /* Prevent body scroll when input is focused */
    #messageInput:focus {
        /* Ensure no unwanted scrolling */
        scroll-margin: 0;
        scroll-snap-margin: 0;
    }
}

#messageInput:focus {
    border-color: #4A90E2;
    background: #ffffff;
}

#sendBtn {
    background: linear-gradient(135deg, #4A90E2 0%, #667eea 50%, #00d4ff 100%);
    color: white;
    border: none;
    font-family: 'Raleway', sans-serif;
    border-radius: 24px;
    min-height: 48px;
    padding: 0 20px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(74, 144, 226, 0.4);
    animation: pulse-glow 3s ease-in-out infinite;
}

/* Mobile send button improvements */
@media (max-width: 767px) {
    #sendBtn {
        min-height: 44px; /* iOS touch target minimum */
        padding: 0 18px;
        border-radius: 22px;
        font-size: 14px;
        min-width: 44px;
    }
}

#sendBtn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

#sendBtn:hover::before {
    left: 100%;
}

#sendBtn:hover:not(:disabled) {
    background: linear-gradient(135deg, #357ABD 0%, #5a67d8 50%, #00b8e6 100%);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 40px rgba(74, 144, 226, 0.6), 0 0 20px rgba(0, 212, 255, 0.3);
}

#sendBtn:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 5px 20px rgba(74, 144, 226, 0.4);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.user-profile {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fafafa;
    position: relative;
    flex-shrink: 0; /* Don't shrink */
    border-top: 1px solid #e5e5e5;
}

/* Mobile user profile improvements */
@media (max-width: 767px) {
    .user-profile {
        padding: 12px 16px;
        background: #ffffff;
        border-top: 1px solid #e5e5e5;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        position: relative;
        z-index: 10;
        flex-shrink: 0;
        /* Ensure it stays at bottom */
        margin-top: auto;
    }
}

.logout-btn {
    background: none;
    border: none;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    text-decoration: none;
    margin-left: auto;
}

.logout-btn:hover {
    background: #f0f0f0;
    color: #ff6b6b;
}

.auth-btn {
    background: linear-gradient(135deg, #4A90E2 0%, #667eea 50%, #764ba2 100%);
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    width: 100%;
    text-align: center;
}

.auth-btn:hover {
    background: linear-gradient(135deg, #357ABD 0%, #5a67d8 50%, #6b46c1 100%);
    transform: translateY(-1px);
}

.guest-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.guest-message {
    font-size: 14px;
    font-weight: 600;
    color: #2B5AA0;
}

.message-limit {
    font-size: 12px;
    color: #666;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: #4A90E2;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-info {
    flex: 1;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: #2B5AA0;
    margin: 0;
}

.loading {
    display: none;
    padding: 10px 20px;
    color: #666;
    font-size: 14px;
}

.loading[style*="block"], .loading[style*="flex"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.loading-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}

.loading-dots .dot {
    width: 6px;
    height: 6px;
    background-color: #4A90E2;
    border-radius: 50%;
    animation: loading-bounce 1.4s infinite ease-in-out both;
}

.loading-dots .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots .dot:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-dots .dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0.8) translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2) translateY(-4px);
        opacity: 1;
    }
}

.error {
    background: #ff6b6b !important;
    color: white !important;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f8f9fa;
}

::-webkit-scrollbar-thumb {
    background: #d1d1d1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #b8b8b8;
}

/* Markdown styles within message bubbles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
    margin: 0.8em 0 0.4em 0;
    font-weight: 600;
}

.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.3em; }
.message-bubble h3 { font-size: 1.2em; }
.message-bubble h4 { font-size: 1.1em; }
.message-bubble h5 { font-size: 1.05em; }
.message-bubble h6 { font-size: 1em; }

.message-bubble p {
    margin: 0.5em 0;
}

.message-bubble ul,
.message-bubble ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.message-bubble li {
    margin: 0.2em 0;
}

.message-bubble code {
    background: rgba(0,0,0,0.1);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.ai-message .message-bubble code {
    background: #f1f3f4;
}

.user-message .message-bubble code {
    background: rgba(255,255,255,0.2);
}

.message-bubble pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 1em;
    margin: 0.5em 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.user-message .message-bubble pre {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

.message-bubble pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.message-bubble blockquote {
    border-left: 4px solid #667eea;
    margin: 0.5em 0;
    padding: 0.5em 1em;
    background: rgba(102, 126, 234, 0.1);
}

.user-message .message-bubble blockquote {
    border-left-color: rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.1);
}

.message-bubble table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
    font-size: 0.9em;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid #e0e0e0;
    padding: 0.4em 0.8em;
    text-align: left;
}

.message-bubble th {
    background: #f8f9fa;
    font-weight: 600;
}

.user-message .message-bubble th,
.user-message .message-bubble td {
    border-color: rgba(255,255,255,0.3);
}

.user-message .message-bubble th {
    background: rgba(255,255,255,0.1);
}

.message-bubble strong {
    font-weight: 600;
}

.message-bubble em {
    font-style: italic;
}

.message-bubble a {
    color: #667eea;
    text-decoration: underline;
}

.user-message .message-bubble a {
    color: rgba(255,255,255,0.9);
}

.message-bubble hr {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 1em 0;
}

.user-message .message-bubble hr {
    border-top-color: rgba(255,255,255,0.3);
}

/* Typing animation */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #999;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile First - Default styles are for mobile */
@media (max-width: 767px) {
    .sidebar-close {
        display: block;
    }
    
    /* Mobile viewport handling for soft keyboard */
    html {
        height: 100dvh; /* Dynamic viewport height */
    }
    
    /* Ensure sidebar doesn't interfere with main content on mobile */
    .sidebar {
        z-index: 1050; /* Higher z-index for overlay */
    }
    
    /* Improved touch targets for mobile */
    .menu-toggle {
        padding: 12px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Character info optimization for mobile */
    .character-info {
        flex: 1;
        min-width: 0; /* Allow text truncation */
    }
    
    .character-details h1 {
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .character-details p {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Input wrapper mobile improvements */
    .input-wrapper {
        gap: 8px;
        align-items: center; /* Keep consistent with desktop */
    }
    
    /* Settings button mobile optimization */
    .settings-btn {
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 16px;
        min-height: 44px; /* Match input field height */
        white-space: nowrap;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Ensure buttons are properly sized for touch */
    button, .btn-primary, .btn-secondary {
        min-height: 44px;
        min-width: 44px;
    }
}

@media (min-width: 768px) {
    .sidebar {
        position: fixed;
        transform: translateX(0);
        width: 280px;
    }
    
    .sidebar.closed {
        transform: translateX(-100%);
    }
    
    .main-content {
        margin-left: 280px;
        transition: margin-left 0.3s ease;
    }
    
    .main-content.sidebar-closed {
        margin-left: 0;
    }
    
    .overlay {
        display: none;
    }
    
    .sidebar-close {
        display: none;
    }
    
    .message-content {
        max-width: 70%;
    }
    
    .chat-messages {
        padding: 30px;
    }
    
    .chat-input-container {
        padding: 20px 30px;
    }
}

@media (min-width: 1024px) {
    .sidebar {
        width: 320px;
    }
    
    .sidebar.closed {
        transform: translateX(-100%);
    }
    
    .main-content {
        margin-left: 320px;
    }
    
    .main-content.sidebar-closed {
        margin-left: 0;
    }
    
    .message-content {
        max-width: 60%;
    }
    
    .message-bubble {
        padding: 15px 20px;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 95%;
    }
    
    .message-bubble {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .chat-messages {
        padding: 12px 8px;
        /* Enhanced scrolling for very small screens */
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch;
        height: 0; /* Critical for flex scrolling */
        flex: 1 1 auto;
        /* Better touch handling */
        touch-action: pan-y;
        will-change: scroll-position;
    }
    
    .chat-input-container {
        padding: 10px 12px;
    }
    
    .input-wrapper {
        gap: 6px;
        align-items: center; /* Ensure center alignment */
    }
    
    #messageInput {
        padding: 10px 14px;
        font-size: 16px; /* Prevents zoom */
        min-height: 42px;
    }
    
    #sendBtn {
        min-height: 42px;
        min-width: 42px;
        padding: 0 14px;
        font-size: 14px;
    }
    
    .chat-header {
        padding: 10px 12px;
        height: 56px;
    }
    
    .character-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .character-details h1 {
        font-size: 14px;
    }
    
    .character-details p {
        font-size: 11px;
    }
    
    /* Very small screen optimizations */
    .settings-btn {
        padding: 6px 10px;
        font-size: 11px;
        min-height: 42px; /* Match input and send button height */
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Message improvements for touch */
    .message {
        margin: 16px 0;
    }
    
    .message-bubble {
        line-height: 1.4;
        word-break: break-word;
    }
}

/* Special handling for mobile keyboards */
@media (max-width: 767px) {
    /* iOS Safari viewport height fix */
    @supports (-webkit-appearance: none) {
        .app-container, .main-content {
            height: -webkit-fill-available;
        }
    }
    
    /* Ensure input stays visible when keyboard appears */
    .chat-input-container {
        position: sticky;
        bottom: 0;
        background: white;
        z-index: 1000;
    }
    
    /* Prevent body scroll when input is focused on iOS */
    body.keyboard-open {
        position: fixed;
        width: 100%;
    }
}

/* Character Management Styles */
.character-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    gap: 12px;
    position: relative;
}

.character-item:hover {
    background: #f0f0f0;
}

.character-item.active {
    background: #e3f2fd;
    color: #1976d2;
}

.character-avatar {
    width: 32px;
    height: 32px;
    background: #4A90E2;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 14px;
    flex-shrink: 0;
}

.character-details {
    flex: 1;
    min-width: 0;
}

.character-name {
    font-weight: 500;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.character-item:hover .character-actions {
    opacity: 1;
}

.character-edit,
.character-delete {
    background: none;
    border: none;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-chat {
    background: none;
    border: none;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    color: #4A90E2;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: underline;
}

.character-chat:hover {
    background: #f0f8ff;
    color: #357ABD;
}

.character-edit:hover {
    background: #e3f2fd;
    color: #1976d2;
}

.character-delete:hover {
    background: #ffebee;
    color: #d32f2f;
}

.menu-button.secondary {
    background: linear-gradient(135deg, #4A90E2 0%, #667eea 50%, #00d4ff 100%);
    color: white;
    border: none;
    font-family: 'Raleway', sans-serif;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(74, 144, 226, 0.4);
    transform: translateY(0);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: pulse-glow 3s ease-in-out infinite;
}

.menu-button.secondary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.menu-button.secondary:hover::before {
    left: 100%;
}

.menu-button.secondary:hover {
    background: linear-gradient(135deg, #357ABD 0%, #5a67d8 50%, #00b8e6 100%);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 40px rgba(74, 144, 226, 0.6), 0 0 20px rgba(0, 212, 255, 0.3);
}

.menu-button.secondary:active {
    transform: translateY(-1px) scale(0.98);
    box-shadow: 0 5px 20px rgba(74, 144, 226, 0.4);
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 8px 32px rgba(74, 144, 226, 0.4);
    }
    50% {
        box-shadow: 0 8px 32px rgba(74, 144, 226, 0.6), 0 0 15px rgba(0, 212, 255, 0.2);
    }
    100% {
        box-shadow: 0 8px 32px rgba(74, 144, 226, 0.4);
    }
}


/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
}

.modal-overlay.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: white;
    border-radius: 0;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-body {
    padding: 20px;
    max-height: calc(90vh - 140px);
    overflow-y: auto;
}

.gallery-modal .modal-body {
    overflow: hidden;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 14px;
    color: #333;
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4A90E2;
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

.btn-primary {
    background: #4A90E2;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background: #357ABD;
}

.btn-secondary {
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: #f5f5f5;
    color: #333;
}

/* Available Characters Grid */
.available-characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    padding: 8px 0;
}

.available-character-card {
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: #fafafa;
}

.available-character-card:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.2);
}

.available-character-card .character-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #4A90E2;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    margin: 0 auto 12px auto;
    overflow: hidden;
}

.available-character-card .character-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.available-character-card .character-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
}

.available-character-card .character-preview {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
    max-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Custom Checkbox Styling */
.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    margin-bottom: 0;
    gap: 8px;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.checkbox-label:hover .checkmark {
    border-color: #4A90E2;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: #4A90E2;
    border-color: #4A90E2;
    color: white;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: "✓";
    font-size: 12px;
    font-weight: bold;
}

.checkbox-label.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.checkbox-label.disabled .checkmark {
    background: #f5f5f5;
    border-color: #ddd;
}

.form-help {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    display: block;
}

/* Character Visibility Indicators */
.visibility-indicator {
    font-size: 8px;
    margin-top: 2px;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: inline-block;
}

.visibility-indicator.public {
    background-color: #3b82f6;
    color: white;
}

.visibility-indicator.private {
    background-color: #64748b;
    color: #e2e8f0;
}

/* Profile Button */
.profile-btn {
    background: #4A90E2;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: 6px;
}

.profile-btn:hover {
    background: #357ABD;
}

/* API Key Selection */
.api-key-selection {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 16px 0;
}

.api-option-card {
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: #fafafa;
}

.api-option-card:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.2);
}

.api-option-card.selected {
    border-color: #4A90E2;
    background: #f0f8ff;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.api-option-title {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 6px;
}

.api-option-description {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.api-option-card.selected .api-option-title {
    color: #4A90E2;
}

/* API Key Status */
.api-key-status {
    margin-top: 12px;
    padding: 8px 12px;
    border-radius: 6px;
    background: #f8f9fa;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #28a745;
}

.status-dot.error {
    background: #dc3545;
}

.status-dot.warning {
    background: #ffc107;
}

.status-text {
    font-size: 13px;
    color: #333;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    z-index: 10000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(0);
}

.toast.toast-success {
    background: #28a745;
}

.toast.toast-error {
    background: #dc3545;
}

.toast.toast-info {
    background: #17a2b8;
}

/* Profile Modal Header Styling */
.profile-modal-header {
    background: linear-gradient(135deg, #4A90E2 0%, #667eea 50%, #00d4ff 100%);
    color: white;
    padding: 20px 24px;
    border-radius: 0;
    position: relative;
    overflow: hidden;
    margin: 0;
}

.profile-modal-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

.profile-header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.profile-user-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.profile-user-info {
    flex: 1;
}

.profile-title {
    margin: 0 0 4px 0;
    font-size: 24px;
    font-weight: 700;
    color: white !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.profile-subtitle {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.profile-modal-close {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

.profile-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Gradient Modal Headers - Apply to all modals */
.gallery-modal-header,
.add-character-modal-header,
.settings-modal-header,
.character-modal-header {
    background: linear-gradient(135deg, #4A90E2 0%, #667eea 50%, #00d4ff 100%);
    color: white;
    padding: 20px 24px;
    border-radius: 0;
    position: relative;
    overflow: hidden;
    margin: 0;
}

.gallery-modal-header::before,
.add-character-modal-header::before,
.settings-modal-header::before,
.character-modal-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shimmer 3s ease-in-out infinite;
}

.modal-header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 1;
}

.modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.modal-info {
    flex: 1;
}

.modal-title {
    margin: 0 0 4px 0;
    font-size: 22px;
    font-weight: 700;
    color: white !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.modal-subtitle {
    margin: 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.gradient-modal-close {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

.gradient-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Model Selection Cards */
.model-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.model-option-card {
    border: 2px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: #fafafa;
}

.model-option-card:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.2);
}

.model-option-card.selected {
    border-color: #4A90E2;
    background: #f0f8ff;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.model-option-card .model-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 6px;
}

.model-option-card .model-description {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
}

.model-option-card.selected .model-name {
    color: #4A90E2;
}