/**
 * Jatelgram Layout – Sidebar Advanced & Scrollbars
 * @version 3.4.0 – Fixed mobile footer visibility (100% height, proper flex)
 */

/* Reset html/body height for mobile */
html, body { height: 100%; margin: 0; padding: 0; }

/* Sidebar Container – use 100% height instead of 100vh for mobile compatibility */
.sidebar-advanced { position: fixed; top: 0; left: 0; height: 100%; width: var(--sidebar-width, var(--sidebar-width-expanded)); background: var(--farghar-footer-bg, #ffffff); border-right: 1px solid var(--farghar-footer-border, #e6e6e6); z-index: 1100; display: flex; flex-direction: column; transition: var(--sidebar-transition); transform: translateX(0); overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--farghar-text-primary, #1a1e23); }
.sidebar-advanced.collapsed { width: var(--sidebar-width-collapsed); }
.sidebar-advanced.resizing-transition { transition: width 0.25s cubic-bezier(0.2, 0.9, 0.4, 1.1); }
body.dark .sidebar-advanced { background: var(--farghar-header-bg, #0d1117); border-right-color: var(--farghar-header-border, #30363d); }

/* Resize Handle (desktop only) */
.sidebar-resize-handle { position: absolute; top: 0; right: calc(-1 * var(--sidebar-resize-handle-width) / 2); width: var(--sidebar-resize-handle-width); height: 100%; cursor: ew-resize; background: transparent; z-index: 1200; transition: background var(--farghar-transition-fast, 0.12s ease-out); }
.sidebar-resize-handle:hover, .sidebar-resize-handle:active { background: rgba(174,130,38,0.3); }
.sidebar-resize-handle:active { background: rgba(174,130,38,0.5); }
.sidebar-advanced.collapsed .sidebar-resize-handle, .sidebar-advanced.mobile-open .sidebar-resize-handle { display: none; }
@media (max-width: 1024px) { .sidebar-resize-handle { display: none; } }
body.dark .sidebar-resize-handle:hover, body.dark .sidebar-resize-handle:active { background: rgba(204,164,62,0.3); }
body.dark .sidebar-resize-handle:active { background: rgba(204,164,62,0.5); }

/* Sidebar Header – fixed at top */
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--farghar-space-md, 16px); height: 64px; border-bottom: 1px solid var(--farghar-footer-border, #e6e6e6); flex-shrink: 0; }
.sidebar-logo-wrapper { display: flex; align-items: center; gap: var(--farghar-space-md, 12px); }
.sidebar-favicon { width: 28px; height: 28px; border-radius: var(--farghar-radius-sm, 6px); flex-shrink: 0; object-fit: cover; }
.sidebar-logo { font-size: 1.2rem; font-weight: 600; text-decoration: none; color: var(--farghar-text-primary, #1a1e23); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.sidebar-logo:hover { text-decoration: underline; opacity: 0.8; }
.collapsed .sidebar-logo { display: none; }
.collapsed .sidebar-logo-wrapper { justify-content: center; }
.collapsed .sidebar-favicon { margin: 0 auto; }
.sidebar-header-actions { display: flex; gap: var(--farghar-space-sm, 8px); }
.sidebar-icon-btn { background: none; border: none; cursor: pointer; width: 32px; height: 32px; border-radius: var(--farghar-radius-sm, 8px); display: flex; align-items: center; justify-content: center; color: var(--farghar-text-secondary, #6c757d); transition: background var(--farghar-transition-fast, 0.12s ease-out); }
.sidebar-icon-btn:hover { background: rgba(0,0,0,0.04); color: var(--farghar-text-primary, #1a1e23); }
.sidebar-icon-btn:focus-visible { outline: 2px solid var(--farghar-gold, #ae8226); outline-offset: 2px; }
.collapsed .sidebar-header-actions .sidebar-icon-btn:first-child { margin-left: auto; }
.sidebar-advanced.collapsed #sidebar-collapse-toggle { display: none; }
.sidebar-advanced.collapsed .sidebar-header { justify-content: center; padding: 0; }
.sidebar-advanced.collapsed .sidebar-header-actions { display: none; }
.sidebar-advanced.collapsed .sidebar-logo-wrapper { justify-content: center; width: 100%; gap: 0; }
.sidebar-advanced.collapsed .sidebar-favicon { width: 36px; height: 36px; margin: 0 auto; }
.sidebar-advanced.collapsed .sidebar-resize-handle { display: none; }

/* Middle area – scrollable (main menu + secondary links) */
.sidebar-middle { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; min-height: 0; }

/* Main Menu */
.sidebar-main-menu { padding: 12px 8px; border-bottom: 1px solid var(--farghar-footer-border, #e6e6e6); }
.sidebar-menu-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 6px; border-radius: 12px; text-decoration: none; color: var(--farghar-text-primary, #1a1e23); transition: background 0.12s ease-out; }
.sidebar-menu-item:last-child { margin-bottom: 0; }
.sidebar-menu-item:hover { background: rgba(0,0,0,0.04); }
.sidebar-menu-item.active { background: rgba(174,130,38,0.1); color: var(--farghar-gold, #ae8226); }
.sidebar-menu-icon { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; stroke-width: 1.8; fill: none; }
.sidebar-menu-label { font-size: 0.9rem; font-weight: 500; white-space: nowrap; }
.collapsed .sidebar-menu-label { display: none; }
.collapsed .sidebar-menu-item { justify-content: center; padding: 10px 0; }
.collapsed .sidebar-menu-icon { width: 24px; height: 24px; }
body.dark .sidebar-menu-item:hover { background: rgba(255,255,255,0.08); }
body.dark .sidebar-menu-item.active { background: rgba(204,164,62,0.15); color: var(--farghar-gold-light, #cca43e); }

/* Secondary Links */
.sidebar-secondary-links { padding: 12px 8px; }
.sidebar-secondary-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin-bottom: 4px; border-radius: 12px; text-decoration: none; color: var(--farghar-text-secondary, #57606a); transition: background 0.12s ease-out; }
.sidebar-secondary-item:last-child { margin-bottom: 0; }
.sidebar-secondary-item:hover { background: rgba(0,0,0,0.04); color: var(--farghar-text-primary, #1a1e23); }
.sidebar-secondary-item.active { background: rgba(174,130,38,0.1); color: var(--farghar-gold, #ae8226); }
.sidebar-secondary-icon { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; stroke-width: 1.8; fill: none; }
.sidebar-secondary-label { font-size: 0.85rem; font-weight: 400; white-space: nowrap; }
.collapsed .sidebar-secondary-links { display: none; }
body.dark .sidebar-secondary-item:hover { background: rgba(255,255,255,0.08); color: var(--farghar-text-primary, #e6edf3); }
body.dark .sidebar-secondary-item.active { background: rgba(204,164,62,0.15); color: var(--farghar-gold-light, #cca43e); }

/* Sidebar Footer – fixed at bottom, always visible */
.sidebar-footer { border-top: 1px solid var(--farghar-footer-border, #e6e6e6); padding: var(--farghar-space-md, 12px) var(--farghar-space-md, 16px); flex-shrink: 0; display: flex; align-items: center; gap: var(--farghar-space-md, 12px); cursor: pointer; transition: background var(--farghar-transition-fast, 0.12s ease-out); position: relative; background: var(--farghar-footer-bg, #fff); width: 100%; box-sizing: border-box; }
.sidebar-footer:hover { background: rgba(0,0,0,0.04); }
body.dark .sidebar-footer { background: var(--farghar-header-bg, #0d1117); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--farghar-gold, #ae8226); display: flex; align-items: center; justify-content: center; color: var(--farghar-white, #fff); font-weight: bold; flex-shrink: 0; overflow: hidden; }
.user-avatar-img { width: 100%; height: 100%; object-fit: cover; }
.user-avatar-initial { font-size: 1rem; font-weight: bold; color: white; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 0.7rem; color: var(--farghar-text-secondary, #6c757d); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-icon-btn { background: none; border: none; cursor: pointer; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--farghar-text-secondary, #6c757d); transition: background 0.2s; flex-shrink: 0; }
.settings-icon-btn:hover { background: rgba(0,0,0,0.04); color: var(--farghar-text-primary, #1a1e23); }
.user-dropdown { position: absolute; bottom: 100%; left: 16px; right: 16px; background: var(--farghar-footer-bg, #fff); border: 1px solid var(--farghar-footer-border, #e6e6e6); border-radius: var(--farghar-radius-md, 12px); box-shadow: var(--farghar-shadow-md, 0 2px 6px rgba(0,0,0,0.08)); z-index: 1300; margin-bottom: 8px; overflow: hidden; }
.user-dropdown .dropdown-item { display: block; padding: var(--farghar-space-sm, 8px) var(--farghar-space-md, 16px); text-decoration: none; color: var(--farghar-text-primary, #1a1e23); transition: background 0.2s; }
.user-dropdown .dropdown-item:hover { background: rgba(0,0,0,0.04); }
body.dark .user-dropdown { background: var(--farghar-header-bg, #0d1117); border-color: var(--farghar-header-border, #30363d); }
body.dark .user-dropdown .dropdown-item { color: var(--farghar-text-primary, #e6edf3); }
body.dark .user-dropdown .dropdown-item:hover { background: rgba(255,255,255,0.08); }
.collapsed .user-info, .collapsed .settings-icon-btn, .collapsed .user-dropdown { display: none; }
.collapsed .sidebar-footer { justify-content: center; }
.collapsed .user-avatar { margin: 0 auto; }

/* Guest Invite Card & Login Icon (inside sidebar-footer for guests) */
.guest-invite-card { margin: 0; padding: 12px; background: var(--farghar-footer-bg, #f6f8fa); border: 1px solid var(--farghar-footer-border, #d0d7de); border-radius: var(--farghar-radius-lg, 12px); text-align: center; width: 100%; }
.sidebar-advanced.collapsed .guest-invite-card { display: none; }
.guest-invite-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 8px; color: var(--farghar-text-primary, #1a1e23); }
.guest-invite-description { font-size: 0.75rem; line-height: 1.3; margin-bottom: 12px; color: var(--farghar-text-secondary, #57606a); }
.guest-invite-btn { display: inline-block; padding: 6px 16px; background: var(--farghar-gold, #ae8226); color: #fff; border-radius: 30px; text-decoration: none; font-weight: 500; font-size: 0.8rem; transition: background 0.2s, transform 0.1s; }
.guest-invite-btn:hover { background: var(--farghar-gold-dark, #7c530b); transform: scale(1.02); }
.guest-login-icon { display: flex; align-items: center; justify-content: center; margin: 0 auto; width: 40px; height: 40px; border-radius: 50%; background: var(--farghar-gold, #ae8226); transition: background 0.2s, transform 0.1s; cursor: pointer; }
.guest-login-icon svg { width: 24px; height: 24px; stroke: #fff; stroke-width: 1.5; fill: none; }
.guest-login-icon:hover { background: var(--farghar-gold-dark, #7c530b); transform: scale(1.05); }
.sidebar-advanced:not(.collapsed) .guest-login-icon { display: none; }
body.dark .guest-invite-card { background: var(--farghar-header-bg, #0d1117); border-color: var(--farghar-header-border, #30363d); }
body.dark .guest-invite-title { color: var(--farghar-text-primary, #e6edf3); }
body.dark .guest-invite-description { color: var(--farghar-text-secondary, #8b949e); }
body.dark .guest-invite-btn { background: var(--farghar-gold-light, #cca43e); color: #0d1117; }
body.dark .guest-invite-btn:hover { background: var(--farghar-gold, #ae8226); color: #fff; }
body.dark .guest-login-icon { background: var(--farghar-gold-light, #cca43e); }
body.dark .guest-login-icon svg { stroke: #0d1117; }
body.dark .guest-login-icon:hover { background: var(--farghar-gold, #ae8226); }
body.dark .guest-login-icon:hover svg { stroke: #fff; }

/* Mobile Overlay */
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1050; opacity: 0; visibility: hidden; transition: opacity 0.25s, visibility 0.25s; }
.sidebar-overlay.active { opacity: 1; visibility: visible; }

/* Mobile Specific Styles – enforce flex structure with 100% height */
.mobile-sidebar-toggle { display: none; }
@media (max-width: 1024px) { 
    .mobile-sidebar-toggle { display: flex; } 
    .sidebar-advanced { transform: translateX(-100%); height: 100%; } 
    .sidebar-advanced.mobile-open { transform: translateX(0); display: flex; flex-direction: column; height: 100%; overflow: hidden; }
    .sidebar-middle { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
    .sidebar-header, .sidebar-footer { flex-shrink: 0; }
    .sidebar-advanced .sidebar-favicon, .sidebar-advanced #sidebar-collapse-toggle { display: none; }
    .sidebar-overlay.active { display: block; }
}
@media (min-width: 1025px) { .mobile-sidebar-toggle, .menu-toggle { display: none !important; } }

/* Responsive Footer in Small Widths (tablet/mobile) */
@media (max-width: 600px) {
    .sidebar-footer { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
    .user-info { min-width: 0; max-width: calc(100% - 70px); }
    .user-name, .user-email { white-space: normal; word-break: break-word; }
    .settings-icon-btn { margin-left: auto; margin-right: 0; }
    .guest-invite-card { padding: 10px; }
    .guest-invite-title { font-size: 0.85rem; }
    .guest-invite-description { font-size: 0.7rem; }
}

/* Custom Scrollbar (only for desktop, mobile uses native) */
@media (min-width: 1025px) {
    .sidebar-advanced, .sidebar__scroll-area { scrollbar-width: thin; scrollbar-color: var(--farghar-gold) var(--farghar-footer-border); }
    .sidebar-advanced::-webkit-scrollbar, .sidebar__scroll-area::-webkit-scrollbar { width: 6px; height: 6px; }
    .sidebar-advanced::-webkit-scrollbar-track, .sidebar__scroll-area::-webkit-scrollbar-track { background: var(--farghar-footer-border, #e6e6e6); border-radius: 3px; }
    .sidebar-advanced::-webkit-scrollbar-thumb, .sidebar__scroll-area::-webkit-scrollbar-thumb { background: var(--farghar-gold, #ae8226); border-radius: 3px; transition: background 0.2s; }
    .sidebar-advanced::-webkit-scrollbar-thumb:hover, .sidebar__scroll-area::-webkit-scrollbar-thumb:hover { background: var(--farghar-gold-dark, #7c530b); }
    body.dark .sidebar-advanced::-webkit-scrollbar-track, body.dark .sidebar__scroll-area::-webkit-scrollbar-track { background: var(--farghar-header-border, #30363d); }
    body.dark .sidebar-advanced::-webkit-scrollbar-thumb, body.dark .sidebar__scroll-area::-webkit-scrollbar-thumb { background: var(--farghar-gold-light, #cca43e); }
}

/* RTL Overrides for Sidebar */
body.rtl .sidebar-advanced { left: auto; right: 0; border-right: none; border-left: 1px solid var(--farghar-footer-border, #e6e6e6); }
body.rtl .sidebar-resize-handle { right: auto; left: calc(-1 * var(--sidebar-resize-handle-width) / 2); }
body.rtl .sidebar-advanced.mobile-open { transform: translateX(0); }
@media (max-width: 1024px) { body.rtl .sidebar-advanced { transform: translateX(100%); } body.rtl .sidebar-advanced.mobile-open { transform: translateX(0); } }
body.rtl .sidebar-icon-btn .sidebar-logo-wrapper { flex-direction: row-reverse; }
body.rtl .sidebar-menu-item, body.rtl .sidebar-secondary-item { flex-direction: row-reverse; text-align: right; }
body.rtl .sidebar-menu-icon, body.rtl .sidebar-secondary-icon { margin-left: 12px; margin-right: 0; }
body.rtl .sidebar-footer { flex-direction: row-reverse; }
body.rtl .user-info { text-align: right; }
body.rtl .user-dropdown { left: 16px; right: 16px; }
body.rtl .sidebar-advanced.collapsed .sidebar-footer { justify-content: center; }