/* Keller Williams / CMX branding, aligned with the UAT CMX shell.
   Primary red #CE011F (KW main red), hover #A80119, active #8A0114.
   Graphite #222222. Content background #F8F9FA. White cards. */

:root {
  --kw-red: #CE011F;
  --kw-red-hover: #A80119;
  --kw-red-active: #8A0114;
  --kw-graphite: #222222;
  --kw-bg: #f8f9fa;
  --kw-border: #e5e7eb;
  --kw-card: #ffffff;
  --kw-amber: #b45309;
  --kw-emerald: #047857;
  --kw-dark-bg: #1e1e1e;
  --kw-dark-text: #f5f5f5;
}

html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  background-color: var(--kw-bg);
  color: var(--kw-graphite);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* --- Links --- */
a {
  color: var(--kw-red);
}
a:hover,
a:focus {
  color: var(--kw-red-hover);
}

/* :where() keeps this at plain "a" specificity, so class-styled links (sidebar items,
   buttons, chips) keep their own colours instead of all turning red in dark mode. */
:where([data-bs-theme="dark"]) a {
  color: #ff6b80;
}
:where([data-bs-theme="dark"]) a:hover,
:where([data-bs-theme="dark"]) a:focus {
  color: #ff97a5;
}

/* ============================================================
   App shell: top header + dark sidebar + light content
   ============================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 16px;
  background-color: var(--kw-card);
  border-bottom: 1px solid var(--kw-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: none;
  color: #6b7280;
  cursor: pointer;
}
.app-menu-toggle:hover {
  background-color: #f3f4f6;
  color: #111827;
}
@media (min-width: 992px) {
  .app-menu-toggle {
    display: none;
  }
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--kw-graphite);
}
.app-brand:hover {
  text-decoration: none;
  color: var(--kw-graphite);
}
.app-brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background-color: var(--kw-red);
  color: #ffffff;
  font-weight: 900;
  font-size: 1.15rem;
  letter-spacing: -0.05em;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
.app-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.app-brand-name {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.app-brand-sub {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--kw-red);
  white-space: nowrap;
}

.app-mc-chip {
  display: none;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--kw-border);
  font-size: 0.75rem;
  color: #6b7280;
  white-space: nowrap;
}
.app-mc-chip strong {
  color: #1f2937;
  font-weight: 600;
}
@media (min-width: 1200px) {
  .app-mc-chip {
    display: inline-flex;
  }
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: #6b7280;
  text-decoration: none;
}
.app-bell:hover {
  background-color: #f3f4f6;
  color: #374151;
}
.app-bell-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background-color: var(--kw-red);
}
.app-bell-count {
  position: absolute;
  top: 2px;
  right: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background-color: var(--kw-red);
  color: #ffffff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.app-user {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--kw-border);
  border-radius: 6px;
  background-color: var(--kw-card);
}
.app-avatar {
  display: inline-flex;
  position: relative;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background-color: var(--kw-red);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
}
/* The kw.com photo covers the initial; if it fails to load the initial shows. */
.app-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
/* Header chip of a user with an agent record: links to their agent profile. */
a.app-user-link {
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}
a.app-user-link:hover,
a.app-user-link:focus-visible {
  border-color: var(--kw-red);
}
.app-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
}
.app-user-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: #111827;
}
.app-user-role {
  font-size: 0.65rem;
  color: #6b7280;
}
@media (max-width: 575px) {
  .app-user-info {
    display: none;
  }
  .app-user {
    padding: 4px;
  }
  .app-header {
    padding: 0 10px;
  }
  .app-header-right {
    gap: 6px;
  }
}
/* Phones: the logo alone carries the brand; the wordmark would run under the header buttons. */
@media (max-width: 479px) {
  .app-brand-text {
    display: none;
  }
}

.app-logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: none;
  color: #6b7280;
  cursor: pointer;
}
.app-logout-btn:hover {
  background-color: #f3f4f6;
  color: var(--kw-red);
}

.app-body {
  display: flex;
  min-height: calc(100vh - 64px);
}

.app-sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 256px;
  flex-shrink: 0;
  background-color: var(--kw-graphite);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
}

.app-sidebar-top {
  padding: 16px 0;
}

.app-sidebar-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 16px 16px;
  padding: 10px 12px;
  border-radius: 6px;
  background-color: var(--kw-red);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.app-sidebar-cta:hover {
  background-color: var(--kw-red-hover);
  color: #ffffff;
  text-decoration: none;
}
.app-sidebar-cta:active {
  background-color: var(--kw-red-active);
}

.app-sidebar-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 16px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #ffffff;
}
.app-sidebar-label .dx-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--kw-red), var(--kw-red-active));
  box-shadow: 0 2px 8px rgba(206, 1, 31, 0.45);
  color: #ffffff;
  font-size: 14px;
}
/* DevExtreme's own .dx-icon rules win on display, so center the glyph by line box */
.app-sidebar-label .dx-icon::before {
  display: block;
  position: static;
  margin: 0;
  line-height: 24px;
  text-align: center;
}
/* Red rule fading out to the right of the title */
.app-sidebar-label::after {
  content: "";
  flex: 1;
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--kw-red), rgba(206, 1, 31, 0));
}

.app-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.app-sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #d1d5db;
  text-decoration: none;
  white-space: nowrap;
}
.app-sidebar-link:hover {
  background-color: #333333;
  color: #ffffff;
  text-decoration: none;
}
.app-sidebar-link.active {
  background-color: var(--kw-red);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.app-sidebar-link.active:hover {
  background-color: var(--kw-red);
  color: #ffffff;
}
.app-sidebar-link .dx-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.app-sidebar-footer {
  padding: 16px;
  border-top: 1px solid #1f2937;
  font-size: 0.7rem;
  color: #9ca3af;
}
.app-sidebar-footer strong {
  color: #d1d5db;
}

/* Mobile: sidebar collapses to an overlay */
@media (max-width: 991px) {
  .app-sidebar {
    display: none;
    position: fixed;
    z-index: 40;
    left: 0;
    top: 64px;
    bottom: 0;
    height: auto;
  }
  body.app-sidebar-open .app-sidebar {
    display: flex;
  }
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 48px;
}
@media (max-width: 767px) {
  .app-main {
    padding: 16px;
  }
}

/* --- Dark mode surfaces (DevExtreme dark theme handles controls) --- */
[data-bs-theme="dark"] body {
  background-color: var(--kw-dark-bg);
  color: var(--kw-dark-text);
}
[data-bs-theme="dark"] .app-header {
  background-color: var(--kw-dark-bg);
  border-bottom-color: #383838;
}
[data-bs-theme="dark"] .app-brand,
[data-bs-theme="dark"] .app-brand:hover {
  color: var(--kw-dark-text);
}
[data-bs-theme="dark"] .app-user {
  background-color: var(--kw-dark-bg);
  border-color: #383838;
}
[data-bs-theme="dark"] .app-user-name {
  color: var(--kw-dark-text);
}
[data-bs-theme="dark"] .app-bell:hover,
[data-bs-theme="dark"] .app-menu-toggle:hover,
[data-bs-theme="dark"] .app-logout-btn:hover {
  background-color: #2a2a2a;
  color: #e5e7eb;
}

/* --- Theme toggle button --- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  align-self: center;
  appearance: none;
  background: none;
  border: 1px solid var(--kw-border);
  border-radius: 0.375rem;
  color: #4b5563;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.theme-toggle:hover,
.theme-toggle:focus {
  border-color: var(--kw-red);
  color: var(--kw-red);
}
.theme-toggle .dx-icon {
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle .dx-icon-sun {
  display: none;
}
[data-bs-theme="dark"] .theme-toggle .dx-icon-moon {
  display: none;
}
[data-bs-theme="dark"] .theme-toggle .dx-icon-sun {
  display: inline-block;
}

/* --- Form controls focus (recolour from Bootstrap blue to KW red) --- */
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--kw-red);
}

