/* Chat Manager Styles */

.chat-section {
    background: var(--bg-secondary, #1a1a1a);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-color, #333);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color, #333);
}

.chat-header h3 {
    margin: 0;
    color: var(--text-primary, #fff);
    font-size: 16px;
    font-weight: 600;
}

.new-chat-btn {
    background: var(--accent-color, #4CAF50);
    border: none;
    border-radius: 6px;
    padding: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn:hover {
    background: var(--accent-hover, #45a049);
    transform: translateY(-1px);
}

.new-chat-btn:active {
    transform: translateY(0);
}

/* Project Selector (Pro tier) */
.project-selector {
    margin-bottom: 16px;
}

.project-select {
    width: 100%;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-primary, #fff);
    font-size: 14px;
}

.project-select:focus {
    outline: none;
    border-color: var(--accent-color, #4CAF50);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

/* Chat List */
.chat-list-container {
    max-height: 300px;
    overflow-y: auto;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-item {
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 6px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-item:hover {
    background: var(--bg-hover, #353535);
    border-color: var(--accent-color, #4CAF50);
}

.chat-item.active {
    background: var(--accent-color, #4CAF50);
    border-color: var(--accent-color, #4CAF50);
    color: white;
}

.chat-item.active .chat-title {
    color: white;
}

.chat-item.active .chat-meta {
    color: rgba(255, 255, 255, 0.8);
}

.chat-item-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-title {
    color: var(--text-primary, #fff);
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary, #888);
}

.chat-date {
    color: inherit;
}

.chat-project-badge {
    background: var(--accent-color, #4CAF50);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 500;
}

/* Empty State */
.chat-list-empty {
    text-align: center;
    padding: 24px 12px;
    color: var(--text-secondary, #888);
}

.chat-list-empty p {
    margin: 0 0 16px 0;
    font-size: 14px;
}

.start-first-chat {
    background: var(--accent-color, #4CAF50);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.start-first-chat:hover {
    background: var(--accent-hover, #45a049);
}

/* Current Chat Info */
.current-chat-info {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #333);
}

.chat-title-edit {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.chat-title-input {
    flex: 1;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 4px;
    padding: 6px 8px;
    color: var(--text-primary, #fff);
    font-size: 12px;
}

.chat-title-input:focus {
    outline: none;
    border-color: var(--accent-color, #4CAF50);
}

.save-title-btn {
    background: var(--accent-color, #4CAF50);
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    color: white;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

.save-title-btn:hover {
    background: var(--accent-hover, #45a049);
}

.chat-actions {
    display: flex;
    justify-content: flex-end;
}

.delete-chat-btn {
    background: var(--danger-color, #f44336);
    border: none;
    border-radius: 4px;
    padding: 6px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-chat-btn:hover {
    background: var(--danger-hover, #d32f2f);
}

/* Scrollbar Styling */
.chat-list-container::-webkit-scrollbar {
    width: 6px;
}

.chat-list-container::-webkit-scrollbar-track {
    background: var(--bg-tertiary, #2a2a2a);
    border-radius: 3px;
}

.chat-list-container::-webkit-scrollbar-thumb {
    background: var(--border-color, #444);
    border-radius: 3px;
}

.chat-list-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary, #666);
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-section {
        padding: 12px;
    }
    
    .chat-header h3 {
        font-size: 14px;
    }
    
    .new-chat-btn {
        padding: 6px;
    }
    
    .chat-item {
        padding: 10px;
    }
    
    .chat-title {
        font-size: 13px;
    }
    
    .chat-meta {
        font-size: 11px;
    }
}

/* Integration with existing sidebar */
.sidebar .chat-section:first-child {
    margin-top: 0;
}

.gallery-container .chat-section:first-child {
    margin-top: 0;
}

/* Dark theme compatibility */
[data-theme="dark"] .chat-section,
.dark-theme .chat-section {
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-hover: #353535;
    --text-primary: #fff;
    --text-secondary: #888;
    --border-color: #333;
    --accent-color: #4CAF50;
    --accent-hover: #45a049;
    --danger-color: #f44336;
    --danger-hover: #d32f2f;
}

/* Light theme compatibility */
[data-theme="light"] .chat-section,
.light-theme .chat-section {
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #fff;
    --bg-hover: #e0e0e0;
    --text-primary: #333;
    --text-secondary: #666;
    --border-color: #ddd;
    --accent-color: #4CAF50;
    --accent-hover: #45a049;
    --danger-color: #f44336;
    --danger-hover: #d32f2f;
}

/* Drag and Drop Styles */
.drag-drop-enabled {
    position: relative;
    transition: all 0.2s ease;
}

.drag-drop-enabled.drag-over {
    background: rgba(76, 175, 80, 0.1) !important;
    border: 2px dashed var(--accent-color, #4CAF50) !important;
    border-radius: 8px;
}

.drag-drop-enabled.drag-over::after {
    content: "Drop image here to add to chat";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--accent-color, #4CAF50);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Draggable image cursor states */
img[draggable="true"] {
    cursor: grab !important;
    transition: opacity 0.2s ease;
}

img[draggable="true"]:active {
    cursor: grabbing !important;
}

/* @ Reference Autocomplete Styles */
.reference-autocomplete {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    min-width: 300px;
    max-width: 450px;
}

.reference-autocomplete-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
}

.reference-autocomplete-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.reference-autocomplete-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.reference-autocomplete-list {
    max-height: 250px;
    overflow-y: auto;
}

.reference-autocomplete-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.reference-autocomplete-item:hover {
    background-color: #f8f9fa;
}

.reference-autocomplete-item:last-child {
    border-bottom: none;
}

.reference-autocomplete-thumbnail {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 12px;
    border: 2px solid #e0e0e0;
}

.reference-autocomplete-info {
    flex: 1;
}

.reference-autocomplete-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    font-size: 14px;
}

.reference-autocomplete-details {
    font-size: 12px;
    color: #666;
    line-height: 1.3;
}

/* ContentEditable Prompt Input Styles */
.prompt-input-editable {
    width: 100%;
    min-height: 40px;
    max-height: 120px; /* Limit expansion to 3x the initial size */
    padding: calc(var(--spacing-unit, 8px) * 0.25) 0;
    border: none;
    background-color: var(--color-bg, #fff) !important;
    color: var(--color-text-main, #333) !important;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.4;
    overflow-y: auto; /* Enable scrolling when content exceeds max-height */
    resize: none;
    outline: none;
    word-wrap: break-word;
    white-space: pre-wrap;
    cursor: text;
    box-sizing: border-box;
    caret-color: var(--color-text-main, #333);
    position: relative;
    z-index: 1;
}

.prompt-input-editable:focus {
    color: var(--color-text-main, #333) !important;
    background-color: var(--color-bg, #fff) !important;
    caret-color: var(--color-text-main, #333);
    border: 1px solid var(--color-primary, #0069c7) !important;
}



.prompt-input-editable:empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-secondary, #888);
    pointer-events: none;
    opacity: 0.7;
}

.prompt-input-editable:focus::before {
    opacity: 0.5;
}

.prompt-input-editable:not(:empty)::before {
    display: none;
}

/* Reference Badge Styles */
.reference-badge {
    display: inline-block;
    background: #2563eb;
    color: white;
    padding: 2px 8px;
    margin: 0 2px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    user-select: none;
    vertical-align: baseline;
    white-space: nowrap;
    transition: all 0.2s ease;
    position: relative;
    border: 2px solid transparent;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reference-badge:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.reference-badge-selected {
    background: #1e40af;
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.5);
}

.reference-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reference-badge:hover::before {
    opacity: 1;
}

.reference-badge-removing {
    animation: badge-remove 0.3s ease forwards;
}

@keyframes badge-remove {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
    100% {
        opacity: 0;
        transform: scale(0);
        margin: 0;
        padding: 0;
        width: 0;
    }
}

.reference-badge-inserting {
    animation: badge-insert 0.3s ease forwards;
}

@keyframes badge-insert {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Badge focus styles for accessibility */
.reference-badge:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

/* Enhanced Reference Picker Popup Styles */
.reference-picker-popup {
    position: fixed;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 450px;
    max-height: 500px;
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.reference-picker-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color, #444);
}

.reference-picker-search {
    width: 100%;
    background: var(--bg-primary, #1a1a1a);
    border: 1px solid var(--border-color, #555);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary, #fff);
    font-size: 14px;
    margin-bottom: 12px;
}

.reference-picker-search:focus {
    outline: none;
    border-color: var(--accent-color, #4CAF50);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.reference-picker-search::placeholder {
    color: var(--text-secondary, #888);
}

.reference-picker-tabs {
    display: flex;
    gap: 8px;
}

.reference-picker-tab {
    flex: 1;
    background: var(--bg-primary, #1a1a1a);
    border: 1px solid var(--border-color, #555);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text-secondary, #888);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
}

.reference-picker-tab:hover {
    background: var(--bg-hover, #353535);
    color: var(--text-primary, #fff);
}

.reference-picker-tab.active {
    background: var(--accent-color, #4CAF50);
    border-color: var(--accent-color, #4CAF50);
    color: white;
}

.reference-picker-content {
    flex: 1;
    padding: 16px;
    overflow: hidden;
}

.reference-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

.reference-picker-image {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.reference-picker-image:hover {
    border-color: var(--accent-color, #4CAF50);
    transform: scale(1.05);
}

.reference-picker-image:focus {
    outline: none;
    border-color: var(--accent-color, #4CAF50);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}

.reference-picker-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.reference-picker-image-number {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--accent-color, #4CAF50);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    z-index: 2;
}

.reference-picker-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary, #888);
}

.reference-picker-empty p {
    margin: 0 0 8px 0;
    font-size: 14px;
}

.reference-picker-loading {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary, #888);
}

/* Scrollbar for reference picker grid */
.reference-picker-grid::-webkit-scrollbar {
    width: 6px;
}

.reference-picker-grid::-webkit-scrollbar-track {
    background: var(--bg-primary, #1a1a1a);
    border-radius: 3px;
}

.reference-picker-grid::-webkit-scrollbar-thumb {
    background: var(--border-color, #555);
    border-radius: 3px;
}

.reference-picker-grid::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary, #888);
}

/* Dark theme overrides */
[data-theme="dark"] .reference-picker-popup {
    background: var(--bg-tertiary, #2a2a2a);
    border-color: var(--border-color, #444);
}

[data-theme="dark"] .reference-picker-search {
    background: var(--bg-primary, #1a1a1a);
    border-color: var(--border-color, #555);
    color: var(--text-primary, #fff);
}

[data-theme="dark"] .reference-picker-tab {
    background: var(--bg-primary, #1a1a1a);
    border-color: var(--border-color, #555);
    color: var(--text-secondary, #888);
}

[data-theme="dark"] .reference-picker-empty,
[data-theme="dark"] .reference-picker-loading {
    color: var(--text-secondary, #888);
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .reference-picker-popup {
        width: 350px;
        max-height: 450px;
    }
    
    .reference-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 10px;
        max-height: 250px;
    }
    
    .reference-picker-image-number {
        width: 18px;
        height: 18px;
        font-size: 9px;
    }
}

@media (max-width: 480px) {
    .reference-picker-popup {
        width: 300px;
        max-height: 400px;
    }
    
    .reference-picker-header {
        padding: 12px;
    }
    
    .reference-picker-content {
        padding: 12px;
    }
    
    .reference-picker-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        gap: 8px;
        max-height: 200px;
    }
    
    .reference-picker-tab {
        padding: 6px 8px;
        font-size: 12px;
    }
}

/* Workflow Recommendations Popup Styles */
.workflow-recommendations-popup {
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
    width: 500px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.recommendations-header {
    background: linear-gradient(135deg, #ff6b6b 0%, #ffa500 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.recommendations-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.recommendations-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.recommendations-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.recommendations-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.recommendations-content > p {
    margin: 0 0 16px 0;
    color: #555;
    font-size: 14px;
}

.recommendations-list {
    margin-bottom: 20px;
}

.recommendation-item {
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.recommendation-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.recommendation-info {
    flex: 1;
    margin-right: 16px;
}

.recommendation-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    font-size: 16px;
}

.recommendation-description {
    color: #666;
    font-size: 14px;
    margin-bottom: 4px;
    line-height: 1.4;
}

.recommendation-reason {
    color: #888;
    font-size: 12px;
    margin-bottom: 4px;
}

.recommendation-confidence {
    color: #667eea;
    font-size: 12px;
    font-weight: 500;
}

.recommendation-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.recommendation-apply,
.recommendation-dismiss {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    min-width: 80px;
}

.recommendation-apply {
    background: #667eea;
    color: white;
}

.recommendation-apply:hover:not(:disabled) {
    background: #5a67d8;
    transform: translateY(-1px);
}

.recommendation-apply:disabled {
    background: #28a745;
    cursor: not-allowed;
}

.recommendation-dismiss {
    background: #f8f9fa;
    color: #666;
    border: 1px solid #e0e0e0;
}

.recommendation-dismiss:hover:not(:disabled) {
    background: #e9ecef;
}

.recommendation-dismiss:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.recommendations-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

.recommendations-apply-all,
.recommendations-dismiss-all {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.recommendations-apply-all {
    background: #667eea;
    color: white;
}

.recommendations-apply-all:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.recommendations-dismiss-all {
    background: #f8f9fa;
    color: #666;
    border: 1px solid #e0e0e0;
}

.recommendations-dismiss-all:hover {
    background: #e9ecef;
}

/* Dark theme support for new components */
[data-theme="dark"] .reference-autocomplete,
.dark-theme .reference-autocomplete {
    background: #2a2a2a;
    border-color: #444;
}

[data-theme="dark"] .reference-autocomplete-item,
.dark-theme .reference-autocomplete-item {
    border-bottom-color: #444;
}

[data-theme="dark"] .reference-autocomplete-item:hover,
.dark-theme .reference-autocomplete-item:hover {
    background-color: #353535;
}

[data-theme="dark"] .reference-autocomplete-name,
.dark-theme .reference-autocomplete-name {
    color: #fff;
}

[data-theme="dark"] .reference-autocomplete-details,
.dark-theme .reference-autocomplete-details {
    color: #aaa;
}

[data-theme="dark"] .workflow-recommendations-popup,
.dark-theme .workflow-recommendations-popup {
    background: #2a2a2a;
}

[data-theme="dark"] .recommendations-content > p,
.dark-theme .recommendations-content > p {
    color: #ccc;
}

[data-theme="dark"] .recommendation-item,
.dark-theme .recommendation-item {
    border-color: #444;
    background: #333;
}

[data-theme="dark"] .recommendation-title,
.dark-theme .recommendation-title {
    color: #fff;
}

[data-theme="dark"] .recommendation-description,
.dark-theme .recommendation-description {
    color: #ccc;
}

[data-theme="dark"] .recommendation-reason,
.dark-theme .recommendation-reason {
    color: #aaa;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .workflow-recommendations-popup {
        width: 90vw;
        max-width: none;
    }
    
    .recommendation-actions {
        flex-direction: row;
    }
    
    .recommendations-footer {
        flex-direction: column;
    }
    
    .reference-autocomplete {
        min-width: 250px;
        max-width: 90vw;
    }
}

/* Upload Button Dropdown Styles */
.dropdown-menu {
    position: absolute;
    bottom: 100%; /* Position above the button in desktop */
    left: 0;
    z-index: var(--z-dropdown, 1000);
    min-width: 200px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: none;
    padding: 8px 0;
    margin-bottom: 8px; /* Space between dropdown and button */
}

.dropdown-menu.show {
    display: block;
}

/* Mobile specific styles */
@media (max-width: 768px) {
    .dropdown-menu {
        position: fixed;
        top: auto;
        bottom: 60px; /* Adjust based on your bottom bar height */
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        max-width: 300px;
        margin: 0;
        border-radius: 12px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: var(--color-text-main);
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s;
    gap: 8px;
    font-size: 14px;
}

.dropdown-item:hover {
    background-color: var(--color-bg-section);
}

.dropdown-item:first-child {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

.dropdown-item:last-child {
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
}

.upload-button-wrapper {
    position: relative;
    display: inline-block;
}

/* Dark theme support for dropdown */
[data-theme="dark"] .dropdown-menu,
.dark-theme .dropdown-menu {
    background: #2a2a2a;
    border-color: #444;
}

[data-theme="dark"] .dropdown-item,
.dark-theme .dropdown-item {
    color: #fff;
}

[data-theme="dark"] .dropdown-item:hover,
.dark-theme .dropdown-item:hover {
    background: #353535;
}

/* ========================================
   CHAT SIDEBAR STYLES
   ======================================== */

.chat-sidebar-header {
    margin-bottom: var(--spacing-unit);
}

.chat-sidebar-header h2 {
    margin: 0 0 var(--spacing-unit) 0;
    font-size: 1.3rem;
    color: var(--color-text-main);
}

#create-new-chat-button {
    width: 100%;
    padding: calc(var(--spacing-unit) * 0.75);
    background-color: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(var(--spacing-unit) * 0.5);
    transition: background-color 0.2s ease, transform 0.1s ease;
}

#create-new-chat-button:hover {
    background-color: var(--color-primary-dark, #0056b3);
    transform: translateY(-1px);
}

#create-new-chat-button:active {
    transform: translateY(0);
}

.button-icon {
    font-size: 1rem;
}

/* Chat List */
.chat-list {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.5);
    max-height: calc(100vh - 200px); /* Adjust based on header height */
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-item {
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.chat-item:hover {
    background-color: var(--color-bg-section);
    border-color: var(--color-border-dark, #ccc);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chat-item.active {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.chat-item.active .chat-name {
    color: white;
    font-weight: 500;
}

.chat-item.active .chat-image-count,
.chat-item.active .chat-last-activity {
    color: rgba(255, 255, 255, 0.9);
}

.chat-item-main {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.25);
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: calc(var(--spacing-unit) * 0.5);
}

.chat-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--color-text-main);
    line-height: 1.2;
    word-break: break-word;
    flex-grow: 1;
}

.chat-actions {
    display: flex;
    gap: calc(var(--spacing-unit) * 0.25);
    opacity: 0;
    transition: opacity 0.2s ease;
}

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

.chat-item.active .chat-actions {
    opacity: 1;
}

.chat-action-button {
    background: none;
    border: none;
    padding: calc(var(--spacing-unit) * 0.25);
    cursor: pointer;
    font-size: 0.8rem;
    border-radius: 3px;
    transition: background-color 0.2s ease;
    color: inherit;
}

.chat-action-button:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.chat-item.active .chat-action-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.chat-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    gap: calc(var(--spacing-unit) * 0.5);
}

.chat-image-count {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.chat-last-activity {
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Empty State */
.empty-chat-list {
    text-align: center;
    padding: calc(var(--spacing-unit) * 2);
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    line-height: 1.4;
}

.empty-chat-list p {
    margin: 0 0 calc(var(--spacing-unit) * 0.5) 0;
}

.empty-chat-list p:last-child {
    margin-bottom: 0;
}

/* Responsive adjustments for chat sidebar */
@media (max-width: 768px) {
    .chat-sidebar-header h2 {
        font-size: 1.1rem;
    }
    
    #create-new-chat-button {
        padding: calc(var(--spacing-unit) * 0.6);
        font-size: 0.85rem;
    }
    
    .chat-item {
        padding: calc(var(--spacing-unit) * 0.6);
    }
    
    .chat-name {
        font-size: 0.9rem;
    }
    
    .chat-item-meta {
        font-size: 0.75rem;
    }
    
    .chat-actions {
        opacity: 1; /* Always show on mobile */
    }
}

/* Scrollbar styling for chat list */
.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track {
    background: var(--color-bg-section);
    border-radius: 3px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.chat-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-border-dark, #999);
}

/* ========================================
   GENERATED IMAGE UI STYLES
   ======================================== */

.chat-images-section {
    margin-top: var(--spacing-unit);
    padding-top: var(--spacing-unit);
    border-top: 1px solid var(--color-border-light, #eee);
}

.chat-images-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: calc(var(--spacing-unit) * 0.75);
}

.chat-images-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--color-text-main);
    font-weight: 500;
}

.chat-images-count {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    background-color: var(--color-bg-section);
    padding: calc(var(--spacing-unit) * 0.25) calc(var(--spacing-unit) * 0.5);
    border-radius: calc(var(--border-radius) / 2);
    border: 1px solid var(--color-border);
}

.chat-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: calc(var(--spacing-unit) * 0.5);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-image-thumbnail {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.chat-image-thumbnail:hover {
    border-color: var(--color-primary);
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chat-image-thumbnail.active {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 105, 199, 0.3);
}

.chat-image-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, rgba(0, 0, 0, 0.6) 0%, transparent 30%);
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    padding: calc(var(--spacing-unit) * 0.25);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-image-thumbnail:hover .chat-image-overlay,
.chat-image-thumbnail.active .chat-image-overlay {
    opacity: 1;
}

.chat-image-index {
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 0.7rem;
    font-weight: 500;
    padding: calc(var(--spacing-unit) * 0.1) calc(var(--spacing-unit) * 0.25);
    border-radius: calc(var(--border-radius) / 2);
    min-width: 16px;
    text-align: center;
    line-height: 1;
}

.empty-chat-images {
    grid-column: 1 / -1;
    text-align: center;
    padding: calc(var(--spacing-unit) * 1.5);
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    background-color: var(--color-bg-section);
    border: 1px dashed var(--color-border);
    border-radius: var(--border-radius);
}

.empty-chat-images p {
    margin: 0;
}

/* Chat Images Filter System */
.chat-images-filter {
    margin: calc(var(--spacing-unit) * 0.75) 0;
    position: relative;
}

/* Filter Button */
.filter-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 36px;
    width: 100%;
    justify-content: flex-start;
    position: relative;
}

.filter-button:hover {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.filter-icon {
    font-size: 1rem;
}

.filter-text {
    font-weight: 500;
}

/* Active Filters Display */
.active-filters {
    margin-top: 8px;
    padding: 8px;
    background-color: var(--color-bg-section);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
}

.active-filters.hidden {
    display: none;
}

.active-filters-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    display: block;
}

.active-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background-color: var(--color-primary);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.remove-chip {
    background: none;
    border: none;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.remove-chip:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.filter-logic-display {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.current-logic {
    font-weight: 600;
    color: var(--color-primary);
}

.logic-options {
    display: flex;
    gap: 4px;
}

.logic-option {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--color-text-secondary);
}

.logic-option.active {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.logic-option:hover {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.clear-all-filters {
    background: none;
    border: none;
    color: var(--color-error);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.clear-all-filters:hover {
    background-color: var(--color-error);
    color: white;
}

/* Filter Popup */
.tag-filter-popup {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-top: 4px;
    max-height: 400px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tag-filter-popup.hidden {
    display: none;
}

.popup-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background-color: var(--color-bg-section);
}

.popup-header h4 {
    margin: 0 0 8px 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.popup-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.logic-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.logic-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.popup-logic-toggle {
    background-color: var(--color-primary);
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: var(--border-radius);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 40px;
}

.popup-logic-toggle:hover {
    background-color: var(--color-text-secondary);
}

.popup-logic-toggle[data-logic="OR"] {
    background-color: var(--color-error);
}

.popup-clear-all {
    background: none;
    border: none;
    color: var(--color-error);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.popup-clear-all:hover {
    background-color: var(--color-error);
    color: white;
}

/* Tag Categories */
.tag-filter-categories {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

.tag-category {
    margin-bottom: 16px;
}

.tag-category:last-child {
    margin-bottom: 0;
}

.category-title {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 4px;
}

.category-tags {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tag-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.85rem;
}

.tag-checkbox-label:hover {
    background-color: var(--color-bg-section);
}

.tag-checkbox-label input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.tag-name {
    flex: 1;
}

.tag-name.system-tag {
    color: var(--color-primary);
    font-weight: 500;
}

.tag-name.user-tag {
    color: var(--color-text);
}

.no-tags-message {
    text-align: center;
    color: var(--color-text-secondary);
    font-style: italic;
    padding: 20px;
}

.popup-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--color-border);
    background-color: var(--color-bg-section);
}

.apply-filter-button {
    width: 100%;
    background-color: var(--color-primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.apply-filter-button:hover {
    background-color: var(--color-text-secondary);
    transform: translateY(-1px);
}

/* Chat Images Actions */
.chat-images-actions {
    margin-top: 8px;
    display: flex;
    justify-content: center;
}

.download-all-button {
    background-color: var(--color-text-secondary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.download-all-button:hover {
    background-color: var(--color-primary);
    transform: translateY(-1px);
}

.download-all-button:disabled {
    background-color: var(--color-border);
    cursor: not-allowed;
    transform: none;
}

.download-all-button:before {
    content: "⬇️";
    font-size: 0.9rem;
}

/* Responsive adjustments for generated image UI */
@media (max-width: 768px) {
    .chat-images-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        gap: calc(var(--spacing-unit) * 0.4);
        max-height: 200px;
    }
    
    .chat-images-header h4 {
        font-size: 0.9rem;
    }
    
    .chat-images-count {
        font-size: 0.75rem;
        padding: calc(var(--spacing-unit) * 0.2) calc(var(--spacing-unit) * 0.4);
    }
    
    .chat-image-index {
        font-size: 0.6rem;
        padding: calc(var(--spacing-unit) * 0.05) calc(var(--spacing-unit) * 0.2);
    }
    
    .empty-chat-images {
        padding: var(--spacing-unit);
        font-size: 0.8rem;
    }
    
    .tag-filter-popup {
        max-height: 350px;
    }
    
    .popup-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .active-filter-chips {
        max-height: 80px;
        overflow-y: auto;
    }
    
    .filter-logic-display {
        flex-wrap: wrap;
    }
}

/* Scrollbar styling for chat images grid */
.chat-images-grid::-webkit-scrollbar {
    width: 4px;
}

.chat-images-grid::-webkit-scrollbar-track {
    background: var(--color-bg-section);
    border-radius: 2px;
}

.chat-images-grid::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.chat-images-grid::-webkit-scrollbar-thumb:hover {
    background: var(--color-border-dark, #999);
} 

/* Template indicator styles */
.template-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    transform: none;
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 12px;
    font-weight: bold;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 2;
    font-family: monospace;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.upload-preview-template {
    position: relative;
}

.upload-preview-template .template-indicator {
    opacity: 0.7;
}

.upload-preview-template:hover .template-indicator {
    opacity: 0.9;
    background: rgba(0, 0, 0, 0.5);
} 

/* Color Selector */
.color-selector-button {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-color, #333);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    margin-right: 8px;
    background: transparent;
    padding: 0;
    overflow: hidden;
}

.color-selector-button::before,
.color-selector-button::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 32px;
    top: 0;
}

.color-selector-button::before {
    left: 0;
    background: var(--primary-color, #000000);
}

.color-selector-button::after {
    right: 0;
    background: var(--secondary-color, #FFFFFF);
}

.color-selector-popup {
    position: fixed;
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    padding: 16px;
    min-width: 240px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: none;
}

.color-selector-popup.show {
    display: block;
}

.color-selector-section {
    margin-bottom: 16px;
}

.color-selector-section:last-child {
    margin-bottom: 0;
}

.color-selector-section h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--text-primary, #fff);
    font-weight: 500;
}

.color-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.color-input-group input[type="color"] {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-color, #444);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.color-input-group input[type="text"] {
    flex: 1;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #444);
    border-radius: 4px;
    padding: 8px;
    color: var(--text-primary, #fff);
    font-size: 14px;
    font-family: monospace;
    text-transform: uppercase;
}

.color-input-group input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color, #4CAF50);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.auto-color-button {
    width: 100%;
    background: var(--accent-color, #4CAF50);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    color: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.auto-color-button:hover {
    background: var(--accent-hover, #45a049);
    transform: translateY(-1px);
}

.auto-color-button:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .color-selector-popup {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-radius: 16px 16px 0 0;
        padding: 24px 16px;
        max-height: 80vh;
        overflow-y: auto;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }

    .color-selector-popup.show {
        transform: translateY(0);
    }
    
    .color-selector-button {
        width: 28px;
        height: 28px;
    }
    
    .color-selector-button::before,
    .color-selector-button::after {
        width: 14px;
        height: 28px;
    }
}

/* Vertical Menu indicator styles */
.vertical-menu-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    transform: none;
    color: white;
    font-size: 12px;
    font-weight: bold;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0.8;
}

.edit-indicator {
    background: rgba(255, 149, 0, 0.8);
}

.remix-indicator {
    background: rgba(255, 45, 85, 0.8);
}

.variation-indicator {
    background: rgba(88, 86, 214, 0.8);
}

.upload-preview-vertical-menu {
    position: relative;
}

.upload-preview-vertical-menu .vertical-menu-indicator {
    opacity: 0.8;
}

.upload-preview-vertical-menu:hover .vertical-menu-indicator {
    opacity: 1;
}

.upload-preview-edit:hover .edit-indicator {
    background: rgba(255, 149, 0, 1);
}

.upload-preview-remix:hover .remix-indicator {
    background: rgba(255, 45, 85, 1);
}

.upload-preview-variation:hover .variation-indicator {
    background: rgba(88, 86, 214, 1);
} 