.agency-crm-workspace,
.agency-crm-workspace *,
.agency-crm-drawer,
.agency-crm-drawer * {
  box-sizing: border-box;
}

.agency-crm-workspace {
  margin-bottom: 20px;
  padding: 22px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: 18px;
  background:
    radial-gradient(
      circle at 92% 4%,
      rgba(48, 120, 255, .09),
      transparent 28%
    ),
    var(--card);
  box-shadow: 0 14px 38px rgba(14, 30, 58, .06);
}

.agency-crm-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.agency-crm-eyebrow {
  margin-bottom: 5px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.agency-crm-title {
  margin: 0;
  color: var(--text);
  font-size: 22px;
  line-height: 1.2;
}

.agency-crm-subtitle {
  max-width: 690px;
  margin: 7px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.agency-crm-refresh {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.agency-crm-refresh:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.agency-crm-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.agency-crm-stat {
  min-width: 0;
  padding: 14px 15px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: color-mix(in srgb, var(--bg) 58%, var(--card));
}

.agency-crm-stat span {
  display: block;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-crm-stat strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 23px;
  line-height: 1;
}

.agency-crm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.agency-crm-search {
  flex: 1 1 320px;
  max-width: 470px;
}

.agency-crm-search input {
  width: 100%;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  background: var(--input-bg, var(--card));
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.agency-crm-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(48, 120, 255, .11);
}

.agency-crm-filters {
  display: flex;
  gap: 5px;
  padding: 4px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--bg) 68%, var(--card));
}

.agency-crm-filters button {
  min-height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}

.agency-crm-filters button.is-active {
  background: var(--card);
  color: var(--blue);
  box-shadow: 0 2px 9px rgba(14, 30, 58, .08);
}

.agency-crm-client-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.agency-crm-client-card {
  display: grid;
  grid-template-columns: minmax(190px, 1.45fr) minmax(130px, .8fr) minmax(125px, .7fr) auto;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--card);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition:
    border-color .16s ease,
    transform .16s ease,
    box-shadow .16s ease;
}

.agency-crm-client-card:hover {
  border-color: color-mix(in srgb, var(--blue) 56%, var(--border));
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(14, 30, 58, .08);
}

.agency-crm-client-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-crm-client-contact,
.agency-crm-client-follow-up {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agency-crm-client-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.agency-crm-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(48, 120, 255, .1);
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.agency-crm-badge.is-dormant,
.agency-crm-badge.is-archived {
  background: rgba(113, 128, 150, .12);
  color: var(--text-muted);
}

.agency-crm-badge.is-high,
.agency-crm-badge.is-key_account,
.agency-crm-badge.is-overdue {
  background: rgba(245, 158, 11, .13);
  color: #c77800;
}

.agency-crm-arrow {
  color: var(--text-muted);
  font-size: 18px;
}

.agency-crm-loading,
.agency-crm-empty,
.agency-crm-error {
  padding: 26px 18px;
  border: 1px dashed var(--border);
  border-radius: 13px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

.agency-crm-error {
  border-color: rgba(239, 68, 68, .3);
  background: rgba(239, 68, 68, .05);
  color: #d33d3d;
}

.agency-crm-drawer {
  width: min(96vw, 920px);
  max-width: 920px;
}

.agency-crm-drawer-head {
  position: relative;
}

.agency-crm-drawer-body {
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 72%, var(--card));
}

.agency-crm-drawer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, .58fr);
  gap: 16px;
}

.agency-crm-panel {
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}

.agency-crm-panel + .agency-crm-panel {
  margin-top: 13px;
}

.agency-crm-panel-title {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
}

.agency-crm-panel-sub {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.45;
}

.agency-crm-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 15px;
}

.agency-crm-field {
  display: grid;
  gap: 6px;
}

.agency-crm-field.is-wide {
  grid-column: 1 / -1;
}

.agency-crm-field span {
  color: var(--text);
  font-size: 11px;
  font-weight: 750;
}

.agency-crm-field input,
.agency-crm-field select,
.agency-crm-field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--input-bg, var(--card));
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.agency-crm-field textarea {
  min-height: 92px;
  resize: vertical;
}

.agency-crm-field input:focus,
.agency-crm-field select:focus,
.agency-crm-field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(48, 120, 255, .1);
}

.agency-crm-primary-btn,
.agency-crm-secondary-btn {
  min-height: 39px;
  padding: 0 14px;
  border-radius: 10px;
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.agency-crm-primary-btn {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}

.agency-crm-secondary-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

.agency-crm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.agency-crm-record-list {
  display: grid;
  gap: 8px;
  margin-top: 13px;
}

.agency-crm-record {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
}

.agency-crm-record strong {
  display: block;
  color: var(--text);
  font-size: 11px;
}

.agency-crm-record span {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.45;
}

.agency-crm-timeline-item {
  position: relative;
  padding: 0 0 14px 17px;
  border-left: 2px solid var(--border);
}

.agency-crm-timeline-item::before {
  position: absolute;
  top: 2px;
  left: -6px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--card);
  border-radius: 50%;
  background: var(--blue);
  content: "";
}

.agency-crm-timeline-item:last-child {
  padding-bottom: 0;
}

.agency-crm-timeline-item strong {
  display: block;
  color: var(--text);
  font-size: 11px;
}

