/* ====================================================================
   BEAMS Premium UI — Global Desk Enhancement
   Applies modern typography, layout density fixes, and premium styling
   to the Frappe/ERPNext v16 Desk interface.
   ==================================================================== */

/* 1. FONTS — Plus Jakarta Sans from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

/* 2. GLOBAL TYPOGRAPHY */
body,
input,
select,
textarea,
button,
.form-control,
.control-label,
.page-title,
.head-title,
.title-text,
.widget-title,
.sidebar-link,
.list-row,
.frappe-control,
.data-pill,
.indicator-pill,
.label-area,
.modal-title {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* 3. LAYOUT WIDTH — The main fix for excessive side gaps */
:root {
  /* Expand form max-width from the default 900px to use more screen space */
  --page-max-width: 1400px !important;

  /* Slim down the sidebar so the form content gets more room */
  --form-sidebar-width: 240px !important;
  --form-sidebar-image-width: 68px !important;

  /* Premium accent color — deep indigo */
  --primary: #5850ec !important;
  --primary-color: #5850ec !important;
  --btn-primary: #5850ec !important;

  /* Modern border radius */
  --border-radius-sm:  4px !important;
  --border-radius:     8px !important;
  --border-radius-md:  10px !important;
  --border-radius-lg:  14px !important;
  --border-radius-xl:  18px !important;

  /* Slightly tighter spacing to reduce "wasted" vertical gaps */
  --padding-xs: 4px !important;
  --padding-sm: 8px !important;
  --padding-md: 12px !important;

  --margin-xs:  4px !important;
  --margin-sm:  8px !important;
  --margin-md:  12px !important;
}

[data-theme="dark"] {
  --primary: #6875f5 !important;
  --primary-color: #6875f5 !important;
  --btn-primary: #6875f5 !important;
}

/* 4. LAYOUT — Make the main form section use full available width on Desktop */
@media (min-width: 992px) {
  body:not(.hide-form-sidebar) .layout-main-section-wrapper {
    width: calc(100% - var(--form-sidebar-width)) !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  body.hide-form-sidebar .layout-main-section-wrapper {
    width: 100% !important;
    flex: 1 !important;
    min-width: 0 !important;
  }
}

/* 4b. MOBILE LAYOUT — Force 100% content width, zero sidebar space */
@media (max-width: 991.98px) {

  /* CRITICAL: Force .layout-main-section-wrapper to occupy 100% of the row.
     Using flex: 0 0 100% (= Bootstrap col-12) ensures no sidebar space remains,
     regardless of whether Bootstrap flex-wrap causes sidebar to stack or not. */
  .layout-main-section-wrapper {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* CRITICAL: Completely zero out the sidebar — no width, no padding, no margin,
     so it takes zero space in the flex row even if display:none doesn't fully work */
  .layout-side-section {
    display: none !important;
    flex: 0 0 0 !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    visibility: hidden !important;
  }

  /* When hamburger is tapped, Frappe adds .opened to the inner overlay-sidebar.
     Restore the parent so the child can be positioned fixed. */
  .layout-side-section:has(.overlay-sidebar.opened) {
    display: block !important;
    flex: 0 0 0 !important;
    width: 0 !important;
    overflow: visible !important;
    visibility: visible !important;
  }

  /* The opened drawer slides in from left as a fixed overlay */
  .overlay-sidebar.opened {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 80vw !important;
    max-width: 320px !important;
    z-index: 1050 !important;
    background: var(--card-bg, #ffffff) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.22) !important;
    overflow-y: auto !important;
    padding: var(--padding-md) !important;
    visibility: visible !important;
  }
}

/* Ensure section-body and section-head expand to the new max-width */
.std-form-layout .section-head,
.std-form-layout .section-body {
  max-width: var(--page-max-width) !important;
  margin: 0 auto !important;
}

/* Reduce the horizontal padding around form sections */
.form-section,
.form-dashboard-section {
  padding: 0 var(--padding-sm) !important;
}

/* 5. CARD STYLING — Premium card look for form pages */
.layout-main-section.frappe-card {
  border-radius: var(--border-radius-lg) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.03) !important;
  overflow: hidden;
}

[data-theme="dark"] .layout-main-section.frappe-card {
  border: 1px solid rgba(255, 255, 255, 0.07) !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35) !important;
}

/* Widgets and dashboard cards */
.widget-box,
.document-link,
.frappe-card {
  border-radius: var(--border-radius-lg) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04) !important;
  transition: box-shadow 0.22s ease, transform 0.22s ease, border-color 0.22s ease !important;
}

.widget-box:hover,
.document-link:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 8px 24px rgba(88, 80, 236, 0.10) !important;
  border-color: var(--primary) !important;
}

