/* ==============================================
   Anima WebUI - Gallery Page Styles
   ============================================== */

/* ── ギャラリーメイン ── */
.gallery-page .main-content,
.gallery-main {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* ── ヘッダー右側 ── */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.gallery-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.ws-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.ws-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.ws-status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* ── ローディング / 空 ── */
.gallery-loading,
.gallery-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 80px 16px;
    color: var(--text-muted);
    text-align: center;
}

/* ── グリッド ── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    padding-bottom: 24px;
}

/* ── カード ── */
.gallery-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    aspect-ratio: 1 / 1;
    background: var(--img-bg);
    border: 1px solid var(--border-subtle);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.gallery-card--new {
    animation: fadeScaleIn 0.5s ease;
    box-shadow: 0 0 20px var(--accent-glow);
}

.gallery-card-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.gallery-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 32px 10px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    opacity: 0;
    transition: opacity 0.2s ease;
}

.gallery-card:hover .gallery-card-overlay {
    opacity: 1;
}

.gallery-card-prompt {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.4;
    margin: 0 0 6px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gallery-card-params {
    display: flex;
    gap: 8px;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    font-family: var(--font-mono);
}

/* ── もっと見る ── */
.gallery-load-more {
    display: flex;
    justify-content: center;
    padding: 24px;
}

/* ── ソートバー ── */
.gallery-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 12px;
    gap: 12px;
}

.gallery-sort-group {
    display: flex;
    gap: 6px;
}

.gallery-sort-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.gallery-sort-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-secondary);
}

.gallery-sort-btn.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(var(--accent-primary-rgb, 99, 102, 241), 0.3);
}

.gallery-sort-btn.active svg {
    filter: brightness(10);
}

.gallery-count-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

/* ── いいねボタン ── */
.gallery-like-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: none;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-mono);
}

.gallery-like-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.08);
}

.gallery-like-btn.liked {
    background: rgba(220, 38, 38, 0.25);
    backdrop-filter: blur(6px);
    color: #ff6b8a;
}

.gallery-like-btn.liked:hover {
    background: rgba(220, 38, 38, 0.4);
}

.like-heart {
    font-size: 0.85rem;
    line-height: 1;
    transition: transform 0.3s ease;
}

.gallery-like-btn.like-animating .like-heart {
    animation: likePopAnim 0.4s ease;
}

@keyframes likePopAnim {
    0% {
        transform: scale(1);
    }

    30% {
        transform: scale(1.5);
    }

    60% {
        transform: scale(0.85);
    }

    100% {
        transform: scale(1);
    }
}

.like-count {
    font-weight: 600;
    min-width: 8px;
    text-align: center;
}

/* ── モデル名バッジ ── */
.gallery-card-model {
    display: inline-block;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--card-badge-color);
    font-size: 0.62rem;
    background: var(--card-badge-bg);
    padding: 1px 6px;
    border-radius: 3px;
}

/* ── キューバッジ ── */
.queue-badge,
.clients-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

/* ============================
   ライトボックス
   ============================ */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.lightbox-content {
    position: relative;
    display: flex;
    max-width: 90vw;
    max-height: 90vh;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    animation: fadeScaleIn 0.3s ease;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}

.lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 1.2rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

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

.lightbox-body {
    display: flex;
    max-height: 90vh;
}

/* ライトボックス 画像エリア（ナビ・ズーム含むコンテナ） */
.lightbox-image-area {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    min-width: 400px;
    max-width: 60vw;
    overflow: hidden;
}

.lightbox-image-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: grab;
}

.lightbox-image-wrap.is-dragging {
    cursor: grabbing;
}

.lightbox-image-wrap.is-zoomed {
    cursor: grab;
}

.lightbox-image {
    max-width: 100%;
    max-height: 88vh;
    object-fit: contain;
    transition: transform 0.15s ease-out;
    transform-origin: center center;
    user-select: none;
    -webkit-user-drag: none;
}

/* ── ナビゲーション矢印 ── */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s, background 0.2s, transform 0.15s;
}

.lightbox-image-area:hover .lightbox-nav {
    opacity: 0.7;
}

