/* Short landscape (844×390) keeps the phone shell even if device-desktop
   or the min-width 769 rail rules also match. Desktop 1280×800 is untouched. */
@media (max-height: 520px) and (orientation: landscape) {
    #main-app.dashboard-container {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto minmax(0, 1fr) !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    #main-app .app-header,
    #main-app .app-container,
    #main-app .support-mode-banner {
        grid-column: 1 !important;
        grid-row: auto !important;
    }

    #main-app .app-sidebar {
        position: fixed !important;
        left: -280px !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        min-width: 0 !important;
        max-width: 280px !important;
        z-index: 1001 !important;
    }

    #main-app .app-sidebar.active {
        left: 0 !important;
    }

    body.device-desktop .bottom-nav,
    .bottom-nav {
        display: block !important;
    }

    #main-app .desktop-only,
    #main-app .desktop-sidebar-toggle,
    #main-app #desktop-header-clock {
        display: none !important;
    }

    /* Page name sits in the same bar as the logo. It must not cover POTENSI. */
    #main-app .desktop-page-title {
        display: block !important;
        position: static !important;
        order: 2 !important;
        flex: 0 1 auto !important;
        min-width: 0 !important;
        max-width: 34% !important;
        margin: 0 8px !important;
        overflow: hidden !important;
    }

    body.device-desktop #main-app .desktop-page-title h1,
    body.device-mobile #main-app .desktop-page-title h1,
    #main-app .desktop-page-title h1 {
        margin: 0 !important;
        color: #122b3d !important;
        font-size: 1rem !important;
        line-height: 1.1 !important;
        font-weight: 800 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    #main-app .mobile-only,
    #main-app .header-brand,
    #main-app .mobile-menu-btn {
        display: flex !important;
    }

    /* Beat desktop-v2 navy (body.device-desktop #main-app .app-header).
       Ink #122b3d on this light bar clears 3:1. */
    body.device-mobile #main-app .app-header,
    body.device-desktop #main-app .app-header,
    #main-app .app-header {
        position: relative !important;
        z-index: 40 !important;
        background: #ffffff !important;
        color: #122b3d !important;
        height: auto !important;
        min-height: calc(48px + var(--safe-top, env(safe-area-inset-top, 0px))) !important;
        padding: var(--safe-top, env(safe-area-inset-top, 0px)) 14px 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    #main-app .header-left {
        display: flex !important;
        flex: 1 1 auto !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        gap: 8px !important;
        justify-content: flex-start !important;
        /* 48px bell + 8px gap + 48px menu, so the title cannot reach the icons. */
        padding-right: 116px !important;
        box-sizing: border-box !important;
    }

    #main-app .header-brand {
        flex: 0 1 auto !important;
        min-width: 0 !important;
        max-width: none !important;
        overflow: hidden !important;
    }

    #main-app .mobile-menu-btn {
        order: 99 !important;
        position: absolute !important;
        right: 8px !important;
        bottom: 0 !important;
        margin-left: 0 !important;
        width: 48px !important;
        height: 48px !important;
        flex: 0 0 48px !important;
    }

    /* Bell then hamburger, both out of the title's flex line. */
    #main-app .app-header .header-user {
        display: flex !important;
        position: absolute !important;
        right: 64px !important;
        top: auto !important;
        bottom: 0 !important;
        flex: 0 0 48px !important;
        width: 48px !important;
        height: 48px !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important;
        z-index: 5 !important;
    }

    #main-app .notification-badge {
        top: 4px !important;
        right: 2px !important;
    }

    /* Portrait bell is ink on the light POTENSI header. Width ≥769 was
       painting --shell-header-muted (#dbeafe), which is for a navy bar. */
    #main-app .notification-bell-btn {
        overflow: visible !important;
        border: 0 !important;
        background: transparent !important;
        box-shadow: none !important;
        color: var(--apk-ink, #122b3d) !important;
    }

    body.device-mobile #main-app .notification-bell-btn .p-icon,
    body.device-desktop #main-app .notification-bell-btn .p-icon,
    #main-app .notification-bell-btn i,
    #main-app .notification-bell-btn .p-icon {
        color: #122b3d !important;
        background-color: #122b3d !important;
        opacity: 1 !important;
    }

    #notification-dropdown,
    .notification-dropdown {
        position: fixed !important;
        top: calc(48px + var(--safe-top, env(safe-area-inset-top, 0px))) !important;
        right: 8px !important;
        left: auto !important;
        bottom: auto !important;
        width: min(380px, calc(100vw - 16px)) !important;
        max-height: calc(100dvh - 48px - var(--safe-top, env(safe-area-inset-top, 0px)) - 96px - var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
        z-index: 35 !important;
        overflow: hidden !important;
        flex-direction: column !important;
    }

    #notification-dropdown[style*="display: block"],
    #notification-dropdown[style*="display:block"],
    .notification-dropdown[style*="display: block"],
    .notification-dropdown[style*="display:block"] {
        display: flex !important;
    }

    #notification-dropdown .notification-list,
    .notification-dropdown .notification-list {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    #edit-profile-modal[open] {
        position: fixed !important;
        top: max(8px, env(safe-area-inset-top, 0px)) !important;
        right: auto !important;
        bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        width: min(640px, calc(100vw - 16px)) !important;
        max-height: calc(100dvh - 16px) !important;
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #edit-profile-modal[open] .modal-content {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: calc(100dvh - 32px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #edit-profile-modal #resign-section .btn-danger {
        width: 100% !important;
        min-height: 48px !important;
        white-space: normal !important;
    }

    body.device-mobile.mobile-drawer-account-only #app-sidebar.active {
        display: flex !important;
        flex-direction: column !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }

    body.device-mobile.mobile-drawer-account-only #app-sidebar .sidebar-user-menu {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }

    body.device-mobile.mobile-drawer-account-only #app-sidebar .sidebar-footer {
        flex: 0 0 auto !important;
        position: relative !important;
        z-index: 2 !important;
    }

    /* Short landscape: pack the account list so Keluar clears the footer,
       and keep a scroll shadow when the list still overflows. */
    body.device-mobile.mobile-drawer-account-only #app-sidebar .sidebar-user-menu {
        gap: 4px !important;
        padding: 8px 12px 0 !important;
        background:
            linear-gradient(var(--apk-panel, #ffffff), var(--apk-panel, #ffffff)) center bottom / 100% 16px no-repeat local,
            radial-gradient(farthest-side at 50% 100%, rgba(18, 43, 61, 0.28), rgba(18, 43, 61, 0)) center bottom / 100% 16px no-repeat scroll !important;
    }

    body.device-mobile.mobile-drawer-account-only #app-sidebar .sidebar-user-menu-item {
        min-height: 40px !important;
    }

    body.device-mobile.mobile-drawer-account-only #app-sidebar .apk-manual-update-version,
    body.device-mobile.mobile-drawer-account-only #app-sidebar .apk-manual-update-status {
        margin: 0 !important;
        line-height: 1.15 !important;
    }

    #main-app .notification-bell-btn:hover,
    #main-app .notification-bell-btn:active {
        background: rgba(18, 43, 61, 0.08) !important;
        color: #0d3b66 !important;
    }

    #main-app .notification-bell-btn:hover i,
    #main-app .notification-bell-btn:hover .p-icon,
    #main-app .notification-bell-btn:active i,
    #main-app .notification-bell-btn:active .p-icon {
        color: #0d3b66 !important;
        background-color: #0d3b66 !important;
    }

    #main-app #header-user-name,
    #main-app .profile-dropdown-icon {
        display: none !important;
    }

    #main-app .app-container,
    #main-app #user-tab,
    #main-app #user-tab .level-welcome,
    #main-app #user-overview-section,
    #main-app .tab-content,
    #main-app .mobile-dashboard-container,
    #main-app .mobile-stat-grid,
    #main-app #wc-mobile-dashboard,
    #main-app #desktop-profile-dashboard,
    #main-app #desktop-control-root,
    #main-app #dc-hero {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
    }

    body.device-mobile.persona-white-collar:not(.native-app-shell) #main-app #user-overview-section > .desktop-profile-dashboard,
    body.device-mobile.persona-blue-collar:not(.native-app-shell) #main-app #user-overview-section > .desktop-profile-dashboard {
        display: block !important;
    }

    /* Native rotation keeps the portrait Beranda (ringkasan), not Profil Portabel. */
    body.native-app-shell #main-app #user-overview-section > .desktop-profile-dashboard,
    body.native-app-shell #desktop-profile-dashboard,
    body.native-app-shell #desktop-control-root {
        display: none !important;
    }

    body.native-app-shell #user-overview-section > #user-welcome-message {
        display: block !important;
    }

    #main-app #dc-hero-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        max-width: none !important;
    }

    #main-app #dc-hero-actions .dc-btn {
        max-width: 100% !important;
        white-space: nowrap !important;
    }

    /* The compact phone gutter (16px) plus the desktop paper panel drew a
       seam at both edges. Let Beranda fill the shell. Card borders stay.
       Width >=769 resets padding to 16px. The fixed bottom nav still covers
       that, so the scroller keeps nav height + offset + safe area. */
    body.device-mobile.window-compact #main-app .app-container,
    #main-app .app-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-bottom: calc(128px + var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
        scroll-padding-bottom: calc(128px + var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
        border: 0 !important;
        outline: 0 !important;
        box-shadow: none !important;
    }

    /* Portrait gutter is 16px (apk-redesign). The zero above is
       body.device-mobile.window-compact #main-app .app-container, so this
       needs the same weight and must come later. */
    body.native-app-shell.device-mobile #main-app .app-container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    #main-app #user-tab,
    #main-app #desktop-profile-dashboard,
    #main-app #desktop-control-root {
        border: 0 !important;
        outline: 0 !important;
        box-shadow: none !important;
    }

    /* Phone bottom nav, not the expanded-window left rail. */
    body.device-mobile.window-medium #bottom-nav,
    body.device-mobile.window-expanded #bottom-nav,
    #bottom-nav,
    .bottom-nav {
        top: auto !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: auto !important;
        border-right: 0 !important;
    }

    body.device-mobile.window-medium .bottom-nav-container,
    body.device-mobile.window-expanded .bottom-nav-container,
    .bottom-nav-container {
        flex-direction: row !important;
        height: auto !important;
        width: 100% !important;
    }

    body.device-mobile.window-medium #main-app,
    body.device-mobile.window-expanded #main-app,
    #main-app.dashboard-container {
        padding-left: 0 !important;
    }
}

