/* ═══════════════════════════════════════════════════════════════════════════
   sidebar.css  —  GigaNexus ERP
   Dedicated sidebar stylesheet. Loaded via <link> in layout.php.
   Old sidebar rules in style.css are kept for backward compat with
   sidebar_*.php files not yet migrated.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens scoped to the sidebar ──────────────────────────────── */
#appSidebar {
    --sb-width:           260px;
    --sb-width-collapsed: 64px;
    --sb-icon-size:       18px;
    --sb-item-radius:     7px;
    --sb-item-hover:      rgba(255,255,255,0.10);
    --sb-item-active:     rgba(255,255,255,0.20);
    --sb-tree-line:       rgba(255,255,255,0.22);
    --sb-search-bg:       rgba(0,0,0,0.20);
    --sb-search-border:   rgba(255,255,255,0.12);
    --sb-flyout-bg:       rgba(15,23,42,0.97);
    --sb-flyout-border:   rgba(255,255,255,0.10);
    --sb-transition:      0.28s ease;
}

/* ── Base sidebar ──────────────────────────────────────────────────────── */
#appSidebar {
    width: var(--sb-width);
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 1.25rem 0.75rem;
    transition: width var(--sb-transition), padding var(--sb-transition);
    overflow-y: auto;
    overflow-x: hidden;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative; /* for z-index stacking */
}

#appSidebar.collapsed {
    width: var(--sb-width-collapsed);
    padding: 1.25rem 0.45rem;
}

/* ── Logo area ─────────────────────────────────────────────────────────── */
.sb-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
    min-height: 52px;
}

.sb-logo-full {
    max-width: 130px;
    max-height: 56px;
    object-fit: contain;
    transition: opacity var(--sb-transition), max-width var(--sb-transition);
}

.sb-logo-monogram {
    display: none;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: var(--sidebar-text);
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#appSidebar.collapsed .sb-logo-full       { display: none; }
#appSidebar.collapsed .sb-logo-monogram   { display: flex; }

/* ── Search box ────────────────────────────────────────────────────────── */
.sb-search-wrap {
    position: relative;
    margin-bottom: 1rem;
    transition: opacity var(--sb-transition);
}

#appSidebar.collapsed .sb-search-wrap {
    display: none;
}

.sb-search-wrap .nav-icon.sb-search-icon {
    position: absolute;
    inset-inline-start: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    pointer-events: none;
    width: 15px;
    height: 15px;
}

#sidebarSearch {
    width: 100%;
    box-sizing: border-box;
    padding: 0.5rem 3.5rem 0.5rem 2rem;
    background: var(--sb-search-bg);
    border: 1px solid var(--sb-search-border);
    border-radius: 8px;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
html[dir="rtl"] #sidebarSearch {
    padding: 0.5rem 2rem 0.5rem 3.5rem;
}

#sidebarSearch::placeholder {
    color: rgba(255,255,255,0.4);
}

#sidebarSearch:focus {
    border-color: rgba(255,255,255,0.35);
    background: rgba(0,0,0,0.28);
}

.sb-search-hint {
    position: absolute;
    inset-inline-end: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    pointer-events: none;
    opacity: 0.45;
}

.sb-search-hint kbd {
    font-family: inherit;
    font-size: 0.68rem;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 3px;
    padding: 0.05rem 0.28rem;
    line-height: 1.5;
    color: inherit;
}

#sidebarSearch:focus ~ .sb-search-hint {
    opacity: 0;
}

/* ── Sidebar menu list ─────────────────────────────────────────────────── */
.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
}

/* ── Section label ─────────────────────────────────────────────────────── */
.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    opacity: 0.5;
    padding: 0.5rem 0.5rem 0.2rem;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
}

#appSidebar.collapsed .sidebar-section-label {
    display: none;
}

/* ── Nav icon (unified SVG icon) ──────────────────────────────────────── */
.nav-icon {
    width: var(--sb-icon-size);
    height: var(--sb-icon-size);
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    display: block;
}

/* ── Sidebar link (unified style) ─────────────────────────────────────── */
.sidebar-link {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.6rem;
    border-radius: var(--sb-item-radius);
    transition: background-color 0.18s;
    min-width: 0;
    position: relative;
}

.sidebar-link:hover {
    background-color: var(--sb-item-hover);
}

.sidebar-link.active {
    background-color: var(--sb-item-active);
    font-weight: 700;
}

/* Active indicator bar (inline-end edge) */
html[dir="rtl"] .sidebar-link.active::before {
    content: '';
    position: absolute;
    right: 0;
    top: 18%;
    height: 64%;
    width: 3px;
    background: #fff;
    border-radius: 3px 0 0 3px;
}
html[dir="ltr"] .sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 18%;
    height: 64%;
    width: 3px;
    background: #fff;
    border-radius: 0 3px 3px 0;
}

/* In collapsed mode: center icon, hide label + chevron */
#appSidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 0.6rem 0;
}

/* ── Label span (ellipsis) ─────────────────────────────────────────────── */
.sidebar-link .label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

/* Keep legacy .text for backward compat with unmigrated files */
.sidebar-link .text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

