/**
 * ==========================================
 * SIDEBAR
 * Sol menü ve navigasyon stilleri
 * ==========================================
 */

/* ========== ANA SIDEBAR ========== */
.sidebar {
    width: var(--by-sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    padding: 0; /* 0 12px değeri 0 olarak güncellendi */
    /* Renkler ve Katman */
    /* Template ile aynı hissi veren dikey gradient + hafif gölge */
    background: linear-gradient(to bottom, #1e293b, #1e293b, #0f172a);
    color: #ffffff;
    font-family: var(--by-font-main);
    z-index: var(--z-sidebar); /* Variables.css'ten gelir (1040) */
    /* Düzen */
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    overflow: visible; /* Logo dropdown; kaydırma .menu-items içinde */
    /* Geçiş Efekti */
    transition: transform var(--by-transition-slow), width var(--by-transition-slow);
    box-shadow: 2px 0 24px rgba(0, 0, 0, 0.10);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

/* ========== LOGO ALANI ========== */
.sidebar .logo {
    height: var(--by-topbar-height); /* 65px */
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    /* Arka planı kaldır: ana sidebar gradient'i logo alanında da devam etsin */
    background: transparent;
    border-bottom: none; /* Geçiş çizgisini kaldırdık */
    flex-shrink: 0; /* Logo alanı asla büzüşmesin */
    position: relative; /* Dropdown için gerekli */
    z-index: 40; /* Bina dropdown açıkken .menu-items (Gelirlerim vb.) üstüne binmesin */
    overflow: visible !important; /* Dropdown'un kesilmemesi için */
}

.sidebar .logo h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #ffffff;
}

/* Logo actions (toggle button container) */
.sidebar .logo .logo-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Toggle button */
.sidebar .logo .toggle-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    padding: 6px 10px;
    border-radius: var(--by-radius-md);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
}

.sidebar .logo .toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar .logo .toggle-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

/* Collapsed durumda toggle button görünür kalmalı */
body.sidebar-collapsed .sidebar .logo .toggle-btn {
    display: flex;
}

/* Apartman dropdown altı: Yazı Boyutu alt menüsü (yatay/sağa açılır) */
.sidebar .dropdown-menu-building .dropend .dropdown-toggle::after {
    margin-left: auto;
}
.sidebar .dropdown-menu-building .dropend .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: 0;
    margin-left: 2px;
    min-width: 140px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
/* ========== MENÜ LİSTESİ ========== */
.menu-items {
    list-style: none;
    margin: 0;
    padding: 14px 0;
    position: relative;
    z-index: 1;
    /* Flex içinde kaydırma: min-height:0 olmadan içerik sidebar’ı şişirir, scrollbar görünmez */
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(100vh - var(--by-topbar-height, 65px));
    overflow-y: auto;
    overflow-x: visible; /* Dropdown için yatay taşmaya izin ver */

    /* Scrollbar — solmenu’daki gibi görünür track + thumb (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.42) rgba(255, 255, 255, 0.08);
}

/* Webkit — track görünür; ince ama okunaklı */
.menu-items::-webkit-scrollbar {
    width: 6px;
}
.menu-items::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
}
.menu-items::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.35);
    border-radius: 6px;
}
.menu-items::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.52);
}

.menu-items li {
    display: flex;
    align-items: center;
    position: relative;
}

.sidebar .nav-item,
.sidebar .menu-items li {
    margin-bottom: 2px;
}

/* Ana menü satırları (tek link) — SaaS panel vurgusu */
.menu-items a.menu-item {
    display: flex;
    align-items: center;
    flex: 1;
    min-height: 44px;
    padding: 0 14px 0 28px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
    border-left: none;
    border-radius: 12px;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    z-index: 5;
}

.menu-items a.menu-item i {
    width: 28px;
    height: 28px;
    font-size: 14px;
    margin-right: 12px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.menu-items a.menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.menu-items a.menu-item:hover i {
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
}

/* Aktif: sol çizgi border-left yerine ::before (border-radius ile köşe çakışması olmasın) */
.menu-items a.menu-item.active {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    box-shadow: none;
}
.menu-items a.menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 3px;
    background: #818cf8;
    pointer-events: none;
}

.menu-items a.menu-item.active i {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    box-shadow: none;
}