.agency-crm-timeline-item p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.agency-crm-timeline-item time {
  display: block;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 9px;
}

@media (max-width: 820px) {
  .agency-crm-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agency-crm-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .agency-crm-search {
    max-width: none;
  }

  .agency-crm-client-card {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .agency-crm-client-contact,
  .agency-crm-client-follow-up {
    grid-column: 1 / -1;
  }

  .agency-crm-client-meta {
    grid-column: 2;
    grid-row: 1;
  }

  .agency-crm-drawer-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .agency-crm-workspace {
    padding: 17px 14px;
    border-radius: 15px;
  }

  .agency-crm-head {
    flex-direction: column;
  }

  .agency-crm-refresh {
    width: 100%;
  }

  .agency-crm-form-grid {
    grid-template-columns: 1fr;
  }

  .agency-crm-field.is-wide {
    grid-column: auto;
  }

  .agency-crm-client-card {
    gap: 8px;
    padding: 13px;
  }
}


.agency-crm-add-record {
  margin-top: 11px;
  border-top: 1px solid var(--border);
}

.agency-crm-add-record summary {
  padding: 11px 0 0;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  list-style-position: inside;
}

.agency-crm-mini-form {
  display: grid;
  gap: 8px;
  margin-top: 11px;
}

.agency-crm-mini-form input,
.agency-crm-mini-form select,
.agency-crm-mini-form textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: var(--input-bg, var(--card));
  color: var(--text);
  font: inherit;
  font-size: 11px;
}

.agency-crm-mini-form textarea {
  min-height: 74px;
  resize: vertical;
}

.agency-crm-mini-form input:focus,
.agency-crm-mini-form select:focus,
.agency-crm-mini-form textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(48, 120, 255, .09);
}

.agency-crm-check,
.agency-crm-mini-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
}

.agency-crm-check input {
  width: 15px;
  min-height: 15px;
  margin: 0;
}

.agency-crm-mini-label {
  align-items: stretch;
  flex-direction: column;
}

.agency-crm-record-action {
  margin-top: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--blue);
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  cursor: pointer;
}

.agency-crm-record-action:hover {
  border-color: var(--blue);
}

/* CRM drawer consistency polish v1 */

.agency-crm-overlay {
  align-items: stretch;
}

.agency-crm-drawer {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: min(96vw, 920px);
  max-width: 920px;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  margin: 0;
  overflow: hidden;
  border-radius: 0;
  background: var(--bg);
  box-shadow:
    -18px 0 50px
    rgba(15, 23, 42, .20);
}

.agency-crm-drawer > .drawer-handle {
  display: none;
}

.agency-crm-drawer-head {
  position: relative;
  inset: auto;
  z-index: 2;
  box-sizing: border-box;
  flex: 0 0 auto;
  width: auto;
  min-height: 0;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.agency-crm-drawer-head > div {
  min-width: 0;
}

.agency-crm-drawer-body {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 30px;
}

@media (max-width: 760px) {
  .agency-crm-drawer {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .agency-crm-drawer-head {
    padding: 16px 18px !important;
  }

  .agency-crm-drawer-head .drawer-title {
    font-size: 19px;
    line-height: 1.2;
  }

  .agency-crm-drawer-head .drawer-sub {
    font-size: 12px;
    line-height: 1.4;
  }

  .agency-crm-drawer-body {
    padding: 14px 12px 24px !important;
  }

  .agency-crm-drawer-grid {
    gap: 12px;
    grid-template-columns: 1fr;
  }

  .agency-crm-panel {
    padding: 15px;
  }

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

  .agency-crm-actions button,
  .agency-crm-mini-form button {
    width: 100%;
  }
}

/* CRM action confirmation popup v1 */

.agency-crm-notice {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1300;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 11px;
  width: min(
    calc(100vw - 40px),
    390px
  );
  padding: 13px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  box-shadow:
    0 18px 46px
    rgba(15, 23, 42, .20);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-14px);
  transition:
    opacity .18s ease,
    transform .18s ease;
}

.agency-crm-notice.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.agency-crm-notice-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: rgba(16, 185, 129, .13);
  color: #059669;
  font-size: 17px;
  font-weight: 900;
}

.agency-crm-notice-copy {
  min-width: 0;
}

.agency-crm-notice-copy strong,
.agency-crm-notice-copy span {
  display: block;
}

.agency-crm-notice-copy strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
}

.agency-crm-notice-copy span {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

.agency-crm-notice-close {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 19px;
  cursor: pointer;
}

.agency-crm-notice-close:hover {
  background:
    color-mix(
      in srgb,
      var(--border) 45%,
      transparent
    );
  color: var(--text);
}

.agency-crm-notice.is-warning {
  border-color:
    rgba(245, 158, 11, .38);
}

.agency-crm-notice.is-warning
.agency-crm-notice-icon {
  background:
    rgba(245, 158, 11, .14);
  color: #c77800;
}

.agency-crm-notice.is-error {
  border-color:
    rgba(239, 68, 68, .38);
}

.agency-crm-notice.is-error
.agency-crm-notice-icon {
  background:
    rgba(239, 68, 68, .13);
  color: #dc2626;
}

@media (max-width: 560px) {
  .agency-crm-notice {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
  }
}
