/* ============================================================
   Smart Business 360 — Application-wide responsive layer
   Loaded last among app CSS so shared breakpoints win.
   Prefer intrinsic sizing, min-width:0, and contained scroll
   regions over page-level overflow-x:hidden.
   ============================================================ */

:root {
  --sbs-bp-xs: 320px;
  --sbs-bp-sm: 576px;
  --sbs-bp-md: 768px;
  --sbs-bp-lg: 992px;
  --sbs-bp-xl: 1200px;
  --sbs-bp-xxl: 1400px;
  --sbs-navbar-height: 56px;
  --sbs-touch-target: 44px;
  --sbs-content-gutter: 1rem;
  --sbs-content-gutter-sm: 0.65rem;
  --sbs-safe-top: env(safe-area-inset-top, 0px);
  --sbs-safe-right: env(safe-area-inset-right, 0px);
  --sbs-safe-bottom: env(safe-area-inset-bottom, 0px);
  --sbs-safe-left: env(safe-area-inset-left, 0px);
  --sbs-profile-menu-gutter: 12px;
}

/* ── Shell: allow flex children to shrink; avoid page-wide X scroll ── */
html {
  overflow-x: clip;
}

body.premium-ui {
  overflow-x: clip;
  max-width: 100vw;
}

body.premium-ui .main-wrapper,
body.premium-ui .page-wrapper,
body.premium-ui .page-content {
  max-width: 100%;
  min-width: 0;
}

body.premium-ui .page-content {
  overflow-x: clip;
  padding-left: var(--sbs-content-gutter);
  padding-right: var(--sbs-content-gutter);
  box-sizing: border-box;
}

body.premium-ui .page-content > .container-fluid,
body.premium-ui .page-content > .container {
  max-width: 100%;
  padding-left: 0;
  padding-right: 0;
}

body.premium-ui .row {
  max-width: 100%;
}

body.premium-ui .row > [class*="col"] {
  min-width: 0;
}

/* Images, embeds, charts */
body.premium-ui img,
body.premium-ui svg,
body.premium-ui canvas,
body.premium-ui video,
body.premium-ui iframe {
  max-width: 100%;
  height: auto;
}

/* Brand artwork keeps its own box. The rule above would otherwise
   stretch the wordmark and crop the collapsed sidebar icon. */
body.premium-ui img.sidebar-brand-logo,
body.premium-ui img.sidebar-brand-icon,
body.premium-ui .navbar-brand-mobile img,
body.premium-ui img.login-brand-logo {
  max-width: none;
  height: auto;
}

body.premium-ui.login-page img.login-brand-logo {
  max-width: min(100%, 280px);
  width: auto;
  height: auto !important;
  object-fit: contain;
  object-position: center;
}

body.premium-ui.login-page img.login-brand-logo--form {
  max-width: min(100%, 220px);
}

body.premium-ui .chart-container,
body.premium-ui canvas,
body.premium-ui .apexcharts-canvas,
body.premium-ui .chartjs-render-monitor {
  max-width: 100% !important;
}

