/* CRM v2 shared design refinement */
:root {
  --crm-surface: #ffffff;
  --crm-surface-soft: #f8fafc;
  --crm-border: #e3e8ef;
  --crm-ink: #152033;
  --crm-muted-ink: #64748b;
  --crm-shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --crm-shadow-md: 0 14px 34px -18px rgba(15, 23, 42, .22);
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease, color .15s ease, opacity .15s ease;
}

.topbar,
header,
.view-sticky {
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}

.panel,
.metric,
.todo,
.feed,
.lead,
.stat,
.kpi,
.form-row,
.prompt-box,
.search-results,
.login-card,
.login-box,
.crm-dialog-panel {
  box-shadow: var(--crm-shadow-sm);
}

.panel-head,
.todo-title,
.feed-title,
.section-title b,
.page-head b {
  letter-spacing: 0;
}

.panel-head b,
.todo-title,
.feed-title {
  font-size: 13px;
}

.metric,
.kpi,
.stat {
  overflow: hidden;
}

.metric b,
.kpi b,
.stat b {
  font-variant-numeric: tabular-nums;
}

.metric small,
.kpi small,
.stat span,
.todo-item span,
.feed-item span,
.muted {
  letter-spacing: 0;
}

.v2-table th {
  background: var(--crm-surface-soft);
  color: #526076;
  font-size: 11px;
}

.v2-table tbody tr:hover td {
  background: #fbfdff;
}

th.crm-col-check,
td.crm-col-check {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  padding-left: 10px !important;
  padding-right: 6px !important;
}

.crm-leads-table {
  table-layout: fixed;
  min-width: 1126px;
}

.crm-leads-table th:nth-child(2),
.crm-leads-table td:nth-child(2) { width: 48px; }
.crm-leads-table th:nth-child(3),
.crm-leads-table td:nth-child(3) { width: 100px; }
.crm-leads-table th:nth-child(4),
.crm-leads-table td:nth-child(4) { width: 118px; }
.crm-leads-table th:nth-child(5),
.crm-leads-table td:nth-child(5) { width: 96px; }
.crm-leads-table th:nth-child(6),
.crm-leads-table td:nth-child(6) { width: 154px; }
.crm-leads-table th:nth-child(7),
.crm-leads-table td:nth-child(7) { width: 82px; }
.crm-leads-table th:nth-child(8),
.crm-leads-table td:nth-child(8) { width: 86px; }
.crm-leads-table th:nth-child(9),
.crm-leads-table td:nth-child(9) { width: 70px; }
.crm-leads-table th:nth-child(10),
.crm-leads-table td:nth-child(10) { width: 86px; }
.crm-leads-table th:nth-child(11),
.crm-leads-table td:nth-child(11) { width: 70px; }
.crm-leads-table th:nth-child(12),
.crm-leads-table td:nth-child(12) { width: 64px; }
.crm-leads-table th:nth-child(13),
.crm-leads-table td:nth-child(13) { width: 116px; }

.crm-leads-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

.crm-leads-body {
  max-height: none !important;
  overflow: visible !important;
}

.crm-leads-scroll {
  max-height: min(520px, 66vh);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #c7d0db transparent;
}

.crm-leads-table.ops-leads-table {
  min-width: 1160px;
}

.crm-leads-table.ops-leads-table th,
.crm-leads-table.ops-leads-table td {
  padding: 11px 12px;
  vertical-align: middle;
}

.crm-leads-table.ops-leads-table tbody tr {
  height: 66px;
}

.crm-leads-table.ops-leads-table th:nth-child(2),
.crm-leads-table.ops-leads-table td:nth-child(2) { width: 200px; }
.crm-leads-table.ops-leads-table th:nth-child(3),
.crm-leads-table.ops-leads-table td:nth-child(3) { width: 126px; }
.crm-leads-table.ops-leads-table th:nth-child(4),
.crm-leads-table.ops-leads-table td:nth-child(4) { width: 176px; }
.crm-leads-table.ops-leads-table th:nth-child(5),
.crm-leads-table.ops-leads-table td:nth-child(5) { width: 88px; }
.crm-leads-table.ops-leads-table th:nth-child(6),
.crm-leads-table.ops-leads-table td:nth-child(6) { width: 142px; }
.crm-leads-table.ops-leads-table th:nth-child(7),
.crm-leads-table.ops-leads-table td:nth-child(7) { width: 132px; }
.crm-leads-table.ops-leads-table th:nth-child(8),
.crm-leads-table.ops-leads-table td:nth-child(8) { width: 132px; }
.crm-leads-table.ops-leads-table th:nth-child(9),
.crm-leads-table.ops-leads-table td:nth-child(9) { width: 156px; }