[data-theme="dark"] .widget-box,
[data-theme="dark"] .document-link,
[data-theme="dark"] .frappe-card {
  border: 1px solid rgba(255, 255, 255, 0.07) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3) !important;
}

/* 6. SECTION HEADINGS — Clean, readable separator lines */
.form-section .section-head {
  font-weight: 600 !important;
  font-size: var(--text-base) !important;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border-color) !important;
  margin-bottom: var(--margin-sm) !important;
  padding: var(--padding-sm) var(--padding-md) !important;
  color: var(--text-color) !important;
}

/* 7. FORM TABS — Modern pill-style active indicator */
.form-tabs-list .nav-item .nav-link.active {
  font-weight: 600 !important;
  color: var(--primary) !important;
  border-bottom: 2px solid var(--primary) !important;
}

.form-tabs-list .nav-item .nav-link {
  transition: color 0.18s ease !important;
}

.form-tabs-list .nav-item .nav-link:hover:not(.active) {
  color: var(--text-color) !important;
}

/* 8. BUTTONS — Polished interactive states */
.btn {
  font-family: inherit !important;
  font-weight: 500 !important;
  letter-spacing: -0.01em;
  border-radius: var(--border-radius) !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.btn-primary {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.btn:not(.btn-reset):not(.nav-link):hover {
  transform: translateY(-1px) !important;
}

.btn:active {
  transform: translateY(0px) !important;
}

/* 9. FORM INPUTS — Refined focus ring */
.form-control {
  border-radius: var(--border-radius) !important;
  transition: border-color 0.18s ease, box-shadow 0.18s ease !important;
}

.form-control:focus,
.form-control.focus,
.awesomplete [aria-selected="true"],
.frappe-control.focused .form-control {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(88, 80, 236, 0.12) !important;
  outline: none !important;
}

/* 10. GRID / TABLE ROWS — Tighter, more modern table styling */
.grid-row {
  border-radius: var(--border-radius-sm) !important;
  transition: background-color 0.15s ease !important;
}

.grid-row:hover {
  background-color: var(--highlight-color) !important;
}

.grid-heading-row .grid-static-col,
.grid-heading-row .sortable-handle {
  font-weight: 600 !important;
  font-size: var(--text-sm) !important;
  letter-spacing: 0.02em !important;
  text-transform: uppercase !important;
  color: var(--text-muted) !important;
}

/* 11. SIDEBAR — Slimmer, more elegant right sidebar on Desktop */
@media (min-width: 992px) {
  .layout-side-section:not(.overlay-sidebar) {
    min-width: var(--form-sidebar-width) !important;
    max-width: var(--form-sidebar-width) !important;
  }
}

.form-sidebar .sidebar-section {
  padding: var(--padding-sm) var(--padding-md) 0 !important;
}

/* 12. LIST VIEW — Cleaner list rows */
.list-row-container .list-row {
  border-radius: var(--border-radius-sm) !important;
  transition: background-color 0.15s ease !important;
}

.list-row-container .list-row:hover {
  background-color: var(--highlight-color) !important;
}

/* 13. NAVBAR & PAGE HEAD — Tighter header spacing */
.navbar {
  font-family: inherit !important;
}

.page-head {
  border-bottom: 1px solid var(--border-color) !important;
}

/* 14. MODAL — Modern dialog styling */
.modal-content {
  border-radius: var(--border-radius-xl) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  overflow: visible !important;
}

.modal-body,
.form-section,
.form-column,
.form-layout {
  overflow: visible !important;
}

.modal-body:has(.awesomplete),
.modal-dialog:has(.awesomplete) .modal-body {
  padding-bottom: 320px !important;
  min-height: 350px !important;
  overflow: visible !important;
}

.modal-dialog .awesomplete > ul,
.awesomplete > ul {
  position: absolute !important;
  z-index: 1055 !important;
  max-height: 380px !important;
  overflow-y: auto !important;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22) !important;
}

.modal-header {
  border-bottom: 1px solid var(--border-color) !important;
  padding: 16px 20px !important;
}

.modal-footer {
  border-top: 1px solid var(--border-color) !important;
  padding: 12px 20px !important;
}

[data-theme="dark"] .modal-content {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5) !important;
}

