:root{
  --brand-blue:#0d6efd;
  --brand-light:#eaf3ff;
  --text-dark:#0b0f1a;
  --crm-page-bg:#f6f9ff;
  --crm-card-bg:#ffffff;
  --crm-text:#0b0f1a;
  --crm-btn-bg:#0d6efd;
  --crm-btn-text:#ffffff;
  --crm-border:#e6efff;
  --crm-input-bg:var(--crm-card-bg);
}

.form-control,
.form-select,
textarea.form-control {
  background-color:var(--crm-input-bg);
  color:var(--crm-text);
  border-color:var(--crm-border);
}
.form-control:focus,
.form-select:focus,
textarea.form-control:focus {
  background-color:var(--crm-input-bg);
  color:var(--crm-text);
  border-color:var(--brand-blue);
}
.form-control:disabled,
.form-select:disabled,
textarea.form-control:disabled,
.form-control[readonly],
textarea.form-control[readonly] {
  background-color:color-mix(in srgb, var(--crm-input-bg) 88%, var(--crm-text));
  color:color-mix(in srgb, var(--crm-text) 72%, transparent);
}

body{
  background:var(--crm-page-bg);
  color:var(--crm-text);
  overflow-x:hidden;
}

/* Контент CRM: поля и таблицы не выходят за экран */
.crm-page-wrap{
  max-width:none;
  margin-left:0;
  margin-right:0;
}
/* Header aligns to common content grid; inner blocks split left/right */
.crm-page{
  max-width:100%;
  overflow-x:clip;
}
.crm-page .form-control,
.crm-page .form-select,
.crm-page .btn-group{
  max-width:100%;
}
.crm-page img,
.crm-page video,
.crm-page canvas{
  max-width:100%;
  height:auto;
}

.topbar{
  background:var(--crm-card-bg);
  border-bottom:1px solid var(--crm-border);
}
.topbar .phones a{
  color:var(--brand-blue);
  font-weight:700;
  text-decoration:none;
  display:block;
  line-height:1.25;
}

