/* CSS Variables for consistent header alignment */
:root {
    --app-header-h: 56px;
    --app-header-px: 16px;
    --app-line-height: 56px;
    /* Lebar sidebar saat expanded (selaraskan dengan app.css --sidebar-width) */
    --sidebar-w: 280px;
}

/* Reset hanya untuk html dan body - tidak agresif */
html {
    --topbar-height: 56px;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
}

/* Topbar Global Styles */
.topbar,
header.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    margin: 0;
    z-index: 1050;
    background: #343a40;
    border-bottom: 1px solid #495057;
    height: var(--app-header-h);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--app-header-px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.topbar-brand h5 {
    margin: 0;
    color: #ffffff;
    font-weight: 600;
    font-size: 1.25rem;
}

/* Mode badge di samping brand */
.mode-badge {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        margin-left: 10px;
        vertical-align: middle;
}
.mode-badge .badge-mode-desktop,
.mode-badge .badge-mode-mobile {
        display: inline-block;
        padding: 2px 6px;
        border-radius: 999px;
        font-size: 0.75rem;
        background: #212529;
        color: #e9ecef;
        border: 1px solid #495057;
}
/* Default: tampilkan teks 'destkop', sembunyikan 'mobile' */
.mode-badge .badge-mode-desktop { display: inline-block; }
.mode-badge .badge-mode-mobile { display: none; }
/* Saat mobile viewport: tampilkan 'mobile', sembunyikan 'destkop' */
@media (max-width: 768px) {
    .mode-badge .badge-mode-desktop { display: none; }
    .mode-badge .badge-mode-mobile { display: inline-block; }
}

/* Session-based override: hormati pilihan mode dari server */
body.ui-mobile .mode-badge .badge-mode-desktop { display: none !important; }
body.ui-mobile .mode-badge .badge-mode-mobile { display: inline-block !important; }
body.ui-desktop .mode-badge .badge-mode-desktop { display: inline-block !important; }
body.ui-desktop .mode-badge .badge-mode-mobile { display: none !important; }

