/* ==============================================
   Anima WebUI - Base Styles (SD WebUI Layout)
   ============================================== */

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ── App Container ── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ── Header ── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 10;
    gap: 16px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.brand-sub {
    font-weight: 400;
    opacity: 0.7;
}

/* ── Header Tabs (SD WebUI style) ── */
.header-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-base);
    border-radius: var(--radius-md);
    padding: 3px;
}

.header-tab {
    padding: 6px 18px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.header-tab:hover:not(:disabled) {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.header-tab.active {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.header-tab:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Tab Badge (LINE風の新着通知バッジ) ── */
.header-tab {
    position: relative;
}

.tab-badge {
    display: none;
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(239, 68, 68, 0.4);
    pointer-events: none;
}

.tab-badge.active {
    display: inline-block;
    animation: badge-pop 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes badge-pop {
    0% {
        transform: scale(0);
    }

    60% {
        transform: scale(1.2);
    }

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

/* ── Header Status ── */
.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-warning);
    transition: background var(--transition-normal);
}

.status-dot.connected {
    background: var(--status-success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.4);
}

.status-dot.error {
    background: var(--status-error);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.4);
}

/* ── Main Content ── */
.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ── Tab Panels (SPA切替) ── */
.tab-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tab-panel.active {
    display: flex;
    opacity: 1;
}

/* ギャラリーパネル：スクロールは .gallery-main に任せる */
#panel-gallery {
    overflow: hidden;
}

#panel-gallery .gallery-main {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    /* flexbox子要素がちゃんと縮小するために必要 */
}

/* ===== 3カラムレイアウト ===== */
.txt2img-layout {
    display: grid;
    grid-template-columns: 1fr 1fr 80px;
    flex: 1;
    overflow: hidden;
}

/* ── 左カラム: プロンプト ── */
.layout-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    font-size: 1.05rem;
}

/* ネガティブプロンプト */
.neg-prompt-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.neg-label {
    font-size: 1.15rem;
}

/* プリセット */
.preset-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}

.preset-label {
    font-size: 1.08rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.preset-btn {
    padding: 4px 12px;
    font-size: 1.15rem;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.preset-category {
    margin-top: 6px;
}

.preset-category-label {
    font-size: 1.08rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 4px;
    border-radius: var(--radius-sm);
    list-style: none;
    user-select: none;
    transition: color 0.15s;
}

.preset-category-label::-webkit-details-marker {
    display: none;
}

.preset-category-label::before {
    content: '▶';
    display: inline-block;
    font-size: 0.55rem;
    margin-right: 4px;
    transition: transform 0.2s ease;
}

.preset-category[open]>.preset-category-label::before {
    transform: rotate(90deg);
}

.preset-category-label:hover {
    color: var(--text-primary);
}

.preset-category>.preset-buttons {
    margin-top: 4px;
    padding-left: 12px;
}

/* ── 中央カラム: 設定バー + プレビュー ── */
.layout-center {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 設定バー */
.settings-bar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.settings-bar-controls {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.sbar-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

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

.sbar-select {
    padding: 4px 6px;
    font-size: 0.82rem;
    min-width: 100px;
}

.sbar-slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sbar-slider {
    width: 80px;
}

.sbar-num {
    width: 48px;
    padding: 4px 4px;
    font-size: 0.8rem;
    text-align: center;
}

.sbar-seed-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.sbar-seed-input {
    width: 90px;
    padding: 4px 6px;
    font-size: 0.82rem;
}

.sbar-icon-btn {
    padding: 4px;
    width: 26px;
    height: 26px;
}

.sbar-gen-btn {
    min-height: 0;
    padding: 6px 16px;
    flex-shrink: 0;
    white-space: nowrap;
}

.sbar-skip-btn {
    padding: 4px 10px;
    flex-shrink: 0;
}

/* qs-input (seed, cfg等で使用) */
.qs-input {
    padding: 5px 6px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    text-align: center;
    outline: none;
    transition: border-color var(--transition-fast);
}

.qs-input:focus {
    border-color: var(--accent-primary);
}

/* Hide number arrows */
.qs-input[type="number"]::-webkit-outer-spin-button,
.qs-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.qs-input[type="number"] {
    -moz-appearance: textfield;
}

/* プレビューエリア (中央カラム下部) */
.layout-center .preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--bg-base);
}

/* ── 過去画像ヒストリーストリップ ── */
.history-strip {
    flex-shrink: 0;
    padding: 6px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    overflow-x: auto;
    min-height: 52px;
}

.history-strip-inner {
    display: flex;
    gap: 4px;
}

.history-strip-inner .history-thumb {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: contain;
    background: var(--img-bg);
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color var(--transition-fast), transform var(--transition-fast), opacity 0.3s ease;
    flex-shrink: 0;
    opacity: 0.75;
}

.history-strip-inner .history-thumb.slide-in {
    animation: slideInFromLeft 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.history-strip-inner .history-thumb:hover {
    opacity: 1;
    border-color: var(--border-default);
    transform: scale(1.05);
}

.history-strip-inner .history-thumb.active {
    opacity: 1;
    border-color: var(--accent-primary);
}

.history-strip::-webkit-scrollbar {
    height: 4px;
}

.history-strip::-webkit-scrollbar-track {
    background: transparent;
}

.history-strip::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 2px;
}

/* ── 右カラム: 縦ギャラリーストリップ ── */
.layout-gallery-strip {
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    overflow-y: auto;
    padding: 0 6px 6px;
    display: flex;
    flex-direction: column;
}

/* ── NSFWぼかしトグルヘッダー ── */
.blur-toggle-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-surface);
}

