/* Sidebar Styles */

.sidebar {
    width: 250px;
    min-width: 260px;
    max-width: 500px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    border-radius: 0 12px 12px 0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 50;
    position: relative;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .sidebar-footer {
    opacity: 0;
    pointer-events: none;
}

.sidebar-header {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header-section {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    justify-content: flex-start;
}

.sidebar-section-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0 0.1rem;
}

.sidebar-section-btns {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.sidebar-header-sep {
    width: 1px;
    background-color: var(--border-color);
    align-self: stretch;
    margin: 0 0.5rem;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* Table List Item */
.table-list-item {
    border-bottom: 1px solid var(--border-color);
}

.table-list-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.table-list-header:hover {
    background-color: var(--bg-hover);
}

.table-list-header.highlighted {
    background-color: var(--highlight-color);
}

.table-list-header.selected {
    background-color: var(--accent-color-alpha);
    border-left: 3px solid var(--accent-color);
}

.table-expand-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.5rem;
    color: var(--text-muted);
    font-size: 1rem;
    transition: transform 0.15s ease;
}

.table-list-item.expanded .table-expand-icon {
    transform: rotate(90deg);
}

.table-list-name {
    flex: 1;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-list-count {
    font-size: 1rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

.table-list-actions-wrapper {
    position: relative;
    margin-left: auto;
}

.table-list-menu-btn {
    font-size: 1.1rem;
    line-height: 1;
}

.table-list-actions {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--bg-secondary, #1f2937);
    border: 1px solid var(--border-color, #374151);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.35);
    z-index: 100;
    min-width: 130px;
    padding: 4px 0;
    flex-direction: column;
}

.table-list-item.menu-open .table-list-actions {
    display: flex;
}

.table-list-item.menu-open .table-list-actions .table-list-action {
    justify-content: flex-start;
    width: 100%;
    height: auto;
    padding: 6px 10px;
    border-radius: 0;
    gap: 6px;
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-secondary);
}

.table-list-item.menu-open .table-list-actions .table-list-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.table-list-item.dragging {
    opacity: 0.5;
}

.sidebar-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.sidebar-group-header.drop-target {
    outline: 2px dashed var(--accent-color, #6366f1);
    outline-offset: -2px;
}
.sidebar-group-hidden-badge {
    margin-left: auto;
    font-size: 1rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 10px;
}
.sidebar-group-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-group-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 1rem;
    flex-shrink: 0;
}
.sidebar-group-toggle:hover {
    color: var(--accent-color, #6366f1);
}
.sidebar-group-collapsed {
    opacity: 0.7;
}

.sidebar-group-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.sidebar-group-delete:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.table-list-action {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 1rem;
}

.table-list-action:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Field List */
.field-list {
    display: none;
    padding: 0.25rem 0;
    background-color: var(--bg-tertiary);
}

.table-list-item.expanded .field-list {
    display: block;
}

.field-list-item {
    display: flex;
    align-items: center;
    padding: 0.375rem 1rem 0.375rem 2.5rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.field-list-item:hover {
    background-color: var(--bg-hover);
}

.field-list-item.highlighted {
    background-color: var(--highlight-color);
}

.field-list-icon {
    width: 16px;
    margin-right: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.field-list-icon.pk {
    color: var(--pk-color);
}

.field-list-icon.fk {
    color: var(--fk-color);
}

.field-list-name {
    flex: 1;
    font-size: 1rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-list-type {
    font-size: 1rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

/* Sidebar Resize Handle */
.sidebar-resize {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    z-index: 60;
    background: transparent;
}

.sidebar-resize:hover,
.sidebar-resize.active {
    background-color: var(--accent-color);
    opacity: 0.5;
}

/* Sidebar Toggle Button - positioned outside sidebar */
.sidebar-toggle {
    position: fixed;
    top: 50%;
    left: 260px; /* matches sidebar min-width */
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 61;
    transition: left 0.15s ease, background-color 0.15s ease;
}

.sidebar-toggle:hover {
    background-color: var(--bg-hover);
}

.sidebar-toggle-icon {
    font-size: 14px;
    color: var(--text-muted);
}

.sidebar-toggle.collapsed {
    left: 0;
}

/* Sidebar toolbar / sort controls */
.sidebar-toolbar,
.sidebar-toolbar-fixed {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    flex-shrink: 0;
}
.sidebar-toolbar-fixed:empty { display: none; }

.sidebar-sort-controls {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.sidebar-sort-label {
    font-size: 1rem;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.sidebar-sort-btn {
    padding: 0.2rem 0.6rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

.sidebar-sort-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-sort-btn.active {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

/* Group header for tag grouping */
.sidebar-group-header {
    padding: 0.375rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    margin-top: 0.25rem;
}

/* Color dot in sidebar */
.table-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.375rem;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.2);
}

/* Tag badges in sidebar */
.table-tag-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    font-size: 1rem;
    border-radius: 3px;
    background: var(--accent-color-alpha);
    color: var(--accent-color);
    margin-left: 0.25rem;
    white-space: nowrap;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hidden table in sidebar */
.table-list-item.table-hidden .table-list-name {
    opacity: 0.45;
    text-decoration: line-through;
}

.table-list-item.table-hidden .table-list-header {
    opacity: 0.6;
}

/* Multi-selected in sidebar */
.table-list-item.multi-selected .table-list-header {
    background-color: rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--accent-color);
}

/* Hover card tooltip for table items */
.table-hover-card {
    position: fixed;
    z-index: 200;
    background-color: var(--bg-tooltip);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    box-shadow: 0 4px 16px var(--shadow-color);
    max-width: 280px;
    min-width: 160px;
    pointer-events: none;
    font-size: 1rem;
    line-height: 1.4;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.table-hover-card.visible {
    opacity: 1;
}
.table-hover-card-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}
.table-hover-card-desc {
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    word-wrap: break-word;
}
.table-hover-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}
.table-hover-card-tag {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background-color: var(--accent-color-alpha);
    color: var(--accent-color);
    font-size: 1rem;
    font-weight: 500;
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 100;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: flex;
    }
}