.lightbox-nav:hover {
    opacity: 1 !important;
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.lightbox-nav--prev {
    left: 12px;
}

.lightbox-nav--next {
    right: 12px;
}

.lightbox-nav:disabled {
    opacity: 0.15 !important;
    cursor: default;
    pointer-events: none;
}

/* ── ズームコントロール ── */
.lightbox-zoom-controls {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 20px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.lightbox-zoom-controls.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-zoom-level {
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: rgba(255, 255, 255, 0.85);
    min-width: 36px;
    text-align: center;
}

.lightbox-zoom-btn {
    width: 26px;
    height: 26px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.lightbox-zoom-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ── ナビゲーション モバイル対応 ── */
@media (max-width: 768px) {
    .lightbox-image-area {
        min-width: unset;
        max-width: 100vw;
    }

    .lightbox-nav {
        width: 36px;
        height: 36px;
        opacity: 0.5;
    }

    .lightbox-nav--prev {
        left: 6px;
    }

    .lightbox-nav--next {
        right: 6px;
    }
}

/*
 * ── ライトボックス 縦レイアウト切り替え ──
 * 画面幅が狭い場合 or 縦長ビューポートの場合、
 * 左右並びから上画像・下プロンプトの縦配置に切り替える
 */

/* 画面幅が狭い場合（画像エリア+情報パネルが横に収まらない） */
@media (max-width: 900px) {
    .lightbox-content {
        max-width: 96vw;
        max-height: 96vh;
        flex-direction: column;
    }

    .lightbox-body {
        flex-direction: column;
        max-height: 96vh;
        overflow-y: auto;
    }

    .lightbox-image-area {
        min-width: unset;
        max-width: 100%;
        min-height: 0;
        max-height: 55vh;
    }

    .lightbox-image {
        max-height: 55vh;
    }

    .lightbox-info {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        padding: 14px 16px;
        overflow-y: auto;
    }

    .lightbox-prompt {
        max-height: 120px;
    }

    .lightbox-prompt--compact {
        max-height: 80px;
    }
}

/* ビューポートが縦長の場合（タブレット縦持ち、スマホ等） */
@media (orientation: portrait) and (min-width: 481px) {
    .lightbox-content {
        max-width: 96vw;
        max-height: 96vh;
    }

    .lightbox-body {
        flex-direction: column;
        max-height: 96vh;
        overflow-y: auto;
    }

    .lightbox-image-area {
        min-width: unset;
        max-width: 100%;
        max-height: 55vh;
    }

    .lightbox-image {
        max-height: 55vh;
    }

    .lightbox-info {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        padding: 14px 16px;
        overflow-y: auto;
    }
}

/* 極小画面（スマホ） */
@media (max-width: 480px) {
    .lightbox-content {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    .lightbox-body {
        flex-direction: column;
        max-height: 100vh;
        overflow-y: auto;
    }

    .lightbox-image-area {
        min-width: unset;
        max-width: 100%;
        max-height: 50vh;
    }

    .lightbox-image {
        max-height: 50vh;
    }

    .lightbox-info {
        width: 100%;
        min-width: unset;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        padding: 12px;
        gap: 10px;
        overflow-y: auto;
    }

    .lightbox-header-row {
        margin-bottom: 8px;
    }

    .lightbox-params {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
    }

    .lightbox-prompt {
        max-height: 100px;
        font-size: 0.72rem;
    }

    .lightbox-close {
        top: 6px;
        right: 6px;
        width: 28px;
        height: 28px;
    }
}

.lightbox-info {
    width: 340px;
    min-width: 280px;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-left: 1px solid var(--border-subtle);
}

.lightbox-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.lightbox-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.lightbox-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lightbox-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.lightbox-section-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.lightbox-copy-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lightbox-copy-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.lightbox-prompt {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text-secondary);
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
}

.lightbox-prompt--neg {
    color: var(--text-muted);
    font-size: 0.72rem;
    max-height: 100px;
}

.lightbox-params {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.lightbox-param {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.lightbox-param-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

.lightbox-param-value {
    font-size: 0.82rem;
    font-family: var(--font-mono);
    color: var(--text-primary);
    font-weight: 500;
}

.lightbox-actions {
    margin-top: auto;
    padding-top: 12px;
}

.lightbox-use-btn {
    width: 100%;
    justify-content: center;
    gap: 6px;
}

/* ============================
   認証モーダル
   ============================ */
.auth-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
}

.auth-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 48px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    animation: fadeScaleIn 0.4s ease;
    min-width: 320px;
}

.auth-icon {
    opacity: 0.8;
}

.auth-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.auth-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.auth-input {
    width: 100%;
    text-align: center;
    font-size: 1rem;
    padding: 10px 16px;
}

.auth-btn {
    width: 100%;
    margin-top: 4px;
}

.auth-error {
    font-size: 0.8rem;
    color: var(--error);
    margin: 4px 0 0;
    min-height: 1.2em;
}