.crm-topbar-inner{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
  gap:0.5rem 1rem;
  width:100%;
}
.crm-topbar-actions{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
  gap:0.5rem;
  margin-left:auto;
}
.crm-user-session{
  display:flex;
  flex-wrap:nowrap;
  align-items:center;
  justify-content:flex-end;
  gap:0.55rem;
}
.crm-user-avatar{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:2.15rem;
  height:2.15rem;
  border-radius:50%;
  border:0;
  padding:0;
  cursor:pointer;
  font:inherit;
  background:linear-gradient(145deg, #3d6fd8 0%, #1e4a9e 100%);
  color:#fff;
  text-decoration:none;
  flex-shrink:0;
  box-shadow:0 1px 2px rgba(30, 74, 158, 0.25);
  transition:transform .12s ease, box-shadow .12s ease;
}
.crm-user-avatar:hover{
  color:#fff;
  transform:translateY(-1px);
  box-shadow:0 2px 6px rgba(30, 74, 158, 0.35);
}
.crm-user-avatar__initials{
  font-size:0.78rem;
  font-weight:700;
  letter-spacing:0.02em;
  line-height:1;
  user-select:none;
}
.crm-user-avatar--photo{
  background:transparent;
  overflow:hidden;
}
.crm-user-avatar__img{
  display:block;
  width:100%;
  height:100%;
  object-fit:cover;
  border-radius:50%;
}
.crm-logout-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:2.15rem;
  height:2.15rem;
  padding:0;
  border:1px solid #cfd8e6;
  border-radius:50%;
  background:#fff;
  color:#4a5568;
  cursor:pointer;
  transition:background .12s ease, color .12s ease, border-color .12s ease;
}
.crm-logout-btn:hover{
  background:#f3f6fb;
  color:#1e4a9e;
  border-color:#9eb6e0;
}
.crm-user-session__info{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  line-height:1.2;
  color:inherit;
  min-width:0;
}
.crm-user-session__name{
  font-weight:700;
  color:var(--brand-blue);
  max-width:16rem;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.crm-user-session__roles{
  font-size:0.75rem;
  color:#6c757d;
  max-width:16rem;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.brand-line{
  background:var(--crm-card-bg);
  border-bottom:1px solid var(--crm-border);
}

.crm-header-inner{
  display:flex;
  flex-wrap:wrap;
  align-items:flex-start;
  justify-content:space-between;
  gap:0.75rem 1.25rem;
  width:100%;
}
.crm-header-brand{
  display:flex;
  align-items:center;
  gap:0.75rem;
  flex:0 1 auto;
  min-width:min(100%, 16rem);
}
.crm-logo-link{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:0.65rem;
  text-decoration:none;
  flex-shrink:0;
}
.crm-logo-text{
  display:block;
  height:28px;
  width:auto;
  max-width:min(95px, 42vw);
}
.crm-logo-symbol{
  display:block;
  height:36px;
  width:auto;
  flex-shrink:0;
}
.crm-header-tagline{
  line-height:1.3;
  white-space:nowrap;
}
@media (max-width: 575.98px){
  .crm-header-brand{
    flex-wrap:wrap;
    align-items:flex-start;
  }
  .crm-header-tagline{
    white-space:normal;
    width:100%;
    padding-left:0;
  }
  .crm-logo-symbol{
    height:32px;
  }
  .crm-logo-text{
    height:24px;
  }
}
.crm-header-nav{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
  align-content:flex-start;
  gap:0.5rem;
  flex:1 1 12rem;
  min-width:0;
  margin-left:auto;
}
.crm-header-nav .btn,
.crm-header-nav form{
  flex:0 0 auto;
}
.crm-nav-mode-intake{
  display:flex;
  flex-wrap:nowrap;
  align-items:center;
  gap:0.5rem;
  flex:0 0 auto;
}
.crm-nav-mode-form,
.crm-nav-logout-form{
  display:flex;
  align-items:center;
  margin:0;
  flex:0 0 auto;
}
.crm-nav-extras .dropdown-menu{
  min-width:12rem;
  max-height:min(70vh, 24rem);
  overflow-y:auto;
}
.crm-nav-extras .dropdown-item.active,
.crm-nav-extras .dropdown-item:active{
  background:var(--brand-blue);
  color:#fff;
}

.brand-badge{
  width:44px;height:44px;
  border-radius:12px;
  background:var(--brand-light);
  display:flex;
  align-items:center;
  justify-content:center;
  color:var(--brand-blue);
  font-weight:800;
  font-size:18px;
}

.order-row-clickable{cursor:default;}
.order-row-actions{display:inline-flex;align-items:center;justify-content:flex-end;gap:.25rem;max-width:none;}
.btn-order-action{
  width:2rem;height:2rem;padding:0;
  display:inline-flex;align-items:center;justify-content:center;
  line-height:1;
  flex:0 0 auto;
}
.btn-order-action.dropdown-toggle::after{display:none;}
.btn-order-action svg{display:block;}
.order-table-actions-col{
  width:1%;
  min-width:8.75rem;
  overflow:visible !important;
  white-space:nowrap !important;
  text-overflow:clip !important;
  position:sticky;
  right:0;
  z-index:3;
  background:var(--crm-card-bg, #fff);
  box-shadow:-6px 0 10px -8px rgba(15, 40, 80, 0.35);
  padding-left:.5rem !important;
  padding-right:.35rem !important;
}
.order-table-head th.order-table-actions-col{
  z-index:5;
}
.order-row--has-changes .order-table-actions-col,
.order-row--hl .order-table-actions-col,
.order-row-selected .order-table-actions-col,
.order-table tbody tr:hover .order-table-actions-col{
  background:inherit;
}
.order-table tbody tr:hover .order-table-actions-col{
  background:var(--crm-card-bg, #fff);
  filter:brightness(0.985);
}
.order-row-selected .order-table-actions-col{
  background:#dbeafe !important;
}
.order-row--has-changes:not(.order-row-selected) .order-table-actions-col,
.order-row--hl:not(.order-row-selected) .order-table-actions-col{
  background:var(--crm-card-bg, #fff);
}
.order-columns-panel{
  width:min(58rem, 96vw);
  max-width:96vw;
  max-height:min(70vh, 36rem);
  overflow:auto;
  padding:1rem 1.1rem !important;
}
.order-columns-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(15.5rem, 1fr));
  gap:.85rem 1.15rem;
}
.order-columns-section__title{
  font-size:.72rem;
  font-weight:600;
  letter-spacing:.04em;
  text-transform:uppercase;
  color:#6b7c93;
  margin-bottom:.4rem;
}
.order-columns-chips{
  display:flex;
  flex-wrap:wrap;
  gap:.35rem;
}
.order-columns-chip{
  display:inline-flex;
  align-items:center;
  gap:.35rem;
  margin:0;
  padding:.18rem .55rem .18rem .35rem;
  border:1px solid #d7e4f5;
  border-radius:999px;
  background:#f7faff;
  font-size:.78rem;
  line-height:1.2;
  cursor:pointer;
  user-select:none;
  max-width:100%;
}
.order-columns-chip span{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.order-columns-chip:has(input:checked){
  background:#e8f1ff;
  border-color:#8eb6ea;
  color:#1b3a6f;
}
.order-columns-chip .form-check-input{
  width:.9rem;
  height:.9rem;
  margin-top:0;
  flex:0 0 auto;
}
.order-columns-order-list{
  display:flex;
  flex-direction:column;
  gap:.35rem;
  max-height:12rem;
  overflow:auto;
  padding:.25rem;
  border:1px solid var(--crm-border, #d7e4f5);
  border-radius:.5rem;
  background:var(--crm-card-bg);
}
.order-columns-order-item{
  display:flex;
  align-items:center;
  gap:.5rem;
  padding:.35rem .5rem;
  border:1px solid var(--crm-border);
  border-radius:.375rem;
  background:var(--brand-light);
  font-size:.82rem;
  cursor:default;
  user-select:none;
}
.order-columns-order-handle{
  cursor:grab;
  color:#8a9bb5;
  font-size:.72rem;
  line-height:1;
  flex:0 0 auto;
  padding:0 .1rem;
}
.order-columns-order-handle:active{
  cursor:grabbing;
}
.order-columns-order-label{
  flex:1;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.order-columns-order-ghost{
  opacity:.45;
}
.order-th-draggable{
  cursor:grab;
  user-select:none;
  white-space:nowrap;
}
.order-th-draggable:active{
  cursor:grabbing;
}
.order-th-label{
  margin-right:.25rem;
}
.order-th-drag-hint{
  opacity:.35;
  font-size:.65rem;
  letter-spacing:-1px;
  vertical-align:middle;
}
.order-th-drag-ghost{
  opacity:.55;
  background:rgba(13,110,253,.08);
}
.order-table-head .order-th-draggable:hover .order-th-drag-hint{
  opacity:.65;
}
.order-th-resizable{
  position:relative;
  overflow:visible;
}
.order-th-resize{
  position:absolute;
  top:0;
  right:-3px;
  width:10px;
  height:100%;
  cursor:col-resize;
  user-select:none;
  z-index:6;
  touch-action:none;
  pointer-events:auto;
}
.order-th-resize.is-active,
.order-th-resize:hover,
body.order-table-col-resizing .order-th-resize{
  background:rgba(13,110,253,.28);
}
body.order-table-col-resizing{
  cursor:col-resize !important;
  user-select:none;
}
body.order-table-col-resizing .order-table-head th{
  cursor:col-resize;
}
.crm-table-scroll > .table.order-table.order-table--sized{
  table-layout:fixed !important;
  width:max(100%, 52rem);
}
.order-table--sized th,
.order-table--sized td{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.order-table--sized .order-tasks-cell,
.order-table--sized .order-tasks-cell .small,
.order-table--sized td .order-inline-extra{
  white-space:normal;
}
.order-table--sized .order-table-actions-col{
  overflow:visible !important;
  white-space:nowrap !important;
  text-overflow:clip !important;
}
.order-row-selected{background:#dbeafe !important;box-shadow:inset 3px 0 0 #2563eb;}
.order-list-print-modal .modal-body {
  background: #eef2f7;
  min-height: 60vh;
}
.order-list-print-frame {
  display: block;
  width: 100%;
  height: min(70vh, 820px);
  border: 0;
  background: #fff;
}
.order-list-print-loading {
  text-align: center;
}
.dropdown-menu-fixed-portal {
  z-index: 1080;
}
/* Печать поверх портальных dropdown; backdrop только пока открыта эта модалка —
   иначе глобальный z-index 1085 перекрывает «Историю изменений» и другие окна */
#orderListPrintModal {
  z-index: 1090 !important;
}
body:has(#orderListPrintModal.show) .modal-backdrop {
  z-index: 1085;
}

.intake-wizard-card{
  max-width:960px;
  margin:0 auto;
}
.intake-wizard-steps{
  display:flex;
  flex-wrap:wrap;
  gap:.5rem 1rem;
  margin:0;
  padding:0;
  list-style:none;
}
.intake-wizard-steps li{
  display:flex;
  align-items:center;
  gap:.4rem;
  color:#64748b;
  font-size:.85rem;
}
.intake-wizard-steps li.is-current{
  color:#0f172a;
  font-weight:600;
}
.intake-wizard-steps li.is-done{
  color:#2563eb;
}
.intake-wizard-num{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:1.4rem;
  height:1.4rem;
  border-radius:999px;
  border:1px solid currentColor;
  font-size:.75rem;
}
.intake-wizard-steps li.is-current .intake-wizard-num{
  background:#2563eb;
  border-color:#2563eb;
  color:#fff;
}

.intake-page-header{
  flex-shrink:0;
}

.intake-start-screen--compact .intake-start-card{
  max-width:920px;
  margin:2rem auto;
}
.intake-start-screen--compact .intake-start-body{
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:2.5rem 1.5rem;
}
.intake-start-screen--compact .intake-start-actions{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  justify-content:center;
  gap:1.25rem;
  width:min(100%, 640px);
  margin:0 auto;
}
@media (min-width:768px){
  .intake-start-screen--compact .intake-start-actions{
    flex-direction:row;
    align-items:stretch;
    width:min(100%, 720px);
  }
}
.intake-start-action-item{
  flex:1 1 0;
  min-width:0;
  min-height:0;
  margin:0;
  display:flex;
  align-self:stretch;
}
.intake-start-action-form{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  min-width:0;
  min-height:0;
  width:100%;
  margin:0;
}
.intake-start-actions .intake-accept-btn{
  flex:1 1 auto;
  width:100%;
  min-height:5rem;
  display:flex;
  align-items:center;
  justify-content:center;
}

/* Полноэкранный режим: две кнопки на всю рабочую область */
.crm-page.intake-full-active{
  display:flex;
  flex-direction:column;
  padding-top:0.75rem !important;
  padding-bottom:0.75rem !important;
  min-height:calc(100dvh - 9.5rem);
}
.crm-page.intake-full-active .intake-page-header{
  margin-bottom:0.5rem !important;
}
.intake-start-screen--full{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  min-height:0;
}
.intake-start-screen--full .intake-start-inner{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  min-height:0;
}
.intake-start-screen--full .intake-start-card{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  min-height:0;
  max-width:none;
  margin:0;
  border:none;
  background:transparent;
  box-shadow:none;
}
.intake-start-screen--full .intake-start-body{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  min-height:0;
  padding:0;
}
.intake-start-screen--full .intake-start-actions{
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap:0.75rem;
  width:100%;
  max-width:none;
  margin:0;
  min-height:0;
}
.intake-start-screen--full .intake-start-action-item{
  flex:1 1 0;
  min-height:0;
}
.intake-start-screen--full .intake-start-action-form,
.intake-start-screen--full .intake-start-action-item > .intake-accept-btn{
  flex:1 1 auto;
  height:100%;
  min-height:0;
}
.intake-start-screen--full .intake-accept-btn{
  font-size:clamp(1.35rem, 3.8vw, 2.75rem);
  border-radius:18px;
}
@media (min-width:768px){
  .intake-start-screen--full .intake-start-actions{
    flex-direction:row;
    flex-wrap:wrap;
    gap:1rem;
  }
  .intake-start-screen--full .intake-start-action-item{
    flex:1 1 calc(33.333% - 0.75rem);
    min-width:12rem;
  }
}

.btn-brand{
  background:var(--brand-blue);
  border-color:var(--brand-blue);
  color:#fff;
}
.btn-brand:hover{filter:brightness(0.95);}

.card{
  border:1px solid var(--crm-border);
  border-radius:16px;
  box-shadow:0 2px 10px rgba(13,110,253,0.06);
  background-color:var(--crm-card-bg);
  color:var(--crm-text);
}

.badge-soft{
  background:var(--brand-light);
  color:var(--brand-blue);
}

.link-muted{color:#6c757d;text-decoration:none;}

.table{
  --bs-table-bg:var(--crm-card-bg);
  --bs-table-color:var(--crm-text);
  --bs-table-border-color:var(--crm-border);
  --bs-table-hover-bg:var(--brand-light);
  --bs-table-hover-color:var(--crm-text);
}
.table thead th{
  background:var(--crm-card-bg);
  border-bottom:1px solid var(--crm-border);
  color:var(--crm-text);
}

/* Docs tables: cleaner visual rhythm and readability */
.docs-table-wrap{
  border-radius:12px;
}
.docs-table{
  --bs-table-bg:#fff;
  margin-bottom:0;
}
.docs-table thead th{
  position:sticky;
  top:0;
  z-index:2;
  background:#f8fbff;
  border-bottom:1px solid #dce9ff;
  color:#3c4a60;
  font-weight:600;
  padding:0.78rem 1rem !important;
}
.docs-table tbody td{
  padding:0.8rem 1rem !important;
  vertical-align:middle;
  border-color:#eef3ff;
}
.docs-table thead th:last-child,
.docs-table tbody td:last-child{
  padding-right:1.15rem !important;
}
.docs-table .btn{
  margin-right:0.1rem;
}
.accounting-chart-type-icons {
  position: relative;
  z-index: 5;
}
.accounting-chart-type-btn {
  cursor: pointer;
  pointer-events: auto;
}
.accounting-chart-type-btn svg {
  pointer-events: none;
}
.accounting-chart-wrap {
  position: relative;
  width: 100%;
  height: clamp(260px, 38vh, 420px);
  overflow: hidden;
}
.accounting-chart-wrap--fullscreen {
  height: calc(100vh - 240px);
  min-height: 320px;
}
.accounting-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  max-height: none;
}
.accounting-fs-toolbar {
  border-bottom: 1px solid #eef3ff;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
}
.accounting-layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #eef4ff;
  border: 1px solid #d8e7ff;
  font-size: 0.78rem;
  margin: 0.15rem 0.25rem 0.15rem 0;
}
.accounting-layer-chip button {
  border: none;
  background: transparent;
  padding: 0;
  line-height: 1;
  color: #6c757d;
  cursor: pointer;
}
.accounting-drilldown-active {
  cursor: pointer;
}
.accounting-drilldown-active:hover {
  background-color: rgba(77, 163, 255, 0.06);
}
.accounting-drilldown-link {
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.docs-table tbody tr:hover{
  background:#f7fbff;
}
.docs-table-title{
  color:#16233a;
}
.docs-format-pill{
  display:inline-block;
  padding:0.18rem 0.55rem;
  border-radius:999px;
  font-size:.78rem;
  background:#eef4ff;
  color:#2f5187;
  border:1px solid #d8e7ff;
}
.docs-mapping-table code{
  color:#1b3a6f;
  background:#eef4ff;
  border:1px solid #d7e6ff;
  border-radius:6px;
  padding:0.12rem 0.35rem;
}

/* Карточка заказа: Диагностика и QR с одинаковыми внутренними отступами */
.order-panel-body{
  padding:1.15rem 1.35rem;
}
#order-codes-card{
  margin-top:1rem;
}
#order-documents{
  overflow:hidden;
}
#order-documents .order-docs-body{
  padding:1.35rem 1.75rem 1.5rem;
}
#order-documents .order-saved-docs-wrap{
  padding:0.35rem 0.55rem 0.7rem;
}
#order-documents .order-docs-table{
  table-layout:fixed;
  width:100%;
  max-width:100%;
  margin-bottom:0;
  font-size:0.78rem;
}
#order-documents .order-docs-table thead th{
  font-size:0.72rem;
  font-weight:600;
  color:#3c4a60;
  white-space:nowrap;
  padding:0.55rem 0.7rem;
}
#order-documents .order-docs-table tbody td{
  padding:0.55rem 0.7rem;
}
#order-documents .order-docs-table th,
#order-documents .order-docs-table td{
  overflow:hidden;
  text-overflow:ellipsis;
  vertical-align:middle;
}
#order-documents .order-docs-table th:nth-child(1),
#order-documents .order-docs-table td:nth-child(1){ width:18%; }
#order-documents .order-docs-table th:nth-child(2),
#order-documents .order-docs-table td:nth-child(2){ width:28%; }
#order-documents .order-docs-table th:nth-child(3),
#order-documents .order-docs-table td:nth-child(3){ width:20%; }
#order-documents .order-docs-table th:nth-child(4),
#order-documents .order-docs-table td:nth-child(4){ width:14%; }
#order-documents .order-docs-table th:nth-child(5),
#order-documents .order-docs-table td:nth-child(5){
  width:20%;
  white-space:normal;
  overflow:visible;
}
#order-documents .order-docs-actions{
  display:flex;
  flex-wrap:wrap;
  justify-content:flex-end;
  gap:.35rem;
}
#docPreviewBody .doc-print-sheet{
  max-width:100%;
  margin:0;
  padding:0 .25rem;
  font-family:"Times New Roman", Times, serif;
  font-size:12pt;
  line-height:1.35;
}
#docPreviewBody .doc-print-sheet table{
  width:100%;
  max-width:100%;
  border-collapse:collapse;
  margin:.6em 0;
}
#docPreviewBody .doc-print-sheet td,
#docPreviewBody .doc-print-sheet th{
  vertical-align:top;
  padding:4px 6px;
  border:1px solid #333;
}

