/* ════════════════════════════════════════════════════════════════════════════
   ENTITY IMAGE - Shared styles for entity image generation, upload, crop
   Used by both game.css and session-zero.css contexts.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Image Section ──────────────────────────────────────────────────────── */

.entity-image-section {
    margin: 8px 0;
}

.entity-image-container {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
    position: relative;
    cursor: pointer;
}

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

.entity-image-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    display: flex;
    gap: 4px;
    align-items: flex-end;
    justify-content: center;
    padding: 24px 8px 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.entity-image-container:hover .entity-image-overlay {
    opacity: 1;
}

/* On touch devices, show overlay on tap (via :active) */
@media (hover: none) {
    .entity-image-container:active .entity-image-overlay {
        opacity: 1;
    }
}

.entity-image-placeholder {
    width: 100%;
    aspect-ratio: 1;
    border: 1px dashed var(--border, rgba(235, 230, 220, 0.08));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
    max-height: 200px;
}

.entity-image-placeholder-icon {
    font-size: 2rem;
    opacity: 0.4;
}

.entity-image-actions {
    display: flex;
    gap: 8px;
}

/* ── Generating State ─────────────────────────────────────────────────── */

.entity-image-generating {
    width: 100%;
    aspect-ratio: 1;
    border: 1px dashed var(--accent, #FFBF00);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
    max-height: 200px;
    animation: entity-img-pulse 2s ease-in-out infinite;
}

.entity-image-gen-label {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
}

@keyframes entity-img-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ── Shared Button Style ────────────────────────────────────────────────── */

.entity-img-btn {
    font-family: 'Courier New', monospace;
    font-size: 0.65rem;
    padding: 5px 10px;
    border: 1px solid rgba(235, 230, 220, 0.2);
    background: rgba(10, 10, 10, 0.7);
    color: var(--text, rgba(235, 230, 220, 0.9));
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
}

.entity-img-btn:hover {
    border-color: var(--accent, #FFBF00);
    color: var(--accent, #FFBF00);
}

.entity-img-btn.primary {
    border-color: var(--accent, #FFBF00);
    color: var(--accent, #FFBF00);
}

.entity-img-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Generation Dialog ──────────────────────────────────────────────────── */

.image-gen-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-gen-dialog {
    background: var(--bg-secondary, #111111);
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
    padding: 20px;
    max-width: 420px;
    width: 90%;
}

.image-gen-dialog h3 {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent, #FFBF00);
    margin-bottom: 16px;
}

.image-gen-label {
    display: block;
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
    margin-bottom: 6px;
}

.image-gen-model-select,
.image-gen-instructions {
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    padding: 8px;
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
    background: var(--bg, #0a0a0a);
    color: var(--text, rgba(235, 230, 220, 0.9));
    margin-bottom: 12px;
    box-sizing: border-box;
}

.image-gen-instructions {
    resize: vertical;
    min-height: 120px;
}

.image-gen-cost {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
    margin-bottom: 16px;
}

.image-gen-status {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-dim, rgba(235, 230, 220, 0.35));
    min-height: 20px;
    margin-bottom: 12px;
}

.image-gen-error {
    color: #c45c4a;
}

.image-gen-buttons {
    display: flex;
    gap: 8px;
}

.image-gen-buttons button {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    padding: 10px;
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
    background: var(--bg, #0a0a0a);
    color: var(--text, rgba(235, 230, 220, 0.9));
    cursor: pointer;
    text-transform: uppercase;
}

.image-gen-buttons button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.image-gen-buttons .primary {
    border-color: var(--accent, #FFBF00);
    color: var(--accent, #FFBF00);
}

/* Spinner animation */
.image-gen-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-dim, rgba(235, 230, 220, 0.35));
    border-top-color: var(--accent, #FFBF00);
    animation: entity-img-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes entity-img-spin {
    to { transform: rotate(360deg); }
}

/* ── Edit Dialog Thumbnail ─────────────────────────────────────────────── */

.image-edit-thumbnail {
    margin-bottom: 12px;
}

.image-edit-thumbnail img {
    width: 100%;
    max-height: 160px;
    object-fit: contain;
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
}

/* ── Crop Modal ─────────────────────────────────────────────────────────── */

.image-crop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.image-crop-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-crop-actions {
    padding: 12px;
    display: flex;
    gap: 8px;
    justify-content: center;
    background: #111111;
    border-top: 1px solid var(--border, rgba(235, 230, 220, 0.08));
}

/* ── Lightbox ───────────────────────────────────────────────────────────── */

.image-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.image-lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
}

/* ── Entity List Thumbnails ─────────────────────────────────────────────── */

.entity-thumb {
    width: 28px;
    height: 28px;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border, rgba(235, 230, 220, 0.08));
}

.entity-thumb-placeholder {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
}

/* ── Mobile Responsive ──────────────────────────────────────────────────── */

@media (max-width: 768px) {
    /* Generation dialog becomes bottom sheet on mobile */
    .image-gen-overlay {
        align-items: flex-end;
    }

    .image-gen-dialog {
        width: 100%;
        max-width: none;
        border-bottom: none;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }

    .image-gen-buttons {
        flex-direction: column;
    }

    .image-gen-buttons button {
        min-height: 44px;
    }

    .entity-image-actions {
        flex-direction: column;
        width: 100%;
        padding: 0 16px;
    }

    .entity-img-btn {
        width: 100%;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Crop modal full screen on mobile */
    .image-crop-overlay {
        flex-direction: column;
    }

    .image-crop-actions {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .image-crop-actions button {
        min-height: 44px;
        flex: 1;
    }

    /* Lightbox - full width on mobile */
    .image-lightbox img {
        max-width: 100vw;
        max-height: 100vh;
    }
}

/* ── Global Generation Lock ───────────────────────────────────────────── */

/* Disable image action buttons while generation is in progress */
body.image-generating .entity-image-actions button,
body.image-generating .entity-image-placeholder {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
}
