/* IBG MART CRM Phase 13 — strict chat viewport + restrained dealership profile.
   Scoped: does not alter OTP/login, dashboard or other module scrolling. */
html:has(.workspace.crm-chat-open),
body:has(.workspace.crm-chat-open) {
  margin:0!important;
  width:100%;height:100%!important;min-height:0!important;
  overflow:hidden!important;overscroll-behavior:none!important;
}
/* The viewport itself never scrolls on chat pages. */
body:has(.workspace.crm-chat-open)>.workspace.crm-chat-open,
.workspace.crm-chat-open {
  position:fixed!important;
  inset:var(--crm13-top,0px) 0 auto 0!important;
  width:100vw!important;
  height:var(--crm13-viewport,100dvh)!important;
  min-height:0!important;
  max-height:var(--crm13-viewport,100dvh)!important;
  box-sizing:border-box!important;
  display:flex!important;
  padding-bottom:0!important;
  overflow:hidden!important;
}
.workspace.crm-chat-open>.rail,
.workspace.crm-chat-open>.contact-pane {min-height:0!important;max-height:100%!important;}
.workspace.crm-chat-open>.contact-pane {overflow:hidden!important;}
.workspace.crm-chat-open>.contact-pane .contact-scroll {flex:1 1 0!important;min-height:0!important;overflow-y:auto!important;}
/* Three explicit rows: fixed header / one scrolling history / fixed composer. */
.workspace.crm-chat-open>.conversation {
  display:grid!important;
  grid-template-columns:minmax(0,1fr)!important;
  grid-template-rows:auto minmax(0,1fr) auto!important;
  align-content:stretch!important;
  flex:1 1 0!important;
  position:relative!important;
  height:100%!important;max-height:100%!important;
  min-width:0!important;min-height:0!important;
  padding:0!important;margin:0!important;
  overflow:hidden!important;
  overscroll-behavior:contain;
}
.workspace.crm-chat-open>.conversation>.conversation-head {
  grid-row:1!important;min-height:0!important;
  position:relative!important;top:auto!important;
  z-index:4!important;flex:none!important;
}
.workspace.crm-chat-open>.conversation>.conversation-body {
  grid-row:2!important;
  height:auto!important;max-height:100%!important;
  min-height:0!important;
  margin:0!important;
  overflow-x:hidden!important;overflow-y:auto!important;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior:contain;
  scroll-behavior:auto;
  padding-bottom:18px!important;
}
.workspace.crm-chat-open>.conversation>.crm-v8-compose-row {
  grid-row:3!important;
  position:relative!important;
  inset:auto!important;
  transform:none!important;
  display:flex!important;
  flex:none!important;
  box-sizing:border-box!important;
  width:100%!important;
  min-height:74px!important;
  max-height:90px!important;
  margin:0!important;
  padding:11px 18px!important;
  border-top:1px solid #e8eff8!important;
  background:#f8fbff!important;
  z-index:20!important;
  overflow:visible!important;
  box-shadow:0 -7px 20px rgba(25,45,79,.035)!important;
}
.workspace.crm-chat-open .crm-v8-plus-wrap {flex-shrink:0;}
.workspace.crm-chat-open .crm-v8-popover {z-index:50!important;}
.workspace.crm-chat-open .crm-v8-compose-form {min-width:0!important;}
.workspace.crm-chat-open .crm-v8-compose-form input {min-width:0!important;}

