/* Main app (dream) specific styles - extends common.css */

/* Mobile layout adjustments */
@media (max-width: 768px) {
    .generate-btn {
        flex-direction: column;
        padding: 0.35rem 0.5rem;
        gap: 0.15rem;
    }

    .btn-icon {
        width: 18px;
        height: 18px;
    }

    .btn-text {
        font-size: 0.75rem;
    }

    /* Model controls - flex layout for mobile */
    .model-controls {
        display: flex !important;
        flex-wrap: wrap;
        gap: 0.15rem;
        padding: 0.2rem;
    }

    /* Row 1 items - expand to fill row */
    .model-controls > .enhance-icon-btn-wrapper {
        flex: 0 0 auto;
    }

    .model-controls > #upload-btn {
        flex: 1 1 12%;
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }

    .model-controls > #global-quantity {
        flex: 1 1 28%;
        padding: 0.2rem 0.25rem;
        font-size: 0.7rem;
        min-width: 0 !important;
        margin: 0 !important;
    }

    .model-controls > #add-model-select {
        flex: 1 1 42%;
        padding: 0.2rem 0.25rem;
        font-size: 0.7rem;
        min-width: 0 !important;
        margin: 0 !important;
    }

    /* Row 2 - preset buttons grow to fill row */
    .model-controls > .preset-btn[data-preset] {
        flex: 1 0 auto;
        padding: 0.2rem 0.3rem;
        font-size: 0.65rem;
        white-space: nowrap;
        text-align: center;
    }

    .enhance-icon-btn {
        padding: 0.15rem 0.25rem !important;
    }

    .enhance-icon-img {
        width: 14px;
        height: 14px;
    }

    /* Model rows mobile */
    .models-row {
        padding: 0.25rem 0.35rem;
    }

    .models-row-label {
        font-size: 0.6rem;
        min-width: 38px;
    }

    .model-chip {
        padding: 0.1rem 0.3rem;
        font-size: 0.6rem;
    }

    .model-chip-name {
        max-width: 70px;
    }
}

/* Prompt row with textarea and upload button */
.prompt-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.prompt-row.drag-over {
    outline: 2px dashed #666;
    outline-offset: 2px;
}

.prompt-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 60px;
    background: var(--paper);
    color: var(--ink);
}

.prompt-input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Reference images (batch-style) */
.reference-images {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}

.ref-image {
    position: relative;
    aspect-ratio: 1;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
    border: 1px solid var(--border);
}

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

.ref-image .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(255, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ref-image .remove-btn:hover {
    background: #ff4444;
}

/* Cost breakdown */
.cost-info {
    border: 1px solid var(--border);
    font-size: 0.85rem;
    background: var(--paper);
    border-radius: 4px;
    box-shadow: 0 1px 3px var(--shadow);
}

/* Model controls bar */
.model-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: #faf8f5;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

/* Enhance icon button */
.enhance-icon-btn-wrapper {
    position: relative;
}

.enhance-icon-btn {
    padding: 0.35rem 0.5rem;
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px var(--shadow);
    transition: all 0.2s ease;
}

.enhance-icon-btn:hover {
    background: #faf8f5;
    box-shadow: 0 2px 4px rgba(61, 46, 36, 0.1);
}

.enhance-icon-img {
    width: 18px;
    height: 18px;
    display: block;
}

.enhance-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(61, 46, 36, 0.15);
    margin-top: 2px;
    min-width: 140px;
    z-index: 1000;
}

.enhance-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

.enhance-option:hover {
    background: #faf8f5;
}

.enhance-option-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.enhance-option span {
    font-size: 0.9rem;
    color: var(--ink);
}

.enhance-header {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink);
    padding: 0.5rem 0.75rem 0.2rem;
}

.enhance-note {
    font-size: 0.65rem;
    color: var(--muted);
    padding: 0.1rem 0.75rem 0.4rem;
    font-style: italic;
    border-bottom: 1px solid var(--border);
}

.preset-btn {
    padding: 0.35rem 0.75rem;
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: normal;
    font-family: inherit;
    box-shadow: 0 1px 2px var(--shadow);
    transition: all 0.2s ease;
}

.preset-btn:hover:not(:disabled) {
    background: #faf8f5;
    box-shadow: 0 2px 4px rgba(61, 46, 36, 0.1);
}

.preset-btn:disabled,
.preset-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Control select (quantity dropdown) - match preset-btn sizing */
.control-select {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: inherit;
    background: var(--paper);
    cursor: pointer;
    box-shadow: 0 1px 2px var(--shadow);
    transition: all 0.2s ease;
    height: auto;
}

.control-select:hover {
    background: #faf8f5;
    box-shadow: 0 2px 4px rgba(61, 46, 36, 0.1);
}

