/* ============================================================
   iPlatinum Frontend – Responsive / Mobile CSS
   Adjusted for Premium Look and Functional Menus
   ============================================================ */

/* ---- 1. Viewport & Base ----------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  /* clip prevents horizontal scroll WITHOUT blocking touch events on
     absolute-positioned children (Select2 dropdowns) - critical for iOS Safari */
  overflow-x: clip !important;
  width: 100% !important;
  position: relative !important;
}

img, video, iframe { max-width: 100%; height: auto; }

/* ---- 2. Mobile Header (≤ 991 px) -------------------------- */
@media (max-width: 991.98px) {

  /* White background for mobile header to match clean look */
  #kt_header_mobile {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    height: 70px;
    background: #ffffff !important; 
    box-shadow: 0 2px 10px rgba(0,0,0,.1) !important;
    border-bottom: 2px solid #ebedf3 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 100001 !important; /* Higher than #kt_header */
  }

  /* Logo text "iPlatinum" in Red like desktop */
  #kt_header_mobile .logotext { 
    color: #9f1521 !important; 
    font-weight: 700; 
  }

  #kt_header_mobile .burger-icon span,
  #kt_header_mobile .burger-icon::before,
  #kt_header_mobile .burger-icon::after { 
    background-color: #3f4254 !important; 
  }

  /* Ensure the header container doesn't block clicks on mobile header bar */
  #kt_header {
    display: block !important;
    height: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    position: relative !important;
    z-index: 100000 !important; 
    background: transparent !important;
    overflow: visible !important;
    pointer-events: none !important; /* Critical: allow clicks to pass through to kt_header_mobile */
  }

  /* But re-enable pointer events for the topbar drawer itself */
  #kt_header #kt_header_topbar {
    pointer-events: auto !important;
  }

  /* Hide children of header EXCEPT the topbar on mobile */
  #kt_header > div:not(.header-top) { display: none !important; }
  #kt_header .header-top > div:not(.container-fluid) { display: none !important; }

  /* Hide the "barisnama" welcome strip – not needed on mobile */
  #barisnama { display: none !important; }

  /* Make the menu container ready */
  #kt_header_topbar {
    display: none !important; /* Start hidden until toggled */
  }

  /* When the mobile topbar drawer opens (Floating Premium Look) */
  #kt_header_topbar.topbar-mobile-on {
     display: flex !important;
     flex-direction: column !important;
     position: fixed !important;
     top: 75px !important; 
     left: 12px !important; 
     right: 12px !important;
     height: auto !important;
     max-height: calc(100vh - 100px) !important; /* FIXED STAY: Ensure drawer stays within view */
     background-color: #ffffff !important; 
     border-radius: 20px !important; 
     padding: 20px 15px 40px 15px !important; 
     z-index: 999999 !important; 
     overflow-y: auto !important; /* ALLOW SCROLL on menu drawer */
     box-shadow: 0 15px 50px rgba(0,0,0,0.3) !important;
     border: 1px solid rgba(0,0,0,0.08) !important;
     -webkit-overflow-scrolling: touch;
  }

  /* Target item containers but RESPECT visibility rules to prevent double buttons */
  #kt_header_topbar.topbar-mobile-on > .topbar-item,
  #kt_header_topbar.topbar-mobile-on > .menuutama,
  #kt_header_topbar.topbar-mobile-on > div:not(.dropdown-menu) {
    margin: 4px 0 !important;
    width: 100% !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    float: none !important;
  }

  /* CRITICAL: Ensure d-none utility works - Fixes the "Double Button" issue */
  #kt_header_topbar.topbar-mobile-on .d-none.d-lg-flex {
    display: none !important;
  }

  /* Ensure dropdowns inside the mobile menu don't force-open unless active */
  #kt_header_topbar.topbar-mobile-on .dropdown-menu {
    position: static !important; 
    width: 100% !important;
    float: none !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1) !important;
    border: 1px solid #ebedf3 !important;
    margin: 10px 0 !important;
    border-radius: 15px !important;
    padding: 10px !important;
    background: #ffffff !important;
    max-height: 350px !important; /* Limit dropdown height */
    overflow-y: auto !important;  /* ALLOW SCROLL inside role list */
  }

  /* Refined "Long" buttons */
  #kt_header_topbar.topbar-mobile-on .btn {
    width: 100% !important;
    height: auto !important;
    min-height: 52px !important; 
    margin: 4px 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 12px 20px !important; 
    font-size: 1.05rem !important; 
    font-weight: 600 !important;
    border-radius: 12px !important;
    text-align: left !important;
    box-shadow: none !important;
    border: 1px solid transparent !important;
    transition: all 0.2s ease !important;
  }

  /* Color themes for buttons */
  #kt_header_topbar.topbar-mobile-on .btn.btn-primary {
    background-color: #9f1521 !important;
    border-color: #9f1521 !important;
    color: #ffffff !important;
    margin-top: 10px !important;
    margin-bottom: 5px !important;
  }
  
  #kt_header_topbar.topbar-mobile-on .btn.btn-secondary {
    background-color: #f3f6f9 !important;
    border-color: #ebedf3 !important;
    color: #3f4254 !important;
  }

  /* ---- Active page highlight: #9f1521 bg + white text ---- */
  #kt_header_topbar.topbar-mobile-on .btn.active-menu,
  #kt_header_topbar.topbar-mobile-on .btn.btn-secondary.active-menu,
  #kt_header_topbar.topbar-mobile-on .btn.btn-primary.active-menu {
    background-color: #9f1521 !important;
    border-color: #9f1521 !important;
    color: #ffffff !important;
    font-weight: 700 !important;
  }

  #kt_header_topbar.topbar-mobile-on .btn.active-menu i {
    color: #ffffff !important;
  }

  /* Sign Out Button - Professional Dark Red Look */
  #kt_header_topbar.topbar-mobile-on .btn-signout {
    background-color: #1a1a1a !important;
    color: #ffffff !important;
    border: none !important;
    margin-top: 20px !important;
  }


  /* PREMIUM LOOK FOR SWITCH ROLE DROPDOWN MENU ITEMS */
  #kt_header_topbar.topbar-mobile-on .dropdown-item {
    border-radius: 10px !important;
    margin-bottom: 5px !important;
    padding: 15px !important;
    background: #f8f9fa !important;
    transition: all 0.3s ease !important;
    border: 1px solid transparent !important;
  }

  #kt_header_topbar.topbar-mobile-on .dropdown-item:hover,
  #kt_header_topbar.topbar-mobile-on .dropdown-item.active {
    background: #a11b27 !important; /* Premium Red */
    border-color: #8b141e !important;
  }

  /* White text for professional look inside dropdown items */
  #kt_header_topbar.topbar-mobile-on .dropdown-item span.text-dark {
    color: #3f4254 !important;
    font-size: 1.1rem !important;
    font-weight: 700 !important;
  }

  #kt_header_topbar.topbar-mobile-on .dropdown-item small.text-muted {
    color: #7e8299 !important;
    font-size: 0.9rem !important;
  }

  #kt_header_topbar.topbar-mobile-on .dropdown-item:hover span,
  #kt_header_topbar.topbar-mobile-on .dropdown-item.active span,
  #kt_header_topbar.topbar-mobile-on .dropdown-item:hover small,
  #kt_header_topbar.topbar-mobile-on .dropdown-item.active small {
    color: #ffffff !important; /* Force white text on red background */
  }

  /* Icons scaled down */
  #kt_header_topbar.topbar-mobile-on .btn i {
    margin-right: 15px !important;
    font-size: 1.2rem !important;
    width: 25px;
    text-align: center;
    color: inherit !important;
  }

  /* Ensure the hamburger icon itself looks clean and right-aligned */
  #custom_mobile_toggle {
    margin-left: auto;
  }
}