.blur-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
    user-select: none;
    width: 100%;
}

.blur-toggle-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-default);
    background: var(--bg-hover);
}

.blur-toggle-btn.blur-active {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb, 139, 92, 246), 0.1);
}

.blur-toggle-btn svg {
    flex-shrink: 0;
}

/* ── NSFWぼかしフィルター ── */
.nsfw-blur .gallery-thumb {
    filter: blur(12px) brightness(0.7);
    transition: filter var(--transition-normal), border-color var(--transition-fast), opacity var(--transition-fast);
}

.nsfw-blur .gallery-thumb:hover {
    filter: blur(12px) brightness(0.85);
}

.gallery-strip-inner {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gallery-strip-inner .gallery-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background: var(--img-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition-fast), opacity var(--transition-fast);
    opacity: 0.7;
}

.gallery-strip-inner .gallery-thumb.slide-in {
    animation: slideInFromBottom 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.gallery-strip-inner .gallery-thumb:hover {
    opacity: 1;
    border-color: var(--border-default);
}

.gallery-strip-inner .gallery-thumb.active {
    opacity: 1;
    border-color: var(--accent-primary);
}

/* スクロールバー */
.layout-prompts::-webkit-scrollbar,
.layout-gallery-strip::-webkit-scrollbar {
    width: 6px;
}

.layout-prompts::-webkit-scrollbar-track,
.layout-gallery-strip::-webkit-scrollbar-track {
    background: transparent;
}

.layout-prompts::-webkit-scrollbar-thumb,
.layout-gallery-strip::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.layout-prompts::-webkit-scrollbar-thumb:hover,
.layout-gallery-strip::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Footer ── */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.footer-text {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ── シンプルライトボックス ── */

.simple-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.simple-lightbox .lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--overlay-light);
    color: #fff;
    font-size: 1.4rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.simple-lightbox .lightbox-close:hover {
    background: var(--overlay-strong);
}

.simple-lightbox-image {
    position: relative;
    z-index: 1;
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    border-radius: var(--radius-md);
    animation: fadeScaleIn 0.25s ease;
    cursor: default;
}

@keyframes fadeScaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideInFromBottom {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }

    to {
        opacity: 0.7;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-16px) scale(0.9);
    }

    to {
        opacity: 0.75;
        transform: translateX(0) scale(1);
    }
}