.ops-filter-panel > summary {
  cursor: pointer;
  list-style: none;
}

.ops-filter-panel > summary::-webkit-details-marker {
  display: none;
}

.ops-primary-line,
.ops-secondary-line,
.ops-attribution-cell,
.ops-source-cell,
.ops-sales-cell,
.ops-follow-cell,
.ops-status-cell {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ops-primary-line {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.ops-primary-line b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ops-row-index {
  color: #98a2b3;
  font-size: 11px;
}

.ops-secondary-line {
  grid-template-columns: minmax(0, 1fr);
  color: var(--muted);
  font-size: 11px;
}

.ops-secondary-line span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ops-attribution-cell b,
.ops-sales-cell b {
  color: var(--ink);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ops-attribution-cell span,
.ops-source-cell > span:last-child,
.ops-sales-cell span,
.ops-follow-cell > span,
.ops-status-cell .muted {
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ops-pool-reason {
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: normal !important;
  overflow-wrap: anywhere;
}

.ops-status-cell > div {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ops-actions-cell .crm-util-flex-g4px {
  align-items: center;
}

.ops-actions-cell .btn.sm {
  min-height: 32px;
  padding: 0 8px;
}

.ops-range-panel {
  margin-bottom: 16px;
}

.ops-range-panel .body {
  align-items: center;
}

.ops-today-panel {
  margin-top: 14px;
}

.ops-today-panel .metrics {
  margin-bottom: 0;
}

.ops-span-all {
  grid-column: 1 / -1;
}

.crm-sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 4;
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding: 10px 0 2px;
  background: var(--panel, #fff);
  border-top: 1px solid var(--crm-border, #e0e5eb);
}

.table-wrap {
  scrollbar-color: #c7d0db transparent;
}

.empty {
  border: 1px dashed var(--crm-border, var(--line));
  border-radius: 8px;
}

.btn {
  box-shadow: inset 0 0 0 1px transparent;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.prompt-box,
.crm-dialog-panel {
  box-shadow: var(--crm-shadow-md);
}

.crm-dialog-panel h3,
.prompt-box h3 {
  margin-top: 0;
}

/* Desktop manager */
.app .sidebar {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .03);
}

.content .page-head {
  margin-bottom: 16px;
}

.content .panel + .panel {
  margin-top: 0;
}

.dispatch-rules-card {
  margin-bottom: 14px;
}

.dispatch-rules-card .panel-head > div {
  min-width: 0;
}

.dispatch-rules-subtitle {
  margin-top: 3px;
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
  font-weight: 400;
}

.dispatch-rule-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.dispatch-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.dispatch-field > span:first-child {
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
  font-weight: 800;
}

.dispatch-control {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.dispatch-control input,
.dispatch-control select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--crm-border, var(--line));
  border-radius: 7px;
  background: #fff;
  color: var(--crm-ink, var(--ink));
  font: inherit;
  font-size: 12px;
}

.dispatch-control input[type="number"] {
  padding-right: 42px;
}

.dispatch-control input:focus,
.dispatch-control select:focus {
  border-color: var(--crm-focus, var(--blue));
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .1);
  outline: none;
}

.dispatch-unit {
  position: absolute;
  right: 10px;
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
  font-style: normal;
  pointer-events: none;
}

.dispatch-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eef1f5;
}

.dispatch-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.dispatch-section-head b {
  font-size: 13px;
}

.dispatch-section-head span {
  display: block;
  margin-top: 2px;
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
}

.dispatch-inline-check,
.dispatch-notify-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--crm-muted-ink, var(--muted));
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.dispatch-inline-check input,
.dispatch-notify-option input,
.dispatch-weekday input {
  width: 14px;
  height: 14px;
  accent-color: var(--blue);
}

.dispatch-schedule-grid,
.dispatch-fallback-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dispatch-fallback-grid {
  align-items: end;
}

.dispatch-notify-option {
  min-height: 36px;
}

.dispatch-weekdays {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}

.dispatch-weekday {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
  white-space: nowrap;
}

.dispatch-note {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid var(--crm-border, var(--line));
  border-radius: 7px;
  background: var(--crm-surface-soft, #f8fafc);
  color: var(--crm-muted-ink, var(--muted));
  font-size: 11px;
  line-height: 1.6;
}

.dispatch-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eef1f5;
}

@media (max-width: 1180px) {
  .dispatch-rule-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .dispatch-rule-grid,
  .dispatch-schedule-grid,
  .dispatch-fallback-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dispatch-section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .dispatch-actions {
    flex-direction: column;
  }

  .dispatch-actions .btn {
    width: 100%;
  }
}

.topbar {
  border-bottom-color: var(--crm-border, #e0e5eb);
}

.search {
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .04);
}

/* Mobile manager */
.phone .hello,
.phone .greeting {
  margin-top: 4px;
}

.phone .todo-item,
.phone .feed-item {
  min-height: 48px;
}

.phone .todo-title {
  align-items: center;
}

.phone nav {
  box-shadow: 0 -1px 0 rgba(15, 23, 42, .06), 0 -8px 24px -20px rgba(15, 23, 42, .18);
}

/* Sales mobile */
.sales-view .lead,
.sales .lead {
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.sales .lead:active,
.sales-view .lead:active {
  transform: translateY(1px);
}

.next {
  box-shadow: 0 14px 30px -18px rgba(10, 40, 28, .35);
}

.next .acts .call {
  gap: 6px;
}

.op-pair .op,
.tag-row button,
.seg-toggle button {
  border-radius: 8px;
}

.tag-row button.on {
  box-shadow: 0 0 0 1px currentColor inset;
}

/* Report emphasis */
#reportBody .metric,
#financeReportBody .metric,
#profitBody .metric {
  border-top: 3px solid transparent;
}

#reportBody .metric.m-blue,
#financeReportBody .metric.m-blue,
#profitBody .metric.m-blue {
  border-top-color: #2456e6;
}

#reportBody .metric.m-green,
#financeReportBody .metric.m-green,
#profitBody .metric.m-green {
  border-top-color: #0d9f6e;
}

