/**
 * Sidebar Component - CSS
 * 
 * Ported from ui-core
 * Source: src/components/Organisms/Sidebar/Sidebar.tsx
 * Design tokens: src/index.css
 * 
 * Tailwind classes have been converted to vanilla CSS.
 * See README.md in this directory for sync instructions.
 *
 * Last synced: 2026-04-14 (ui-core v2.0.81)
 *
 * v2.0.81 changes: trailingBadge, collapsedTrailingBadge, external-link
 *   ArrowUpRight icon, expandedWidthClassName prop (CSS-side: label is now a
 *   flex row when expanded so badge + external icon sit inline).
 */

@import '../tokens.css';

/* ===== Sidebar Container ===== */
:is(#app-sidebar, .sidebar-root) {
    display: flex;
    flex-direction: column;
    /* Fallback avoids transparent panel if `--sidebar` / tokens fail to load */
    background-color: var(--uicore-sidebar, #ffffff);
    border-right: 1px solid var(--color-gray-200, #edf1f2);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 50;
    transition: all 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-no-transition,
.app-layout.sidebar-no-transition {
    transition: none !important;
}

/* Sidebar States */
:is(#app-sidebar, .sidebar-root).sidebar-expanded {
    width: 256px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed {
    width: 64px;
}

:is(#app-sidebar, .sidebar-root).sidebar-hidden {
    width: 0;
    pointer-events: none;
    overflow: hidden;
}

/* ===== Sidebar Header (Logo + Toggle) ===== */
.sidebar-header {
    display: flex;
    width: 100%;
    padding-bottom: 8px;
    transition: all 0.3s ease-in-out;
    justify-content: center;
    align-items: center;
}

.sidebar-logo {
    display: flex;
    padding-top: 16px;
    transition: all 0.3s ease-in-out;
    text-decoration: none;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-logo {
    justify-content: flex-start;
    padding-left: 24px;
    padding-right: 24px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-logo {
    justify-content: center;
    width: 100%;
}

.sidebar-logo img {
    transition: all 0.3s ease-in-out;
}

.sidebar-logo-full {
    width: 140px;
    height: 40px;
}

.sidebar-logo-mini {
    width: 32px;
    height: 32px;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-logo-full {
    display: block;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-logo-mini {
    display: none;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-logo-full {
    display: none;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-logo-mini {
    display: block;
}

/*
 * Toggle stroke: between rail icons (--color-neutral-400) and body-muted text
 * (--uicore-muted-foreground). Matches ui-core menu control contrast without matching
 * either extreme.
 */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--color-neutral-500, hsl(210 11% 43%));
    cursor: pointer;
    transition: all 0.3s ease-in-out;
}

.dark .sidebar-toggle {
    color: var(--uicore-muted-foreground);
}

.sidebar-toggle:hover {
    background-color: rgba(0, 197, 123, 0.05);
    color: var(--color-green, #00c57b);
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-toggle {
    align-self: flex-end;
}

/* Toggle section below header when collapsed */
.sidebar-toggle-section {
    padding: 8px;
    border-top: 1px solid var(--color-gray-200, #edf1f2);
    transition: all 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-toggle-section {
    display: flex;
    justify-content: flex-end;
    padding-left: 24px;
    padding-right: 24px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-toggle-section {
    display: flex;
    justify-content: center;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-header .sidebar-toggle {
    display: none;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-toggle-section .sidebar-toggle {
    display: none;
}

/* ===== Navigation ===== */
.sidebar-nav {
    transition: all 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-nav {
    padding: 0 24px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-nav {
    padding: 0 8px;
}

/* Navigation Items */
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 12px 8px;
    font-size: 14px;
    line-height: 20px; /* Tailwind v4 text-sm = 14px/20px */
    font-weight: 500;
    border-radius: 8px; /* Tailwind v4 rounded-md */
    text-decoration: none;
    color: var(--uicore-foreground);
    transition: all 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-item {
    justify-content: flex-start;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-item {
    justify-content: center;
}

.sidebar-item:hover {
    background-color: rgba(0, 197, 123, 0.05);
    color: var(--color-green-700, #009960);
}

.sidebar-item.active {
    background-color: rgba(0, 197, 123, 0.1);
    color: var(--color-green, #00c57b);
}

/* Item Icon — light theme: softer than `muted-foreground` (aligned with section labels). Dark: use semantic muted. */
.sidebar-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    transition: all 0.3s ease-in-out;
    color: var(--color-neutral-400, hsl(210 12% 61%));
}

.dark .sidebar-item-icon {
    color: var(--uicore-muted-foreground);
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-item-icon {
    margin-right: 12px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-item-icon {
    margin-right: 0;
}

.sidebar-item:hover .sidebar-item-icon {
    color: var(--color-green, #00c57b);
}

.sidebar-item.active .sidebar-item-icon {
    color: var(--color-green, #00c57b);
}

/* Item Label — expanded: flex row so badge + external icon sit inline */
.sidebar-item-label {
    transition: all 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-item-label {
    opacity: 1;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px; /* Tailwind gap-1.5 */
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-item-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    flex: 0;
}

/* Inner text span inside label (line-clamp-3, word-wrap) */
.sidebar-item-label-text {
    min-width: 0;
    flex: 1;
    text-align: left;
    overflow-wrap: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Trailing Badge (orange chip — normalizeSidebarTrailingBadge) ===== */
.sidebar-trailing-badge {
    flex-shrink: 0;
    border-radius: 9999px;
    background-color: var(--color-orange-100, #ffedd5);
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--color-orange-600, #ea580c);
}

.dark .sidebar-trailing-badge {
    background-color: rgba(154, 52, 18, 0.5); /* orange-950/50 */
    color: var(--color-orange-400, #fb923c);
}

/* ===== Collapsed Badge Overlay (collapsedTrailingBadge on icon) ===== */
.sidebar-collapsed-badge-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-collapsed-badge-wrap {
    margin-right: 12px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-collapsed-badge-wrap {
    margin-right: 0;
}

/* Hide badge overlay when expanded (React only renders it when collapsed) */
:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-collapsed-badge-overlay {
    display: none;
}

.sidebar-collapsed-badge-overlay {
    pointer-events: none;
    position: absolute;
    right: -2px;
    top: -2px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ===== External Link Icon (ArrowUpRight) ===== */
.sidebar-external-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--color-neutral-500, hsl(210 11% 43%));
    transition: all 0.3s ease-in-out;
}

.sidebar-item:hover .sidebar-external-icon {
    color: var(--color-green, #00c57b);
}

.dark .sidebar-external-icon {
    color: var(--color-white, #ffffff);
}

.dark .sidebar-item:hover .sidebar-external-icon {
    color: var(--color-green-400);
}

/* ===== Section Labels ===== */
.sidebar-section-label {
    padding: 0 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-neutral-400, #8f9aa8);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: opacity 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-section-label {
    opacity: 1;
    height: auto;
    margin-bottom: 8px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-section-label {
    opacity: 0;
    height: 0;
    overflow: hidden;
    margin-bottom: 0;
}

/* ===== Sidebar Sections ===== */
.sidebar-section {
    transition: all 0.3s ease-in-out;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-section {
    margin-top: 16px;
    padding: 0 24px;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-section {
    padding: 0 8px;
}

/* Section dividers between mainSections */
.sidebar-section-divider {
    border-top: 1px solid var(--color-gray-200, #edf1f2);
    padding-top: 16px;
    margin-top: 16px;
}

.sidebar-section nav {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ===== User Profile Section ===== */
.sidebar-user {
    margin-top: auto;
    border-top: 1px solid var(--color-gray-200, #edf1f2);
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-user {
    padding: 8px;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-user {
    padding: 16px;
}

.sidebar-user-collapsed {
    display: flex;
    justify-content: center;
}

/* Expanded view: centered vertical layout (matches ui-core v2.0.76) */
.sidebar-user-expanded {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.sidebar-user-expanded-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

:is(#app-sidebar, .sidebar-root).sidebar-expanded .sidebar-user-collapsed {
    display: none;
}

:is(#app-sidebar, .sidebar-root).sidebar-collapsed .sidebar-user-expanded {
    display: none;
}

/* Avatar */
.sidebar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--color-gray-200, #edf1f2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-gray-600, #4e4e4e);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* User Info */
.sidebar-user-info {
    text-align: center;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--uicore-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.sidebar-user-email {
    font-size: 10px;
    color: var(--uicore-muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

/* Logout Button */
.sidebar-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-orange, #f98d00);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s ease;
}

.sidebar-logout:hover {
    color: var(--color-orange-400, #f19202);
}

.sidebar-logout:focus-visible {
    outline: 2px solid var(--color-orange, #f98d00);
    outline-offset: 2px;
    border-radius: 2px;
}

.sidebar-logout svg {
    width: 14px;
    height: 14px;
}

/* ===== Responsive Styles ===== */
/* Above 1024px (Tailwind lg): sticky sidebar — keep z-index 50 so main content cannot paint above */
@media (min-width: 1024px) {
    :is(#app-sidebar, .sidebar-root) {
        position: sticky;
        z-index: 50;
    }
}

/* Below 1024px: fixed drawer with overlay */
@media (max-width: 1023px) {
    :is(#app-sidebar, .sidebar-root) {
        position: fixed;
        z-index: 1000;
    }

    :is(#app-sidebar, .sidebar-root).sidebar-no-transition {
        width: 0;
        pointer-events: none;
        overflow: hidden;
    }

    /* Open drawer: solid surface + interaction (overrides no-transition if both classes briefly overlap) */
    :is(#app-sidebar, .sidebar-root).sidebar-expanded {
        width: 256px;
        pointer-events: auto;
        overflow-y: auto;
        background-color: var(--uicore-sidebar, #ffffff);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-content {
    flex: 1;
    min-width: 0;
    transition: margin-left 0.3s ease-in-out;
    padding: 0 16px;
}

@media (max-width: 1023px) {
    .app-content {
        margin-left: 0;
        padding: 0;
    }
}

/* ===== Disabled Items ===== */
.sidebar-item.disabled {
    color: var(--color-neutral-500, hsl(210 11% 43%));
    cursor: not-allowed;
}

.sidebar-item.disabled .sidebar-item-icon {
    color: var(--color-neutral-500, hsl(210 11% 43%));
}

.sidebar-item.disabled:hover {
    background-color: transparent;
    color: var(--color-neutral-400, #8f9aa8);
}