.form-floating > .form-control-plaintext::placeholder,
.form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder,
.form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* --- Alerts --- */
.app-alert {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.app-alert-ok {
  background-color: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}
.app-alert-err {
  background-color: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}
[data-bs-theme="dark"] .app-alert-ok {
  background-color: rgba(4, 120, 87, 0.18);
  color: #6ee7b7;
  border-color: rgba(110, 231, 183, 0.35);
}
[data-bs-theme="dark"] .app-alert-err {
  background-color: rgba(185, 28, 28, 0.18);
  color: #fca5a5;
  border-color: rgba(252, 165, 165, 0.35);
}

/* --- Page / panel chrome (white cards, like UAT) --- */
.app-page-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
/* Why a record cannot be deleted, under its disabled «Устгах» button. */
.cmx-remove-blocked {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.85rem;
  text-align: right;
}
@media (max-width: 767.98px) {
  .cmx-remove-blocked { text-align: left; }
}
.app-page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--kw-graphite);
  margin-bottom: 0.25rem;
}
[data-bs-theme="dark"] .app-page-title {
  color: var(--kw-dark-text);
}
.app-page-subtitle {
  color: #6b7280;
  font-size: 0.8rem;
  margin-bottom: 1.25rem;
}

.app-panel {
  border: 1px solid var(--kw-border);
  border-radius: 0.5rem;
  margin-bottom: 1.25rem;
  overflow: hidden;
  background-color: var(--kw-card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
[data-bs-theme="dark"] .app-panel {
  background-color: #262626;
  border-color: #383838;
}
/* Colours: see "Section headers" below. */
.app-panel-head {
  padding: 0.75rem 1rem;
  font-weight: 600;
}
/* Padded content area under a panel head (forms, detail fields, grids). */
.app-panel-body {
  padding: 1rem 1.25rem 1.25rem;
}
.app-panel-body + .app-panel-body {
  padding-top: 0;
}
.app-panel-note {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: #6b7280;
}
.app-panel-body .dx-form + .dx-datagrid,
.app-panel-body .dx-datagrid + .dx-form,
.app-panel-body .dx-form + .dx-form {
  margin-top: 1rem;
}
.app-section-title {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.app-form-actions-bar {
  display: flex;
  gap: 0.75rem;
  margin: 0.5rem 0 2rem;
}

/* --- Forms --- */
.app-form {
  padding: 1rem;
}
.app-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}
.app-form-field {
  flex: 1 1 200px;
}
.app-form-field label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  color: #6b7280;
}
.app-form-actions {
  flex: 0 0 auto;
}

/* --- Grid badges / status --- */
.app-username {
  font-weight: 600;
  margin-right: 0.5rem;
}
.app-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 999px;
  background-color: #f3f4f6;
  color: #374151;
}
[data-bs-theme="dark"] .app-badge {
  background-color: #3a3a3a;
  color: #cccccc;
}
.app-status {
  font-size: 0.85rem;
}
.app-status-on {
  color: var(--kw-emerald);
}
.app-status-off {
  color: #b91c1c;
}
[data-bs-theme="dark"] .app-status-on {
  color: #6ee7b7;
}
[data-bs-theme="dark"] .app-status-off {
  color: #fca5a5;
}
.app-row-actions {
  display: flex;
  gap: 0.5rem;
}

/* --- Chips (agents / tags) --- */
.app-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.app-chip {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.72rem;
  line-height: 1.4;
  border-radius: 999px;
  background-color: #f3f4f6;
  border: 1px solid var(--kw-border);
  color: #374151;
  white-space: nowrap;
}
[data-bs-theme="dark"] .app-chip {
  background-color: #3a3a3a;
  border-color: #4a4a4a;
  color: #e5e7eb;
}

/* --- Property construction-state badges --- */
.app-status-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 999px;
  white-space: nowrap;
}
.app-status-planned {
  background-color: #eef2ff;
  color: #4338ca;
}
.app-status-under {
  background-color: #fffbeb;
  color: #b45309;
}
.app-status-completed {
  background-color: #ecfdf5;
  color: #047857;
}
.app-status-suspended {
  background-color: #fef2f2;
  color: #b91c1c;
}
[data-bs-theme="dark"] .app-status-planned {
  background-color: rgba(79, 70, 229, 0.2);
  color: #a5b4fc;
}
[data-bs-theme="dark"] .app-status-under {
  background-color: rgba(180, 83, 9, 0.2);
  color: #fbbf24;
}
[data-bs-theme="dark"] .app-status-completed {
  background-color: rgba(4, 120, 87, 0.2);
  color: #6ee7b7;
}
[data-bs-theme="dark"] .app-status-suspended {
  background-color: rgba(185, 28, 28, 0.2);
  color: #fca5a5;
}

/* --- Edit dialog --- */
.app-edit-field {
  margin-bottom: 1rem;
}
.app-edit-field label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
  color: #6b7280;
}
.app-edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* --- Dashboard stat cards (like UAT) --- */
.app-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}
@media (max-width: 991px) {
  .app-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 575px) {
  .app-stats {
    grid-template-columns: 1fr;
  }
}

.app-stat-card {
  border: 1px solid var(--kw-border);
  border-radius: 0.5rem;
  background-color: var(--kw-card);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  padding: 16px;
}
[data-bs-theme="dark"] .app-stat-card {
  background-color: #262626;
  border-color: #383838;
}
.app-stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.app-stat-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: #4b5563;
}
[data-bs-theme="dark"] .app-stat-title {
  color: #9ca3af;
}
.app-stat-head .dx-icon {
  color: var(--kw-red);
  font-size: 1rem;
}
.app-stat-head .dx-icon-amber {
  color: var(--kw-amber);
}
.app-stat-head .dx-icon-emerald {
  color: var(--kw-emerald);
}
.app-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--kw-graphite);
  line-height: 1.2;
}
[data-bs-theme="dark"] .app-stat-value {
  color: var(--kw-dark-text);
}
.app-stat-note {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: #6b7280;
}

.app-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.app-section-title h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--kw-graphite);
}
[data-bs-theme="dark"] .app-section-title h2 {
  color: var(--kw-dark-text);
}
.app-section-title a {
  font-size: 0.75rem;
  font-weight: 600;
}

/* --- Login / AccessDenied --- */
.app-login-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.app-login-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  border: 1px solid var(--kw-border);
  border-radius: 0.75rem;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
[data-bs-theme="dark"] .app-login-card {
  background-color: #262626;
  border-color: #383838;
}
.app-login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.app-login-logo {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--kw-red);
  color: #ffffff;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 0.5rem;
}
.app-login-brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
}
.app-login-brand-sub {
  font-size: 0.8rem;
  color: var(--kw-red);
  font-weight: 600;
  letter-spacing: 0.08em;
}
.app-login-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.app-login-sub {
  color: var(--bs-secondary-color, #666666);
  margin-bottom: 1.5rem;
}
.app-login-accounts {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.app-login-account {
  margin: 0;
}
.app-login-link {
  display: inline-block;
  margin-top: 1rem;
}
.app-login-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--bs-secondary-color, #666666);
  font-size: 0.8rem;
}
.app-login-divider::before,
.app-login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--kw-border);
}
.app-login-admin {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.app-login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.app-login-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--bs-secondary-color, #666666);
}

/* --- Contract detail grid --- */
.app-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem 1.5rem;
}
.app-detail-item span:last-child {
  overflow-wrap: anywhere;
}
/* Notes / document lists below a detail grid, separated by a rule. */
.app-detail-after {
  margin: 1rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--kw-border);
}
[data-bs-theme="dark"] .app-detail-after {
  border-top-color: #383838;
}
@media (max-width: 767px) {
  .app-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 479px) {
  .app-detail-grid {
    grid-template-columns: 1fr;
  }
}
.app-detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.9rem;
}
.app-detail-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #6b7280;
}
[data-bs-theme="dark"] .app-detail-label {
  color: #9ca3af;
}
.app-muted {
  color: #6b7280;
  font-size: 0.8rem;
}
[data-bs-theme="dark"] .app-muted {
  color: #9ca3af;
}
.app-doc-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.app-doc-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}
.app-doc-kind {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 0.25rem;
  background-color: var(--kw-red);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 600;
}

