/* Sidebar, workspace switcher, sidebar nav, and mobile bottom nav styles. */

[data-theme="light"] .sidebar {
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.05);
}

/* --- Sidebar --- */
/* Width animates via .collapsed; icon chrome is .rail (after width + fade).
   .sidebar-shell keeps expanded content width during the clip so labels do not
   reflow into icons mid-transition. */
.sidebar {
    display: flex;
    flex-direction: column;
    font-size: 15px;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    /* Ease-out so collapse decelerates into the rail (closer to expand feel). */
    transition: width 220ms cubic-bezier(0.32, 0.72, 0, 1),
                min-width 220ms cubic-bezier(0.32, 0.72, 0, 1);
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 50;
    flex-shrink: 0;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
    /* Clip expanded content while width animates; rail re-enables overflow. */
    overflow: hidden;
}

.sidebar.rail {
    /* Icon tooltips paint outside the rail, above main content. */
    overflow: visible;
    z-index: 90;
}

.sidebar-shell {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    box-sizing: border-box;
    transition: opacity 110ms ease;
}

/* Hide the layout swap (expanded clip -> icon rail) under a short fade. */
.sidebar.chrome-fading .sidebar-shell {
    opacity: 0;
    pointer-events: none;
}

.sidebar.rail .sidebar-shell {
    width: 100%;
    min-width: 0;
}

/* Soften labels while width is clipping (before rail chrome). */
.sidebar.collapsed:not(.rail) .nav-label,
.sidebar.collapsed:not(.rail) .sidebar-section-label,
.sidebar.collapsed:not(.rail) .design-nav-group-chevron,
.sidebar.collapsed:not(.rail) .ws-switcher-chevron,
.sidebar.collapsed:not(.rail) .sidebar-brand-lockup {
    opacity: 0;
    transition: opacity 160ms ease;
}

/* Brand row: expanded = lockup + toggle; collapsed = mark above expand. */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 48px;
    padding: 10px 10px 0;
    flex-shrink: 0;
}

.sidebar-brand-lockup {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--text-primary);
    line-height: 0;
}

.sidebar-brand-lockup .ideavibes-brand {
    display: block;
    width: 112px;
    height: 26px;
    aspect-ratio: 460 / 112;
    flex: 0 0 auto;
    overflow: visible;
}

.sidebar-brand-mark {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--navbar-control-radius);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    line-height: 0;
    transition: background var(--transition-speed);
}

.sidebar-brand-mark:hover {
    background: var(--bg-tertiary);
}

.sidebar-brand-mark .ideavibes-mark {
    display: block;
    width: 28px;
    height: 28px;
    aspect-ratio: 1;
    object-fit: contain;
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--navbar-control-height);
    height: var(--navbar-control-height);
    flex: 0 0 auto;
    border-radius: var(--navbar-control-radius);
    color: var(--text-secondary);
    background: transparent;
    border: 0;
    cursor: pointer;
    transition: background var(--transition-speed), color var(--transition-speed);
}

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

.sidebar-toggle-icon {
    display: block;
    transition: transform var(--transition-speed) ease;
}

/* Collapsed: flip so the rail sits on the right (expand toward content). */
.sidebar-toggle-icon.is-collapsed {
    transform: scaleX(-1);
}

.sidebar.rail .sidebar-brand {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 4px;
    min-height: 0;
    padding: 10px 12px 4px;
}

.sidebar.rail .sidebar-brand-lockup {
    display: none;
}

.sidebar.rail .sidebar-brand-mark {
    display: flex;
}

.sidebar.rail .sidebar-toggle {
    width: 40px;
    height: 32px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 8px 12px 0;
    overflow: visible;
    flex-shrink: 0;
}

.sidebar-header > .ws-switcher {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
}

.sidebar-header > .ws-switcher .ws-dropdown {
    right: 0;
    left: 0;
}

.sidebar.rail .sidebar-header {
    height: auto;
    padding: 4px 0 0;
    justify-content: center;
}

.sidebar.rail .sidebar-header > .ws-switcher {
    flex: 0 0 auto;
    width: 40px;
}

/* --- Workspace Switcher --- */
.ws-switcher {
    position: relative;
    padding: 12px 12px 0;
}
.ws-switcher-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.ws-switcher-btn:hover { background: var(--bg-hover); }
/* Keep the same left padding as expanded so the initial glyph does not jump. */
.sidebar.rail .ws-switcher-btn {
    justify-content: flex-start;
    padding: 8px 10px;
    overflow: hidden;
}
.sidebar.rail .ws-switcher-name {
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}
.sidebar.rail .ws-switcher-chevron {
    display: none;
}
.ws-switcher-chevron { color: var(--text-muted); display: flex; }

.ws-backdrop {
    position: fixed;
    inset: 0;
    z-index: 199;
}
.ws-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 12px;
    right: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 200;
    overflow: hidden;
    min-width: 220px;
}
.sidebar.rail .ws-dropdown { left: 100%; top: 0; right: auto; width: 240px; }

.ws-dropdown-label {
    padding: 8px 12px 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ws-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}