/* Wide native (including tall landscape) must not drop the phone greeting.
   user-profile-desktop.css hides every overview child except the desktop profile at >=769px. */
@media (min-width: 769px) {
    body.native-app-shell #main-app #user-overview-section > .desktop-profile-dashboard,
    body.native-app-shell #desktop-profile-dashboard,
    body.native-app-shell #desktop-control-root {
        display: none !important;
    }

    body.native-app-shell #user-overview-section > #user-welcome-message {
        display: block !important;
    }

    /* styles.css @min-width 769 paints #main-app p with --text-muted !important.
       That ID rule beats the APK hero's white and leaves dark type on the navy card.
       Title and subtitle are <p>; the kicker is a span. */
    body.native-app-shell #main-app #user-welcome-message .level-welcome-title,
    body.native-app-shell #main-app #user-welcome-message .hero-welcome-kicker {
        color: #ffffff !important;
    }

    body.native-app-shell #main-app #user-welcome-message .level-welcome-text {
        color: rgba(255, 255, 255, 0.85) !important;
    }

    body.native-app-shell.device-mobile #main-app .app-container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* 769px "simple hero" hides the portrait avatar and "N dari X" row.
       Native landscape must keep that ringkasan. Web desktop has no .native-app-shell. */
    body.native-app-shell .hero-welcome-avatar {
        display: flex !important;
    }

    body.native-app-shell .hero-welcome-stat {
        display: flex !important;
    }

    /* Same weight as the 769–1024 #mobile-stat-grid unhide, plus .native-app-shell
       so #hasil-tiga-desktop / Pusat Kendali stay the web path. */
    body.native-app-shell.device-mobile.persona-blue-collar #main-app #user-overview-section > #hasil-tiga-mobile,
    body.native-app-shell.device-mobile.persona-white-collar #main-app #user-overview-section > #hasil-tiga-mobile,
    body.native-app-shell.touch-device.persona-blue-collar #main-app #user-overview-section > #hasil-tiga-mobile,
    body.native-app-shell.touch-device.persona-white-collar #main-app #user-overview-section > #hasil-tiga-mobile {
        display: block !important;
    }
}