/* Горизонтальная прокрутка таблиц на узких экранах */
.crm-table-scroll{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  padding:0 0.75rem 0.75rem;
  box-sizing:border-box;
}
.card > .crm-table-scroll:first-child,
.card-body.p-0.crm-table-scroll{
  padding:0.75rem;
}
.crm-table-scroll > .table{
  width:100%;
  max-width:100%;
  margin-bottom:0;
  table-layout:auto;
}
.crm-table-scroll > .table.order-table{
  min-width:min(100%, 52rem);
}

/* Список заказов: прокрутка тела таблицы, шапка колонок закреплена */
.order-list-table-card{
  display:flex;
  flex-direction:column;
  max-height:calc(100vh - 11.5rem);
  min-height:16rem;
  overflow:hidden;
}
.crm-order-list-scroll{
  flex:1 1 auto;
  min-height:0;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
  /* запас справа/снизу, чтобы кнопки и меню не упирались в край */
  scroll-padding-inline-end:0.5rem;
  scroll-padding-bottom:0.75rem;
}
.order-table-head th{
  position:sticky;
  top:0;
  z-index:4;
  background:var(--crm-card-bg);
  color:var(--crm-text);
  box-shadow:0 1px 0 var(--crm-border);
}
.crm-pagination .pagination{
  flex-wrap:wrap;
  justify-content:flex-end;
}

