/* sidebar.css — Sidebar, file list, search, breadcrumb, cross-repo */

.sidebar {
    width: 250px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    flex-shrink: 0;
}

/* サイドバーリサイズハンドル */
.sidebar-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    transition: background 0.15s;
}
.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
    background: var(--accent-primary);
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; transition: background 0.2s; }
.sidebar:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); }

.sidebar.collapsed {
    width: 0 !important;
    padding: 0;
    border-right: none;
    transition: width 0.2s ease;
}

.main-container.sidebar-collapsed .sidebar {
    width: 0 !important;
    padding: 0;
    border-right: none;
}

/* Sidebar header */
#fileListHeader {
    cursor: pointer;
    padding: 8px 12px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    transition: background-color 0.1s;
    margin: 0;
    display: flex;
    align-items: center;
}

#fileListHeader:hover {
    background: var(--overlay-light);
}

.sidebar-actions {
    margin-left: auto;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.1s;
}
#fileListHeader:hover .sidebar-actions { opacity: 1; }

.sidebar-action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1;
}
.sidebar-action-btn:hover {
    background: var(--overlay-medium);
    color: var(--text-bright);
}

#fileListHeader #repoName {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#fileListHeader .header-chevron {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.6;
    transition: opacity 0.1s;
}

#fileListHeader:hover .header-chevron {
    opacity: 1;
}

/* Search */
.search-container {
    position: relative;
    margin: 0;
    padding: 4px 8px 8px;
}

.search-mode-toggle {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 4px;
    padding: 2px;
    background: var(--bg-base);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
}

.search-mode-toggle input[type="radio"] {
    display: none;
}

.search-mode-toggle label {
    flex: 1;
    padding: 2px 6px;
    text-align: center;
    font-size: var(--font-size-xs);
    cursor: pointer;
    border-radius: 2px;
    transition: all 0.1s;
    color: var(--text-secondary);
}

.search-mode-toggle input[type="radio"]:checked + label {
    background: var(--accent-primary);
    color: var(--on-accent);
}

.search-mode-toggle label:hover {
    background: var(--overlay-medium);
}

.search-mode-toggle input[type="radio"]:checked + label:hover {
    background: var(--accent-hover);
}

.search-input {
    width: 100%;
    padding: 4px 26px 4px 8px;
    background: var(--bg-base);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    color: var(--text-code);
    font-size: var(--font-size-base);
    outline: none;
    transition: border-color 0.1s;
}

.search-input:focus {
    border-color: var(--border-active);
    outline: 1px solid var(--border-active);
    outline-offset: -1px;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.clear-search {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 2px;
    font-size: var(--font-size-xs);
    transition: background 0.1s;
}

.clear-search:hover {
    background: var(--overlay-medium);
    color: var(--text-code);
}

/* Search results */
.search-results-info {
    padding: 4px 12px;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--border-default);
    background: rgba(14, 99, 156, 0.1);
}

.no-results {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    font-size: var(--font-size-sm);
}