/* 15. INDICATOR PILLS — More polished */
.indicator-pill,
.indicator-pill::before {
  border-radius: 20px !important;
}

/* 16. LINK FIELDS — Better autocomplete dropdown */
.awesomplete > ul {
  border-radius: var(--border-radius-md) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10) !important;
  border: 1px solid var(--border-color) !important;
  overflow: hidden;
}

/* 17. SIDEBAR NAV ITEMS */
.sidebar-link {
  border-radius: var(--border-radius) !important;
  transition: background-color 0.15s ease, color 0.15s ease !important;
}

.sidebar-link.selected,
.sidebar-link:hover {
  background-color: var(--highlight-color) !important;
}

/* 18. PAGE CONTAINER — Adjust form & page container padding without breaking navbar */
.page-body .container,
.std-form-layout .container {
  padding-left: 8px !important;
  padding-right: 8px !important;
}

/* 19. FORM FOOTER spacing fix */
.form-footer {
  padding: 0 8px !important;
}

/* 20. DASHBOARD / HOME WIDGETS — Better grid layout */
.widget-group .widget-group-head {
  font-weight: 700 !important;
  font-size: var(--text-md) !important;
  letter-spacing: -0.02em !important;
}

/* 21. SCROLLBAR — Slim, modern scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* 22. ALERT / BANNER STYLING */
.alert {
  border-radius: var(--border-radius-md) !important;
  border: none !important;
}

/* 23. DROPDOWN MENUS */
.dropdown-menu {
  border-radius: var(--border-radius-md) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10) !important;
  border: 1px solid var(--border-color) !important;
}

.dropdown-menu:not(.notifications-list) {
  padding: 4px !important;
}

.dropdown-item {
  border-radius: var(--border-radius-sm) !important;
  transition: background-color 0.12s ease !important;
}

/* 24. PAGE BODY — Ensure content area expands properly */
.page-body .container {
  max-width: 100% !important;
}

/* 25. BREADCRUMBS */
.breadcrumb-container .breadcrumb-item a {
  font-weight: 500 !important;
}

/* 26. FIX: Remove extra left/right margin on standard form layout page wrapper */
body:not(.full-width) .std-form-layout > .form-layout > .form-page {
  padding: 0 4px !important;
}

/* 27. NAVBAR, PROFILE & APP SWITCHER ALIGNMENT */
.navbar .nav-item {
  display: flex;
  align-items: center;
}

.navbar .dropdown-navbar-user .dropdown-menu,
.navbar .dropdown-help .dropdown-menu,
.navbar .dropdown-notifications .dropdown-menu {
  margin-top: 4px;
}