/* ── Tables: contained horizontal scroll only ── */
body.premium-ui .table-responsive,
body.premium-ui .dataTables_wrapper,
body.premium-ui .dt-container,
body.premium-ui .sbs-table-scroll {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

body.premium-ui .table-responsive > .table,
body.premium-ui .sbs-table-scroll > .table {
  margin-bottom: 0;
  min-width: 640px;
}

body.premium-ui .table td,
body.premium-ui .table th {
  word-break: normal;
  overflow-wrap: anywhere;
  vertical-align: middle;
}

body.premium-ui .table .text-nowrap {
  white-space: nowrap;
}

/* Row action menus use Popper strategy:fixed (see _Layout.cshtml),
   so keep table scroll containment even while a menu is open. */
body.premium-ui .table-responsive:has(.dropdown-menu.show),
body.premium-ui .table-responsive:has(.table-actions-dropdown .show) {
  overflow-x: auto;
  overflow-y: visible;
}

/* ── Forms ── */
body.premium-ui .form-control,
body.premium-ui .form-select,
body.premium-ui .input-group,
body.premium-ui textarea.form-control {
  max-width: 100%;
}

body.premium-ui .input-group {
  flex-wrap: wrap;
}

body.premium-ui .btn-toolbar,
body.premium-ui .btn-group {
  flex-wrap: wrap;
  gap: 0.35rem;
}

body.premium-ui .btn-group > .btn {
  flex: 0 1 auto;
}

body.premium-ui label,
body.premium-ui .form-label,
body.premium-ui .form-text,
body.premium-ui .invalid-feedback,
body.premium-ui .field-validation-error,
body.premium-ui .validation-summary-errors {
  overflow-wrap: anywhere;
}

/* Long unbroken strings in content */
body.premium-ui .card-body,
body.premium-ui .modal-body,
body.premium-ui .dropdown-menu:not(.profile-menu),
body.premium-ui .notification-list {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ── Page header / filters / tabs ── */
body.premium-ui .centralized-page-header .row {
  align-items: flex-start;
}

body.premium-ui .page-header-actions,
body.premium-ui .filter-bar,
body.premium-ui .filters-row,
body.premium-ui .company-dash-nav,
body.premium-ui .nav-tabs,
body.premium-ui .nav-pills,
body.premium-ui [role="tablist"] {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 100%;
}

/* Dense tab strips (System Settings, etc.): scroll instead of wrapping labels */
body.premium-ui .nav-tabs.flex-nowrap,
body.premium-ui .settings-tabs,
body.premium-ui [role="tablist"].flex-nowrap {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

body.premium-ui .nav-tabs.flex-nowrap .nav-link,
body.premium-ui .settings-tabs .nav-link,
body.premium-ui [role="tablist"].flex-nowrap .nav-link {
  white-space: nowrap;
  flex: 0 0 auto;
}

body.premium-ui .company-dash-nav {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  padding-bottom: 0.15rem;
}

body.premium-ui .company-dash-nav .nav-link {
  white-space: nowrap;
  flex: 0 0 auto;
}

/* ── Modals, dropdowns, toasts, drawers ── */
body.premium-ui .modal-dialog {
  margin: 0.75rem auto;
  max-width: min(100% - 1.5rem, var(--bs-modal-width, 500px));
}

body.premium-ui .modal-content {
  max-height: calc(100dvh - 1.5rem);
  display: flex;
  flex-direction: column;
}

body.premium-ui .modal-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

body.premium-ui .dropdown-menu:not(.profile-menu) {
  max-width: min(100vw - 1rem, 24rem);
  max-height: min(70vh, 28rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

body.premium-ui .notification-dropdown {
  width: min(22rem, calc(100vw - 1rem)) !important;
  max-width: calc(100vw - 1rem) !important;
}

body.premium-ui .swal2-popup {
  max-width: min(32rem, calc(100vw - 1.5rem)) !important;
}

body.premium-ui .swal2-container {
  padding: 0.5rem !important;
}

/* ── Statistic cards row safety ── */
body.premium-ui .row > [class*="col"] > .dashboard-card,
body.premium-ui .row > [class*="col"] > .card.dashboard-card {
  width: 100%;
}

body.premium-ui .dashboard-card .pc-value,
body.premium-ui .dashboard-card .card-number,
body.premium-ui .dashboard-card .pc-title,
body.premium-ui .dashboard-card .card-text {
  max-width: 100%;
}

/* ── Touch targets ── */
@media (pointer: coarse) {
  body.premium-ui .btn,
  body.premium-ui .page-header-btn,
  body.premium-ui .sbs-action-btn,
  body.premium-ui .nav-link.topnav-link,
  body.premium-ui .sbs-mobile-menu-toggle,
  body.premium-ui .ai-chat-toggle {
    min-height: var(--sbs-touch-target);
    min-width: var(--sbs-touch-target);
  }

  body.premium-ui .form-check-input {
    width: 1.15rem;
    height: 1.15rem;
  }
}

/* ── Focus visibility ── */
body.premium-ui :focus-visible {
  outline: 2px solid #258cfb;
  outline-offset: 2px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  body.premium-ui *,
  body.premium-ui *::before,
  body.premium-ui *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Mobile sidebar: in-flow accordion panels (no clipped flyouts) ── */
@media (max-width: 991.98px) {
  body.premium-ui.sidebar-open .sidebar-dropdown-parent {
    position: static;
  }

  body.premium-ui.sidebar-open .sidebar-dropdown-panel,
  body.premium-ui.sidebar-open .sidebar-dropdown-panel.show {
    position: static !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    max-height: none !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    overflow: visible !important;
  }

  body.premium-ui.sidebar-open .sidebar-dropdown-header {
    display: none;
  }

  body.premium-ui.sidebar-open .sidebar-dropdown-menu,
  body.premium-ui.sidebar-open .sidebar-dropdown-scroll {
    max-height: none !important;
    overflow: visible !important;
    padding-left: 0.75rem !important;
  }

  body.premium-ui.sidebar-open .sidebar-dropdown-menu .nav-link {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body.premium-ui .page-content {
    padding-left: var(--sbs-content-gutter-sm);
    padding-right: var(--sbs-content-gutter-sm);
  }

  body.premium-ui .main-content {
    padding: 0.65rem;
  }

  /* AI FAB safe area */
  body.premium-ui .ai-chat-widget {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  body.premium-ui .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }
}

/* Tablet portrait / small laptop */
@media (max-width: 1024px) {
  body.premium-ui .page-header-actions {
    justify-content: flex-start;
  }

  body.premium-ui .page-header-btn {
    white-space: normal;
    text-align: center;
  }
}

/* Standard mobile and below */
@media (max-width: 767.98px) {
  body.premium-ui .table-responsive > .table,
  body.premium-ui .sbs-table-scroll > .table {
    min-width: 560px;
    font-size: 0.875rem;
  }

  /* Do not force-stack every Bootstrap column; only tighten gutters and wrap actions */
  body.premium-ui .card-body {
    padding: 0.9rem;
  }

  body.premium-ui .d-flex.gap-2,
  body.premium-ui .d-flex.gap-3 {
    flex-wrap: wrap;
  }

  body.premium-ui .btn-group.w-100,
  body.premium-ui .action-buttons {
    width: 100%;
  }

  body.premium-ui .action-buttons .btn,
  body.premium-ui .d-grid .btn {
    width: 100%;
  }
}

/* Small phones (320–414) */
@media (max-width: 414.98px) {
  body.premium-ui .page-header-title {
    font-size: 1.1rem;
  }

  body.premium-ui .navbar .navbar-content {
    padding-left: 0.4rem !important;
    padding-right: 0.4rem !important;
    gap: 0.25rem;
  }

  body.premium-ui .sbs-mobile-menu-toggle {
    width: 40px;
    height: 40px;
    margin-right: 0.35rem;
  }

  body.premium-ui .table-responsive > .table,
  body.premium-ui .sbs-table-scroll > .table {
    min-width: 480px;
    font-size: 0.8125rem;
  }

  body.premium-ui .dashboard-card .pc-value,
  body.premium-ui .dashboard-card .card-number {
    font-size: clamp(0.95rem, 5vw, 1.35rem) !important;
  }
}

/* Large desktop: keep content readable, avoid stretched forms */
@media (min-width: 1920px) {
  body.premium-ui .page-content > .container-fluid {
    max-width: 1800px;
    margin-inline: auto;
  }
}

/* Zoom / high DPI: keep navbar tools from overflowing */
@media (max-width: 1280px) and (min-resolution: 1.25dppx) {
  body.premium-ui .topnav-link > span:not(.topnav-icon-wrap):not(.topnav-badge) {
    display: none;
  }

  body.premium-ui .topnav-link .topnav-icon-wrap {
    display: inline-flex;
  }
}

/* Landscape phones: keep content usable under short viewport */
@media (max-height: 500px) and (orientation: landscape) {
  body.premium-ui .modal-content {
    max-height: calc(100dvh - 0.75rem);
  }

  body.premium-ui .ai-chat-widget {
    bottom: 8px;
  }
}

body.premium-ui .footer {
  max-width: 100%;
  white-space: normal !important;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-left: 0.75rem !important;
  padding-right: 0.75rem !important;
  padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px)) !important;
}

body.premium-ui .footer p,
body.premium-ui .footer .footer-legal {
  max-width: 100%;
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin-bottom: 0.25rem;
  text-align: center;
}

body.premium-ui .footer-legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.55rem;
}

body.premium-ui .page-content {
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 991.98px) {
  body.premium-ui .page-content {
    /* Clear floating AI assistant so footer copy is not covered */
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }

  body.premium-ui .footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (min-width: 768px) {
  body.premium-ui .footer p,
  body.premium-ui .footer .footer-legal {
    text-align: left;
    justify-content: flex-start;
  }
}

/* Pipeline / kanban: keep stage scroller contained */
body.premium-ui .pipeline-board,
body.premium-ui .pipeline-stages-row,
body.premium-ui .kanban-board,
body.premium-ui .kanban-board-area {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* Kanban columns are fixed-width flex items — contain them, don't shrink cards */
body.premium-ui .kanban-column {
  flex: 0 0 auto;
  min-width: min(280px, 85vw);
  max-width: 320px;
}

@media (max-width: 575.98px) {
  body.premium-ui .pipeline-stage-body {
    height: auto !important;
    max-height: none !important;
    min-height: 220px;
  }
}

@media print {
  body.premium-ui .sidebar,
  body.premium-ui .navbar,
  body.premium-ui .ai-chat-widget,
  body.premium-ui .sbs-mobile-menu-toggle {
    display: none !important;
  }

  body.premium-ui .page-content {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  body.premium-ui .table-responsive,
  body.premium-ui .sbs-table-scroll {
    overflow: visible !important;
  }

  body.premium-ui .table-responsive > .table,
  body.premium-ui .sbs-table-scroll > .table {
    min-width: 0 !important;
  }
}

/* ============================================================
   Profile / Me popover
   Anchored to the header trigger and sized to the visual
   viewport. Wrapping stays on word boundaries so emails and
   theme labels do not fracture one character at a time.
   ============================================================ */

body.premium-ui:has(#profileMenu.show) .navbar {
  z-index: 100000 !important;
}

body.premium-ui .topnav-links .dropdown-menu.profile-menu {
  --profile-menu-width: min(
    22rem,
    calc(
      100dvw - (var(--sbs-profile-menu-gutter) * 2) - var(--sbs-safe-left) -
        var(--sbs-safe-right)
    )
  );
  position: fixed !important;
  top: calc(
    var(--sbs-navbar-height) + 8px + var(--sbs-safe-top)
  );
  /* Fallback before JS runs: pin to the Me control (navbar is the fixed
     containing block because of backdrop-filter). */
  right: max(var(--sbs-profile-menu-gutter), var(--sbs-safe-right));
  left: auto;
  z-index: 2 !important;
  display: none;
  width: var(--profile-menu-width);
  min-width: 0;
  max-width: var(--profile-menu-width);
  max-height: calc(
    100dvh - var(--sbs-navbar-height) - 16px - var(--sbs-safe-top) -
      var(--sbs-safe-bottom)
  );
  margin: 0;
  padding: 0;
  overflow: hidden;
  overflow-wrap: normal;
  word-break: normal;
  transform: none !important;
  border-radius: 12px;
  box-sizing: border-box;
  container: profilemenu / inline-size;
}

body.premium-ui .profile-menu.dropdown-menu.show {
  display: flex !important;
  flex-direction: column;
}

body.premium-ui .profile-menu__scroll {
  flex: 0 1 auto;
  min-height: 0;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.45) transparent;
}

body.premium-ui .profile-menu--scrollable .profile-menu__scroll {
  overflow-y: scroll;
  scrollbar-gutter: stable;
  box-shadow: inset 0 -16px 14px -16px rgba(15, 23, 42, 0.4);
}

body.premium-ui .profile-menu__scroll::-webkit-scrollbar {
  width: 8px;
}

body.premium-ui .profile-menu__scroll::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.45);
  border-radius: 8px;
}

body.premium-ui .profile-menu__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

body.premium-ui .profile-menu__avatar {
  flex: 0 0 auto;
}

body.premium-ui .profile-menu__photo,
body.premium-ui .profile-menu .user-avatar-large {
  width: 56px;
  height: 56px;
  font-size: 1.15rem;
  object-fit: cover;
  border-radius: 50%;
}

body.premium-ui .profile-menu__identity {
  width: 100%;
  min-width: 0;
  text-align: center;
}

body.premium-ui .profile-menu__name,
body.premium-ui .profile-menu__email {
  margin: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.45;
}

body.premium-ui .profile-menu__name {
  font-size: 0.9375rem;
  font-weight: 700;
}

body.premium-ui .profile-menu__email {
  margin-top: 0.2rem;
  font-size: 0.8125rem;
  color: #5c6770;
}

body.premium-ui .profile-menu__list {
  margin: 0;
  padding: 0.35rem;
}

body.premium-ui .profile-menu__logout-form {
  margin: 0;
  width: 100%;
}

body.premium-ui .profile-menu__action {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  min-height: var(--sbs-touch-target);
  margin: 0;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

body.premium-ui .profile-menu__action i {
  flex: 0 0 1.25rem;
  width: 1.25rem;
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

body.premium-ui .profile-menu__action span {
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.3;
}

body.premium-ui .profile-menu__action:hover,
body.premium-ui .profile-menu__action:focus-visible {
  background: rgba(0, 51, 102, 0.08);
  color: #003366;
}

body.premium-ui .profile-menu__action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

body.premium-ui .profile-menu__theme-current {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: var(--sbs-touch-target);
  padding: 0.35rem 0.75rem;
  cursor: default;
}

body.premium-ui .profile-menu__theme-current #currentThemeLabel {
  white-space: nowrap;
}

body.premium-ui .profile-theme-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0 0.35rem 0.35rem;
  padding: 0.3rem;
  border-radius: 0.75rem;
  background: rgba(0, 0, 0, 0.04);
}

body.premium-ui .profile-theme-grid .theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  width: 100%;
  min-width: 0;
  min-height: 3.75rem;
  height: 100%;
  padding: 0.4rem 0.25rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  box-sizing: border-box;
}

body.premium-ui .profile-theme-grid .theme-btn__icon {
  font-size: 1.05rem;
  line-height: 1;
  flex: 0 0 auto;
}

body.premium-ui .profile-theme-grid .theme-btn__label {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
  line-height: 1.2;
}

body.premium-ui .profile-theme-grid .theme-check-icon {
  font-size: 0.7rem;
  line-height: 1;
  height: 0.7rem;
  flex: 0 0 0.7rem;
}

body.premium-ui .profile-theme-grid .theme-btn.active,
body.premium-ui .profile-theme-grid .theme-btn[aria-pressed="true"] {
  box-shadow: inset 0 0 0 2px currentColor;
}

@container profilemenu (max-width: 17rem) {
  body.premium-ui .profile-theme-grid {
    grid-template-columns: 1fr;
  }

  body.premium-ui .profile-theme-grid .theme-btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.5rem;
    padding-left: 0.75rem;
  }

  body.premium-ui .profile-theme-grid .theme-check-icon {
    margin-left: auto;
  }
}

body.theme-dark .profile-menu__header,
body.theme-dark .profile-menu .dropdown-divider {
  border-color: rgba(255, 255, 255, 0.12);
}

body.theme-dark .profile-menu__email {
  color: #a8b3c4;
}

body.theme-dark .profile-menu__action:hover,
body.theme-dark .profile-menu__action:focus-visible {
  background: rgba(74, 144, 217, 0.18);
  color: #e2e8f0;
}

body.theme-dark .profile-theme-grid {
  background: rgba(255, 255, 255, 0.06);
}

body.theme-dark .profile-menu__scroll {
  scrollbar-color: rgba(226, 232, 240, 0.45) transparent;
}

body.theme-dark .profile-menu--scrollable .profile-menu__scroll {
  box-shadow: inset 0 -16px 14px -16px rgba(0, 0, 0, 0.55);
}

body.theme-monochrome .profile-menu__email {
  color: #4a5d73;
}

body.theme-monochrome .profile-menu__action:hover,
body.theme-monochrome .profile-menu__action:focus-visible {
  background: rgba(0, 51, 102, 0.08);
  color: #003366;
}

@media (min-width: 768px) {
  body.premium-ui .profile-menu__photo,
  body.premium-ui .profile-menu .user-avatar-large {
    width: 64px;
    height: 64px;
    font-size: 1.35rem;
  }
}

/* Sidebar wordmark and collapsed mark */
body.premium-ui .sidebar .sidebar-header .sidebar-brand {
  overflow: visible;
  max-width: 100%;
}

body.premium-ui img.sidebar-brand-logo {
  width: auto !important;
  height: 40px !important;
  max-height: 40px !important;
  max-width: calc(100% - 8px) !important;
  object-fit: contain;
  object-position: left center;
}

body.premium-ui img.sidebar-brand-icon {
  width: 36px !important;
  height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  object-fit: contain;
  object-position: center;
}

body.premium-ui.sidebar-folded .sidebar .sidebar-header .sidebar-brand {
  width: 100% !important;
  justify-content: center !important;
  overflow: hidden;
}

body.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-logo,
body.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-logo {
  display: none !important;
}

body.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-icon.icon-black,
body.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-icon.icon-black {
  display: inline-block !important;
}

body.theme-dark.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-icon.icon-black,
body.theme-dark.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-icon.icon-black,
body.theme-monochrome.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-icon.icon-black,
body.theme-monochrome.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-icon.icon-black {
  display: none !important;
}

body.theme-dark.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-icon.icon-white,
body.theme-dark.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-icon.icon-white,
body.theme-monochrome.premium-ui.sidebar-folded:not(.open-sidebar-folded) img.sidebar-brand-icon.icon-white,
body.theme-monochrome.premium-ui.sidebar-folded.open-sidebar-folded.no-hover-expand img.sidebar-brand-icon.icon-white {
  display: inline-block !important;
}

/* ==========================================================
   Mobile bug-pass fixes (BUG-005 … BUG-023)
   ========================================================== */

/* BUG-008: lock page scroll + solid backdrop when mobile drawer is open */
@media (max-width: 991.98px) {
  body.premium-ui.sidebar-open {
    overflow: hidden !important;
    touch-action: none;
  }

  body.premium-ui.sidebar-open .main-wrapper::before {
    content: "" !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.45) !important;
    z-index: 998 !important;
    display: block !important;
    pointer-events: auto !important;
  }

  body.premium-ui.sidebar-open .sidebar {
    z-index: 999 !important;
  }
}

/* BUG-005 / BUG-013: page-header action clusters on phones */
@media (max-width: 767.98px) {
  body.premium-ui .page-header-actions--desktop {
    display: none !important;
  }

  body.premium-ui .page-header-actions--mobile {
    display: flex !important;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
  }

  body.premium-ui .page-header-actions--mobile > .btn,
  body.premium-ui .page-header-actions--mobile > .dropdown {
    flex: 1 1 calc(50% - 0.35rem);
    min-width: min(100%, 9.5rem);
  }

  body.premium-ui .page-header-actions--mobile > .dropdown > .btn {
    width: 100%;
  }

  body.premium-ui .page-header-actions .page-header-btn {
    width: 100%;
    min-width: 0 !important;
    flex: none !important;
    justify-content: center;
    white-space: normal;
    overflow: visible;
    text-align: center;
    font-size: 0.8125rem;
    padding: 0.55rem 0.65rem;
    line-height: 1.25;
  }

  body.premium-ui .page-header-actions .page-header-btn i {
    margin-right: 0.35rem !important;
  }
}

@media (max-width: 419.98px) {
  body.premium-ui .page-header-actions--mobile > .btn,
  body.premium-ui .page-header-actions--mobile > .dropdown {
    flex: 1 1 100%;
  }
}

/* BUG-006: pagination polish */
body.premium-ui .pagination {
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
}

body.premium-ui .pagination .page-link {
  min-width: 2.25rem;
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem !important;
  margin: 0;
}

body.premium-ui .pagination .page-item.active .page-link {
  background-color: var(--primary-navy, #003366);
  border-color: var(--primary-navy, #003366);
  border-radius: 0.5rem !important;
  box-shadow: none;
}

/* BUG-007 / BUG-021: stacked form action rows */
@media (max-width: 575.98px) {
  body.premium-ui .form-actions-mobile,
  body.premium-ui .lead-edit-actions,
  body.premium-ui .opportunity-edit-actions,
  body.premium-ui .employee-create-actions {
    display: flex !important;
    flex-direction: column-reverse;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }

  body.premium-ui .form-actions-mobile > *,
  body.premium-ui .lead-edit-actions > *,
  body.premium-ui .lead-edit-actions > div,
  body.premium-ui .opportunity-edit-actions > *,
  body.premium-ui .opportunity-edit-actions > div,
  body.premium-ui .employee-create-actions > * {
    width: 100%;
  }

  body.premium-ui .lead-edit-actions > div,
  body.premium-ui .opportunity-edit-actions__primary {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  body.premium-ui .lead-edit-actions .btn,
  body.premium-ui .opportunity-edit-actions .btn,
  body.premium-ui .employee-create-actions .btn {
    width: 100%;
    margin: 0 !important;
    white-space: normal;
  }

  body.premium-ui .employee-create-actions .btn-lg {
    font-size: 1rem;
    padding: 0.65rem 1rem;
  }
}

/* Opportunity edit actions: keep Delete + Update side-by-side until xs, then stack */
@media (max-width: 767.98px) and (min-width: 576px) {
  body.premium-ui .opportunity-edit-actions {
    flex-wrap: wrap;
    gap: 0.5rem !important;
  }

  body.premium-ui .opportunity-edit-actions > .btn-secondary {
    flex: 1 1 100%;
    order: 3;
  }

  body.premium-ui .opportunity-edit-actions__primary {
    flex: 1 1 100%;
    display: flex;
    gap: 0.5rem;
  }

  body.premium-ui .opportunity-edit-actions__primary .btn {
    flex: 1 1 0;
  }
}

/* BUG-009: opportunity notes wrap */
body.premium-ui .opportunity-notes,
body.premium-ui .opportunity-overview-table td,
body.premium-ui .opportunity-overview-value {
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  min-width: 0;
}

/* BUG-010: modal backdrop + content isolation */
body.premium-ui .modal-backdrop {
  background-color: #0f172a;
  opacity: 0.55 !important;
}

body.premium-ui.modal-open {
  overflow: hidden;
}

body.premium-ui .modal.show .modal-content {
  position: relative;
  z-index: 1;
  background: #fff;
}

/* BUG-011: hide empty-state CTA when header primary exists on small screens */
@media (max-width: 767.98px) {
  body.premium-ui .activity-timeline-card #noActivitiesMessage .btn-primary {
    display: none;
  }

  body.premium-ui .quick-actions-card .btn-outline-secondary[onclick*="addActivity"] {
    display: none;
  }
}

/* BUG-014 / 019 / 022: stats card gaps */
body.premium-ui .row.stats-gap > [class*="col"],
body.premium-ui .row.mb-4 > [class*="col-xl-3"],
body.premium-ui .row.mb-4 > [class*="col-md-3"],
body.premium-ui .row.mb-4 > [class*="col-md-6"],
body.premium-ui .row.mb-4 > [class*="col-sm-6"] {
  margin-bottom: 0.85rem;
}

body.premium-ui .dashboard-card {
  height: 100%;
  margin-bottom: 0;
}

/* BUG-015: convert lead modal actions */
body.premium-ui .convert-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  justify-content: stretch;
}

body.premium-ui .convert-modal-actions > .btn,
body.premium-ui .convert-modal-actions > a.btn,
body.premium-ui .convert-modal-actions > form {
  flex: 1 1 auto;
  margin: 0 !important;
}

body.premium-ui .convert-modal-actions > form .btn {
  width: 100%;
}

@media (max-width: 575.98px) {
  body.premium-ui .convert-modal-actions {
    flex-direction: column;
  }

  body.premium-ui .convert-modal-actions > .btn,
  body.premium-ui .convert-modal-actions > a.btn,
  body.premium-ui .convert-modal-actions > form {
    width: 100%;
  }
}

/* BUG-016: Help Center mobile */
@media (max-width: 991.98px) {
  body.premium-ui .help-article-nav.sticky-top,
  body.premium-ui .article-sidebar.sticky-top,
  body.premium-ui [class*="help"] .sticky-top {
    position: static !important;
    top: auto !important;
  }

  body.premium-ui .article-content,
  body.premium-ui .help-content,
  body.premium-ui .markdown-body {
    max-width: 100%;
    overflow-x: auto;
  }

  body.premium-ui .article-content img,
  body.premium-ui .help-content img,
  body.premium-ui .markdown-body img,
  body.premium-ui .article-content table {
    max-width: 100%;
  }
}

/* BUG-017: AI chat header title visibility */
@media (max-width: 575.98px) {
  body.premium-ui .ai-chat-header {
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: flex-start !important;
  }

  body.premium-ui .ai-chat-header-info {
    flex: 1 1 auto;
    min-width: 0;
  }

  body.premium-ui .ai-chat-title {
    display: inline !important;
    font-size: 0.95rem;
    font-weight: 700;
  }

  body.premium-ui .ai-chat-status {
    display: none !important;
  }

  body.premium-ui .ai-header-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }
}

/* BUG-018: Work Information spacing when stacked */
@media (max-width: 767.98px) {
  body.premium-ui .employee-work-information,
  body.premium-ui .employee-profile-work {
    margin-top: 1.25rem;
  }
}

/* BUG-020: toast close icon geometry */
body.premium-ui .swal2-toast .swal2-close,
body.premium-ui .swal2-popup .swal2-close,
.swal2-toast-custom .swal2-close {
  width: 1.5rem !important;
  height: 1.5rem !important;
  border-radius: 50% !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 1rem !important;
  line-height: 1 !important;
  top: 0.35rem !important;
  right: 0.35rem !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* BUG-023 helpers: expandable parent triggers stay clear */
@media (max-width: 991.98px) {
  body.premium-ui .sidebar-dropdown-trigger {
    pointer-events: auto;
  }

  body.premium-ui .sidebar-dropdown-panel .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* ==========================================================
   Responsiveness pass: off-canvas sidebar, stack tables,
   and compact page-header overflow menu
   ========================================================== */

/* Mobile: fully hide folded icon rail; drawer opens as full labels */
@media (max-width: 991.98px) {
  body.premium-ui .sidebar,
  body.premium-ui.sidebar-folded .sidebar,
  body.premium-ui.sidebar-folded:not(.open-sidebar-folded) .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: min(280px, 86vw) !important;
    max-width: 280px !important;
    margin-left: 0 !important;
    transform: translateX(-105%) !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: transform 0.2s ease, visibility 0.2s ease !important;
    z-index: 999 !important;
  }

  body.premium-ui.sidebar-open .sidebar,
  body.premium-ui.sidebar-open.sidebar-folded .sidebar,
  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded) .sidebar {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-header,
  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-body
    .nav
    > .nav-item
    > .nav-link {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 44px !important;
    justify-content: flex-start !important;
    padding: 0.65rem 1rem !important;
    border-radius: 0 !important;
  }

  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-body
    .nav
    > .nav-item
    > .nav-link
    .link-title,
  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-body
    .nav
    > .nav-item
    > .nav-link
    .link-arrow,
  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-header
    .sidebar-brand {
    display: inline !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: auto !important;
  }

  body.premium-ui.sidebar-open.sidebar-folded:not(.open-sidebar-folded)
    .sidebar
    .sidebar-body
    .nav
    > .nav-item
    > .nav-link
    > i:first-child {
    margin-right: 0.65rem !important;
  }
}

/* Page-header: desktop keeps full button row; mobile uses compact overflow */
body.premium-ui .page-header-actions--desktop {
  display: none;
}

body.premium-ui .page-header-actions--mobile {
  display: flex;
  width: 100%;
  gap: 0.5rem;
  flex-wrap: wrap;
}

body.premium-ui .page-header-actions--mobile > .btn,
body.premium-ui .page-header-actions--mobile > .dropdown {
  flex: 1 1 calc(50% - 0.35rem);
  min-width: min(100%, 9.5rem);
}

body.premium-ui .page-header-actions--mobile > .dropdown > .btn {
  width: 100%;
}

@media (min-width: 768px) {
  body.premium-ui .page-header-actions--desktop {
    display: flex;
  }

  body.premium-ui .page-header-actions--mobile {
    display: none !important;
  }
}

/* Stack wide data tables into readable cards below md */
@media (max-width: 767.98px) {
  body.premium-ui .table-responsive.sbs-stack-table {
    overflow: visible;
    -webkit-overflow-scrolling: auto;
  }

  body.premium-ui .table-responsive.sbs-stack-table > .table {
    min-width: 0 !important;
    width: 100%;
  }

  body.premium-ui .sbs-stack-table thead {
    display: none;
  }

  body.premium-ui .sbs-stack-table tbody tr {
    display: block;
    margin: 0 0 0.85rem;
    padding: 0.25rem 0;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 0.75rem;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  }

  body.premium-ui .sbs-stack-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
    border: 0 !important;
    padding: 0.45rem 0.9rem !important;
  }

  body.premium-ui .sbs-stack-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 36%;
    max-width: 42%;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    color: #64748b;
    padding-top: 0.15rem;
  }

  body.premium-ui .sbs-stack-table tbody td:not([data-label])::before,
  body.premium-ui .sbs-stack-table tbody td[data-label=""]::before {
    content: none;
    display: none;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-primary {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    padding-top: 0.75rem !important;
    padding-bottom: 0.55rem !important;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-primary::before {
    display: none;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-actions {
    justify-content: flex-end;
    align-items: center;
    border-top: 1px solid rgba(15, 23, 42, 0.06) !important;
    margin-top: 0.15rem;
    padding-top: 0.65rem !important;
    padding-bottom: 0.75rem !important;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-actions::before {
    display: none;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-check {
    justify-content: flex-start;
    padding-bottom: 0 !important;
  }

  body.premium-ui .sbs-stack-table tbody td > *:last-child {
    flex: 1 1 auto;
    min-width: 0;
    text-align: right;
  }

  body.premium-ui .sbs-stack-table tbody td.sbs-stack-primary > *:last-child,
  body.premium-ui .sbs-stack-table tbody td.sbs-stack-actions > *:last-child,
  body.premium-ui .sbs-stack-table tbody td.sbs-stack-check > *:last-child {
    text-align: left;
  }

  body.premium-ui .sbs-stack-table .table-avatar-link {
    justify-content: flex-start;
  }
}


/* ==========================================================
   QA polish batch (equal cards, filters, empty states, FABs)
   ========================================================== */
body.premium-ui .qa-equal-cards,
body.premium-ui .row.qa-equal-cards > [class*='col'] {
  display: flex;
}
body.premium-ui .qa-equal-cards .card,
body.premium-ui .row.qa-equal-cards > [class*='col'] > .card {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
}

body.premium-ui .detail-label-grid,
body.premium-ui .user-detail-meta,
body.premium-ui .permission-override-row {
  display: grid;
  grid-template-columns: minmax(7rem, 10rem) 1fr;
  gap: 0.35rem 1rem;
  align-items: center;
}

body.premium-ui .btn.page-header-btn,
body.premium-ui .btn.btn-secondary.cancel-btn,
body.premium-ui a.btn.btn-outline-secondary.js-app-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

body.premium-ui .kanban-empty-state .btn,
body.premium-ui .empty-state .btn,
body.premium-ui .leave-empty-state .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
}

body.premium-ui .filter-panel .form-control,
body.premium-ui .filter-panel .form-select,
body.premium-ui .report-filters .form-control,
body.premium-ui .report-filters .form-select,
body.premium-ui .trial-balance-filters .form-control,
body.premium-ui .trial-balance-filters .form-select,
body.premium-ui .project-pnl-filters .form-control,
body.premium-ui .project-pnl-filters .form-select {
  border: 1px solid var(--bs-border-color, #ced4da);
}
body.premium-ui .filter-panel .form-control:focus,
body.premium-ui .filter-panel .form-select:focus,
body.premium-ui .report-filters .form-control:focus,
body.premium-ui .report-filters .form-select:focus,
body.premium-ui .trial-balance-filters .form-control:focus,
body.premium-ui .trial-balance-filters .form-select:focus,
body.premium-ui .project-pnl-filters .form-control:focus,
body.premium-ui .project-pnl-filters .form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.2);
}

body.premium-ui .chip-group,
body.premium-ui .pay-rules-tags,
body.premium-ui .attendance-pay-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

body.premium-ui .status-card i,
body.premium-ui .followup-status-card i {
  margin-right: 0.5rem;
}

body.premium-ui .dept-expense-amount,
body.premium-ui .metric-amount {
  position: relative;
  z-index: 1;
}

body.premium-ui .table-actions-cell .dropdown-menu {
  z-index: 1080;
}

body.premium-ui .purchase-register-card,
body.premium-ui .register-full-width {
  width: 100%;
  max-width: 100%;
}

body.premium-ui .modal-dialog-scrollable .modal-body {
  max-height: min(70vh, 32rem);
}

body.premium-ui .footer {
  padding-bottom: max(1rem, calc(env(safe-area-inset-bottom, 0px) + 4.5rem));
}

body.theme-dark .page-link {
  color: var(--td-text) !important;
}