.control-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Ensure consistent height for all model control elements */
.model-controls .preset-btn,
.model-controls .control-select,
.model-controls .add-model-select {
    height: 32px;
    box-sizing: border-box;
}

/* Selected models container with two rows */
.selected-models {
    display: flex;
    flex-direction: column;
    background: var(--paper);
}

.models-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.models-row:last-child {
    border-bottom: none;
}

.models-row-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    min-width: 50px;
    padding-top: 0.2rem;
    flex-shrink: 0;
}

.models-row-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    flex: 1;
    min-height: 24px;
}

/* Individual chip - clickable to remove */
.model-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    background: #f8f8f8;
    border-left: 4px solid #ccc;
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--ink);
    position: relative;
    transition: all 0.15s ease;
    cursor: pointer;
}

.model-chip:hover {
    background: #ffe8e8;
    border-left-color: #c00;
}

/* Chip name */
.model-chip-name {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Incompatible chip (edit mode) */
.model-chip.incompatible {
    opacity: 0.4;
    border-style: dashed;
}

/* Tooltip on hover */
.model-chip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.65rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.model-chip:hover::after {
    opacity: 1;
}

/* Add model dropdown */
.add-model-select {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    background: var(--paper);
    cursor: pointer;
    min-width: 140px;
    margin-right: 0.75rem;
    box-shadow: 0 1px 2px var(--shadow);
    transition: all 0.2s ease;
}

.add-model-select:hover {
    background: #faf8f5;
    box-shadow: 0 2px 4px rgba(61, 46, 36, 0.1);
}

.add-model-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Cost summary row */
.cost-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background: #faf8f5;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink);
    border-top: 1px solid var(--border);
}

/* Edit mode styles */
.edit-mode-notice {
    font-size: 0.8rem;
    color: var(--muted);
    padding: 0.4rem 0.5rem;
    background: #fef6e8;
    border: 1px solid #e8d4b8;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

/* Type Badges */
.type-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
    margin-right: 0.25rem;
}

.type-badge.txt2img {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}

.type-badge.img2img {
    background: #f3e5f5;
    color: #6a1b9a;
    border: 1px solid #ce93d8;
}

.type-badge.txt2vid {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffb74d;
}

.type-badge.img2vid {
    background: #fce4ec;
    color: #c2185b;
    border: 1px solid #f48fb1;
}

.type-cell {
    white-space: nowrap;
}

/* Generate button */
.generate-btn {
    padding: 0.5rem 0.75rem;
    background: var(--ink);
    color: var(--paper);
    border: none;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    box-shadow: 0 2px 6px rgba(61, 46, 36, 0.2);
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.generate-btn:hover:not(:disabled) {
    background: #2a1f18;
    box-shadow: 0 4px 8px rgba(61, 46, 36, 0.25);
    transform: translateY(-1px);
}

.generate-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.generate-btn.loading .btn-icon {
    animation: spin 6s steps(6) infinite;
}

.generate-btn:disabled .btn-icon {
    opacity: 0.5;
}

.generate-btn.loading .btn-text {
    font-weight: 700;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Center section between input and output */
.center-section {
    margin-bottom: 1rem;
}

.generation-info {
    padding: 0.5rem 0 0.5rem 0.5rem;
    text-align: left;
    font-size: 0.8rem;
    color: var(--muted);
}

/* Generation progress indicator */
.generation-progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: #f0f7ff;
    border: 1px solid #cce0ff;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.progress-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #cce0ff;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#progress-text {
    font-size: 0.85rem;
    color: #3b82f6;
    font-weight: 500;
}

/* Results header */
.results-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.results-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.sort-controls {
    display: flex;
    align-items: center;
}

.sort-select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 0.2s ease;
}

.sort-select:hover {
    background: #faf8f5;
    box-shadow: 0 2px 5px rgba(61, 46, 36, 0.12);
    transform: translateY(-1px);
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent);
}

.results-actions {
    display: flex;
    gap: 1rem;
}

/* Split button */
.split-btn-group {
    position: relative;
    display: flex;
}

.split-btn-main {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: none;
}

.split-btn-toggle {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    padding: 0.5rem 0.5rem;
    min-width: auto;
}

.split-btn-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--paper);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(61, 46, 36, 0.15);
    z-index: 100;
    display: none;
    min-width: 150px;
}

.split-btn-dropdown.active {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--ink);
    transition: background 0.2s;
}

.dropdown-item:first-child {
    border-radius: 4px 4px 0 0;
}

.dropdown-item:last-child {
    border-radius: 0 0 4px 4px;
}

.dropdown-item:hover {
    background: #faf8f5;
}

/* Image grid - 6 columns on desktop, 2 on mobile */
.results-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
}