.navbar .dropdown-navbar-user button,
.navbar .dropdown-help button,
.navbar .dropdown-notifications button {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dropdown-navbar-user .dropdown-item,
.app-switcher .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 28. LOGIN SCREEN & WEBSITE BRAND LOGO FIX */
/* Navbar brand: constrain the logo image tightly */
html body .navbar-brand img,
html body .navbar-brand svg,
html body .navbar-brand .brand-logo {
  max-height: 40px !important;
  max-width: 160px !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  display: block !important;
}

/* Login page: .app-logo is an IMG on the login page */
html body .page-card-head img.app-logo,
html body .page-login img.app-logo,
html body .login-content img.app-logo,
html body .form-signin img.app-logo,
html body .page-card img.app-logo,
html body img.app-logo {
  max-height: 48px !important;
  max-width: 180px !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  display: block !important;
  margin: 0 auto 16px auto !important;
}

/* 29. DESK NAVBAR LOGO STYLING — for .app-logo used in desk navbar */
html body .navbar .app-logo,
html body .navbar-brand .app-logo,
html body .navbar-home img {
  max-height: 28px !important;
  height: 28px !important;
  width: auto !important;
  object-fit: contain !important;
}

/* 30. APPS LAUNCHER PAGE ALIGNMENT & APP ICONS (/apps) */

/* Outer container layout for /apps */
html body .container:has(.apps-container),
html body .apps-container,
.apps-container {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
}

html body .container:has(.apps-container) {
  min-height: 100vh !important;
  max-width: 100vw !important;
  padding: 24px !important;
  margin: 0 !important;
  background: var(--bg-color, #f8fafc) !important;
}

html body .apps-container,
.apps-container {
  background: var(--card-bg, #ffffff) !important;
  padding: 40px 60px !important;
  border-radius: 20px !important;
  border: 1px solid var(--border-color, #e2e8f0) !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08) !important;
  gap: 32px !important;
  min-height: auto !important;
}

html body .apps-container .title,
.apps-container .title {
  font-size: 18px !important;
  font-weight: 600 !important;
  color: var(--text-color, #0f172a) !important;
  margin-bottom: 8px !important;
}

/* Apps flex container */
html body .apps-container .apps,
html body .apps,
.apps {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 28px !important;
  justify-content: center !important;
  align-items: flex-start !important;
}

/* Individual App Card Container */
html body .apps-container .apps .app-icon,
html body .apps .app-icon,
html body .app-icon,
.app-icon {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 10px !important;
  text-decoration: none !important;
  position: relative !important;
  width: 90px !important;
}

/* APPS PAGE APP LOGO CARD (div.app-logo container) — scoped to /apps page only */
html body .apps-container .apps .app-icon .app-logo,
html body .apps-container .apps .app-logo,
html body .apps .app-icon .app-logo,
html body .apps .app-logo,
html body .app-icon div.app-logo,
html body div.app-logo.app-name-cls,
html body div.app-name-cls {
  width: 68px !important;
  height: 68px !important;
  max-width: 68px !important;
  max-height: 68px !important;
  min-width: 68px !important;
  min-height: 68px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 16px !important;
  position: relative !important;
  overflow: hidden !important; /* CRITICAL: Prevent any logo overflow */
  background: var(--card-bg, #ffffff) !important;
  border: 1px solid var(--border-color, #e2e8f0) !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.22s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.22s ease !important;
  padding: 6px !important;
  box-sizing: border-box !important;
}

/* CRITICAL: Force EVERY IMG tag inside app-logo / app-icon / app-name-cls to fit 100% inside container */
html body .apps-container .apps .app-icon .app-logo img,
html body .apps-container .apps .app-logo img,
html body .apps .app-icon .app-logo img,
html body .apps .app-logo img,
html body .app-icon .app-logo img,
html body .app-logo.app-name-cls img,
html body .app-name-cls img,
html body .app-logo img,
html body .app-icon img,
.app-logo img,
.app-name-cls img {
  width: 100% !important;
  height: 100% !important;
  max-width: 52px !important;
  max-height: 52px !important;
  object-fit: contain !important;
  display: block !important;
  margin: auto !important;
}

/* App icon hover animation */
html body .app-icon:hover .app-logo,
html body .apps .app-icon:hover .app-logo {
  transform: translateY(-3px) scale(1.05) !important;
  border-color: var(--primary, #5850ec) !important;
  box-shadow: 0 10px 24px rgba(88, 80, 236, 0.18) !important;
}

/* App title text */
html body .app-title,
html body .apps .app-title,
html body .apps-container .app-title,
.app-title {
  font-size: 13px !important;
  font-weight: 600 !important;
  color: var(--text-color, #1e293b) !important;
  text-align: center !important;
  margin-top: 4px !important;
  white-space: nowrap !important;
  width: 100% !important;
}

/* Set Default Checkmark Badge - anchored inside top-right of .app-logo */
html body .apps-container .set-default,
html body .apps .set-default,
html body .app-logo .set-default,
html body .app-icon .set-default,
.set-default {
  position: absolute !important;
  top: 4px !important;
  right: 4px !important;
  z-index: 20 !important;
  border-radius: 50% !important;
  background: #000000 !important;
  color: #ffffff !important;
  width: 20px !important;
  height: 20px !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25) !important;
  border: 2px solid #ffffff !important;
}

html body .set-default svg,
.set-default svg {
  width: 12px !important;
  height: 12px !important;
}

/* Logout button on /apps page */
html body .apps-container .logout-btn,
html body .logout-btn,
.logout-btn {
  margin-top: 12px !important;
  padding: 8px 24px !important;
  border-radius: var(--border-radius-md, 10px) !important;
  font-weight: 500 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
}