/* Dealer layout — calm visual rhythm and highly scannable information. */
.crm13-dealer-detail {
  padding:26px clamp(16px,3vw,45px) 42px!important;
  overflow-y:auto!important;
  background:#f6f9fd!important;
}
.crm13-dealer-top {display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:17px;}
.crm13-back {display:inline-flex;align-items:center;gap:6px;min-height:36px;padding:7px 12px;border-radius:10px;background:#fff;border:1px solid #e5ebf4;font-size:12px;font-weight:700;color:#2769cb;}
.crm13-profile-overline {font-size:10px;letter-spacing:.14em;font-weight:800;color:#99a8ba;white-space:nowrap;}
.crm13-dealer-hero {display:flex;align-items:center;gap:16px;padding:21px 24px;margin-bottom:16px;background:#fff;border:1px solid #e5ebf4;border-radius:20px;box-shadow:0 4px 20px rgba(18,40,72,.025);}
.crm13-dealer-monogram {display:grid;place-items:center;width:56px;height:56px;flex:0 0 56px;border-radius:17px;background:#e9f1ff;color:#276ada;font-weight:760;font-size:25px;}
.crm13-dealer-identity {flex:1;min-width:0;}
.crm13-dealer-identity h1 {margin:0 0 7px;font-size:clamp(19px,2.5vw,28px);font-weight:760;line-height:1.2;letter-spacing:-.04em;overflow-wrap:anywhere;}
.crm13-hero-meta {display:flex;gap:10px;align-items:center;flex-wrap:wrap;color:#8494a9;font-size:11px;line-height:1.4;}
.crm13-meta-divider{display:block;flex:0 0 3px;width:3px;height:3px;border-radius:50%;background:#b4c0d0;}
.crm13-call-link {flex:0 0 auto;display:flex;align-items:center;gap:9px;border:1px solid #d8e7fd;background:#edf4ff;color:#2367d2;border-radius:12px;padding:11px 15px;font-size:12px;font-weight:750;}
.crm13-detail-layout {grid-template-columns:minmax(0,1fr) minmax(285px,325px)!important;gap:16px!important;align-items:start!important;}
.crm13-dealer-chat {height:min(680px,calc(100dvh - 243px))!important;min-height:390px!important;background:#f9fbff!important;border:1px solid #e3eaf4!important;border-radius:19px!important;}
.crm13-history-heading {flex:0 0 auto;display:flex;justify-content:space-between;align-items:center;padding:17px 21px;background:#fff;border-bottom:1px solid #e9eef6;}
.crm13-history-heading h2 {margin:0;font-size:15px;font-weight:750;letter-spacing:-.02em;color:#1c304d;}
.crm13-history-heading span {font-size:11px;color:#899bb1;}
.crm13-dealer-chat .crm12-dealer-events {padding:18px 20px!important;}
.crm13-dealer-chat .crm12-history-item {box-shadow:none!important;border:1px solid #e5ebf3;border-radius:15px!important;padding:12px 14px!important;max-width:min(85%,430px);}
.crm13-dealer-chat .crm12-kind-note,.crm13-dealer-chat .crm12-kind-order {background:#e9f7ef;border-color:#d9efe3;}
.crm13-dealer-chat .crm12-history-item p {margin:6px 0 9px;font-size:12px;line-height:1.6;color:#2a3950;}
.crm13-dealer-chat .crm12-history-item header {gap:10px;flex-wrap:wrap;}
.crm13-dealer-chat .crm12-history-item header span {font-weight:500;}
.crm13-history-empty{margin:auto;color:#9aabc0;font-size:12px;text-align:center;}
.crm13-dealer-chat .crm12-dealer-composer {padding:12px 15px!important;min-height:69px;background:#fff!important;}
.crm13-dealer-chat .crm12-dealer-composer input {background:#f7f9fc;min-height:43px;border-radius:22px;}
.crm13-dealer-chat .crm12-dealer-composer button {flex:0 0 43px;min-width:43px;min-height:43px;display:grid;place-items:center;}
.crm13-dealer-side {display:flex!important;flex-direction:column!important;gap:11px!important;min-width:0;}
.crm13-dealer-side .crm12-info-card {padding:18px 19px!important;border-radius:16px!important;}
.crm13-dealer-side .crm12-info-card h2 {font-size:14px;font-weight:740;letter-spacing:-.02em;margin-bottom:12px;}
.crm13-summary-card .crm13-phone {display:inline-block;margin-bottom:12px;color:#276add;font-weight:720;font-size:13px;}
.crm13-summary-card address {font-size:12px;color:#576a85;font-style:normal;line-height:1.6;overflow-wrap:anywhere;}
.crm13-summary-card address span{display:block;margin-top:3px;}
.crm13-owner {display:flex;justify-content:space-between;align-items:flex-start;gap:12px;border-top:1px solid #eef1f6;margin-top:13px;padding-top:12px;font-size:11px;}
.crm13-owner span {color:#8a9ab0;flex:0 0 auto;}
.crm13-owner strong {color:#31455f;text-align:right;font-weight:700;overflow-wrap:anywhere;}
.crm13-card-heading{display:flex;align-items:center;justify-content:space-between;gap:9px;}
.crm13-card-heading h2{margin-bottom:7px!important;}
.crm13-due-dot {width:7px;height:7px;background:#20b88d;border-radius:50%;}
.crm13-dealer-side .crm13-due-date {margin:4px 0;font-size:12px;color:#253b55;font-weight:690;}
.crm13-dealer-side .crm13-due-note {margin:6px 0;font-size:12px;}
.crm13-neutral-text{margin:1px 0!important;color:#9ba9ba!important;font-size:12px!important;}
.crm13-action-form{margin-top:12px;}
.crm13-actions-card{border:1px solid #e3eaf4;border-radius:16px;background:#fff;overflow:hidden;}
.crm13-action-details + .crm13-action-details{border-top:1px solid #edf1f6;}
.crm13-action-details summary,.crm13-danger-details summary {list-style:none;cursor:pointer;display:flex;justify-content:space-between;align-items:center;gap:12px;font-weight:710;font-size:12px;color:#2d425f;min-height:50px;padding:13px 18px;}
.crm13-action-details summary::-webkit-details-marker,.crm13-danger-details summary::-webkit-details-marker {display:none;}
.crm13-action-details summary>span{font-size:20px;color:#8da2bf;line-height:1;}
.crm13-action-details[open] summary>span{transform:rotate(45deg);}
.crm13-action-details form{padding:0 18px 17px;}
.crm13-action-details .crm12-dealer-form label {font-size:11px;}
.crm13-action-details .crm12-primary {width:100%;}
.crm13-danger-details {border:1px solid #f1dfe1;border-radius:15px;background:#fff;overflow:hidden;}
.crm13-danger-details summary{color:#b25b63;min-height:43px;}
.crm13-danger-details[open] summary{border-bottom:1px solid #f5e8e8;}
.crm13-danger-form{display:flex;flex-direction:column;align-items:stretch;gap:9px;padding:14px 16px 17px;}
.crm13-danger-form label {display:block!important;margin:0!important;font-size:11px!important;color:#94626a!important;}
.crm13-danger-form input {display:block!important;width:100%!important;min-height:43px!important;margin:0!important;padding:10px 12px!important;background:#fff!important;border:1px solid #edc7cc!important;border-radius:10px!important;}
/* All permanent-delete controls: readable spacing and no text collisions. */
.crm12-danger-btn,
.crm12-danger-inline .crm12-danger-btn {
  display:inline-flex!important;align-items:center!important;justify-content:center!important;
  width:auto;max-width:100%;min-height:43px;box-sizing:border-box;
  margin:6px 0 0!important;padding:11px 17px!important;
  white-space:normal!important;line-height:1.3!important;word-break:normal!important;
  font-size:12px!important;letter-spacing:0!important;text-align:center;
}
.crm13-danger-form .crm12-danger-btn {width:100%;}
.crm12-danger-inline {display:flex!important;flex-direction:column!important;gap:10px!important;}
.crm12-danger-inline input {width:100%!important;min-height:42px;box-sizing:border-box;margin:0!important;}
.crm12-danger-inline label {margin:0!important;line-height:1.5!important;}
.crm12-danger-inline .crm12-danger-btn {width:100%;}
.crm13-dealership .crm12-dealer-card{box-shadow:none;border-radius:14px;}
.crm13-dealership .crm12-dealer-card:hover{transform:none;}
@media(max-width:1050px) {
 .crm13-detail-layout{grid-template-columns:minmax(0,1fr) 285px!important;}
}
@media(max-width:900px) {
 .crm13-detail-layout{grid-template-columns:minmax(0,1fr)!important;}
 .crm13-dealer-chat{height:min(64dvh,650px)!important;min-height:350px!important;}
 .crm13-dealer-side{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));}
 .crm13-summary-card{grid-row:span 2;}
 .crm13-actions-card,.crm13-danger-details{min-width:0;}
}
@media(max-width:680px) {
 .workspace.crm-chat-open {padding-top:calc(54px + env(safe-area-inset-top,0px))!important;}
 .workspace.crm-chat-open>.conversation>.crm-v8-compose-row{
   min-height:60px!important;max-height:78px!important;
   padding:7px 9px calc(7px + env(safe-area-inset-bottom,0px))!important;
   gap:8px!important;
 }
 .workspace.crm-chat-open .conversation-body {padding-bottom:13px!important;}
 .crm13-dealer-detail{padding:14px 12px 28px!important;}
 .crm13-dealer-top {margin-bottom:12px;}
 .crm13-dealer-hero{padding:15px;gap:11px;flex-wrap:wrap;border-radius:17px;}
 .crm13-dealer-monogram{width:44px;height:44px;flex-basis:44px;font-size:20px;border-radius:13px;}
 .crm13-dealer-identity h1{font-size:19px;}
 .crm13-hero-meta{gap:6px;font-size:10px;}
 .crm13-call-link{margin-left:auto;padding:8px 13px;min-height:39px;}
 .crm13-detail-layout{grid-template-columns:minmax(0,1fr)!important;}
 .crm13-dealer-chat{height:min(60dvh,540px)!important;min-height:330px!important;}
 .crm13-dealer-side{display:flex!important;flex-direction:column!important;}
 .crm13-dealer-chat .crm12-dealer-events{padding:12px!important;}
 .crm13-dealer-chat .crm12-history-item{max-width:94%;}
 .crm13-profile-overline{font-size:9px;}
 .crm12-danger-inline .crm12-danger-btn,.crm13-danger-form .crm12-danger-btn {width:100%;}
}
@media(prefers-reduced-motion:reduce){.crm13-action-details summary>span{transition:none}}