/* Дефекты диагностики: теги по категоричности */
.defect-tag{
  display:inline-flex;
  align-items:center;
  gap:0.25rem;
  font-weight:500;
  padding:0.4em 0.65em;
}
.defect-tag-probable{
  background:#fff3cd;
  color:#664d03;
  border:1px solid #ffc107;
}
.defect-tag-certain{
  background:#f8d7da;
  color:#58151c;
  border:1px solid #dc3545;
}
.defect-tag .defect-tag-remove{
  opacity:0.85;
  filter:none;
}
.defect-tag-certain .defect-tag-remove{
  filter:invert(1) grayscale(1);
}

/* Панели фильтров и inline-форм */
.crm-toolbar{
  display:flex;
  flex-wrap:wrap;
  gap:0.5rem;
  align-items:flex-end;
  width:100%;
}
.crm-toolbar > *{
  flex:1 1 10rem;
  min-width:0;
  max-width:100%;
}
.crm-toolbar > .btn,
.crm-toolbar > .btn-group,
.crm-toolbar > .crm-toolbar-actions{
  flex:0 0 auto;
}
.crm-toolbar-field{
  flex:1 1 12rem;
  min-width:min(100%, 10rem);
  max-width:100%;
}
.crm-toolbar-field .form-control,
.crm-toolbar-field .form-select{
  width:100%;
}

/* Формы в карточках заказа: поля на всю ширину колонки */
.crm-form-row{
  display:flex;
  flex-wrap:wrap;
  gap:0.5rem;
  align-items:flex-end;
  width:100%;
}
.crm-form-row > .crm-form-field{
  flex:1 1 12rem;
  min-width:min(100%, 8rem);
  max-width:100%;
}
.crm-form-row > .crm-form-field .form-control,
.crm-form-row > .crm-form-field .form-select{
  width:100%;
}
.crm-form-row > .btn{
  flex:0 0 auto;
  align-self:flex-end;
}
.crm-form-field--narrow{flex:0 1 7rem; min-width:min(100%, 5rem);}
.crm-form-field--wide{flex:2 1 16rem; min-width:min(100%, 12rem);}

.kpi{
  font-size:34px;
  font-weight:800;
  color:var(--text-dark);
}