#reportBody .metric.m-red,
#financeReportBody .metric.m-red,
#profitBody .metric.m-red {
  border-top-color: #dc4a4d;
}

#reportBody .metric.m-amber,
#financeReportBody .metric.m-amber,
#profitBody .metric.m-amber {
  border-top-color: #d97706;
}

#reportBody .metric.m-ink,
#financeReportBody .metric.m-ink,
#profitBody .metric.m-ink {
  border-top-color: #152033;
}

#reportBody .panel > .body {
  max-height: none;
  overflow: visible;
}

.crm-report-scroll {
  max-height: min(420px, 60vh);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #c7d0db transparent;
}

.report-toolbar .body {
  padding-top: 14px;
  padding-bottom: 14px;
}

.report-toolbar-main {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.report-date-group {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.report-ai-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 360px;
  min-width: 260px;
  margin-left: auto;
}

.report-ai-inline input {
  flex: 1;
  min-width: 220px;
}

.report-ai-inline.is-disabled {
  flex: 0 0 auto;
  justify-content: flex-end;
}

.report-prompt-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.report-prompt-chips button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: #eef2f7;
  color: #526076;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.report-prompt-chips button:hover {
  background: #e2e8f0;
  color: var(--ink, #152033);
}

.report-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.report-card {
  display: flex;
  flex-direction: column;
  height: 320px;
  min-width: 0;
}

.report-card > .panel-head {
  flex: 0 0 auto;
}

.report-card > .body {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
}

#reportBody .report-card-table > .body {
  display: flex;
  overflow: hidden;
}

#reportBody .report-card-table .crm-report-scroll {
  width: 100%;
  height: 100%;
  max-height: none;
}

#reportBody .report-card.is-empty > .body {
  display: grid;
  place-items: center;
  text-align: center;
}

#reportBody .report-card.is-empty .crm-report-scroll {
  width: 100%;
  height: auto;
  max-height: none;
  overflow: visible;
}

#reportBody .report-card.is-empty .v2-table thead {
  display: none;
}

.report-signal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 100%;
}

.report-signal-grid > div {
  min-width: 0;
}

.service-card {
  height: 360px;
}

.service-card-wide {
  grid-column: 1 / -1;
}

.service-card-table > .body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.service-filterbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.service-filterbar input {
  flex: 1 1 240px;
  min-width: 180px;
}

.service-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #c7d0db transparent;
}

.service-table-scroll .v2-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