.menu-items a.menu-item.active:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.menu-items a.menu-item.active:hover i {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

/* Legacy: sistem/solmenu.php — .menu-item sınıfı kullanılmaz */
.menu-items a:not(.menu-item) {
    display: flex;
    align-items: center;
    flex: 1;
    min-height: 44px;
    padding: 0 14px 0 28px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
    border-left: 4px solid transparent;
    border-radius: 12px;
    transition: all 0.18s var(--by-transition-normal);
    position: relative;
    z-index: 5;
}
.menu-items a:not(.menu-item) i {
    width: 28px;
    height: 28px;
    font-size: 14px;
    margin-right: 12px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
}
.menu-items a:not(.menu-item):hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #ffffff;
}
.menu-items a:not(.menu-item).active {
    font-weight: 600;
    background-color: rgba(255, 255, 255, 0.10);
    color: #ffffff;
    border-left-color: transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
.menu-items a:not(.menu-item).active i {
    background: #3B7FB9;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(59, 127, 185, 0.40);
}
.menu-items a:not(.menu-item).active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: #818cf8;
    border-radius: 0 2px 2px 0;
}

/* Gelirlerim üst menü + alt menü */
.sidebar .menu-items li.menu-item-has-children {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
}
.sidebar .menu-items li.menu-item-has-children .drag-handle {
    align-self: flex-start;
    height: 46px;
}
.sidebar .menu-items .menu-group-details {
    flex: 1;
    min-width: 0;
}
.sidebar .menu-items .menu-group-summary {
    display: flex;
    align-items: center;
    min-height: 46px;
    padding: 0 14px 0 28px;
    /* Tek linkli menülerle aynı pasif renk; seçiliymiş gibi görünmesin */
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    border-left: 4px solid transparent;
    transition: all 0.2s;
    position: relative;
    z-index: 15; /* Dropdown aç/kapa tıklanabilir olsun */
    pointer-events: auto;
    user-select: none;
}
.sidebar .menu-items .menu-group-summary::-webkit-details-marker { display: none; }
.sidebar .menu-items .menu-group-summary .menu-group-chevron {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.2s ease;
}
.sidebar .menu-items .menu-group-details[open] .menu-group-chevron {
    transform: rotate(-180deg);
}
.sidebar .menu-items .menu-group-summary:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}
.sidebar .menu-items .menu-group-summary i:first-of-type {
    width: 28px;
    font-size: 14px;
    margin-right: 12px;
    text-align: center;
}
.sidebar .menu-items .submenu {
    list-style: none;
    padding: 0 0 6px 14px;
    margin: 0 0 0 28px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar .menu-items .submenu li a.menu-item {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 600;
    color: rgba(223, 230, 238, 0.95);
    text-decoration: none;
    border-radius: 8px;
    border-left: none;
    position: relative;
    transition: background 0.2s ease, color 0.2s ease;
}
.sidebar .menu-items .submenu li a.menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}
.sidebar .menu-items .submenu li a.menu-item:hover i {
    color: #cbd5e1;
}
.sidebar .menu-items .submenu li a.menu-item.active {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}
.sidebar .menu-items .submenu li a.menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 3px;
    background: #818cf8;
    pointer-events: none;
}
.sidebar .menu-items .submenu li a.menu-item.active i {
    color: #ffffff;
}
.sidebar .menu-items .submenu li a.menu-item.active:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}
.sidebar .menu-items .submenu li a.menu-item.active:hover i {
    color: #ffffff;
}
.sidebar .menu-items .submenu li a.menu-item i {
    width: 22px;
    font-size: 14px;
    margin-right: 10px;
    text-align: center;
    transition: color 0.2s ease;
}

/* Legacy alt menü: solmenu — .menu-item yok */
.sidebar .menu-items .submenu li a:not(.menu-item) {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 0 12px;
    font-size: 12px;
    color: rgba(223, 230, 238, 0.9);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
}
.sidebar .menu-items .submenu li a:not(.menu-item):hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}
.sidebar .menu-items .submenu li a:not(.menu-item).active {
    font-weight: 600;
    background-color: rgba(13, 110, 253, 0.18);
    color: #ffffff;
}
.sidebar .menu-items .submenu li a:not(.menu-item) i {
    width: 22px;
    font-size: 14px;
    margin-right: 10px;
    text-align: center;
}

body.sidebar-collapsed .sidebar .menu-items .submenu,
body.sidebar-collapsed .sidebar .menu-items .menu-group-summary span {
    display: none;
}

