/* ===== Tag Palette Sidebar ===== */

:root {
    --sidebar-width: 340px;
    --sidebar-toggle-size: 36px;
}

/* サイドバー本体 */
.tag-palette-sidebar {
    position: fixed;
    top: var(--header-height, 44px);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height, 44px));
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.tag-palette-sidebar.open {
    transform: translateX(0);
}

/* サイドバーヘッダー */
.tag-palette-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-default);
    flex-shrink: 0;
    background: var(--bg-elevated);
}

.tag-palette-sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

/* ドラッグハンドル: デフォルトは非表示 (モバイルのみ表示) */
.palette-drag-handle {
    display: none;
}

.tag-palette-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.tag-palette-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* サイドバーコンテンツ（タブパネル共通） */
.sidebar-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

.sidebar-tab-content.active {
    display: block;
}

.sidebar-tab-content::-webkit-scrollbar {
    width: 5px;
}

.sidebar-tab-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-tab-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

/* サイドバー内のパレットセクション */
.sidebar-tab-content .prompt-section--quickpreset {
    margin: 0;
    border: none;
    background: none;
    padding: 0;
    border-radius: 0;
}

/* サイドバー内ではセクションヘッダー(折りたたみUI)を非表示 */
.sidebar-tab-content .prompt-section--quickpreset>.prompt-section-header {
    display: none;
}

.sidebar-tab-content .prompt-section-body {
    padding: 0 4px 8px;
}

/* サイドバー内では collapsed 解除 */
.sidebar-tab-content .prompt-section-body.collapsed {
    display: block;
    max-height: none;
    overflow: visible;
}

/* サイドバー内のボタンサイズ */
.sidebar-tab-content .quickpreset-btn {
    font-size: 13px;
    padding: 4px 8px;
}

.sidebar-tab-content .quickpreset-category-label {
    font-size: 13px;
    font-weight: 600;
    margin-top: 8px;
    margin-bottom: 4px;
}

/* セパレーター */
.sidebar-tab-content .palette-separator {
    height: 1px;
    background: var(--border-default);
    margin: 8px 0;
}

/* トグルボタン */
.tag-palette-toggle-btn {
    position: fixed;
    top: calc(var(--header-height, 44px) + 8px);
    left: 0;
    z-index: 199;
    width: var(--sidebar-toggle-size);
    height: var(--sidebar-toggle-size);
    border: 1px solid var(--border-default);
    border-left: none;
    border-radius: 0 8px 8px 0;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-sm);
}

.tag-palette-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    width: calc(var(--sidebar-toggle-size) + 4px);
    box-shadow: var(--shadow-md);
}

/* サイドバーが開いた時トグルボタンを右にずらす */
.tag-palette-toggle-btn.sidebar-open {
    left: var(--sidebar-width);
    border-left: none;
    border-radius: 0 10px 10px 0;
}

/* メインコンテンツのシフト */
.main-content {
    margin-left: var(--sidebar-toggle-size);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.sidebar-shifted {
    margin-left: calc(var(--sidebar-width) + var(--sidebar-toggle-size));
}

/* ヘッダーもシフト */
.header {
    margin-left: var(--sidebar-toggle-size);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.header.sidebar-shifted {
    margin-left: calc(var(--sidebar-width) + var(--sidebar-toggle-size));
}

/* モバイル対応 */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 85vw;
    }

    /* モバイルではオーバーレイスタイル(メインをずらさない) */
    .main-content.sidebar-shifted,
    .header.sidebar-shifted {
        margin-left: 0;
    }

    /* 背景オーバーレイ */
    .tag-palette-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 199;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .tag-palette-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}

/* スマホ縦向き: 左余白削除 & 浮遊トグルボタン非表示 */
@media (orientation: portrait) and (max-width: 768px) {
    .main-content {
        margin-left: 0 !important;
    }

    .header {
        margin-left: 0 !important;
    }

    /* 浮遊トグルボタンを非表示（インラインボタンに置換） */
    .tag-palette-toggle-btn {
        display: none !important;
    }
}