/* ──── 検索結果コンテナ（DRY: 共通構造） ──── */
.file-info-column,
.file-content-preview {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.file-content-preview {
    gap: 4px;
}

/* ──── Mode A: テキスト切り詰め（SSOT: サイドバー共通デフォルト） ──── */
.folder-name,
.file-name,
.line-content,
.cross-repo-file .fragment,
.repo-selector-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ──── Mode B: テキスト折り返し（SSOT: 検索結果 — Mode Aを上書き） ──── */
.file-info-column .file-name,
.file-content-preview .file-name,
.cross-repo-file .file-name,
.file-path-hint {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: break-word;
}

.file-content-preview .file-name {
    font-weight: bold;
    color: var(--text-code);
}

.file-path-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.match-count {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.match-line {
    font-size: 12px;
    background: var(--overlay-subtle);
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 4px;
    display: flex;
    gap: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.match-line:hover {
    background: rgba(100, 180, 255, 0.1);
}

.line-number {
    color: var(--text-muted);
    font-weight: bold;
    flex-shrink: 0;
}

.line-content {
    color: var(--text-primary);
}

.line-content mark {
    background: #ffd700;
    color: #000;
    font-weight: bold;
    padding: 0 2px;
    border-radius: 2px;
}

.more-matches {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 4px;
}

/* Breadcrumb & file list */
.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1px;
    padding: 4px 12px;
    font-size: var(--font-size-xs);
    min-height: 20px;
}
.breadcrumb:empty {
    display: none;
}
.breadcrumb-item {
    cursor: pointer;
    color: var(--text-link);
    padding: 1px 3px;
    border-radius: 2px;
    transition: background 0.1s;
}
.breadcrumb-item:hover {
    text-decoration: underline;
    background: var(--bg-hover);
}
.breadcrumb-current {
    color: var(--text-primary);
    padding: 1px 3px;
}
.breadcrumb-separator {
    color: var(--text-muted);
}

.file-list {
    margin-top: 0;
}

.parent-folder-item {
    padding: 3px 12px 3px 20px;
    cursor: pointer;
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-default);
    transition: background 0.1s;
}
.parent-folder-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.file-item, .folder-item {
    padding: 3px 12px 3px 20px;
    cursor: pointer;
    font-size: var(--font-size-base);
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    border-left: 2px solid transparent;
    transition: background 0.1s;
}

.file-item:hover, .folder-item:hover {
    background: var(--bg-hover);
}

.file-item.active {
    background: var(--bg-active);
    border-left-color: var(--accent-primary);
}

.folder-icon, .file-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.folder-name, .file-name {
    flex: 1;
}

.folder-item {
    font-weight: 500;
    color: var(--text-bright);
}

.file-item {
    color: var(--text-primary);
}

.search-results-info {
    padding: 4px 12px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-default);
    margin-bottom: 4px;
    background: rgba(14, 99, 156, 0.1);
}

.no-results {
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    font-size: var(--font-size-sm);
}

/* Cross-repo search results */
.cross-repo-filter {
    display: flex;
    gap: 2px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-default);
}

.cross-repo-filter button {
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid var(--border-default);
    border-radius: 3px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.cross-repo-filter button.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.cross-repo-group {
    margin-bottom: 2px;
}

.cross-repo-header {
    padding: 6px 12px;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-bright);
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: default;
}

.cross-repo-header .repo-icon {
    font-size: 12px;
    opacity: 0.7;
}

.cross-repo-file {
    padding: 4px 12px 4px 28px;
    cursor: pointer;
    font-size: var(--font-size-base);
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-left: 2px solid transparent;
    transition: background 0.1s;
}

.cross-repo-file-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.cross-repo-file:hover {
    background: var(--bg-hover);
}

.cross-repo-file .file-name {
    color: var(--text-primary);
    min-width: 0;
}

.cross-repo-file .fragment {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.cross-repo-file .fragment mark {
    background: rgba(255, 213, 79, 0.3);
    color: var(--text-bright);
    border-radius: 2px;
    padding: 0 1px;
}

.cross-repo-footer {
    padding: 8px 12px;
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    border-top: 1px solid var(--border-default);
}

@media (max-width: 768px) {
    .sidebar {
        width: 85%;
        height: calc(var(--vh, 1vh) * 100 - 60px);
        max-height: calc(var(--vh, 1vh) * 100 - 60px);
        border-right: none;
        border-bottom: none;
        padding: 0;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        transform: translateX(-100%);
        transition: transform 0.3s ease, visibility 0s 0.3s;
        position: fixed;
        top: 60px;
        left: 0;
        z-index: 300;
        background: var(--bg-surface);
        box-shadow: none;
        display: flex;
        flex-direction: column;
        visibility: hidden;
    }

    .sidebar h3 {
        padding: 15px 15px 10px 15px;
        margin: 0;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border-default);
        flex-shrink: 0;
    }

    .file-list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
        visibility: visible;
        transition: transform 0.3s ease;
    }

    .sidebar-toggle-btn {
        display: none;
    }

    .sidebar-resize-handle {
        display: none;
    }
}

@media (max-width: 400px) {
    .sidebar {
        width: 90%;
        height: calc(var(--vh, 1vh) * 100 - 50px);
        max-height: calc(var(--vh, 1vh) * 100 - 50px);
        top: 50px;
    }
}