@media (max-width: 1200px) {
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

@media (max-width: 600px) {
    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Section headings for grouped sort (prompt/model) */
.grid-section-heading {
    grid-column: 1 / -1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 500;
    color: #5a4a3f;
    background: linear-gradient(to right, #f0ebe4, transparent);
    padding: 0.75rem 1rem;
    margin: 1.5rem 0 0.75rem 0;
    border-left: 3px solid #8b7355;
    border-radius: 0 4px 4px 0;
    line-height: 1.5;
}

.grid-section-heading:first-of-type {
    margin-top: 0.5rem;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem;
    color: var(--muted);
}

/* Image cards */
.image-card {
    border: 1px solid var(--border);
    background: var(--paper);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: 0 2px 4px var(--shadow);
    border-radius: 4px;
    overflow: hidden;
}

.image-card:hover {
    box-shadow: 0 4px 12px rgba(61, 46, 36, 0.15);
    transform: translateY(-2px);
}

.image-card.selected {
    border-color: var(--ink);
    border-width: 3px;
    box-shadow: 0 0 0 2px var(--ink);
}

/* Upload card */
.upload-card {
    border: 2px dashed var(--border);
    background: #faf8f5;
}

.upload-card:hover {
    border-color: var(--accent);
    background: var(--paper);
}

.upload-container {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-container.drag-over {
    background: #e8f4f8;
    border-color: var(--ink);
}

.upload-prompt {
    text-align: center;
    color: var(--muted);
}

.upload-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 0.25rem;
}

.upload-subtext {
    font-size: 0.8rem;
    color: var(--muted);
}

.upload-input {
    display: none;
}

.image-container {
    position: relative;
    width: 100%;
    height: 280px;
    overflow: hidden;
}

.image-container img,
.image-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #f5f5f5;
}

.image-container .card-video {
    pointer-events: none;
}

/* Image overlays - always visible */
.image-overlays {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.overlay-tag {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 2px;
}

.overlay-cost {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 2px;
}

.overlay-format {
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 400;
    text-transform: uppercase;
    border-radius: 2px;
}

/* Image info - always visible */
.image-info {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    position: relative;
    cursor: pointer;
}

.image-model {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.image-prompt {
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-right: 2rem;
}

/* Selection checkbox */
.selection-checkbox {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--paper);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    color: #fff;
    transition: all 0.2s ease;
}

.image-card.selected .selection-checkbox {
    background: var(--ink);
    border-color: var(--ink);
}

.image-card.selected .selection-checkbox::before {
    content: '✓';
}

/* Modal extensions */
.modal-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
}

.modal-info {
    background: var(--paper);
    padding: 1rem;
}

.modal-actions {
    position: absolute;
    top: -40px;
    right: 0;
    display: flex;
    gap: 8px;
}

.modal-action-btn {
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-action-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* Responsive - Results section */
@media (max-width: 768px) {
    .results-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .results-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .sort-controls {
        width: 100%;
    }

    .sort-select {
        width: 100%;
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }

    .results-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-start;
    }

    .secondary-btn {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
        white-space: nowrap;
        flex: 0 1 calc(33.333% - 0.35rem);
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Split button adjustments - also fits in 3-column grid */
    .split-btn-group {
        flex: 0 1 calc(33.333% - 0.35rem);
        min-width: 0;
    }

    .split-btn-main {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
        white-space: nowrap;
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .split-btn-toggle {
        padding: 0.4rem 0.3rem;
        min-width: auto;
        flex-shrink: 0;
    }
}

@media (max-width: 360px) {
    /* Improve button sizing on very small screens */
    .secondary-btn {
        font-size: 0.65rem;
        padding: 0.4rem 0.3rem;
    }

    .split-btn-main {
        font-size: 0.65rem;
        padding: 0.4rem 0.3rem;
    }

    .split-btn-toggle {
        padding: 0.4rem 0.25rem;
    }
}

/* Performance Optimizations - Lazy Loading & Load More */
.image-container img {
    transition: opacity 0.3s ease;
}

.image-container img.loading {
    opacity: 0.5;
    filter: blur(5px);
}

.image-container img.loaded {
    opacity: 1;
    filter: none;
    animation: fadeIn 0.3s ease;
}

.image-container img.error {
    opacity: 0.3;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* LLM Icons */
.llm-icon {
    height: 20px;
    filter: brightness(0) invert(1);
}

.btn-icon.generating {
    animation: spin 2s linear infinite;
}

/* Video play overlay */
.video-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.video-play-overlay::after {
    content: '';
    width: 0;
    height: 0;
    border-left: 20px solid white;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    margin-left: 4px;
}

/* Modal video */
.modal-video {
    max-width: 100%;
    max-height: 80vh;
    background: #000;
}