.topbar-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Company selector */
.topbar .company-btn{
    display:inline-flex;align-items:center;gap:.25rem;
    padding:.25rem .5rem;border-radius:.375rem;
    background:#343a40;color:#e9ecef;border:1px solid #495057;
    font-size:.9rem;white-space:nowrap;
}
.topbar .company-btn:hover{background:#495057;}
.topbar .company-menu{min-width:280px;}
.company-list .dropdown-item{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
.company-list .dropdown-item.active,
.company-list .dropdown-item:active{background:#0d6efd;color:#fff}

/* Center search */
.topbar-center { align-items: center; }
.topbar-search .form-control::placeholder { color: #9aa0a6; }
.topbar-search .form-control { height: 36px; }
.topbar-search .input-group-text { height: 36px; }
.topbar-search .btn { height: 36px; }
.topbar-search .dropdown-menu { background:#212529; color:#e9ecef; border:1px solid #495057; }
.topbar-search .dropdown-item { color:#e9ecef; }
.topbar-search .dropdown-item:hover { background:#343a40; }
.topbar-search .match-path { color:#9aa0a6; font-size:12px; }
/* Paksa dropdown tampil saat kelas .show ditambahkan (tanpa Bootstrap JS) */
.topbar-search .dropdown-menu.show{ display:block; }

/* Posisi dropdown hasil pencarian tepat di bawah input */
.topbar-search.position-relative #globalSearchDropdown{
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    z-index: 2001;
}

.topbar-item {
    position: relative;
}

.icon-btn {
    position: relative;
    border: 0;
    background: transparent;
    padding: 6px 10px;
    font-size: 18px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    height: var(--app-header-h);
    display: flex;
    align-items: center;
    color: #ffffff;
}

.icon-btn:hover {
    background-color: #495057;
}

.icon-btn .badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #e02424;
    color: #fff;
    border-radius: 999px;
    padding: 0 6px;
    font-size: 11px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    height: var(--app-header-h);
}

.user-btn:hover {
    background-color: #495057;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1f2937;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
}

.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Notification dropdown styles */
.notif-menu {
    width: 320px;
    max-width: calc(100vw - 32px);
    max-height: 480px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
}

.notif-list {
    max-height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
}

.notif-item {
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.notif-item:hover {
    background-color: #f8fafc;
}

.notif-item.unread {
    background: #f0fdfa;
    border-left: 3px solid #14b8a6;
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-time {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 2px;
}

.notif-text {
    font-size: 13px;
    line-height: 1.4;
    color: #374151;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.dropdown-footer {
    border-top: 1px solid #e5e7eb;
    background-color: #f9fafb;
}

/* Download dropdown styles */
.download-menu {
    width: 320px;
    max-width: calc(100vw - 32px);
    max-height: 480px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
}

.download-list {
    max-height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
}

.download-list .dropdown-item {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.download-list .task-done {
    opacity: 0.7;
}

.download-list .text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

/* Kalender Offcanvas */
.calendar-offcanvas { width: 360px; }
.calendar-month-badge {
    display:inline-block; padding:.5rem .75rem; border-radius:.5rem; background:#f1f5f9; color:#111827; font-weight:600;
}
.calendar-grid {
    display:grid; grid-template-columns: repeat(7, 1fr); gap:6px; user-select:none;
}
.calendar-grid .dow { font-size:12px; color:#6b7280; text-align:center; padding:2px 0; }
.calendar-grid .day { text-align:center; padding:.5rem 0; border-radius:.375rem; cursor:default; }
.calendar-grid .day.other-month { color:#94a3b8; opacity:.6; }
.calendar-grid .day.today { background:#0ea5e9; color:#fff; font-weight:700; }
.calendar-grid .day:hover { background:#e5e7eb; }
/* Penanda event: garis bawah/indicator ungu */
.calendar-grid .day.has-event { position: relative; font-weight:700; color:#1f2937; background: #ede9fe; }
.calendar-grid .day.has-event::after{ content:""; position:absolute; left:50%; bottom:4px; transform:translateX(-50%); width:18px; height:4px; border-radius:999px; background:#7c3aed; }
.calendar-grid .day.today.has-event{ background:#c4b5fd; color:#111827; }
.calendar-grid .day.today.has-event::after{ background:#5b21b6; }

/* Body adjustment for fixed topbar */
body.has-topbar {
    padding-top: var(--app-header-h);
}

/* Mode UI mobile: sembunyikan topbar sepenuhnya dan hilangkan padding atas */
body.ui-mobile header.topbar,
body.ui-mobile .topbar {
    display: none !important;
}
body.ui-mobile.has-topbar { padding-top: 0 !important; }
body.ui-mobile .sidebar { top: 0 !important; height: 100vh !important; }
body.ui-mobile main.col-md-9,
body.ui-mobile main.col-lg-10 { padding-top: 0 !important; }

/* Sidebar fixed: selalu terlihat saat scroll */
.sidebar {
    position: fixed;
    top: var(--app-header-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    height: calc(100vh - var(--app-header-h));
    overflow-y: auto;
}

/* Ukuran font menu dan sub menu (dikurangi satu tingkat) */
.sidebar .nav-link { font-size: 0.95rem; }
.sidebar .dropdown-item { font-size: 0.90rem; }
.sidebar .nav-link i { font-size: 1rem; }
.sidebar .submenu-icon { font-size: 0.95rem; }
.sidebar-bottom-toggle .btn { font-size: 0.95rem; }

/* Tombol bawah menyatu: ikon+teks dalam satu tombol */
.sidebar-bottom-toggle { gap: 8px; }
.sidebar-bottom-toggle .btn {
    width: 100%;
    border-radius: 999px;
    padding: 8px 14px;
    background: #111; /* background hitam */
    color: #fff;
    border: 1px solid #222;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.sidebar-bottom-toggle .btn:hover { background: #0f0f0f; color:#fff; }
.sidebar-bottom-toggle .btn .icon-expanded { display: inline-block; }
.sidebar-bottom-toggle .btn .icon-collapsed { display: none; }
/* Saat collapsed: sembunyikan teks, tampilkan ikon list, pusatkan */
body.menu-collapsed .sidebar-bottom-toggle .btn {
    width: 40px;
    height: 40px;
    padding: 0;
}
body.menu-collapsed .sidebar-bottom-toggle .btn .toggle-text { display: none; }
body.menu-collapsed .sidebar-bottom-toggle .btn .icon-expanded { display: none; }
body.menu-collapsed .sidebar-bottom-toggle .btn .icon-collapsed { display: inline-block; font-size: 1.1rem; }

/* Main content column adjustment */
main.col-md-9,
main.col-lg-10 {
    padding-top: 0; /* Hilangkan jarak atas konten utama */
}

/* Sidebar toggle floating button (pojok kiri bawah) */
.sidebar-toggle {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 2000;
    display: block !important; /* paksa tampil di semua viewport */
    pointer-events: auto;
}
.sidebar-toggle .btn {
    /* Tombol bulat kecil mengikuti referensi: mengambang, kontras, ikon jelas */
    width: 46px;
    height: 46px;
    border-radius: 999px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #14b8a6, #0f766e);
    color: #fff;
    border: 0;
    box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
.sidebar-toggle .btn:hover { filter: brightness(0.95); }
.sidebar-toggle .btn:active { transform: translateY(1px); }
.sidebar-toggle .toggle-text { display: none !important; }
.sidebar-toggle .bi { font-size: 1.25rem; line-height: 1; }

/* Sejajarkan tombol (bulat 46px) ke tengah kolom ikon (56px) saat menu collapsed */
body.menu-collapsed .sidebar-toggle {
    left: calc((56px - 46px) / 2) !important;
}

/* Transisi sidebar halus */
.sidebar { transition: margin-left .2s ease, flex-basis .2s ease, max-width .2s ease, width .2s ease; }

/* Mode collapsed: sidebar tetap terlihat sebagai bar ikon 56px */
body.menu-collapsed .sidebar {
    /* Tampilkan sidebar sebagai bar ikon sempit */
    margin-left: 0 !important;
    width: 56px !important;
    flex: 0 0 56px !important;
    max-width: 56px !important;
    pointer-events: auto;
}

/* Sembunyikan teks menu, pusatkan ikon */
body.menu-collapsed .sidebar .nav-link,
body.menu-collapsed .sidebar .dropdown-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    font-size: 0; /* sembunyikan teks tanpa ubah markup */
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}
body.menu-collapsed .sidebar .nav-link .bi,
body.menu-collapsed .sidebar .dropdown-item .bi,
body.menu-collapsed .sidebar .dropdown-item .submenu-icon {
    font-size: 1.35rem; /* tampilkan ikon lebih besar */
}
/* Sembunyikan teks label yang ada setelah ikon pada nav-link ketika collapsed */
body.menu-collapsed .sidebar .nav-link .me-2 + span,
body.menu-collapsed .sidebar .dropdown-item .submenu-icon + span {
    display: none !important;
}
body.menu-collapsed .sidebar .nav-link .me-2 { margin-right: 0 !important; }
body.menu-collapsed .sidebar .dropdown-toggle::after { display: none !important; }

/* Sembunyikan submenu saat collapsed */
body.menu-collapsed .sidebar .collapse,
body.menu-collapsed .sidebar .dropdown-menu { display: none !important; }

/* Pastikan tombol bawah sidebar tetap tampil saat collapsed sebagai ikon bulat */
body.menu-collapsed .sidebar-bottom-toggle { display: block !important; }
/* Selaraskan padding agar tombol bulat (40px) tepat di tengah kolom ikon (56px - 8px*2) */
body.menu-collapsed .sidebar-bottom-toggle { padding-left: 8px !important; padding-right: 8px !important; }
body.menu-collapsed .sidebar-bottom-toggle .btn { width: 100% !important; height: 40px !important; }

/* Main tetap bergeser 56px agar tidak tertutup bar ikon */
body.menu-collapsed main.col-md-9,
body.menu-collapsed main.col-lg-10 {
    /* Sisakan ruang 56px untuk bar ikon agar konten tidak menutupi */
    margin-left: 56px !important;
    /* Pastikan konten fit sisa layar, tanpa overflow ke kanan */
    width: calc(100% - 56px) !important;
    max-width: calc(100% - 56px) !important;
    flex: 0 0 auto;
}

/* Saat sidebar tampil, geser main ke kanan sebesar lebar sidebar (desktop) */
@media (min-width: 768px) {
    body:not(.menu-collapsed) main.col-md-9,
    body:not(.menu-collapsed) main.col-lg-10 {
    margin-left: var(--sidebar-w) !important;
    /* Lebar main diset relatif ke sisa ruang agar tidak perlu zoom/out dan tidak terpotong */
    width: calc(100% - var(--sidebar-w)) !important;
    max-width: calc(100% - var(--sidebar-w)) !important;
    flex: 0 0 auto;
    }
}
body.menu-collapsed .sidebar-toggle .toggle-text { content: 'Tampilkan Menu'; }

/* Override tambahan untuk memastikan aturan di atas menang dari versi sebelumnya */
/* Ditaruh di bagian bawah file agar prioritas cascade lebih tinggi */
body.menu-collapsed .sidebar { transition: margin-left .2s ease; }

/* Sembunyikan tombol toggle di dalam sidebar agar tidak duplikat dengan tombol mengambang */
.sidebar-bottom-toggle { display: none !important; }

/* Responsive adjustments */
@media (max-width: 767px) {
    body.has-topbar {
        padding-top: var(--app-header-h);
    }
    
    .sidebar {
        margin-top: 0;
        padding-top: 1rem;
    }
}

/* Main content adjustment */
.app-container,
main.col-md-9 {
    padding-top: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --app-header-h: 52px;
        --app-header-px: 12px;
        --app-line-height: 52px;
    }
    
    .topbar {
        padding: 0 var(--app-header-px);
        height: var(--app-header-h);
    }
    
    .user-name {
        display: none;
    }
    
    .notif-menu {
        width: 280px;
        max-width: calc(100vw - 24px);
    }
    
    .download-menu {
        width: 280px;
        max-width: calc(100vw - 24px);
    }
    
    .topbar-right {
        gap: 8px;
    }
}
/* Sembunyikan elemen tertentu di mode UI mobile */
body.ui-mobile .topbar .company-btn,
body.ui-mobile .topbar #btn-downloads,
body.ui-mobile .topbar #btn-inbox {
    /* Sembunyikan dropdown perusahaan, ikon pusat unduhan, dan inbox di tampilan mobile */
    display: none !important;
}
/* (Hapus override lama yang mengecilkan sidebar agar konsisten di 380px) */

    /* ====== Tighten left gap: rapatkan konten ke sidebar ====== */
    /* Hilangkan gutter antar kolom di baris utama (sidebar + main) */
    .container-fluid > .row { --bs-gutter-x: 0 !important; }
    /* Hilangkan padding horizontal bootstrap di elemen main */
    main.col-md-9,
    main.col-lg-10 {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