/* ========== BİNA SEÇİCİ BUTONU ========== */
/* !important kullanmadan stil veriyoruz */
.sidebar .logo .btn-building {
    /* BY4 template bina butonu stili — yükseklik .toggle-btn ile aynı */
    background: linear-gradient(to right, #3B7FB9, #2E6A9D);
    border: none;
    color: #ffffff;
    padding: 0 10px;
    border-radius: var(--by-radius-md);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    width: auto;
    min-width: 100%;
    max-width: min(280px, calc(100vw - 88px));
    text-align: left;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(59, 127, 185, 0.40);
    transition: all 0.18s var(--by-transition-slow);
    box-sizing: border-box;
    min-height: 36px;
    height: 36px;
}

.sidebar .logo .btn-building:hover {
    background: linear-gradient(to right, #2E6A9D, #25587D);
    box-shadow: 0 10px 28px rgba(59, 127, 185, 0.55);
}

/* Bina adı: buton boyutunu geçmesin, kısaltma ile */
.sidebar .logo .btn-building span {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.1;
}

.sidebar .logo .btn-building i {
    font-size: 11px;
}

/* ========== BİNA DROPDOWN MENÜSÜ ========== */
/* Bina seçici: sidebar genişliği sabit; buton + menü sağa taşarak genişler */
.sidebar .logo .logo-row {
    width: 100%;
    min-width: 0;
    overflow: visible;
}

.sidebar .logo .logo-actions {
    flex-shrink: 0;
}

.sidebar .building-dropdown {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    overflow: visible;
}

.sidebar .dropdown-menu-building {
    width: max-content !important;
    /* Logo padding (16px) kadar sola: alttaki sürükleme ızgaraları görünmesin */
    min-width: max(calc(100% + 16px), 200px) !important;
    max-width: min(320px, calc(100vw - 24px)) !important;
    left: -16px !important;
    right: auto !important;
    margin-top: 4px !important;
    position: absolute !important;
    top: 100% !important;
    transform: none !important;
    background: #ffffff !important; /* Alt menü satırlarının üstünden görünmesin */
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 50 !important;
    isolation: isolate;
}

/* Dropdown açıkken görünür olsun */
.sidebar .dropdown-menu-building.show {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Bina dropdown: .sidebar-item olmayan satır (yedek) */
.sidebar .dropdown-menu-building .dropdown-item:not(.sidebar-item) {
    color: #1f2933;
    padding: 10px 16px;
    font-size: 13px;
}

/* Bina dropdown — modern SaaS satır stili (Kullanıcı menüsü, yazı boyutu, çıkış) */
.sidebar .dropdown-menu-building .dropdown-item.sidebar-item,
.sidebar .dropdown-menu-font-size .dropdown-item.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 8px 4px;
    width: calc(100% - 16px);
    box-sizing: border-box;
    border-radius: 10px;
    color: #555;
    transition: all 0.2s ease;
    font-size: 13px;
}

.sidebar .dropdown-menu-building .dropdown-item.sidebar-item > i,
.sidebar .dropdown-menu-font-size .dropdown-item.sidebar-item > i {
    margin-right: 0 !important;
    flex-shrink: 0;
}

.sidebar .dropdown-menu-building .dropdown-item.sidebar-item:hover,
.sidebar .dropdown-menu-font-size .dropdown-item.sidebar-item:hover {
    background: #f3f4f6;
    color: #555;
}

/* Premium aktif (seçili yazı boyutu vb.) — indigo SaaS */
.sidebar .dropdown-menu-building .dropdown-item.sidebar-item.active,
.sidebar .dropdown-menu-font-size .dropdown-item.sidebar-item.active {
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 500;
}

.sidebar .dropdown-menu-building .dropdown-item.sidebar-item.active:hover,
.sidebar .dropdown-menu-font-size .dropdown-item.sidebar-item.active:hover {
    background: #e0e7ff;
    color: #4338ca;
}

/* Çıkış — kırmızı metin + hover */
.sidebar .dropdown-menu-building .dropdown-item.sidebar-item.text-danger {
    color: #dc2626;
}

.sidebar .dropdown-menu-building .dropdown-item.sidebar-item.text-danger:hover {
    background: #fef2f2;
    color: #b91c1c;
}

.sidebar .dropdown-menu-building .dropdown-item:not(.sidebar-item):hover {
    background: rgba(0, 0, 0, 0.05);
    color: #1f2933;
}

.sidebar .dropdown-menu-building .dropdown-header {
    color: #6b7280; /* Gri başlık rengi */
    /* Başlık da global liste font değişiminden etkilenmesin */
    font-size: 11px;
    padding: 8px 16px 4px;
    font-weight: 600;
}

.sidebar .dropdown-menu-building .dropdown-divider {
    border-color: rgba(0, 0, 0, 0.1);
    margin: 8px 0;
}

/* ========== DARALTILMIŞ (COLLAPSED) MOD ========== */
body.sidebar-collapsed .sidebar {
    width: var(--by-sidebar-collapsed);
    padding: 0;
}

body.sidebar-collapsed .sidebar .menu-items a span,
body.sidebar-collapsed .sidebar .logo h2,
body.sidebar-collapsed .sidebar .btn-building span {
    display: none; /* Yazıları gizle */
}

/* Bina dropdown menüsünü gizle (bina seçici butonu) */
body.sidebar-collapsed .sidebar .logo .building-dropdown {
    display: none;
}

/* Collapsed durumda toggle button görünür kalmalı */
body.sidebar-collapsed .sidebar .logo .logo-actions {
    display: flex;
    justify-content: center;
    width: 100%;
}

body.sidebar-collapsed .sidebar .menu-items a {
    justify-content: center;
    min-height: 46px;
    padding: 0;
}

body.sidebar-collapsed .sidebar .menu-items a i {
    margin-right: 0;
}

/* SortableJS stilleri */
.sortable-ghost {
    opacity: 0.4;
    background: rgba(255, 255, 255, 0.1);
}

.sortable-chosen {
    cursor: grabbing !important;
}

.sortable-drag {
    opacity: 0.8;
}

.sortable-fallback {
    opacity: 0.9;
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    transform: scale(1.02);
}

/* Drag handle - sol tarafta sürükleme alanı (menü taşıma) */
.sidebar .menu-items .drag-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 22px;
    height: 100%;
    cursor: grab;
    z-index: 25;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    pointer-events: auto; /* Sürüklenebilir olmalı */
}

/* Link'in z-index'ini düşür ki drag-handle üstte kalsın */
.sidebar .menu-items a {
    position: relative;
    z-index: 5; /* drag-handle (z-index: 25) üstte kalsın, menü taşıma çalışsın */
}

.sidebar .menu-items .drag-handle:hover {
    background: rgba(255, 255, 255, 0.05); /* Hover'da renk değişmesin */
}

.sidebar .menu-items .drag-handle:active {
    cursor: grabbing !important;
    background: rgba(255, 255, 255, 0.05); /* Active'de de aynı kalsın */
}

.sidebar .menu-items .drag-handle i {
    display: block;
    font-size: 0.7rem;
    line-height: 1;
    opacity: 0.55;
    color: rgba(255, 255, 255, 0.7);
    pointer-events: none;
}

/* Collapsed durumda handle gizle */
body.sidebar-collapsed .sidebar .menu-items .drag-handle {
    display: none;
}

/* Toast animasyonu */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(10px); }
    20% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