/* Ubah Profil at phone width: primary is one full-width row, Batal under it. */
@media (max-width: 480px) {
    #edit-profile-modal[open] {
        position: fixed !important;
        top: max(8px, env(safe-area-inset-top, 0px)) !important;
        bottom: max(8px, env(safe-area-inset-bottom, 0px)) !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        width: min(640px, calc(100vw - 16px)) !important;
        max-height: calc(100dvh - 16px) !important;
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #edit-profile-modal[open] .modal-content {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: calc(100dvh - 32px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #edit-profile-modal #resign-section h5,
    #edit-profile-modal #resign-section .btn-danger {
        max-width: 100% !important;
        white-space: normal !important;
        overflow: visible !important;
    }

    #edit-profile-modal #resign-section .btn-danger {
        width: 100% !important;
        min-height: 48px !important;
    }

    #edit-profile-modal .modal-actions {
        position: static !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    #edit-profile-modal .modal-actions button {
        width: 100% !important;
        min-height: 48px !important;
        white-space: nowrap !important;
    }
}

/* Agenda is position:fixed at z-index 900 and starts under the header.
   The header context is otherwise ~40, so a dropdown z-index alone stays under it. */
html.agenda-v2-on:has(#tasks-tab.active) #main-app .app-header {
    z-index: 1100 !important;
}