#appSidebar.collapsed .sidebar-link .label,
#appSidebar.collapsed .sidebar-link .text {
    display: none;
}

/* ── Chevron arrow ─────────────────────────────────────────────────────── */
.sidebar-link .chevron {
    flex-shrink: 0;
    opacity: 0.55;
    transition: transform 0.22s;
    margin-inline-start: auto;
}

/* No arrows in collapsed mode */
#appSidebar.collapsed .sidebar-link .chevron {
    display: none;
}

.sidebar-dropdown.open > .sidebar-link > .chevron,
.sidebar-dropdown.open > a > .chevron {
    transform: rotate(180deg);
}

/* ── Active dot badge ──────────────────────────────────────────────────── */
.active-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    margin-inline-start: auto;
    flex-shrink: 0;
    opacity: 0.85;
}

#appSidebar.collapsed .active-dot {
    display: none;
}

/* ── Dropdown menu (first-level children) ─────────────────────────────── */
.dropdown-menu {
    display: none;
    list-style: none;
    padding: 0.2rem 0;
    margin: 0;
}

.sidebar-dropdown.open > .dropdown-menu {
    display: block;
}

/* In collapsed mode: never show inline dropdown */
#appSidebar.collapsed .dropdown-menu {
    display: none !important;
}

/* ── Tree line for child links ─────────────────────────────────────────── */
.dropdown-menu,
.subdropdown-menu {
    padding-inline-start: 0.6rem;
    border-inline-start: 1.5px solid var(--sb-tree-line);
    margin-inline-start: 1.1rem;
    margin-top: 0.1rem;
    margin-bottom: 0.15rem;
}

/* ── Sub-links (children) ──────────────────────────────────────────────── */
.sidebar-link.sub-link {
    padding: 0.38rem 0.5rem;
    font-size: 0.845rem;
    border-radius: 5px;
}

.sidebar-link.sub-link.active {
    background-color: rgba(255,255,255,0.16);
}

/* ── Sub-dropdown (inventory group headers) ────────────────────────────── */
.sidebar-subdropdown-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.42rem 0.5rem;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    border-radius: 5px;
    transition: color 0.15s, background-color 0.15s;
    gap: 0.4rem;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-subdropdown-toggle:hover {
    color: rgba(255,255,255,0.9);
    background-color: rgba(255,255,255,0.06);
}

.sidebar-subdropdown-toggle .label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.subdropdown-menu {
    display: none;
    list-style: none;
    padding: 0;
    margin-bottom: 0.25rem;
}

.subdropdown-menu.open {
    display: block;
}

.sidebar-subdropdown-toggle .chevron {
    flex-shrink: 0;
    opacity: 0.5;
    transition: transform 0.22s;
}

.sidebar-subdropdown-toggle.open .chevron {
    transform: rotate(180deg);
}

/* ── Flyout submenu (collapsed mode) ───────────────────────────────────── */
.sidebar-flyout {
    position: fixed;
    z-index: 9999;
    min-width: 200px;
    max-width: 240px;
    background: var(--sb-flyout-bg);
    border: 1px solid var(--sb-flyout-border);
    border-radius: 10px;
    padding: 0.4rem 0.3rem;
    box-shadow: 0 16px 40px rgba(0,0,0,0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: none;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.18s, transform 0.18s;
}

html[dir="rtl"] .sidebar-flyout {
    transform: translateX(6px);
}

.sidebar-flyout.visible {
    pointer-events: auto;
    opacity: 1;
    transform: translateX(0);
}

.sidebar-flyout .flyout-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    opacity: 0.5;
    padding: 0.25rem 0.5rem 0.35rem;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-flyout a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.55rem;
    border-radius: 6px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.855rem;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-flyout a:hover,
.sidebar-flyout a:focus {
    background: rgba(255,255,255,0.1);
    outline: none;
}

.sidebar-flyout a.active {
    background: rgba(255,255,255,0.18);
    font-weight: 600;
}

.sidebar-flyout .flyout-group-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.42;
    padding: 0.55rem 0.5rem 0.2rem;
    color: #fff;
}

/* ── Divider ────────────────────────────────────────────────────────────── */
.sb-divider {
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 0.5rem 0.25rem;
}

/* ── Favorites divider ─────────────────────────────────────────────────── */
.sb-fav-divider {
    height: 1px;
    background: var(--sb-tree-line);
    margin: 0.4rem 0.25rem 0.5rem;
}

/* ── RTL / LTR sidebar border ──────────────────────────────────────────── */
html[dir="rtl"] #appSidebar {
    border-left: 1px solid rgba(255,255,255,0.06);
}
html[dir="ltr"] #appSidebar {
    border-right: 1px solid rgba(255,255,255,0.06);
}

/* ── Scrollbar inside sidebar ──────────────────────────────────────────── */
#appSidebar::-webkit-scrollbar {
    width: 4px;
}
#appSidebar::-webkit-scrollbar-track {
    background: transparent;
}
#appSidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.18);
    border-radius: 4px;
}

/* ── Hover tooltip for collapsed icons (title attr handled natively) ────── */
#appSidebar.collapsed .sidebar-link {
    position: relative;
}