/* --- Contract form: read-only values, duplicate notices --- */
.app-readonly-value {
  padding: 0.45rem 0;
  font-weight: 500;
}
.app-alert-warn {
  border: 1px solid #f5d38a;
  background-color: #fff8e6;
  color: #7a5a00;
}
[data-bs-theme="dark"] .app-alert-warn {
  border-color: #6b5521;
  background-color: #3a3220;
  color: #f1d48a;
}
.cmx-dup-notices .app-alert {
  margin: 0.75rem 0 0;
}
.cmx-dup-list {
  margin: 0.4rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.85rem;
}
.dx-datagrid .dx-row.cmx-row-blocking > td {
  background-color: rgba(206, 1, 31, 0.08);
}
.dx-datagrid .dx-row.cmx-row-warning > td {
  background-color: rgba(245, 180, 0, 0.12);
}

/* --- Section headers (app-wide): main-red panel heads, form group captions,
   section titles and popup titles, matching the contract form. --- */
.app-panel-head,
.dx-overlay-wrapper .dx-popup-title.dx-toolbar {
  background-color: var(--kw-red);
  color: #fff;
  border-bottom: 1px solid var(--kw-red-hover);
  border-left: 4px solid var(--kw-red-active);
}
.app-panel-head {
  font-size: 0.9rem;
}
/* A grid placed straight under a panel head (no padded .app-panel-body): its toolbar
   (add, Excel export, column chooser, search) would touch the head and the panel's edge. */
.app-panel > .dx-widget > .dx-datagrid > .dx-datagrid-header-panel {
  padding: 0.625rem 0.75rem;
}
/* The popup close button sits on the red title bar: white like the title text. */
.dx-overlay-wrapper .dx-popup-title.dx-toolbar .dx-closebutton .dx-icon {
  color: #fff;
}
.dx-overlay-wrapper .dx-popup-title.dx-toolbar .dx-closebutton.dx-state-hover {
  background-color: var(--kw-red-hover);
}
.app-section-title,
.dx-form .dx-form-group-caption {
  color: var(--kw-red);
  border-bottom: 2px solid var(--kw-red);
  padding-bottom: 0.25rem;
}
/* Dark mode: a full red slab glares on a dark page, so heads become a raised dark
   surface that keeps the KW red as the accent bar on the left. */
[data-bs-theme="dark"] .app-panel-head,
[data-bs-theme="dark"] .dx-overlay-wrapper .dx-popup-title.dx-toolbar {
  background-color: #303030;
  color: #f5f5f5;
  border-bottom-color: #3d3d3d;
  border-left-color: var(--kw-red);
}
[data-bs-theme="dark"] .dx-overlay-wrapper .dx-popup-title.dx-toolbar .dx-closebutton.dx-state-hover {
  background-color: #404040;
}
[data-bs-theme="dark"] .app-section-title,
[data-bs-theme="dark"] .dx-form .dx-form-group-caption {
  color: #ffb3bc;
  border-bottom-color: #5a2a2f;
}

/* Confirm dialog (window.cmxConfirm): red "Тийм", grey "Үгүй". */
.cmx-dialog .cmx-dialog-message {
  padding: 0.25rem 0;
  font-size: 0.95rem;
}
.cmx-dialog .dx-button.dx-button-danger {
  background-color: var(--kw-red);
  border-color: var(--kw-red);
  color: #fff;
}
.cmx-dialog .dx-button.dx-button-danger.dx-state-hover {
  background-color: var(--kw-red-hover);
}
.cmx-dialog .dx-button.cmx-dialog-no {
  background-color: #e5e7eb;
  border-color: #d1d5db;
  color: #374151;
}
.cmx-dialog .dx-button.cmx-dialog-no.dx-state-hover {
  background-color: #d1d5db;
}
[data-bs-theme="dark"] .cmx-dialog .dx-button.cmx-dialog-no {
  background-color: #4b5563;
  border-color: #4b5563;
  color: #f3f4f6;
}

/* Single-property section laid out like the template's clause 2.1 table. */
.cmx-template-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.cmx-template-table td {
  border: 1px solid var(--kw-border);
  padding: 0.5rem 0.65rem;
  vertical-align: top;
}
.cmx-template-table td:first-child {
  text-align: center;
  font-weight: 600;
  color: #A80119;
  background-color: #fdf5f6;
}
.cmx-template-table td:nth-child(2) {
  font-weight: 500;
}
[data-bs-theme="dark"] .cmx-template-table td {
  border-color: #383838;
}
[data-bs-theme="dark"] .cmx-template-table td:first-child {
  background-color: #2f2224;
  color: #ffb3bc;
}
.cmx-cell-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.cmx-cell-row > div {
  flex: 1 1 200px;
}
.cmx-cell-label {
  margin: 0.25rem 0 0.2rem;
  font-size: 0.78rem;
  color: #6b7280;
}
.cmx-cell-hint {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: #6b7280;
}
@media (max-width: 640px) {
  .cmx-template-table colgroup col:nth-child(2) {
    width: 30% !important;
  }
}