.small-note{color:#6c757d;font-size:12px;}

/* Публичные страницы входа / регистрации */
.auth-page{
  min-height:100vh;
  display:flex;
  flex-direction:column;
  background:linear-gradient(165deg,#dde9ff 0%,#eaf3ff 38%,#f6f9ff 72%,#ffffff 100%);
}
.auth-topbar{
  background:rgba(255,255,255,0.92);
  backdrop-filter:blur(8px);
  border-bottom:1px solid #e6efff;
}
.auth-main{margin-top:auto;margin-bottom:auto;}
.auth-card{
  max-width:440px;
  background:#ffffff;
  border:1px solid #e6efff;
  border-radius:20px;
  padding:2rem 1.75rem 1.75rem;
  box-shadow:0 10px 40px rgba(13,110,253,0.1);
}

@media (min-width: 576px){
  .auth-card{padding:2.25rem 2.25rem 2rem;}
}

.crm-mode-select{
  min-width:10rem;
  max-width:14rem;
}

@media (max-width: 991.98px){
  .crm-header-nav{
    flex:1 1 100%;
    margin-left:0;
    justify-content:flex-start;
  }
  .crm-nav-mode-form{
    width:100%;
  }
  .crm-nav-mode-form .crm-mode-select{
    width:100%;
    max-width:100%;
  }
}

@media (max-width: 575.98px){
  .crm-topbar-inner{
    flex-direction:column;
    align-items:flex-start;
  }
  .crm-topbar-actions{
    margin-left:0;
    width:100%;
    justify-content:flex-start;
  }
  .crm-user-session{
    width:auto;
    justify-content:flex-end;
  }
  .crm-user-session__info{
    align-items:flex-start;
  }
}

/* Kanban (встроен в «Заказы») */
.kanban-board{
  display:flex;
  gap:12px;
  overflow-x:auto;
  padding-bottom:8px;
  width:100%;
  max-width:100%;
}
.kanban-col{
  flex:0 0 auto;
  width:min(320px, 88vw);
  min-width:min(260px, 85vw);
  background:#fff;
  border:1px solid #e6efff;
  border-radius:14px;
}
.kanban-col-head{padding:10px 12px; border-bottom:1px solid #e6efff; background:linear-gradient(0deg, #ffffff, #f7fbff); border-top-left-radius:14px; border-top-right-radius:14px; display:flex; justify-content:space-between; align-items:center;}
.kanban-drop{min-height:120px; padding:10px;}
.kanban-drop.drop-hover{background:#eaf3ff;}
.kanban-card{background:#fff; border:1px solid #e6efff; border-radius:12px; padding:10px; margin-bottom:10px; box-shadow:0 1px 0 rgba(0,0,0,0.02);}
.kanban-card.dragging{opacity:0.6;}
.kanban-card--has-changes,
.order-row--has-changes,
.order-cell--changed{
  background:#fff3cd !important;
  box-shadow:inset 0 -2px 0 #ffc107;
}
/* Bootstrap 5 красит td, а не tr — цвет автозадачи нужно задавать ячейкам */
.order-table > tbody > tr.order-row--hl > *{
  background-color: var(--order-hl) !important;
  box-shadow: none;
}
.order-table.table-hover > tbody > tr.order-row--hl:hover > *{
  background-color: var(--order-hl) !important;
}
.kanban-card.order-row--hl{
  background-color: var(--order-hl) !important;
}
.order-tasks-cell{min-width:8rem; max-width:16rem;}
.kanban-card-tasks{
  border-top:1px dashed #d7e4f5;
  padding-top:.35rem;
}
.kanban-tasks-toggle{
  font-size:.8rem;
  text-decoration:none;
}
.order-field--changed{
  background-color:#fffbeb;
  border-radius:6px;
  padding:2px 4px;
}
.order-field--changed .form-control,
.order-field--changed .form-select,
.order-field--changed textarea{
  border-color:#ffc107;
  background-color:#fffbeb;
}
.field-change-hint{
  color:#856404;
  line-height:1.35;
}
.field-change-hint__badge{
  display:inline-block;
  font-size:.7rem;
  font-weight:600;
  text-transform:uppercase;
  letter-spacing:.03em;
  background:#ffc107;
  color:#332701;
  border-radius:4px;
  padding:.1rem .35rem;
  margin-right:.25rem;
}

/* Order detail: funnel stages in one horizontal row */
.order-funnel-rail{
  display:flex;
  flex-wrap:nowrap;
  gap:.45rem;
  overflow-x:auto;
  overflow-y:hidden;
  -webkit-overflow-scrolling:touch;
  padding-bottom:.2rem;
}
.order-funnel-stage-form{
  flex:0 0 auto;
  margin:0;
}
.order-funnel-stage{
  border:0;
  color:#fff;
  font-weight:600;
  font-size:.82rem;
  line-height:1.1;
  border-radius:999px;
  padding:.42rem .75rem;
  white-space:nowrap;
  box-shadow:0 1px 3px rgba(0,0,0,.15);
}
.order-funnel-stage.is-active{
  outline:2px solid rgba(13,110,253,.35);
  outline-offset:1px;
}

/* Inline edit in order list table */
.order-inline-cell {
  cursor: text;
  position: relative;
}
.order-inline-cell:hover {
  outline: 1px dashed rgba(13, 110, 253, 0.35);
  outline-offset: -1px;
}
.order-inline-editor {
  min-width: 6rem;
  max-width: 16rem;
  margin: 0;
}
.order-inline-editor[type="date"],
.order-inline-editor[type="time"] {
  min-width: 9.5rem;
  max-width: 11rem;
}

/* Поля карточки: одна строка, display = размер form-control-sm */
.order-field-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: .35rem .75rem;
  margin: 0;
}
.order-field-wrap > .form-label,
.order-field-wrap > .order-field-wrap__label {
  flex: 0 0 var(--crm-field-label-width, 10rem);
  max-width: 38%;
  margin: 0;
  padding-top: .3rem;
  line-height: 1.5;
  font-size: .8125rem;
}
.order-field-wrap__value {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}
.order-field-wrap__value > .form-control,
.order-field-wrap__value > .form-select,
.order-field-wrap__value > .form-check,
.order-field-wrap__value > .d-flex,
.order-card-inline-editor > .form-control,
.order-card-inline-editor > .form-select,
.order-card-inline-editor > .form-check,
.order-card-inline-editor > .d-flex {
  width: auto;
  max-width: 100%;
}
.order-field-wrap--text .order-field-wrap__value > .form-control,
.order-field-wrap--text .order-card-inline-editor > .form-control,
.order-field-wrap--text .order-field-wrap__value > textarea.order-field-single-line,
.order-field-wrap--text .order-card-inline-editor > textarea.order-field-single-line,
.order-field-wrap--text .order-card-inline-display:not(.is-multiline):not(.order-card-inline-display--compact),
.order-field-wrap--textarea .order-field-wrap__value > textarea,
.order-field-wrap--textarea .order-card-inline-editor > textarea,
.order-field-wrap--textarea .order-field-wrap__value > .order-card-inline-display {
  width: var(--crm-field-input-width, 100%);
  min-width: min(var(--crm-field-input-width, 12rem), 12rem);
  max-width: 100%;
  box-sizing: border-box;
}
.order-field-wrap--text,
.order-field-wrap--textarea {
  width: 100%;
  --crm-field-input-width: max(12rem, calc((100% - var(--crm-field-label-width, 10rem) - 0.75rem) * var(--crm-field-input-width-ratio, 1)));
}
.order-field-wrap--text .order-field-wrap__value,
.order-field-wrap--textarea .order-field-wrap__value {
  flex: 1 1 calc(100% - var(--crm-field-label-width, 10rem) - 0.75rem);
  min-width: min(100%, 14rem);
  max-width: 100%;
}
.order-field-wrap--decimal .order-field-wrap__value > .form-control,
.order-field-wrap--decimal .order-card-inline-editor > .form-control,
.order-field-wrap--decimal .order-card-inline-display:not(.is-multiline) {
  min-width: 6rem;
  width: fit-content;
  max-width: min(100%, var(--crm-field-decimal-max-width, 28rem));
}
.order-field-wrap--text textarea.order-field-single-line,
.order-field-wrap--text .order-card-inline-editor > textarea.order-field-single-line,
.order-field-wrap--textarea .order-field-wrap__value > textarea,
.order-field-wrap--textarea .order-card-inline-editor > textarea {
  min-height: calc(var(--crm-field-textarea-min-rows, 2) * 1.5em + .5rem + 2px);
  resize: vertical;
  overflow: auto;
  field-sizing: normal;
}
.order-field-wrap--date .order-field-wrap__value > .form-control,
.order-field-wrap--time .order-field-wrap__value > .form-control,
.order-field-wrap--date .order-card-inline-editor > .form-control,
.order-field-wrap--time .order-card-inline-editor > .form-control,
.order-card-inline-display.order-card-inline-display--compact {
  min-width: 9.5rem;
  width: var(--crm-field-date-width, 10.5rem);
  max-width: 100%;
}
.order-field-wrap--select_stage .order-field-wrap__value > .form-select,
.order-field-wrap--select_device .order-field-wrap__value > .form-select,
.order-field-wrap--select_work_mode .order-field-wrap__value > .form-select,
.order-field-wrap--select_stage .order-card-inline-editor > .form-select,
.order-field-wrap--select_device .order-card-inline-editor > .form-select,
.order-field-wrap--select_work_mode .order-card-inline-editor > .form-select {
  min-width: 8rem;
  width: fit-content;
  max-width: min(100%, var(--crm-field-select-max-width, 20rem));
}
.order-inline-editor textarea {
  resize: both;
  max-width: 100%;
}
.customer-contact-label {
  min-width: 8rem;
  width: 10rem;
  max-width: 14rem;
}
.customer-contact-value {
  min-width: 9rem;
  width: 11rem;
  max-width: 16rem;
}
/* Визуально тот же бокс, что у .form-control-sm */
.order-card-inline-display {
  display: block;
  box-sizing: border-box;
  width: var(--crm-field-input-width, auto);
  min-width: min(var(--crm-field-input-width, 6rem), 12rem);
  max-width: 100%;
  min-height: calc(1.5em + .5rem + 2px);
  margin: 0;
  padding: .25rem .5rem;
  font-size: .875rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--crm-text);
  background-color: var(--crm-input-bg);
  border: 1px solid var(--crm-border);
  border-radius: var(--bs-border-radius-sm, .25rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-card-inline-display.order-card-inline-display--sized,
.order-field-wrap--text .order-card-inline-display.order-card-inline-display--sized {
  white-space: pre-wrap;
  overflow: auto;
  text-overflow: unset;
}
.order-card-inline-display.is-multiline {
  white-space: pre-wrap;
  overflow: auto;
  text-overflow: unset;
  min-height: calc(var(--crm-field-textarea-min-rows, 2) * 1.5em + .5rem + 2px);
  width: var(--crm-field-input-width, 100%);
  min-width: min(var(--crm-field-input-width, 12rem), 12rem);
  max-width: 100%;
}
.order-card-inline.is-editable .order-card-inline-display {
  cursor: text;
}
.order-card-inline.is-editable:not(.is-editing):hover .order-card-inline-display {
  border-color: color-mix(in srgb, var(--brand-blue) 55%, var(--crm-border));
  background: color-mix(in srgb, var(--brand-blue) 8%, var(--crm-input-bg));
}
.order-card-inline.is-editing .order-card-inline-editor {
  margin: 0;
  width: auto;
  max-width: 100%;
}
.order-card-inline.is-editing .order-card-inline-display {
  display: none !important;
}
.order-field-wrap .field-change-hint {
  flex: 1 0 100%;
  margin-left: calc(var(--crm-field-label-width, 10rem) + .75rem);
}

/* Inline-редактор раскладки карточки */
.order-card-layout-root {
  position: relative;
  min-width: 0;
  padding-top: 0.15rem;
}
.order-card-layout-edit-float {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 12;
}
.order-card-layout-edit-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 0.375rem;
  background: var(--crm-card-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.order-card-layout-editing .order-card-layout-edit-toggle {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: var(--crm-btn-text);
}
.order-card-layout-tabs,
.order-card-layout-toolbar {
  margin-top: 0.25rem;
}
.order-card-layout-editing .order-card-layout-tabs {
  margin-top: 0.5rem;
}
.order-card-layout-mosaic {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}
.order-card-layout-band {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: start;
  min-width: 0;
  width: 100%;
}
.order-card-layout-band--full {
  display: block;
}
.order-card-layout-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  max-width: 100%;
  align-self: start;
  overflow: hidden;
}
.order-card-layout-stack--left {
  grid-column: 1 / span 6;
}
.order-card-layout-stack--right {
  grid-column: 7 / span 6;
}
.order-card-layout-stack[data-stack-span="4"].order-card-layout-stack--left {
  grid-column: 1 / span 4;
}
.order-card-layout-stack[data-stack-span="4"].order-card-layout-stack--right {
  grid-column: 9 / span 4;
}
.order-card-layout-stack[data-stack-span="8"].order-card-layout-stack--left {
  grid-column: 1 / span 8;
}
.order-card-layout-stack[data-stack-span="8"].order-card-layout-stack--right {
  grid-column: 5 / span 8;
}
.order-card-layout-section {
  position: relative;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  align-self: start;
  height: fit-content;
  box-sizing: border-box;
}
.order-card-layout-section > .card,
.order-card-layout-section > .order-card-layout-section-card,
.order-card-layout-section .order-funnel-card {
  max-width: 100%;
  height: fit-content;
}
.order-card-layout-section-card .card-body,
.order-card-layout-section .card .card-body {
  min-height: unset;
}
.order-card-layout-section-handle {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 12;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.35rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c8d4e6;
  color: #5a6a7e;
  font-size: 0.72rem;
  line-height: 1;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.order-card-layout-section-handle:active {
  cursor: grabbing;
}
.order-card-layout-section-remove {
  position: absolute;
  top: 0.35rem;
  right: 2.25rem;
  z-index: 12;
  width: 1.75rem;
  height: 1.75rem;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 0.35rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #e8b4b4;
  color: #c0392b;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.order-card-layout-editing .order-card-layout-section-remove {
  display: flex;
}
.order-card-layout-editing .order-card-layout-section > .card > .card-header,
.order-card-layout-editing .order-card-layout-section > .order-funnel-card > .card-header {
  padding-right: 4.75rem;
}
.order-card-layout-section-remove:hover {
  background: #fdecea;
  border-color: #dc3545;
  color: #a71d2a;
}
[data-ui-theme="dark"] .order-card-layout-section-handle,
[data-ui-theme="dark"] .order-card-layout-section-remove {
  background: color-mix(in srgb, var(--crm-card-bg) 92%, #000);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .order-card-layout-section-remove {
  border-color: color-mix(in srgb, #dc3545 45%, var(--crm-border));
  color: #f08080;
}
[data-ui-theme="dark"] .order-card-layout-section-remove:hover {
  background: color-mix(in srgb, #dc3545 18%, var(--crm-card-bg));
  color: #ffb3b3;
}
.order-card-layout-width-tools {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 4;
  display: flex;
  gap: 0.2rem;
}
.order-card-layout-width-btn {
  border: 1px solid #c8d4e6;
  background: rgba(255, 255, 255, 0.95);
  color: #4a5a70;
  font-size: 0.65rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border-radius: 0.25rem;
  cursor: pointer;
}
.order-card-layout-width-btn.active {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: var(--crm-btn-text);
}
.order-card-layout-field {
  position: relative;
  min-width: 0;
  padding-left: 0.5rem;
}
.order-card-layout-field-handle {
  position: absolute;
  left: 0;
  top: 0.2rem;
  z-index: 2;
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  background: var(--brand-light);
  border: 1px solid var(--crm-border);
  color: #6b7c93;
  font-size: 0.65rem;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.order-card-layout-editing .order-card-layout-mosaic {
  min-height: 4rem;
  outline: 1px dashed var(--crm-border);
  outline-offset: 4px;
  padding: 0.35rem;
  border-radius: 0.5rem;
}
.order-card-layout-mosaic--dragging {
  background-image: repeating-linear-gradient(
    to right,
    transparent,
    transparent calc(100% / 12 - 1px),
    rgba(13, 110, 253, 0.07) calc(100% / 12 - 1px),
    rgba(13, 110, 253, 0.07) calc(100% / 12)
  );
}
.order-card-layout-section.order-card-layout-dragging {
  opacity: 0.35;
  pointer-events: none;
}
.order-card-layout-drag-ghost {
  position: fixed;
  z-index: 1080;
  margin: 0;
  pointer-events: none;
  opacity: 0.88;
  transform: translate(-50%, -0.75rem);
  box-shadow: 0 8px 24px rgba(13, 110, 253, 0.22);
  max-width: min(92vw, 36rem);
}
.order-card-layout-drop-marker {
  min-height: 2.5rem;
  border: 2px dashed var(--brand-blue);
  border-radius: 0.5rem;
  background: rgba(13, 110, 253, 0.1);
  pointer-events: none;
  flex-shrink: 0;
}
.order-card-layout-drop-marker--stack {
  width: 100%;
}
.order-card-layout-editing .order-card-layout-section > .card,
.order-card-layout-editing .order-card-layout-section > .order-card-layout-section-card,
.order-card-layout-editing .order-card-layout-section .order-funnel-card {
  outline: 1px dashed rgba(13, 110, 253, 0.35);
  outline-offset: 2px;
}
.order-card-layout-editing .order-card-inline.is-editable {
  pointer-events: none;
}
.order-card-layout-editing .order-card-layout-fields {
  min-height: 1.5rem;
}
.order-card-layout-ghost {
  opacity: 0.45;
}
.order-card-layout-chosen {
  z-index: 5;
}
.order-card-layout-drag {
  opacity: 0.85;
}
.order-card-layout-field-ghost {
  opacity: 0.5;
  background: var(--brand-light);
  border-radius: 0.35rem;
}
body.order-card-layout-editing {
  user-select: none;
}
@media (max-width: 991.98px) {
  .order-card-layout-section {
    grid-column: span 12 !important;
  }
  .order-card-layout-width-tools {
    display: none !important;
  }
}

/* Темы оформления */
.card,
.brand-line,
.topbar {
  background-color: var(--crm-card-bg);
}
.card-header.bg-white {
  background-color: var(--crm-card-bg) !important;
}
.btn-brand {
  background-color: var(--crm-btn-bg);
  border-color: var(--crm-btn-bg);
  color: var(--crm-btn-text);
}
.btn-brand:hover,
.btn-brand:focus {
  filter: brightness(0.95);
  color: var(--crm-btn-text);
}
.text-muted {
  color: color-mix(in srgb, var(--crm-text) 62%, transparent) !important;
}
.table-light {
  --bs-table-bg: var(--brand-light);
}
[data-ui-theme="dark"] .order-table-head th {
  background: var(--crm-card-bg);
  box-shadow: 0 1px 0 var(--crm-border);
}
html[data-ui-theme="dark"] {
  color-scheme: dark;
  --crm-input-bg: color-mix(in srgb, var(--crm-card-bg) 90%, #000);
  --bs-body-bg: var(--crm-page-bg);
  --bs-body-color: var(--crm-text);
  --bs-border-color: var(--crm-border);
  --bs-secondary-bg: var(--crm-input-bg);
  --bs-secondary-color: color-mix(in srgb, var(--crm-text) 75%, transparent);
  --bs-tertiary-bg: var(--crm-card-bg);
  --bs-tertiary-color: color-mix(in srgb, var(--crm-text) 50%, transparent);
  --bs-emphasis-color: var(--crm-text);
  --bs-highlight-bg: color-mix(in srgb, #ffc107 22%, var(--crm-card-bg));
  --bs-highlight-color: var(--crm-text);
}
[data-ui-theme="dark"] .table {
  --bs-table-bg: var(--crm-card-bg);
  --bs-table-color: var(--crm-text);
  --bs-table-border-color: var(--crm-border);
  --bs-table-hover-bg: color-mix(in srgb, var(--brand-light) 88%, var(--crm-card-bg));
  --bs-table-hover-color: var(--crm-text);
  --bs-table-striped-bg: color-mix(in srgb, var(--crm-card-bg) 92%, #fff);
  --bs-table-active-bg: var(--brand-light);
  --bs-table-active-color: var(--crm-text);
}
[data-ui-theme="dark"] .table > :not(caption) > * > * {
  background-color: var(--bs-table-bg);
  color: var(--bs-table-color);
  border-color: var(--bs-table-border-color);
}
[data-ui-theme="dark"] .table-hover > tbody > tr:hover > * {
  color: var(--bs-table-hover-color);
  background-color: var(--bs-table-hover-bg);
}
[data-ui-theme="dark"] .order-list-table-card,
[data-ui-theme="dark"] .order-list-table-card .card-body {
  background-color: var(--crm-card-bg);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .order-bulk-toolbar {
  background: var(--brand-light);
  border-bottom-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .dropdown-menu {
  background-color: var(--crm-card-bg);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .dropdown-item {
  color: var(--crm-text);
}
[data-ui-theme="dark"] .dropdown-item:hover,
[data-ui-theme="dark"] .dropdown-item:focus,
[data-ui-theme="dark"] .dropdown-item.active {
  background-color: var(--brand-light);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .dropdown-divider {
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .form-control,
[data-ui-theme="dark"] .form-select,
[data-ui-theme="dark"] textarea.form-control {
  background-color: var(--crm-input-bg);
  color: var(--crm-text);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .form-control:focus,
[data-ui-theme="dark"] .form-select:focus,
[data-ui-theme="dark"] textarea.form-control:focus {
  background-color: var(--crm-input-bg);
  color: var(--crm-text);
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 0.25rem color-mix(in srgb, var(--brand-blue) 22%, transparent);
}
[data-ui-theme="dark"] input:-webkit-autofill,
[data-ui-theme="dark"] input:-webkit-autofill:hover,
[data-ui-theme="dark"] input:-webkit-autofill:focus,
[data-ui-theme="dark"] textarea:-webkit-autofill,
[data-ui-theme="dark"] select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--crm-input-bg) inset !important;
  box-shadow: 0 0 0 1000px var(--crm-input-bg) inset !important;
  -webkit-text-fill-color: var(--crm-text) !important;
  caret-color: var(--crm-text);
}
[data-ui-theme="dark"] .order-card-inline-display {
  background-color: var(--crm-input-bg);
  color: var(--crm-text);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .order-card-inline.is-editable:not(.is-editing):hover .order-card-inline-display {
  border-color: color-mix(in srgb, var(--brand-blue) 55%, var(--crm-border));
  background: color-mix(in srgb, var(--brand-blue) 8%, var(--crm-input-bg));
}
[data-ui-theme="dark"] .order-field--changed {
  background-color: color-mix(in srgb, #ffc107 14%, var(--crm-card-bg));
}
[data-ui-theme="dark"] .order-field--changed .form-control,
[data-ui-theme="dark"] .order-field--changed .form-select,
[data-ui-theme="dark"] .order-field--changed textarea,
[data-ui-theme="dark"] .order-field--changed .order-card-inline-display {
  border-color: #ffc107;
  background-color: color-mix(in srgb, #ffc107 14%, var(--crm-input-bg));
}
[data-ui-theme="dark"] .field-change-hint {
  color: color-mix(in srgb, #ffc107 75%, var(--crm-text));
}
[data-ui-theme="dark"] .order-columns-order-list {
  background: var(--crm-card-bg);
}
[data-ui-theme="dark"] .order-columns-order-item {
  background: var(--crm-input-bg);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .order-columns-chip {
  background: var(--crm-input-bg);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .order-columns-chip:has(input:checked) {
  background: color-mix(in srgb, var(--brand-blue) 18%, var(--crm-card-bg));
  border-color: color-mix(in srgb, var(--brand-blue) 45%, var(--crm-border));
  color: var(--crm-text);
}
[data-ui-theme="dark"] .form-control::placeholder {
  color: color-mix(in srgb, var(--crm-text) 45%, transparent);
}
[data-ui-theme="dark"] input[type="date"],
[data-ui-theme="dark"] input[type="time"],
[data-ui-theme="dark"] input[type="datetime-local"],
[data-ui-theme="dark"] input[type="month"],
[data-ui-theme="dark"] input[type="week"] {
  color-scheme: dark;
}
[data-ui-theme="dark"] .btn-outline-secondary,
[data-ui-theme="dark"] .btn-outline-primary {
  color: var(--crm-text);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .btn-outline-secondary:hover,
[data-ui-theme="dark"] .btn-outline-primary:hover {
  background-color: var(--brand-light);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .btn-outline-dark {
  color: var(--crm-text);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .btn-outline-dark:hover {
  background-color: var(--brand-light);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .link-muted,
[data-ui-theme="dark"] a:not(.btn):not(.nav-link) {
  color: var(--brand-blue);
}
[data-ui-theme="dark"] .crm-logout-btn {
  background: color-mix(in srgb, var(--crm-card-bg) 92%, #000);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .crm-logout-btn:hover {
  background: var(--brand-light);
  color: var(--crm-text);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .kanban-col {
  background: var(--crm-card-bg);
  border-color: var(--crm-border);
}
[data-ui-theme="dark"] .kanban-col-head {
  background: var(--brand-light);
  border-bottom-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .kanban-card {
  background: var(--crm-card-bg);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .kanban-drop.drop-hover {
  background: var(--brand-light);
}
[data-ui-theme="dark"] .pagination .page-link {
  background-color: var(--crm-card-bg);
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .pagination .page-item.active .page-link {
  background-color: var(--crm-btn-bg);
  border-color: var(--crm-btn-bg);
  color: var(--crm-btn-text);
}
[data-ui-theme="dark"] .alert-info {
  background-color: color-mix(in srgb, var(--brand-blue) 18%, var(--crm-card-bg));
  border-color: var(--crm-border);
  color: var(--crm-text);
}
[data-ui-theme="dark"] .badge-soft {
  background: var(--brand-light);
  color: var(--brand-blue);
}
[data-ui-theme="dark"] .badge.bg-light {
  background-color: var(--brand-light) !important;
  color: var(--crm-text) !important;
}

/* Переход к заказу по номеру в шапке карточки */
.order-goto-form {
  font-weight: 400;
}
.order-goto-input {
  width: 6.5rem;
  max-width: 40vw;
  font-weight: 600;
}
.order-goto-btn {
  line-height: 1;
  padding: 0.2rem 0.45rem;
}

/* Document preview / print sheet */
.doc-print-sheet {
  color: #000;
  font-family: "Times New Roman", Times, serif;
  font-size: 12pt;
  line-height: 1.35;
  background: #fff;
}
.doc-print-sheet p { margin: 0 0 .55em; }
.doc-print-sheet h1,
.doc-print-sheet h2,
.doc-print-sheet h3 {
  margin: .8em 0 .4em;
  font-weight: 700;
}
.doc-print-sheet table,
.doc-print-sheet .doc-print-table {
  width: 100%;
  border-collapse: collapse;
  margin: .6em 0;
}
.doc-print-sheet td,
.doc-print-sheet th {
  vertical-align: top;
  padding: 4px 6px;
}
.doc-print-sheet .doc-print-table td,
.doc-print-sheet .doc-print-table th {
  border: 1px solid #333;
}
.doc-print-sheet img {
  max-width: 100%;
  height: auto;
}
#docPreviewBody .doc-print-sheet,
#templatePreviewModalBody .doc-print-sheet {
  border: 1px solid #e6efff;
  border-radius: 8px;
  padding: 1rem 1.25rem;
}

/* --- Order staff chat popup --- */
.order-chat {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1085;
  width: min(380px, calc(100vw - 1.5rem));
  font-size: 0.9rem;
}
.order-chat__panel {
  display: flex;
  flex-direction: column;
  max-height: min(520px, calc(100vh - 2rem));
  background: var(--crm-card-bg, #fff);
  color: var(--crm-text, #212529);
  border: 1px solid var(--crm-border, #dbe7f7);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(15, 40, 80, 0.18);
  overflow: hidden;
}
.order-chat__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  background: linear-gradient(180deg, #f5f9ff, #eef4fc);
  border-bottom: 1px solid var(--crm-border, #dbe7f7);
}
.order-chat__title-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  flex: 1;
}
.order-chat__title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order-chat__actions {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}
.order-chat__icon-btn {
  border: 0;
  background: transparent;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  line-height: 1;
  font-size: 1.1rem;
  color: #445;
}
.order-chat__icon-btn:hover {
  background: rgba(13, 110, 253, 0.1);
}
.order-chat__body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.order-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 220px;
  max-height: 320px;
  background: var(--crm-page-bg, #f7fafc);
}
.order-chat__empty {
  margin: auto;
  text-align: center;
  padding: 1rem;
}
.order-chat__msg {
  align-self: flex-start;
  max-width: 92%;
  background: #fff;
  border: 1px solid var(--crm-border, #dbe7f7);
  border-radius: 10px;
  padding: 0.4rem 0.55rem 0.35rem;
}
.order-chat__msg.is-mine {
  align-self: flex-end;
  background: #e8f1ff;
  border-color: #c9ddff;
}
.order-chat__msg-meta {
  font-size: 0.72rem;
  color: #6c757d;
  margin-bottom: 0.15rem;
}
.order-chat__msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}
.order-chat__tag {
  color: #0d6efd;
  font-weight: 600;
}
.order-chat__msg-status {
  margin-top: 0.2rem;
  text-align: right;
}
.order-chat__delivery {
  font-size: 0.7rem;
  color: #8a93a3;
}
.order-chat__delivery.is-delivered {
  color: #5c6b7a;
}
.order-chat__delivery.is-read {
  color: #0d6efd;
}
.order-chat__composer {
  position: relative;
  border-top: 1px solid var(--crm-border, #dbe7f7);
  padding: 0.5rem;
  background: var(--crm-card-bg, #fff);
}
.order-chat__input {
  resize: none;
}
.order-chat__composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.order-chat__mention-menu {
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: calc(100% - 0.15rem);
  max-height: 180px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--crm-border, #dbe7f7);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15, 40, 80, 0.12);
  z-index: 2;
}
.order-chat__mention-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.4rem 0.55rem;
  text-align: left;
}
.order-chat__mention-item:hover,
.order-chat__mention-item.is-active {
  background: #eef4fc;
}
.order-chat__minimized {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--crm-border, #dbe7f7);
  background: var(--crm-card-bg, #fff);
  color: var(--crm-text, #212529);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  box-shadow: 0 6px 18px rgba(15, 40, 80, 0.14);
  font-weight: 600;
}
.order-chat__minimized:hover {
  background: #f5f9ff;
}
.order-chat-open-btn .badge {
  margin-left: 0.25rem;
}