/* ---- 3. Content Area -------------------------------------- */
@media (max-width: 991.98px) {
  /* Zero out paddings to remove whitespace "rings" */
  #kt_wrapper { 
    padding: 0 !important; 
    margin: 0 !important;
    width: 100% !important;
  }
  .content { padding: 0 !important; margin: 0 !important; }
  #kt_content { padding: 0 !important; margin: 0 !important; }
  .container, .container-fluid { 
    padding: 0 15px !important; 
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Force vertical layout for main content flex containers */
  .d-flex.flex-row:not(.select2-selection),
  .d-flex.flex-column.flex-lg-row,
  .d-flex.flex-lg-row {
    flex-direction: column !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Content area expansion */
  .flex-row-fluid {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow-x: clip !important;
  }

  /* Title & Breadcrumbs styling */
  .judul-utama {
    margin: 0 !important;
    padding: 15px 10px !important;
    background: #ffffff;
    border-bottom: 1px solid #ebedf3;
  }

  .isi-judul-utama {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    text-align: center !important;
    width: 100% !important;
  }

  .isi-judul-utama h3 {
    font-size: 1.1rem !important;
    margin-bottom: 10px !important;
    font-weight: 700 !important;
  }

  .isi-judul-utama h3 small {
    display: block !important;
    margin-top: 5px;
    font-size: 0.85rem !important;
  }

  .breadcrumbc {
    float: none !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 5px 0 0 !important;
    font-size: 0.8rem !important;
  }
}

/* ---- 4. Visibility Helpers -------------------------------- */
@media (max-width: 991.98px) {
  .d-mobile-none { display: none !important; }
}

/* ---- 4. Tables -------------------------------------------- */
@media (max-width: 767.98px) {
  .table-responsive {
    border: 0 !important;
    margin-bottom: 20px;
  }
  table.table {
    min-width: 600px; /* Force scroll for cramped tables */
  }
}

/* ---- 5. Utility ------------------------------------------- */
.d-mobile-block { display: none; }
@media (max-width: 991.98px) {
  .d-mobile-block { display: block !important; }
  .d-mobile-none { display: none !important; }
}

/* ---- 6. Grantee & All Pages: sidebar (#kt_profile_aside) inside mobile hamburger drawer --- */
@media (max-width: 991.98px) {

  /* Hide the desktop sidebar shell — width & position cleared */
  #kt_profile_aside,
  #kt_profile_aside.flex-row-auto,
  #kt_profile_aside.offcanvas-mobile,
  .flex-row-auto.offcanvas-mobile.w-250px,
  .flex-row-auto.offcanvas-mobile.w-400px,
  .flex-row-auto.offcanvas-mobile.w-xl-280px,
  .flex-row-auto.offcanvas-mobile.w-xl-400px {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    flex: 0 0 0 !important;
    visibility: hidden !important;
  }

  /* Also hide the header-bottom wrapper used by backend grantee side-grantee */
  #kt_header_bottom {
    display: none !important;
  }

  /* Section wrapper inside drawer */
  .mobile-nav-left-section {
    border-bottom: 2px solid #ebedf3;
    padding-bottom: 15px;
    margin-bottom: 10px;
    width: 100%;
  }

  /* Section heading label */
  .mobile-nav-left-section .mobile-nav-left-heading {
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-size: 0.8rem !important;
    margin-bottom: 10px !important;
    padding-left: 5px !important;
  }

  /* Convert navi-link items into full-width pill buttons */
  .mobile-nav-left-section .navi-link,
  .mobile-nav-left-inner .navi-link {
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    padding: 12px 15px !important;
    margin: 4px 0 !important;
    background: #f3f6f9 !important;
    border-radius: 12px !important;
    color: #3f4254 !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    font-size: 0.95rem !important;
    border: 1px solid #ebedf3 !important;
    transition: background 0.2s ease !important;
    position: relative !important;
  }

  .mobile-nav-left-section .navi-link.active,
  .mobile-nav-left-inner .navi-link.active {
    background: #9f1521 !important;
    color: #ffffff !important;
    border-color: #9f1521 !important;
  }

  .mobile-nav-left-section .navi-link.active i,
  .mobile-nav-left-inner .navi-link.active i {
    color: #ffffff !important;
  }

  /* Push the rightmost label (chevron / count) to the right */
  .mobile-nav-left-section .navi-link .label.rightmost,
  .mobile-nav-left-inner .navi-link .label.rightmost {
    margin-left: auto !important;
    position: static !important;
    right: auto !important;
  }

  /* Count badge (ml-3 label) styling */
  .mobile-nav-left-section .navi-link .label.ml-3,
  .mobile-nav-left-inner .navi-link .label.ml-3 {
    margin-left: 8px !important;
    font-size: 0.75rem !important;
  }

  /* Dropdown menus inside the nav (used by backend side-grantee) */
  .mobile-nav-left-section .dropdown-menu,
  .mobile-nav-left-inner .dropdown-menu {
    position: static !important;
    width: 100% !important;
    float: none !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08) !important;
    border: 1px solid #ebedf3 !important;
    margin: 6px 0 !important;
    border-radius: 12px !important;
    padding: 8px !important;
    background: #ffffff !important;
    display: block !important;
  }

  .mobile-nav-left-section .dropdown-menu .dropdown-item,
  .mobile-nav-left-inner .dropdown-menu .dropdown-item {
    border-radius: 8px !important;
    margin: 3px 0 !important;
    padding: 10px 14px !important;
    background: #f8f9fa !important;
    color: #3f4254 !important;
    font-weight: 500 !important;
    transition: all 0.2s ease !important;
  }

  .mobile-nav-left-section .dropdown-menu .dropdown-item:hover,
  .mobile-nav-left-inner .dropdown-menu .dropdown-item:hover {
    background: #9f1521 !important;
    color: #ffffff !important;
  }

  /* Submit proposal / action button full width */
  .mobile-nav-left-section .btn-block,
  .mobile-nav-left-section form .btn,
  .mobile-nav-left-inner .btn-block,
  .mobile-nav-left-inner form .btn {
    width: 100% !important;
    border-radius: 12px !important;
    margin: 8px 0 4px !important;
    min-height: 48px !important;
    font-weight: 700 !important;
  }

  /* Revision note box – limit height so it doesn't swamp the drawer */
  .mobile-nav-left-section .table-responsive,
  .mobile-nav-left-inner .table-responsive {
    max-height: 200px !important;
    overflow-y: auto !important;
  }

  /* Profile card inside drawer (side-details.php) */
  .mobile-nav-left-section .card,
  .mobile-nav-left-inner .card {
    box-shadow: none !important;
    border: 1px solid #ebedf3 !important;
    border-radius: 12px !important;
    margin-bottom: 10px !important;
  }

  /* Profile photo in drawer */
  .mobile-nav-left-section .symbol img,
  .mobile-nav-left-inner .symbol img {
    width: 60px !important;
    height: 60px !important;
    border-radius: 10px !important;
    object-fit: cover !important;
  }

  /* ---- Grantee content area: full width when sidebar removed ---- */
  /* Ensure the content-wrapper expands fully */
  .d-flex.flex-row > .flex-row-fluid.ml-lg-8 {
    margin-left: 0 !important;
    border-left: none !important;
  }

  /* ---- Status flow tiles on mobile (contract data, etc.) ---- */
  .status {
    font-size: 0.8rem !important;
    padding: 4px 8px !important;
  }

  /* Breadcrumb trimming on mobile */
  .breadcrumbc {
    float: none !important;
    font-size: 0.78rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 100% !important;
    display: block !important;
  }

  /* Card status header area: stack status badges vertically on small screens */
  .card-header .card-title .d-flex.align-items-center {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  /* Hide back button absolute-positioned element on tiny screens */
  .btnback {
    position: static !important;
    margin-top: 5px !important;
    display: inline-block !important;
  }
}