html.agenda-v2-on:has(#tasks-tab.active) #notification-dropdown {
    z-index: 1200 !important;
}

/* Portrait compact uses #main-app --page-pad-bottom-mobile (88px), which stops
   short of the floating 70px bar plus its 8px offset. Own the scroller pad here. */
body.device-mobile.window-compact #main-app {
    --page-pad-bottom-mobile: calc(128px + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
}

body.device-mobile.window-compact #main-app .app-container {
    padding-bottom: calc(128px + var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
    scroll-padding-bottom: calc(128px + var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
}

/* Phone header: one line + ellipsis. A wrapping badge grew the bar past
   48px and, with the Agenda z-index lift, covered the Hari Ini title.
   48px bell + 8px gap + 48px menu stay clear in portrait and landscape. */
body.device-mobile #main-app .header-left {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    min-width: 0 !important;
    width: 100% !important;
}

body.device-mobile #main-app .header-brand {
    overflow: hidden !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: calc(100vw - 140px) !important;
}

body.device-mobile #main-app .brand-info {
    flex: 0 0 auto !important;
    min-width: 0 !important;
}

body.device-mobile #main-app .brand-info h2 {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    max-width: 100% !important;
}

body.device-mobile #main-app .header-company-badge[style*="display: flex"],
body.device-mobile #main-app .header-company-badge[style*="display:flex"] {
    display: flex !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: min(42vw, 180px) !important;
    height: 28px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
}

@media (max-width: 480px) {
    body.device-mobile #main-app .header-company-badge[style*="display: flex"],
    body.device-mobile #main-app .header-company-badge[style*="display:flex"] {
        flex: 1 1 auto !important;
        max-width: calc(100vw - 220px) !important;
    }
}

body.device-mobile #main-app .header-company-name {
    display: block !important;
    min-width: 0 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    line-height: 1.2 !important;
}

/* Portrait bell: the 480px sheet used 100vh and the list max-height ran under the nav. */
@media (max-width: 768px) {
    body.device-mobile #notification-dropdown[style*="display: block"],
    body.device-mobile #notification-dropdown[style*="display:block"] {
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        max-height: calc(100dvh - 56px - var(--safe-top, env(safe-area-inset-top, 0px)) - 96px - var(--safe-bottom, env(safe-area-inset-bottom, 0px))) !important;
    }

    body.device-mobile #notification-dropdown .notification-list {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
}
