/* CRM_ADAPTIVE_RESPONSIVE_STYLE_V104
   Adaptive profiles:
   compact-mobile, mobile-landscape, tablet-portrait,
   tablet-landscape, desktop, wide-desktop.
*/
:root {
  --crm-safe-top: env(safe-area-inset-top, 0px);
  --crm-safe-right: env(safe-area-inset-right, 0px);
  --crm-safe-bottom: env(safe-area-inset-bottom, 0px);
  --crm-safe-left: env(safe-area-inset-left, 0px);
  --crm-viewport-height: 100dvh;
  --crm-touch-target: 44px;
  --crm-space-1: clamp(4px, .45vw, 7px);
  --crm-space-2: clamp(8px, .8vw, 12px);
  --crm-space-3: clamp(12px, 1.2vw, 18px);
  --crm-space-4: clamp(16px, 1.7vw, 24px);
  --crm-font-body: clamp(13px, .22vw + 12.5px, 15px);
  --crm-font-small: clamp(11px, .18vw + 10.5px, 13px);
  --crm-font-title: clamp(20px, 1.15vw + 15px, 30px);
  --crm-card-radius: clamp(14px, 1.2vw, 20px);
  --crm-sidebar-width: 252px;
}

html,
body {
  max-width: 100%;
  min-height: 100%;
  overflow-x: clip;
}

body {
  font-size: var(--crm-font-body);
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-x: none;
}

body,
button,
input,
select,
textarea {
  font-size: var(--crm-font-body);
}

button,
[role="button"],
input,
select,
textarea {
  min-height: var(--crm-touch-target);
}

button,
.nav-btn,
.erp-nav-tree-toggle,
.erp-nav-tree-item {
  touch-action: manipulation;
}

img,
svg,
canvas {
  max-width: 100%;
}

.workspace,
.workspace main,
.panel,
.metric,
.module,
.modal-card,
.form-grid > *,
.details-grid > *,
.role-dashboard-section,
.role-dashboard-grid {
  min-width: 0;
}

.workspace {
  container-type: inline-size;
  container-name: crm-workspace;
}

main,
.panel,
.modal-card,
.table-wrap,
.role-dashboard-section {
  container-type: inline-size;
}

.workspace h2 {
  font-size: var(--crm-font-title);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.panel h3,
.module h3,
.metric strong {
  overflow-wrap: anywhere;
}

.badge,
.nav-count,
code,
.erp-nowrap,
[data-nowrap="true"],
.table th {
  white-space: nowrap;
}

.panel-head,
.actions,
.module-top,
.notification-head {
  flex-wrap: wrap;
}

.actions > button,
.panel-head > button,
.panel-head > .actions {
  flex: 0 0 auto;
}

.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
  gap: var(--crm-space-2);
}

.form-grid .span-2,
.form-grid [data-span="full"],
.form-grid textarea,
.form-grid .wide-field {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  min-width: 0;
}

textarea {
  min-height: 96px;
}

.metric-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
}

.module-grid,
.role-dashboard-grid,
.health-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
}