.ws-dropdown-item:hover { background: var(--bg-hover); }
.ws-dropdown-item:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.ws-dropdown-item:disabled:hover { background: none; }
.ws-dropdown-item.active { color: var(--text-primary); }
.ws-dropdown-item.create { color: var(--accent); font-weight: 500; padding: 8px 12px; }
.ws-dropdown-avatar {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ws-dropdown-info { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.ws-dropdown-name { font-weight: 500; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-dropdown-meta { font-size: 14px; color: var(--text-muted); }
.ws-dropdown-check { color: var(--accent); display: flex; flex-shrink: 0; }
.ws-dropdown-divider { height: 1px; background: var(--border); margin: 2px 0; }
.ws-create-plus {
    width: 28px; height: 28px;
    border-radius: 6px;
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--accent);
    flex-shrink: 0;
}
.ws-create-form {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
}
.ws-create-form .form-input { flex: 1; font-size: 14px; padding: 6px 8px; }
.ws-dropdown-error {
    margin: 0;
    padding: 0 12px 10px;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 2px;
}

.sidebar-section-label {
    padding: 16px 12px 6px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.rail .sidebar-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 15px;
    transition: background var(--transition-speed), color var(--transition-speed);
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item .nav-icon svg {
    width: 18px;
    height: 18px;
}

.nav-item .nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hide labels without recentering icons — same left edge as expanded rows. */
.sidebar.rail .nav-label {
    display: none;
}

.sidebar.rail .nav-item {
    justify-content: flex-start;
    padding: 8px 12px;
    overflow: visible !important;
}

.sidebar.rail .design-nav-row,
.sidebar.rail .design-nav-row .design-nav-group-toggle,
.sidebar.rail .design-nav-row .nav-item {
    overflow: visible !important;
}

/* Explicit tooltip for Idea Design / Imported Repos group rows.
   Pseudo-element tooltips conflict with .design-nav-row.active::before. */
.sidebar-rail-tooltip {
    display: none;
}

.sidebar.rail .sidebar-rail-tooltip {
    position: absolute;
    top: 50%;
    left: calc(100% + 10px);
    z-index: 500;
    display: block;
    max-width: 220px;
    padding: 7px 11px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-primary) 92%, #000 8%);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent),
        0 10px 28px rgba(0, 0, 0, 0.32);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-6px, -50%);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        visibility 140ms ease;
}

.sidebar.rail .design-nav-row:hover,
.sidebar.rail .design-nav-row:focus-within {
    z-index: 220;
}

.sidebar.rail .design-nav-row:hover .sidebar-rail-tooltip,
.sidebar.rail .design-nav-row:focus-within .sidebar-rail-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}

[data-theme="light"] .sidebar.rail .sidebar-rail-tooltip {
    background: #ffffff;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 85%, transparent),
        0 8px 20px rgba(15, 23, 42, 0.12);
}

@media (prefers-reduced-motion: reduce) {
    .sidebar.rail .sidebar-rail-tooltip {
        transition: none;
    }
}

.sidebar.rail .ws-switcher,
.sidebar.rail .ws-switcher-btn {
    overflow: visible !important;
}

.sidebar.rail .sidebar-nav {
    overflow: visible;
}

/* Custom collapsed-rail tooltips (not native title). */
.sidebar.rail [data-tooltip] {
    position: relative;
}

/* Raise the hovered row so its tooltip paints above later siblings. */
.sidebar.rail [data-tooltip]:hover,
.sidebar.rail [data-tooltip]:focus-within {
    z-index: 200;
}

/* Only ::after is used for the bubble so design-nav-row.active::before
   (accent bar) is not overwritten. */
.sidebar.rail [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 50%;
    left: calc(100% + 10px);
    z-index: 400;
    max-width: 220px;
    padding: 7px 11px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-primary) 92%, #000 8%);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 70%, transparent),
        0 10px 28px rgba(0, 0, 0, 0.32);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.01em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-6px, -50%);
    transition:
        opacity 140ms ease,
        transform 140ms ease,
        visibility 140ms ease;
}

/* Row wrappers: hover the row or focus the control inside. */
.sidebar.rail [data-tooltip]:hover::after,
.sidebar.rail [data-tooltip]:focus-visible::after,
.sidebar.rail [data-tooltip]:focus-within::after {
    opacity: 1;
    visibility: visible;
    transform: translate(0, -50%);
}

[data-theme="light"] .sidebar.rail [data-tooltip]::after {
    background: #ffffff;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--border) 85%, transparent),
        0 8px 20px rgba(15, 23, 42, 0.12);
    color: var(--text-primary);
}

@media (prefers-reduced-motion: reduce) {
    .sidebar.rail [data-tooltip]::after {
        transition: none;
    }
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.sidebar-cost {
    display: flex;
    flex-direction: column;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-cost .cost-label {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.sidebar-cost .cost-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar.rail .sidebar-footer {
    display: none;
}

/* --- Mobile Bottom Nav --- */
.mobile-bottom-nav {
    display: none;
}

.mobile-nav-item {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 54px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.mobile-nav-item.active {
    color: var(--text-primary);
}

.mobile-nav-current.active {
    color: var(--accent);
}

.mobile-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.mobile-nav-icon svg {
    width: 20px;
    height: 20px;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
}