.service-pager {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--crm-border, #e0e5eb);
  background: var(--crm-surface, #fff);
}

.service-tag-cloud {
  display: flex;
  align-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.service-tag {
  height: 28px;
  margin: 0 !important;
  font-size: 12px;
}

.service-copy-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.service-copy-toolbar b {
  font-size: 13px;
}

.service-copy-toolbar > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.service-copy-toolbar .muted {
  font-size: 11px;
}

.service-copy-item {
  padding: 8px 10px;
  margin: 0 0 8px;
  border: 1px solid var(--crm-border, #e0e5eb);
  border-radius: 7px;
  background: #f8fafc;
  color: var(--crm-muted-ink, #64748b);
  font-size: 12px;
  line-height: 1.6;
}

.kb-table-card {
  display: flex;
  flex-direction: column;
  height: min(620px, 72vh);
  min-height: 300px;
}

.kb-table-card > .body {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.kb-filterbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.kb-filterbar input {
  flex: 1 1 240px;
  min-width: 180px;
}

.kb-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #c7d0db transparent;
}

.kb-table-scroll .v2-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

.kb-pager {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--crm-border, #e0e5eb);
  background: var(--crm-surface, #fff);
}

.finance-filterbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.finance-filterbar input {
  min-width: 150px;
}

.finance-pager {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--crm-border, #e0e5eb);
  background: var(--crm-surface, #fff);
}

.finance-ledger-table {
  min-width: 1180px;
}

.finance-ledger-remark {
  display: block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finance-remark-list {
  display: grid;
  gap: 6px;
}

.finance-remark-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 120px;
  gap: 10px;
  align-items: center;
  min-height: 34px;
  padding: 0 2px;
  border-bottom: 1px solid var(--crm-border, #e0e5eb);
}

.finance-remark-row:last-child {
  border-bottom: 0;
}

.finance-remark-row b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.finance-remark-row span {
  color: var(--crm-muted-ink, #667085);
  font-size: 12px;
}

.finance-remark-row strong {
  color: var(--crm-ink, #152033);
  text-align: right;
}

.team-rules-card > .body {
  min-height: 0;
}

.team-rules-scroll {
  max-height: min(440px, 62vh);
  overflow: auto;
  overscroll-behavior: contain;
}

.team-rules-scroll .v2-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

#financeReportBody > .grid2 > .panel,
#financeReportBody > .panel {
  display: flex;
  flex-direction: column;
  height: 340px;
  min-height: 0;
}

#financeReportBody > .grid2 > .panel > .body,
#financeReportBody > .panel > .body,
#profitBody > .panel > .body {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#financeReportBody .table-wrap,
#profitBody .panel .body {
  min-height: 0;
  overflow: auto;
}

.kb-scenario-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kb-scenario-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kb-scenario-card {
  height: 380px;
}

.kb-scenario-overview-card {
  height: 180px;
}

.kb-scenario-card > .body {
  overflow: auto;
}

.kb-diff-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.kb-diff-grid > section {
  min-width: 0;
}

.kb-diff-title {
  margin-bottom: 6px;
  color: var(--crm-ink, #152033);
  font-size: 12px;
  font-weight: 800;
}

.kb-diff-grid pre {
  max-height: 62vh;
  margin: 0;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--crm-border, #e0e5eb);
  border-radius: 8px;
  background: #f8fafc;
  font: 12px/1.65 ui-monospace, SFMono-Regular, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.crm-detail-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.crm-detail-section {
  min-width: 0;
}

.crm-detail-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 7px;
  font-size: 12px;
}

.crm-detail-section-title b {
  color: var(--crm-ink, #152033);
}

.crm-detail-section-title span {
  font-size: 11px;
}

.crm-detail-scroll {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--crm-border, #e0e5eb);
  border-radius: 8px;
  overscroll-behavior: contain;
}

.crm-detail-scroll .v2-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

@media (max-width: 1100px) {
  .report-board {
    grid-template-columns: minmax(0, 1fr);
  }

  .report-card {
    height: 300px;
  }

  .service-card {
    height: 340px;
  }

  .service-card-wide {
    grid-column: auto;
  }

  .kb-scenario-card {
    height: 340px;
  }

  .kb-scenario-grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }

}

@media (max-width: 700px) {
  .crm-detail-sections {
    grid-template-columns: minmax(0, 1fr);
  }

  .service-copy-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .kb-diff-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Desktop service tables stay tabular at medium widths; horizontal scrolling is clearer than cardifying cells to the right. */
@media (min-width: 701px) {
  #servicePane .crm-responsive-table,
  #kbPane .crm-responsive-table,
  #financeSubBody .crm-responsive-table {
    display: table;
    width: 100% !important;
    min-width: 920px !important;
    white-space: normal !important;
  }

  #servicePane .crm-responsive-table thead,
  #kbPane .crm-responsive-table thead,
  #financeSubBody .crm-responsive-table thead {
    display: table-header-group;
  }

  #servicePane .crm-responsive-table tbody,
  #kbPane .crm-responsive-table tbody,
  #financeSubBody .crm-responsive-table tbody {
    display: table-row-group;
  }

  #servicePane .crm-responsive-table tr,
  #kbPane .crm-responsive-table tr,
  #financeSubBody .crm-responsive-table tr {
    display: table-row;
    margin: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  #servicePane .crm-responsive-table td,
  #kbPane .crm-responsive-table td,
  #financeSubBody .crm-responsive-table td {
    display: table-cell;
    width: auto !important;
    min-width: 0 !important;
    min-height: 0;
    padding: 9px 8px;
    border-bottom: 1px solid var(--crm-border, #e0e5eb);
    text-align: left;
    white-space: nowrap !important;
  }

  #servicePane .crm-responsive-table td::before,
  #kbPane .crm-responsive-table td::before,
  #financeSubBody .crm-responsive-table td::before {
    content: none;
  }
}

@media (min-width: 701px) {
  .team-rules-card .crm-responsive-table {
    display: table;
    width: 100% !important;
    min-width: 900px !important;
  }

  .team-rules-card .crm-responsive-table thead {
    display: table-header-group;
  }

  .team-rules-card .crm-responsive-table tbody {
    display: table-row-group;
  }

  .team-rules-card .crm-responsive-table tr {
    display: table-row;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .team-rules-card .crm-responsive-table td {
    display: table-cell;
    width: auto !important;
    min-width: 0 !important;
    padding: 9px 8px;
    border-bottom: 1px solid var(--crm-border, #e0e5eb);
    text-align: left;
    white-space: nowrap !important;
  }

  .team-rules-card .crm-responsive-table td::before {
    content: none;
  }
}

#reportBody .v2-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--crm-border, #e0e5eb);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light;
  }
}

@media (max-width: 1280px) {
  #contentBody > .metrics {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

/* Stable card bodies: grid cards keep a bounded height, content scrolls inside */
@media (min-width: 1101px) {
  #contentBody > .grid2,
  #contentBody > .grid3,
  #financeSubBody > .grid2,
  #financeSubBody > .grid3,
  #reportBody > .grid2,
  #reportBody > .grid3 {
    align-items: stretch;
  }

  #contentBody > .grid2 > .panel,
  #contentBody > .grid3 > .panel,
  #financeSubBody > .grid2 > .panel,
  #financeSubBody > .grid3 > .panel,
  #reportBody > .grid2 > .panel,
  #reportBody > .grid3 > .panel {
    max-height: min(420px, 62vh);
  }

  #contentBody > .grid2 > .panel > .body,
  #contentBody > .grid3 > .panel > .body,
  #financeSubBody > .grid2 > .panel > .body,
  #financeSubBody > .grid3 > .panel > .body,
  #reportBody > .grid2 > .panel > .body,
  #reportBody > .grid3 > .panel > .body {
    max-height: min(360px, 54vh);
    overflow: auto;
    overscroll-behavior: contain;
  }

  #contentBody > .panel > .body,
  #financeSubBody > .panel > .body,
  #settingsSubBody > .panel > .body,
  #kbPane > .panel > .body,
  #servicePane > .panel > .body,
  #financeReportBody > .panel > .body,
  #profitBody > .panel > .body {
    max-height: min(520px, 66vh);
    overflow: auto;
    overscroll-behavior: contain;
  }

  #contentBody > .panel > .body .grid2,
  #financeSubBody > .panel > .body .grid2,
  #contentBody > .panel > .body .grid3,
  #financeSubBody > .panel > .body .grid3 {
    max-height: none;
  }
}

/* Mobile: frequent list cards should not own the whole screen */
@media (max-width: 430px) {
  .phone .todo,
  .phone .feed,
  .phone .panel {
    display: flex;
    flex-direction: column;
    max-height: 74vh;
  }

  .phone .todo .todo-title,
  .phone .feed .feed-title,
  .phone .panel .panel-head {
    flex: 0 0 auto;
  }

  .phone .todo .todo-list,
  .phone .feed .feed-list,
  .phone .todo .body,
  .phone .panel .body {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  #settingsSubBody .panel {
    display: block;
    max-height: none;
  }

  #settingsSubBody .panel .body {
    flex: none;
    min-height: 0;
    overflow: visible;
  }
}