/* --- Contract PDF preview (DevExpress Web Document Viewer, Contracts/Preview) --- */
.app-pdf-viewer {
  height: calc(100vh - 200px);
  min-height: 480px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
[data-bs-theme="dark"] .app-pdf-viewer {
  border-color: #383838;
}
/* Mobile viewer: its export popover lists formats as white text meant for a dark popover;
   the KW light swatch makes the popover white, so give each format a KW red tile. */
.dxrd-menu-export-popover .dxrd-menu-export-item {
  background-color: var(--kw-red);
  border-radius: 8px;
  font-weight: 600;
}
@media (max-width: 767px) {
  /* Mobile browsers' toolbars change the viewport height; dvh follows the visible area. */
  .app-pdf-viewer {
    height: calc(100dvh - 190px);
    min-height: 420px;
  }
}

/* --- kw.com listing cards (DevExtreme CardView, Views/Shared/_ListingCards) --- */
.cmx-listing {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.cmx-listing-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--kw-red);
}
.cmx-listing-title {
  font-weight: 600;
  /* Always two lines tall, so the facts, place and chips line up across a row of cards. */
  line-height: 1.4;
  min-height: 2.8em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cmx-listing-facts,
.cmx-listing-place {
  font-size: 0.85rem;
  color: #4b5563;
}
.cmx-listing-place {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmx-listing .app-chips {
  margin-top: 0.2rem;
}
.cmx-listing-status-Closed {
  opacity: 0.7;
}
/* An active kw.com listing stands out; every other status stays a plain chip. */
.app-chip.cmx-listing-status-Open {
  background-color: var(--kw-emerald);
  border-color: var(--kw-emerald);
  color: #ffffff;
  font-weight: 600;
}
/* Listing date chip, coloured by age (cmxListingAge): ≤ 1 month, ≤ 3, ≤ 6, older. */
.app-chip.cmx-listing-age { font-variant-numeric: tabular-nums; }
.app-chip.cmx-listing-age-new { background-color: #d1fae5; border-color: #6ee7b7; color: #065f46; }
.app-chip.cmx-listing-age-recent { background-color: #e0f2fe; border-color: #7dd3fc; color: #075985; }
.app-chip.cmx-listing-age-aging { background-color: #fef3c7; border-color: #fcd34d; color: #92400e; }
.app-chip.cmx-listing-age-old { background-color: #fee2e2; border-color: #fca5a5; color: #991b1b; }
[data-bs-theme="dark"] .app-chip.cmx-listing-age-new { background-color: #064e3b; border-color: #047857; color: #a7f3d0; }
[data-bs-theme="dark"] .app-chip.cmx-listing-age-recent { background-color: #0c4a6e; border-color: #0369a1; color: #bae6fd; }
[data-bs-theme="dark"] .app-chip.cmx-listing-age-aging { background-color: #78350f; border-color: #b45309; color: #fde68a; }
[data-bs-theme="dark"] .app-chip.cmx-listing-age-old { background-color: #7f1d1d; border-color: #b91c1c; color: #fecaca; }
/* The cards sit in an app-panel-body, which already pads them like every other panel: drop
   the CardView's own 24px so the toolbar and cards line up with the filter panel above
   (more specific than the theme's `.dx-swatch-keller-williams .dx-cardview`). */
.app-panel-body .cmx-listing-cards.dx-cardview {
  padding: 0;
}
/* The toolbar's age buttons: room beside the search box (or above it when it wraps on a
   phone); a pressed band takes its chip's colours. */
.cmx-listing-age-buttons {
  margin-right: 0.5rem;
}
.cmx-listing-cards .cmx-listing-age-buttons,
.cmx-listing-cards .dx-cardview-search-panel {
  margin-bottom: 0.4rem;
}
/* The filtered listing count at the right end of the toolbar. */
.cmx-listing-cards .dx-cardview-search-panel {
  margin-right: 0.75rem;
}
.cmx-listing-count {
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-new { background-color: #d1fae5; border-color: #6ee7b7; color: #065f46; }
.cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-recent { background-color: #e0f2fe; border-color: #7dd3fc; color: #075985; }
.cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-aging { background-color: #fef3c7; border-color: #fcd34d; color: #92400e; }
.cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-old { background-color: #fee2e2; border-color: #fca5a5; color: #991b1b; }
[data-bs-theme="dark"] .cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-new { background-color: #064e3b; border-color: #047857; color: #a7f3d0; }
[data-bs-theme="dark"] .cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-recent { background-color: #0c4a6e; border-color: #0369a1; color: #bae6fd; }
[data-bs-theme="dark"] .cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-aging { background-color: #78350f; border-color: #b45309; color: #fde68a; }
[data-bs-theme="dark"] .cmx-listing-age-buttons .dx-button.dx-item-selected.cmx-age-btn-old { background-color: #7f1d1d; border-color: #b91c1c; color: #fecaca; }
.cmx-listing-linked {
  color: var(--kw-emerald);
  font-weight: 600;
}
.cmx-listing-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.cmx-listing-agent {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.dx-cardview-card {
  cursor: pointer;
}
/* Cards of a row share a height: the agent line and social icons sit at the bottom of every
   card, whatever the title, facts or chips above take. */
.cmx-listing-cards .dx-cardview-card {
  display: flex;
  flex-direction: column;
}
.cmx-listing-cards .dx-cardview-card > div {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}
.cmx-listing-cards .dx-cardview-card-content {
  flex: 1 1 auto;
  align-content: start;
}
/* When any card shows social icons, cards without them keep the same empty row, so the agent
   line stays level across the row. */
.cmx-listing-cards:has(.cmx-social-compact .cmx-social) .cmx-social-compact:empty {
  display: flex;
  min-height: 30px;
}
.dx-cardview-card .dx-card-cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cmx-listing-footer {
  padding: 0.5rem 0.75rem 0.75rem;
}
[data-bs-theme="dark"] .cmx-listing-facts,
[data-bs-theme="dark"] .cmx-listing-place {
  color: #c4c9cf;
}
[data-bs-theme="dark"] .cmx-listing-linked {
  color: #34d399;
}

/* --- Agent directory cards (DevExtreme CardView, Views/Agents/Index) --- */
/* Portraits are mostly 4:5: a 4:5 cover shows them whole, anchored at the top so a crop never
   cuts a head. The image is CMX's 400 px copy (Agents/Photo, Services/AgentPhotos), not kw.com's
   large original, which the browser would shrink ~8x into jagged noise. */
#agentCards .dx-card-cover .dx-card-cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  background: #e5e7eb;
}
/* Cards of a row share its height: the content grows, so every footer sits at the bottom. */
#agentCards .dx-cardview-card > div:first-child {
  height: 100%;
  display: flex;
  flex-direction: column;
}
#agentCards .dx-cardview-card-content {
  flex: 1 1 auto;
  grid-template-columns: minmax(0, 1fr);
}
#agentCards .dx-cardview-card-content > * {
  min-width: 0;
}
.cmx-agent-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.cmx-agent-card-name {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.cmx-agent-card-place {
  font-size: 0.8rem;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmx-agent-card .cmx-social-compact {
  margin-top: 0.35rem;
}
.cmx-agent-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  min-height: 36px;
  padding: 0 0.35rem 0.4rem 0.75rem;
}
.cmx-agent-card-actions {
  display: flex;
}
[data-bs-theme="dark"] .cmx-agent-card-place {
  color: #c4c9cf;
}
/* Dark mode: a CardView inside a panel would draw a second, darker rounded box. */
[data-bs-theme="dark"] .app-panel .dx-cardview {
  background-color: transparent;
}
[data-bs-theme="dark"] #agentCards .dx-card-cover .dx-card-cover-image {
  background: #2a2a2a;
}

/* Agent page: the kw.com profile photo, shown large (CMX's 400 px copy, sharp at 2x). */
.cmx-agent-photo {
  width: 200px;
  height: 250px;
  border-radius: 16px;
  object-fit: cover;
  object-position: center top;
  border: 3px solid var(--kw-card);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  flex: none;
}
/* Photo, name, stats and facts in one profile header (no separate info panels). */
.cmx-agent-head {
  display: flex;
  align-items: flex-start;
  gap: 1.75rem;
  /* Basis 0, so the back button keeps its place top-right instead of wrapping. */
  flex: 1 1 0;
  min-width: 0;
}
.cmx-agent-page-head {
  margin-bottom: 1.75rem;
}
.cmx-agent-page-head .app-page-actions {
  align-self: flex-start;
}
.cmx-agent-head .app-page-title {
  font-size: 2rem;
}
.cmx-agent-profile {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1 1 auto;
  min-width: 0;
}
.cmx-agent-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.75rem;
}
.cmx-agent-stats div {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.cmx-agent-stats strong {
  font-size: 1.5rem;
  line-height: 1;
}
.cmx-agent-stats span {
  font-size: 0.8rem;
  color: #6b7280;
}
.cmx-agent-stat-active strong {
  color: var(--kw-emerald);
}
.cmx-agent-facts {
  gap: 0.6rem 1.5rem;
  /* Columns sized to their content, so an e-mail stays on one line. */
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  column-gap: 2.5rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--kw-border);
}
.cmx-agent-bank {
  display: block;
}
/* Agents' social links (_SocialLinkIcons, _AgentSocialLinks): brand icon + handle as a chip. */
.cmx-social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.5rem;
}
.cmx-social {
  --cmx-social-color: #4b5563;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  font-size: 0.85rem;
  line-height: 1.2;
  color: inherit;
}
.cmx-social-links .cmx-social {
  padding: 0.3rem 0.7rem 0.3rem 0.5rem;
  border: 1px solid var(--kw-border);
  border-radius: 999px;
  text-decoration: none;
}
.cmx-social-links a.cmx-social:hover {
  border-color: var(--cmx-social-color);
}
.cmx-social > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cmx-social svg,
.cmx-social .dx-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  font-size: 18px;
  fill: var(--cmx-social-color);
  color: var(--cmx-social-color);
}
.cmx-social-Facebook { --cmx-social-color: #0866ff; }
.cmx-social-Instagram { --cmx-social-color: #e4405f; }
.cmx-social-LinkedIn { --cmx-social-color: #0a66c2; }
.cmx-social-YouTube { --cmx-social-color: #ff0000; }
.cmx-social-Telegram { --cmx-social-color: #26a5e4; }
.cmx-social-WhatsApp { --cmx-social-color: #25d366; }
.cmx-social-Viber { --cmx-social-color: #7360f2; }
.cmx-social-WeChat { --cmx-social-color: #07c160; }
.cmx-social-Website { --cmx-social-color: var(--kw-red); }
/* X, TikTok and Threads are black marks: they follow the text colour (white on dark). */
.cmx-social-X,
.cmx-social-TikTok,
.cmx-social-Threads { --cmx-social-color: currentColor; }
.cmx-social-edit {
  font-size: 0.85rem;
}
/* Icons only, on cards (cmx-social.js): small round buttons; nothing at all when there are none. */
.cmx-social-compact {
  gap: 0.3rem;
  margin-top: 0.5rem;
}
.cmx-social-compact:empty {
  display: none;
}
.cmx-social-links.cmx-social-compact .cmx-social {
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
}
.cmx-social-compact .cmx-social svg,
.cmx-social-compact .cmx-social .dx-icon {
  width: 16px;
  height: 16px;
  font-size: 16px;
}
[data-bs-theme="dark"] .cmx-social-links .cmx-social {
  border-color: #383838;
}
[data-bs-theme="dark"] .cmx-agent-stats span {
  color: #9ca3af;
}
[data-bs-theme="dark"] .cmx-agent-stat-active strong {
  color: #34d399;
}
[data-bs-theme="dark"] .cmx-agent-facts {
  border-top-color: #383838;
}
@media (max-width: 767px) {
  .cmx-agent-head {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    flex-basis: 100%;
  }
  .cmx-agent-profile > div:first-child {
    text-align: center;
  }
  .cmx-agent-stats {
    justify-content: center;
  }
  /* Facts stay two columns on a phone: label + short value fits, the page stays short. */
  .cmx-agent-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 1rem;
  }
  .cmx-agent-email {
    grid-column: span 2;
  }
  .cmx-agent-page-head .app-page-actions {
    margin-top: 0.5rem;
  }
  .cmx-agent-photo {
    width: 160px;
    height: 200px;
  }
  .cmx-agent-head .app-page-title {
    font-size: 1.6rem;
  }
}
[data-bs-theme="dark"] .cmx-agent-photo {
  border-color: #2a2a2a;
}
.cmx-listing-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
}

/* --- Support: help button, contact block, error code --- */
.app-help-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
}
[data-bs-theme="dark"] .app-help-btn:hover {
  background-color: #2a2a2a;
  color: var(--kw-dark-text);
}
.cmx-support-contact {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--kw-border);
  border-radius: 0.5rem;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
[data-bs-theme="dark"] .cmx-support-contact {
  border-color: #383838;
}
.cmx-support-contact-title {
  font-weight: 600;
}
.cmx-support-contact a {
  overflow-wrap: anywhere;
}
.cmx-help-actions {
  display: grid;
  gap: 0.5rem;
}
.cmx-support-intro {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  align-items: flex-start;
  justify-content: space-between;
}
.cmx-support-intro > div:first-child {
  flex: 1 1 320px;
}
.cmx-support-intro .cmx-support-contact {
  margin-top: 0;
  flex: 0 1 300px;
}
.cmx-error-code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--kw-red);
}

/* --- Status pills (support requests, broadcasts) --- */
.cmx-status {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.35rem;
  background: #e5e7eb;
  color: #374151;
}
.cmx-status-new {
  background: #fde2e5;
  color: var(--kw-red-active);
}
.cmx-status-progress {
  background: #dbeafe;
  color: #1e40af;
}
.cmx-status-wait {
  background: #fef3c7;
  color: var(--kw-amber);
}
.cmx-status-done {
  background: #d1fae5;
  color: var(--kw-emerald);
}
.cmx-status-gone {
  background: #e5e7eb;
  color: #4b5563;
}
/* Faint cell text (headcount report: active agents, start dates not from kw.com). */
.cmx-muted { color: #6b7280; }
.cmx-date-source {
  margin-left: 0.35rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
[data-bs-theme="dark"] .cmx-muted { color: #9ca3af; }
[data-bs-theme="dark"] .cmx-status { background: #374151; color: #e5e7eb; }
[data-bs-theme="dark"] .cmx-status-new { background: #4c0d16; color: #fca5ad; }
[data-bs-theme="dark"] .cmx-status-progress { background: #1e3a5f; color: #bfdbfe; }
[data-bs-theme="dark"] .cmx-status-wait { background: #4a3410; color: #fcd34d; }
[data-bs-theme="dark"] .cmx-status-done { background: #064e3b; color: #a7f3d0; }

/* --- Search request cards (DevExtreme CardView, Views/SearchRequests/_SearchRequestCards):
   the comment and the criteria lead, then the agent; the place stays small. --- */
/* The theme's two-column content grid (caption, value) grows with its widest line: one column
   inside the card. .dx-cardview: the theme's stylesheet loads later with the same weight. */
.dx-cardview.cmx-request-cards .dx-cardview-card-content {
  grid-template-columns: minmax(0, 1fr);
}
/* Cards of a row share a height: the footer stays at the bottom. */
.cmx-request-cards .dx-cardview-card {
  display: flex;
  flex-direction: column;
}
.cmx-request-cards .dx-cardview-card > div {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}
.cmx-request-cards .dx-cardview-card-content {
  flex: 1 1 auto;
}
/* ... and the agent lines up across the row, right above the footer. */
.cmx-request-cards .dx-cardview-card-content > div {
  display: flex;
  min-width: 0;
}
.cmx-request {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-width: 0;
}
.cmx-request-agent {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(128, 128, 128, 0.25);
}
/* kw.com portraits are 4:5. */
.cmx-request-photo {
  display: block;
  width: 64px;
  height: 80px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
  object-position: center top;
  background: #e5e7eb;
}
.cmx-request-contacts {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1 1 0;
}
.cmx-request-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-decoration: none;
}
.cmx-request-name:hover {
  text-decoration: underline;
}
.cmx-request-contact {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  font-size: 0.875rem;
  /* A contact is read in full: long e-mails wrap instead of being cut. */
  overflow-wrap: anywhere;
}
.cmx-request-contact .dx-icon {
  flex: none;
  font-size: 16px;
}
.cmx-request-phone {
  font-weight: 600;
}
.cmx-request-note {
  padding: 0.6rem 0.75rem;
  border-left: 4px solid var(--kw-red);
  border-radius: 4px;
  background: rgba(206, 1, 31, 0.07);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: pre-line;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cmx-request-purpose {
  font-weight: 600;
}
.cmx-request-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  font-size: 1rem;
  font-weight: 600;
}
.cmx-request-fact-label {
  font-size: 0.875rem;
  font-weight: 400;
}
.cmx-request-fact-label,
.cmx-request-place,
.cmx-request-footer-end {
  color: #6b7280;
}
.cmx-request-place {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cmx-request-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem 0.75rem;
  font-size: 0.85rem;
}
.cmx-request-footer-end {
  display: flex;
  gap: 0.75rem;
  margin-left: auto;
}
[data-bs-theme="dark"] .cmx-request-note { background: rgba(206, 1, 31, 0.2); }
[data-bs-theme="dark"] .cmx-request-photo { background: #374151; }
[data-bs-theme="dark"] .cmx-request-fact-label,
[data-bs-theme="dark"] .cmx-request-place,
[data-bs-theme="dark"] .cmx-request-footer-end { color: #c4c9cf; }

/* --- Search requests: age, min – max pairs --- */
.cmx-search-age-warn {
  color: var(--kw-amber);
  font-weight: 600;
}
.cmx-search-age-old {
  color: #b91c1c;
  font-weight: 600;
}
[data-bs-theme="dark"] .cmx-search-age-old { color: #fca5a5; }
[data-bs-theme="dark"] .cmx-search-age-warn { color: #fcd34d; }
.cmx-range {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cmx-range > .dx-numberbox {
  flex: 1 1 0;
  min-width: 0;
}
.cmx-range-sep {
  color: var(--kw-muted, #6b7280);
}
.cmx-agent-photo-small {
  width: 56px;
  height: 56px;
}

/* --- Support conversation --- */
.cmx-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.cmx-message {
  border: 1px solid var(--kw-border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  max-width: 85%;
}
.cmx-message-support {
  align-self: flex-end;
  background: #fff5f6;
  border-color: #f5c2c8;
}
[data-bs-theme="dark"] .cmx-message { border-color: #383838; }
[data-bs-theme="dark"] .cmx-message-support { background: #2d1a1d; border-color: #5c2a31; }
.cmx-thread-event {
  margin: 4px 0 10px;
  font-size: 0.85rem;
  text-align: center;
}
.cmx-message-head {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}
.cmx-message-body,
.cmx-broadcast-body,
.cmx-broadcast-popup-body {
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.cmx-message-attachment {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.cmx-message-image {
  display: block;
  margin-top: 0.5rem;
  max-width: 100%;
  max-height: 320px;
  border-radius: 4px;
  border: 1px solid var(--kw-border);
}
@media (max-width: 767px) {
  .cmx-message { max-width: 100%; }
}

/* --- Broadcasts: banner, cards, form --- */
.cmx-broadcast-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid;
  font-size: 0.9rem;
}
.cmx-broadcast-banner > .dx-icon {
  font-size: 18px;
  margin-top: 2px;
}
.cmx-broadcast-text {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  overflow-wrap: anywhere;
}
.cmx-broadcast-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.cmx-broadcast-important { background: #fffbeb; border-color: #fcd34d; color: #78350f; }
.cmx-broadcast-urgent { background: #fef2f2; border-color: #fca5a5; color: var(--kw-red-active); }
[data-bs-theme="dark"] .cmx-broadcast-info { background: #172554; border-color: #1e40af; color: #dbeafe; }
[data-bs-theme="dark"] .cmx-broadcast-important { background: #3a2a0a; border-color: #a16207; color: #fde68a; }
[data-bs-theme="dark"] .cmx-broadcast-urgent { background: #3b0a12; border-color: #9f1239; color: #fecdd3; }
.cmx-broadcast-banner a { color: inherit; font-weight: 600; text-decoration: underline; }
.cmx-broadcast-close {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0 0.25rem;
  opacity: 0.7;
}
.cmx-broadcast-close:hover { opacity: 1; }
.cmx-broadcast-card {
  display: block;
  margin-bottom: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--kw-border);
  border-radius: 0.5rem;
  background: var(--kw-card);
  color: inherit;
  text-decoration: none;
}
.cmx-broadcast-card:hover { border-color: var(--kw-red); color: inherit; }
[data-bs-theme="dark"] .cmx-broadcast-card { background: #262626; border-color: #383838; }
.cmx-broadcast-card.cmx-unread { border-left: 4px solid var(--kw-red); }
.cmx-broadcast-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.5rem;
}
.cmx-broadcast-card-body {
  margin: 0.35rem 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.cmx-broadcast-card-foot { font-size: 0.8rem; }
.cmx-channel-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.cmx-broadcast-preview { margin-bottom: 0.75rem; }
.cmx-warning-text { color: var(--kw-red); }

/* --- Contract: "Дараагийн алхам" --- */
.cmx-next-steps {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--kw-border);
  border-left: 4px solid var(--kw-red);
  border-radius: 0.5rem;
  background: var(--kw-card);
}
[data-bs-theme="dark"] .cmx-next-steps { background: #262626; border-color: #383838; border-left-color: var(--kw-red); }
.cmx-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  font-size: 0.85rem;
  color: #6b7280;
}
.cmx-steps li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cmx-step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid currentColor;
  font-size: 0.75rem;
  font-weight: 700;
}
.cmx-step-done { color: var(--kw-emerald); }
.cmx-step-current { color: var(--kw-red); font-weight: 600; }
.cmx-step-current .cmx-step-dot { background: var(--kw-red); border-color: var(--kw-red); color: #fff; }
.cmx-next-text { font-size: 0.92rem; }

/* --- Help guides --- */
.cmx-guide {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* --- Detail pages: tab strip (_DetailTabs) over server-rendered panes (cmx-tabs.js) --- */
.cmx-detail-tabs {
  margin: 0 0 1rem;
  border-bottom: 1px solid var(--kw-border);
}
[data-bs-theme="dark"] .cmx-detail-tabs {
  border-bottom-color: #383838;
}
.cmx-detail-tabs .dx-tabs {
  max-width: 100%;
}
.cmx-tab-pane[hidden] {
  display: none !important;
}
/* Before cmx-tabs.js runs, only the first pane shows (no flash of every section). */
.cmx-tab-pane:not(:first-of-type) {
  display: none;
}
.cmx-tabs-ready .cmx-tab-pane:not([hidden]) {
  display: block;
}
/* A link to another record's detail page inside a detail grid / list. */
.app-detail-link {
  color: var(--kw-red, #ce011f);
  font-weight: 600;
  text-decoration: none;
}
.app-detail-link:hover {
  text-decoration: underline;
}

/* Agent page: links to the person / user records, below the profile. */
.cmx-agent-links {
  justify-content: flex-start;
  margin-top: 0.75rem;
}

/* Contract slips: an issued slip past its return deadline. */
.cmx-overdue { color: var(--kw-red, #CE011F); font-weight: 600; }
.dx-datagrid .dx-row.cmx-row-overdue > td { background: rgba(206, 1, 31, 0.06); }

/* The contract page's «Гэрээ» tab: the key-in form, read-only, inside the page. */
.cmx-contract-view > .app-page { padding: 0; margin: 0; max-width: none; }

/* --- Dashboard: to-dos, clickable stat cards, quick links --- */
.cmx-todo-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
}
.cmx-todo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-left: 3px solid transparent;
  color: inherit;
  text-decoration: none;
}
.cmx-todo:hover {
  background-color: rgba(0, 0, 0, 0.03);
  color: inherit;
}
[data-bs-theme="dark"] .cmx-todo:hover {
  background-color: rgba(255, 255, 255, 0.05);
}
.cmx-todo .dx-icon {
  font-size: 1.1rem;
  flex: 0 0 auto;
}
.cmx-todo-text {
  flex: 1 1 auto;
  min-width: 0;
}
.cmx-todo-count {
  flex: 0 0 auto;
  min-width: 2rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: #ffffff;
}
.cmx-todo-danger { border-left-color: var(--kw-red); }
.cmx-todo-danger .dx-icon { color: var(--kw-red); }
.cmx-todo-danger .cmx-todo-count { background-color: var(--kw-red); }
.cmx-todo-warning { border-left-color: var(--kw-amber); }
.cmx-todo-warning .dx-icon { color: var(--kw-amber); }
.cmx-todo-warning .cmx-todo-count { background-color: var(--kw-amber); }
.cmx-todo-info { border-left-color: #6b7280; }
.cmx-todo-info .dx-icon { color: #6b7280; }
.cmx-todo-info .cmx-todo-count { background-color: #6b7280; }
[data-bs-theme="dark"] .cmx-todo-warning .dx-icon { color: #f59e0b; }
[data-bs-theme="dark"] .cmx-todo-info .dx-icon { color: #9ca3af; }
.cmx-todo-empty {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  color: var(--kw-emerald);
}
[data-bs-theme="dark"] .cmx-todo-empty {
  color: #34d399;
}
.cmx-todo-panel {
  margin-bottom: 1.5rem;
}
a.cmx-stat-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease;
}
a.cmx-stat-link:hover {
  border-color: var(--kw-red);
  color: inherit;
}
.cmx-panel-foot {
  display: flex;
  justify-content: flex-end;
  padding: 0.25rem 0.5rem;
}
.cmx-quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem;
}
#dashboardContractsGrid .dx-data-row {
  cursor: pointer;
}
/* Short cards: two per row on phones, so the to-dos and contracts stay near the top. */
@media (max-width: 575px) {
  .cmx-dashboard .app-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .cmx-dashboard .app-stat-card {
    padding: 12px;
  }
}

/* --- Managers' reports (Admin → Тайлан) --- */
.cmx-report-period {
  padding: 12px 16px;
}
.cmx-report-period-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.cmx-report-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cmx-reports .cmx-detail-tabs {
  margin-bottom: 1rem;
}
.cmx-report-charts {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
}
@media (max-width: 991px) {
  .cmx-report-charts {
    grid-template-columns: minmax(0, 1fr);
  }
}
.cmx-report-note,
.cmx-report-empty {
  font-size: 0.82rem;
  color: #6b7280;
  margin: 0;
  padding: 0.75rem 1rem;
}
[data-bs-theme="dark"] .cmx-report-note,
[data-bs-theme="dark"] .cmx-report-empty {
  color: #9ca3af;
}
/* Report grid cells (cmx-reports.js): zero as a faint dot, a merged count with its parts on
   hover, and the agent's listing age bar in the listing cards' age colours. */
.cmx-zero {
  color: #c4c9cf;
}
[data-bs-theme="dark"] .cmx-zero {
  color: #5b6168;
}
.cmx-has-breakdown {
  cursor: help;
  border-bottom: 1px dotted currentColor;
}
.cmx-age-bar {
  display: flex;
  height: 10px;
  min-width: 60px;
  border-radius: 999px;
  overflow: hidden;
  gap: 1px;
}
.cmx-age-bar > span {
  flex-basis: 0;
  min-width: 3px;
}
.cmx-age-bar-new { background-color: #10B981; }
.cmx-age-bar-recent { background-color: #0EA5E9; }
.cmx-age-bar-aging { background-color: #F59E0B; }
.cmx-age-bar-old { background-color: #EF4444; }
.cmx-reports .app-stat-value {
  overflow-wrap: anywhere;
}
@media (max-width: 575px) {
  .cmx-reports .app-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .cmx-reports .app-stat-card {
    padding: 12px;
  }
  .cmx-report-period .dx-daterangebox {
    width: 100% !important;
  }
}
.cmx-report-movers {
  padding: 0 1rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}
.cmx-report-jump {
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.cmx-report-jump:hover {
  color: var(--kw-red);
}

/* The listings tab has six cards (total and active first): three per row on wide screens. */
@media (min-width: 992px) {
  .cmx-report-stats-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
/* The number a page leads with (e.g. active listings): a red edge and a larger value. */
.app-stat-card.cmx-stat-lead {
  border-left: 4px solid var(--kw-red);
}
.cmx-stat-lead .app-stat-value {
  color: var(--kw-red);
  font-size: 2rem;
}
[data-bs-theme="dark"] .cmx-stat-lead .app-stat-value {
  color: #ff6b7d;
}

/* --- UAT (test instance) only: Infrastructure/TestInstance, Views/Shared/_UatNotice.
   An orange header, a warning banner on every page and a striped login page, so nobody
   mistakes UAT for production. Kept last so it wins over the dark-theme header rules. --- */
.app-uat-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px 16px;
  background-color: #c2410c;
  color: #ffffff;
  font-size: 0.9rem;
  text-align: center;
}
.app-uat-banner-label {
  font-weight: 800;
  letter-spacing: 0.03em;
}
.app-uat-banner-link,
.app-uat-banner-link:hover,
.app-uat-banner-link:focus {
  color: #ffffff;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.app-header.app-header-uat {
  background-color: #f97316;
  border-bottom-color: #c2410c;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.app-header-uat .app-brand,
.app-header-uat .app-brand:hover,
.app-header-uat .app-menu-toggle,
.app-header-uat .app-bell,
.app-header-uat .app-logout-btn,
.app-header-uat .theme-toggle,
.app-header-uat .app-user-name {
  color: #ffffff;
}
.app-header-uat .app-brand-sub,
.app-header-uat .app-user-role {
  color: rgba(255, 255, 255, 0.88);
}
.app-header-uat .app-brand-logo {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}
.app-header-uat .app-menu-toggle:hover,
.app-header-uat .app-bell:hover,
.app-header-uat .app-logout-btn:hover {
  background-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}
.app-header-uat .theme-toggle:hover {
  border-color: #ffffff;
  color: #ffffff;
}
.app-header-uat .app-user {
  background-color: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.45);
}
.app-header-uat .app-avatar {
  border-color: rgba(255, 255, 255, 0.5);
  background-color: rgba(255, 255, 255, 0.15);
}

/* Login pages: orange warning stripes behind the card and a notice inside it. */
body.app-uat .app-login-wrap {
  min-height: calc(100vh - 40px);
  background: repeating-linear-gradient(-45deg, #fff7ed 0 24px, #fed7aa 24px 48px);
}
[data-bs-theme="dark"] body.app-uat .app-login-wrap {
  background: repeating-linear-gradient(-45deg, #1e1e1e 0 24px, #3b2412 24px 48px);
}
body.app-uat .app-login-card {
  border-top: 6px solid #f97316;
}
.app-uat-card-notice {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid #fdba74;
  border-left: 5px solid #ea580c;
  border-radius: 0.5rem;
  background-color: #fff7ed;
  color: #7c2d12;
  font-size: 0.9rem;
  line-height: 1.45;
}
.app-uat-card-notice strong {
  display: block;
  margin-bottom: 0.25rem;
  color: #c2410c;
}
.app-uat-card-notice a {
  color: #c2410c;
  font-weight: 700;
  text-decoration: underline;
}
[data-bs-theme="dark"] .app-uat-card-notice {
  background-color: rgba(234, 88, 12, 0.15);
  border-color: rgba(253, 186, 116, 0.4);
  border-left-color: #ea580c;
  color: #fed7aa;
}
[data-bs-theme="dark"] .app-uat-card-notice strong,
[data-bs-theme="dark"] .app-uat-card-notice a {
  color: #fdba74;
}

/* --- Agents' business plans (Views/AgentPlans) --- */
.cmx-plan .cmx-plan-of {
  font-size: 0.85rem;
  font-weight: 500;
  color: #6b7280;
}
.cmx-plan .cmx-plan-bar {
  margin: 0.4rem 0 0.35rem;
}
.cmx-plan .cmx-plan-bar .dx-progressbar-range {
  background-color: var(--kw-amber);
  border-color: var(--kw-amber);
}
.cmx-plan .cmx-plan-bar-ok .dx-progressbar-range {
  background-color: #047857;
  border-color: #047857;
}
.cmx-plan .cmx-plan-counters .app-form-field {
  flex: 1 1 150px;
}
.cmx-plan .cmx-plan-months .app-form-field {
  flex: 1 1 150px;
}
.cmx-plan .cmx-plan-strategy {
  margin-top: 0.5rem;
}
.cmx-plan #planModelForm .app-form-row {
  align-items: flex-start;
}
@media (max-width: 575px) {
  .cmx-plan .app-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 1rem;
  }
  .cmx-plan .app-stat-card {
    padding: 10px;
  }
  .cmx-plan .app-stat-value {
    font-size: 1.15rem;
  }
  .cmx-plan .cmx-plan-of {
    display: block;
    font-size: 0.75rem;
  }
}

/* Spacing: every panel's content keeps 1rem from the panel's edge — notes, forms, grids and
   the chart alike — and form rows keep a gap between them. */
.cmx-plan .app-form-row + .app-form-row {
  margin-top: 0.875rem;
}
.cmx-plan .app-form-row + .cmx-plan-strategy {
  margin-top: 0.5rem;
}
.cmx-plan .app-form > p.app-muted,
.cmx-plan .app-form-field > p.app-muted {
  font-size: 0.82rem;
}
.cmx-plan .app-panel > .cmx-report-note {
  padding: 0.875rem 1rem 0;
}
.cmx-plan .app-panel > .dx-widget,
.cmx-plan .app-panel > .cmx-plan-chart {
  margin: 1rem;
}
.cmx-plan .app-panel > .cmx-report-note + .dx-widget {
  margin-top: 0.75rem;
}
.cmx-plan .app-panel > .dx-widget > .dx-datagrid > .dx-datagrid-header-panel {
  padding: 0 0 0.625rem;
}
.cmx-plan .cmx-plan-actions {
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.cmx-plan form > .app-edit-actions {
  margin: 0 0 1.25rem;
}
.cmx-plan .cmx-plan-date {
  flex: 0 1 220px;
}
.cmx-plan .app-stats {
  margin-bottom: 1.25rem;
}
.cmx-plan .cmx-detail-tabs {
  margin-bottom: 1rem;
}

/* Table headers: a tinted, semibold header row (band captions centred in the views) and a
   tinted totals row, so targets and results read as a table rather than loose numbers. */
.cmx-plan .dx-datagrid .dx-datagrid-headers .dx-header-row > td {
  background-color: #f3f4f6;
  color: #374151;
  font-weight: 600;
  font-size: 0.8rem;
  padding-top: 9px;
  padding-bottom: 9px;
}
.cmx-plan .dx-datagrid .dx-datagrid-total-footer {
  background-color: #f9fafb;
}
.cmx-plan .dx-datagrid .dx-datagrid-total-footer .dx-datagrid-summary-item {
  font-weight: 700;
}
[data-bs-theme="dark"] .cmx-plan .dx-datagrid .dx-datagrid-headers .dx-header-row > td {
  background-color: #2f2f2f;
  color: #e5e7eb;
}
[data-bs-theme="dark"] .cmx-plan .dx-datagrid .dx-datagrid-total-footer {
  background-color: #262626;
}
@media (max-width: 575px) {
  .cmx-plan .app-panel > .dx-widget,
  .cmx-plan .app-panel > .cmx-plan-chart {
    margin: 0.75rem;
  }
  .cmx-plan .cmx-plan-date {
    flex: 1 1 100%;
  }
}

/* UAT: a thick orange frame round the window and a "ТУРШИЛТ" watermark over every page
   (fixed, click-through, below DevExtreme overlays), so the test server never looks like
   production even deep inside a form. */
body.app-uat::before,
body.app-uat::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
}
body.app-uat::before {
  border: 6px solid #f97316;
}
body.app-uat::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='340' height='220'%3E%3Ctext x='170' y='120' text-anchor='middle' transform='rotate(-25 170 110)' font-family='Arial,sans-serif' font-size='40' font-weight='800' fill='%23ea580c' fill-opacity='0.11'%3E%D0%A2%D0%A3%D0%A0%D0%A8%D0%98%D0%9B%D0%A2%3C/text%3E%3C/svg%3E");
  background-repeat: repeat;
}
body.app-uat .app-main {
  background: repeating-linear-gradient(-45deg, transparent 0 40px, rgba(249, 115, 22, 0.07) 40px 80px);
}

/* The periodic UAT reminder (wwwroot/js/cmx-uat.js). */
.cmx-uat-dialog .dx-popup-title.dx-toolbar {
  background-color: #ea580c !important;
}
.cmx-uat-reminder {
  max-width: 440px;
  font-size: 1rem;
  line-height: 1.5;
}
.cmx-uat-reminder p {
  margin: 0 0 0.6rem;
}
.cmx-uat-reminder p:last-child {
  margin-bottom: 0;
}

/* UAT: the warning strip stays on screen. It is pinned above the (also sticky) header at a
   fixed height, one line, and the header and sidebar move down by that height. On phones
   the link to production is left out (the reminder dialog offers it). */
body.app-uat .app-uat-banner {
  position: sticky;
  top: 0;
  z-index: 31;
  height: 36px;
  padding: 0 12px;
  flex-wrap: nowrap;
  overflow: hidden;
  white-space: nowrap;
}
body.app-uat .app-uat-banner-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
body.app-uat .app-header {
  top: 36px;
}
body.app-uat .app-body {
  min-height: calc(100vh - 100px);
}
body.app-uat .app-sidebar {
  top: 100px;
  height: calc(100vh - 100px);
}
@media (max-width: 991px) {
  body.app-uat .app-sidebar {
    top: 100px;
    height: auto;
  }
}
@media (max-width: 767px) {
  body.app-uat .app-uat-banner {
    font-size: 0.8rem;
  }
  body.app-uat .app-uat-banner-link {
    display: none;
  }
}

/* The economic model as a sheet (Views/AgentPlans/_PlanModel), after the workbook: label and
   value columns, yellow cells for what the agent enters, tinted rows for subtotals. */
.cmx-plan .cmx-sheet-wrap {
  margin: 1rem;
  overflow-x: auto;
}
.cmx-plan .cmx-sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.cmx-plan .cmx-sheet-4 {
  min-width: 620px;
}
.cmx-plan .cmx-sheet th,
.cmx-plan .cmx-sheet td {
  border: 1px solid #d1d5db;
  padding: 7px 10px;
  vertical-align: middle;
}
.cmx-plan .cmx-sheet th {
  background-color: #f3f4f6;
  color: #374151;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: right;
}
.cmx-plan .cmx-sheet th:first-child {
  text-align: left;
}
.cmx-plan .cmx-sheet td:first-child {
  width: 40%;
}
.cmx-plan .cmx-sheet-3 td:nth-child(2),
.cmx-plan .cmx-sheet-3 th:nth-child(2) {
  width: 90px;
}
.cmx-plan .cmx-sheet-2 td:last-child {
  width: 200px;
}
.cmx-plan .cmx-sheet-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cmx-plan .cmx-sheet td.cmx-sheet-void {
  background-color: #fafafa;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet td.cmx-sheet-void {
  background-color: #242424;
}
.cmx-plan .cmx-sheet-sum td {
  background-color: #f9fafb;
  font-weight: 600;
}
.cmx-plan .cmx-sheet-total td {
  background-color: #fde8ea;
  font-weight: 700;
}
.cmx-plan .cmx-sheet-hint,
.cmx-plan .cmx-sheet-link {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: #6b7280;
}
.cmx-plan .cmx-sheet-link {
  color: var(--kw-red);
}
/* Input cells: yellow, with the editor flush in the cell like a spreadsheet cell. */
.cmx-plan .cmx-sheet td.cmx-sheet-in {
  background-color: #fff3b0;
  padding: 3px;
}
.cmx-plan .cmx-sheet-in .dx-texteditor,
.cmx-plan .cmx-sheet-in .dx-texteditor.dx-editor-outlined {
  background-color: #fff8cc;
  border-color: transparent;
  width: 100%;
}
.cmx-plan .cmx-sheet-in .dx-texteditor.dx-state-focused {
  background-color: #fff;
  border-color: var(--kw-red);
}
.cmx-plan .cmx-sheet td.cmx-sheet-in .dx-texteditor-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.cmx-plan .cmx-sheet-texts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 1rem;
}
.cmx-plan .cmx-sheet-text-head {
  background-color: #f3f4f6;
  border: 1px solid #d1d5db;
  border-bottom: 0;
  color: #374151;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 10px;
}
.cmx-plan .cmx-sheet-text > .cmx-sheet-in {
  background-color: #fff3b0;
  border: 1px solid #d1d5db;
  padding: 3px;
}
.cmx-plan .cmx-sheet-guide {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.85rem;
  color: #4b5563;
}
.cmx-plan .cmx-sheet-guide li + li {
  margin-top: 0.35rem;
}
.cmx-plan .cmx-sheet-key {
  display: inline-block;
  width: 1.6rem;
  height: 0.9rem;
  margin-right: 0.25rem;
  vertical-align: -2px;
  background-color: #fff3b0;
  border: 1px solid #d1d5db;
}
.cmx-plan .cmx-plan-expense-totals {
  margin-top: 0;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet th,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet td,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-text-head,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-text > .cmx-sheet-in,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-key {
  border-color: #4b4b4b;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet th,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-text-head {
  background-color: #2f2f2f;
  color: #e5e7eb;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-sum td {
  background-color: #262626;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-total td {
  background-color: #3a2226;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet td.cmx-sheet-in,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-text > .cmx-sheet-in,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-key {
  background-color: #4a4215;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-in .dx-texteditor {
  background-color: #3b350f;
}
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-hint,
[data-bs-theme="dark"] .cmx-plan .cmx-sheet-guide {
  color: #9ca3af;
}
@media (max-width: 767px) {
  .cmx-plan .cmx-sheet-texts {
    grid-template-columns: minmax(0, 1fr);
  }
  .cmx-plan .cmx-sheet-wrap {
    margin: 0.75rem;
  }
  .cmx-plan .cmx-sheet th,
  .cmx-plan .cmx-sheet td {
    padding: 6px 8px;
  }
  .cmx-plan .cmx-sheet-3 td:nth-child(2),
  .cmx-plan .cmx-sheet-3 th:nth-child(2) {
    width: 58px;
  }
  /* Four columns do not fit a phone: the sheet scrolls sideways and its labels stay put. */
  .cmx-plan .cmx-sheet-4 {
    min-width: 500px;
    font-size: 0.8rem;
  }
  .cmx-plan .cmx-sheet-4 th:first-child,
  .cmx-plan .cmx-sheet-4 td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 150px;
    min-width: 150px;
    max-width: 150px;
  }
  .cmx-plan .cmx-sheet-4 td:first-child {
    background-color: var(--kw-card);
  }
  .cmx-plan .cmx-sheet-4 .cmx-sheet-sum td:first-child {
    background-color: #f9fafb;
  }
  .cmx-plan .cmx-sheet-4 .cmx-sheet-total td:first-child {
    background-color: #fde8ea;
  }
  [data-bs-theme="dark"] .cmx-plan .cmx-sheet-4 td:first-child,
  [data-bs-theme="dark"] .cmx-plan .cmx-sheet-4 .cmx-sheet-sum td:first-child {
    background-color: #262626;
  }
  [data-bs-theme="dark"] .cmx-plan .cmx-sheet-4 .cmx-sheet-total td:first-child {
    background-color: #3a2226;
  }
}

/* The monthly targets list: a narrow month column, the input next to it. */
.cmx-plan .cmx-sheet-months td:first-child,
.cmx-plan .cmx-sheet-months th:first-child {
  width: 22%;
}
.cmx-plan .cmx-sheet-months {
  min-width: 0;
}
@media (max-width: 767px) {
  .cmx-plan .cmx-sheet-months {
    min-width: 440px;
  }
  .cmx-plan .cmx-sheet-months th:first-child,
  .cmx-plan .cmx-sheet-months td:first-child {
    width: 84px;
    min-width: 84px;
    max-width: 84px;
  }
}