body.sidebar-collapsed .app-content {
    margin-left: var(--by-sidebar-collapsed);
    width: calc(100% - var(--by-sidebar-collapsed));
}

/* ========== MOBİL MENÜ ========== */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%); /* Varsayılan olarak gizle */
    }
    
    .sidebar.is-open {
        transform: translateX(0); /* Açıkken göster */
        box-shadow: 5px 0 15px rgba(0,0,0,0.3);
    }
}

/* Desktop'ta sidebar varsayılan olarak görünür */
@media (min-width: 993px) {
    .sidebar {
        transform: translateX(0);
        display: flex;
        visibility: visible;
        opacity: 1;
    }
}
/* Bootstrap tabanlı sidebar nav-link kullanan sayfalar için uyumlu stil */
.sidebar .nav-link {
    display: flex;
    align-items: center;
    min-height: 46px;
    font-size: 17px;
    font-weight: 500;
    line-height: 1.5;
    padding: 0 14px;
    color: #dfe6ee;
    border-left: 4px solid transparent;
    position: relative;
}

.sidebar .nav-link i {
    font-size: 22px;
    margin-right: 12px;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
}

.sidebar .nav-link.active {
    font-weight: 600;
    background: rgba(13, 110, 253, 0.18);
    border-left: 4px solid #0d6efd;
    color: #ffffff;
}