.metric,
.panel,
.module,
.role-dashboard-card {
  border-radius: var(--crm-card-radius);
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.table th,
.table td {
  max-width: min(38vw, 420px);
  overflow-wrap: anywhere;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 3;
}

.crm-density-compact .table th,
.crm-density-compact .table td {
  padding: 8px 9px;
}

.crm-density-compact .metric,
.crm-density-compact .panel,
.crm-density-compact .module {
  padding: 12px;
}

.crm-density-comfortable .table th,
.crm-density-comfortable .table td {
  padding: 14px;
}

.adaptive-table-toolbar {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 7px 0;
}

.adaptive-view-toggle {
  min-height: 36px;
  padding: 6px 10px;
  font-size: var(--crm-font-small);
}

.adaptive-card-list {
  display: none;
  gap: 10px;
}

.adaptive-data-card {
  display: grid;
  gap: 10px;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #dfe5ef);
  border-radius: 15px;
  padding: 13px;
  box-shadow: 0 5px 18px rgba(23, 34, 59, .05);
}

.adaptive-data-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.adaptive-data-card-title {
  min-width: 0;
  font-weight: 850;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.adaptive-data-card-subtitle {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.adaptive-card-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.adaptive-card-field {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.adaptive-card-field > small {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.adaptive-card-field > div {
  overflow-wrap: anywhere;
}

.adaptive-card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  padding-top: 3px;
  border-top: 1px solid var(--line);
}

.adaptive-more {
  border: 0;
  background: transparent;
  color: var(--accent);
  min-height: 34px;
  padding: 4px 0;
  justify-self: start;
}

.adaptive-secondary-fields {
  display: none;
  grid-column: 1 / -1;
  grid-template-columns: inherit;
  gap: inherit;
}

.adaptive-data-card.expanded .adaptive-secondary-fields {
  display: grid;
}

.adaptive-menu-toggle,
.adaptive-density-toggle,
.adaptive-sidebar-toggle {
  display: none;
  min-width: var(--crm-touch-target);
  width: var(--crm-touch-target);
  height: var(--crm-touch-target);
  padding: 0;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.adaptive-density-toggle {
  width: auto;
  padding-inline: 11px;
  font-size: 12px;
}

.adaptive-sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 35, .58);
  z-index: 44;
}

.crm-header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.crm-orientation-transition *,
.crm-resizing * {
  transition-duration: 0s !important;
}

dialog {
  max-height: calc(var(--crm-viewport-height) - var(--crm-safe-top) - var(--crm-safe-bottom) - 20px);
}

.modal-card {
  max-height: calc(var(--crm-viewport-height) - var(--crm-safe-top) - var(--crm-safe-bottom) - 28px);
  overflow: auto;
  overscroll-behavior: contain;
}

.toast {
  max-width: min(420px, calc(100vw - 28px - var(--crm-safe-left) - var(--crm-safe-right)));
  right: calc(14px + var(--crm-safe-right));
  bottom: calc(14px + var(--crm-safe-bottom));
}

/* Wide desktop */
html[data-crm-profile="wide-desktop"] main {
  max-width: 1760px;
}

html[data-crm-profile="wide-desktop"] .metric-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

/* Tablet landscape rail */
html[data-crm-profile="tablet-landscape"] .shell {
  grid-template-columns: 76px minmax(0, 1fr);
  transition: grid-template-columns .2s ease;
}

html[data-crm-profile="tablet-landscape"] body.crm-sidebar-expanded .shell {
  grid-template-columns: 260px minmax(0, 1fr);
}

html[data-crm-profile="tablet-landscape"] .sidebar {
  width: 100%;
  overflow-x: hidden;
}

html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .sidebar .brand > div,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .sidebar .profile strong,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .sidebar .profile span,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .sidebar .profile button,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .erp-nav-tree-label,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .erp-nav-tree-count,
html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .erp-nav-tree-children {
  display: none !important;
}

html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .brand {
  justify-content: center;
}

html[data-crm-profile="tablet-landscape"] body:not(.crm-sidebar-expanded) .erp-nav-tree-toggle {
  justify-content: center;
}

html[data-crm-profile="tablet-landscape"] .adaptive-sidebar-toggle,
html[data-crm-profile="tablet-portrait"] .adaptive-sidebar-toggle {
  display: inline-flex;
}

/* Tablet portrait */
html[data-crm-profile="tablet-portrait"] .shell {
  grid-template-columns: 220px minmax(0, 1fr);
}

html[data-crm-profile="tablet-portrait"] main {
  padding-inline: 16px;
}

html[data-crm-profile="tablet-portrait"] .table [data-priority="4"] {
  display: none;
}

/* Mobile profiles */
html[data-crm-profile="compact-mobile"] .shell,
html[data-crm-profile="mobile-landscape"] .shell {
  display: block;
}

html[data-crm-profile="compact-mobile"] .sidebar,
html[data-crm-profile="mobile-landscape"] .sidebar {
  display: flex !important;
  position: fixed;
  inset: 0 auto 0 0;
  width: min(88vw, 328px);
  height: var(--crm-viewport-height);
  padding:
    calc(14px + var(--crm-safe-top))
    13px
    calc(14px + var(--crm-safe-bottom))
    calc(13px + var(--crm-safe-left));
  z-index: 45;
  transform: translateX(-105%);
  transition: transform .22s ease;
  box-shadow: 22px 0 60px rgba(10, 18, 35, .28);
  overflow-y: auto;
}

html[data-crm-profile="compact-mobile"] body.crm-sidebar-open .sidebar,
html[data-crm-profile="mobile-landscape"] body.crm-sidebar-open .sidebar {
  transform: translateX(0);
}

html[data-crm-profile="compact-mobile"] body.crm-sidebar-open .adaptive-sidebar-scrim,
html[data-crm-profile="mobile-landscape"] body.crm-sidebar-open .adaptive-sidebar-scrim {
  display: block;
}

html[data-crm-profile="compact-mobile"] .adaptive-menu-toggle,
html[data-crm-profile="mobile-landscape"] .adaptive-menu-toggle {
  display: inline-flex;
}

html[data-crm-profile="compact-mobile"] .adaptive-density-toggle,
html[data-crm-profile="mobile-landscape"] .adaptive-density-toggle,
html[data-crm-profile="tablet-portrait"] .adaptive-density-toggle,
html[data-crm-profile="tablet-landscape"] .adaptive-density-toggle {
  display: inline-flex;
}

html[data-crm-profile="compact-mobile"] .workspace header,
html[data-crm-profile="mobile-landscape"] .workspace header {
  min-height: 64px;
  height: auto;
  gap: 8px;
  padding:
    calc(8px + var(--crm-safe-top))
    calc(10px + var(--crm-safe-right))
    8px
    calc(10px + var(--crm-safe-left));
}

html[data-crm-profile="compact-mobile"] .workspace header > div:first-child,
html[data-crm-profile="mobile-landscape"] .workspace header > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

html[data-crm-profile="compact-mobile"] .workspace header .eyebrow,
html[data-crm-profile="mobile-landscape"] .workspace header .eyebrow {
  display: none;
}

html[data-crm-profile="compact-mobile"] .workspace h2,
html[data-crm-profile="mobile-landscape"] .workspace h2 {
  font-size: clamp(18px, 5vw, 22px);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

html[data-crm-profile="compact-mobile"] #coreBadge,
html[data-crm-profile="mobile-landscape"] #coreBadge {
  display: none;
}

html[data-crm-profile="compact-mobile"] main,
html[data-crm-profile="mobile-landscape"] main {
  padding:
    12px
    calc(12px + var(--crm-safe-right))
    calc(92px + var(--crm-safe-bottom))
    calc(12px + var(--crm-safe-left));
}

html[data-crm-profile="compact-mobile"] .metric-grid,
html[data-crm-profile="compact-mobile"] .module-grid,
html[data-crm-profile="compact-mobile"] .health-grid,
html[data-crm-profile="compact-mobile"] .role-dashboard-grid {
  grid-template-columns: 1fr;
}

html[data-crm-profile="mobile-landscape"] .metric-grid,
html[data-crm-profile="mobile-landscape"] .module-grid,
html[data-crm-profile="mobile-landscape"] .health-grid,
html[data-crm-profile="mobile-landscape"] .role-dashboard-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

html[data-crm-profile="compact-mobile"] .panel,
html[data-crm-profile="mobile-landscape"] .panel {
  padding: 13px;
  margin-top: 11px;
}

html[data-crm-profile="compact-mobile"] .form-grid,
html[data-crm-profile="mobile-landscape"] .form-grid {
  grid-template-columns: 1fr;
}

html[data-crm-profile="compact-mobile"] .form-grid > *,
html[data-crm-profile="mobile-landscape"] .form-grid > * {
  grid-column: 1 / -1;
}

html[data-crm-profile="compact-mobile"] .adaptive-table-toolbar,
html[data-crm-profile="mobile-landscape"] .adaptive-table-toolbar {
  display: flex;
}

html[data-crm-profile="compact-mobile"] .table-wrap[data-adaptive-mode="cards"] > .table,
html[data-crm-profile="mobile-landscape"] .table-wrap[data-adaptive-mode="cards"] > .table {
  display: none;
}

html[data-crm-profile="compact-mobile"] .table-wrap[data-adaptive-mode="cards"] > .adaptive-card-list,
html[data-crm-profile="mobile-landscape"] .table-wrap[data-adaptive-mode="cards"] > .adaptive-card-list {
  display: grid;
}

html[data-crm-profile="compact-mobile"] .table [data-priority="3"],
html[data-crm-profile="compact-mobile"] .table [data-priority="4"],
html[data-crm-profile="mobile-landscape"] .table [data-priority="4"] {
  display: none;
}

html[data-crm-profile="compact-mobile"] .adaptive-card-fields {
  grid-template-columns: 1fr;
}

html[data-crm-profile="compact-mobile"] dialog,
html[data-crm-profile="mobile-landscape"] dialog {
  width: 100vw;
  max-width: 100vw;
  height: var(--crm-viewport-height);
  max-height: var(--crm-viewport-height);
  margin: 0;
  padding: 0;
}

html[data-crm-profile="compact-mobile"] dialog[open],
html[data-crm-profile="mobile-landscape"] dialog[open] {
  display: block;
}

html[data-crm-profile="compact-mobile"] .modal-card,
html[data-crm-profile="mobile-landscape"] .modal-card {
  min-height: var(--crm-viewport-height);
  max-height: var(--crm-viewport-height);
  border-radius: 0;
  padding:
    calc(56px + var(--crm-safe-top))
    calc(14px + var(--crm-safe-right))
    calc(84px + var(--crm-safe-bottom))
    calc(14px + var(--crm-safe-left));
}

html[data-crm-profile="compact-mobile"] .modal-card .close,
html[data-crm-profile="mobile-landscape"] .modal-card .close {
  position: fixed;
  top: calc(8px + var(--crm-safe-top));
  right: calc(8px + var(--crm-safe-right));
  z-index: 2;
  min-width: 44px;
  min-height: 44px;
}

html[data-crm-profile="compact-mobile"] .mobile-nav,
html[data-crm-profile="mobile-landscape"] .mobile-nav {
  padding-bottom: var(--crm-safe-bottom);
}

html[data-crm-profile="compact-mobile"] .mobile-nav button,
html[data-crm-profile="mobile-landscape"] .mobile-nav button {
  min-height: 54px;
}

/* Landscape mobile uses space more aggressively. */
html[data-crm-profile="mobile-landscape"] .workspace header {
  position: sticky;
}

html[data-crm-profile="mobile-landscape"] main {
  padding-top: 8px;
}

html[data-crm-profile="mobile-landscape"] .modal-card {
  min-height: var(--crm-viewport-height);
}

/* Container-level adaptation for narrow panels inside wide screens. */
@container crm-workspace (max-width: 680px) {
  .details-grid,
  .scope-modes,
  .role-dashboard-grid {
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: flex-start;
  }
}

@container (max-width: 520px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .details-grid,
  .adaptive-card-fields {
    grid-template-columns: 1fr;
  }
}

/* Browser zoom and larger system text must not collapse controls. */
@media (max-width: 430px) {
  :root {
    --crm-touch-target: 46px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions > button,
  .actions > a {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
