/* TC-017D — clients workspace.
   Scope: compact clients registry, verification state and client detail panel. */

.clients-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(440px, 480px);
  gap: 16px;
  align-items: start;
}

.clients-workspace.clients-panel-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.clients-registry {
  min-width: 0;
  height: calc(100vh - var(--shell-topbar-height, 64px) - 112px);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.clients-registry-head {
  flex: 0 0 auto;
  padding: 16px 16px 0;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.clients-registry-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.clients-registry-title-copy {
  min-width: 0;
}

.clients-registry-title h3 {
  margin: 0;
  color: var(--color-text);
  font-size: 18px;
  line-height: 26px;
  font-weight: 650;
}

.clients-result-count {
  margin-left: 6px;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 500;
}

.clients-registry-subtitle {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 18px;
}

.clients-primary-action {
  flex: 0 0 auto;
}

.clients-view-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.clients-view-strip::-webkit-scrollbar {
  display: none;
}

.clients-view-btn {
  min-height: 34px;
  padding: 0 11px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 12px;
  line-height: 18px;
  font-weight: 600;
  cursor: pointer;
  transition:
    color var(--motion-fast) var(--motion-ease),
    background-color var(--motion-fast) var(--motion-ease),
    border-color var(--motion-fast) var(--motion-ease);
}

.clients-view-btn:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

.clients-view-btn.active,
.clients-view-btn[aria-pressed="true"] {
  border-color: #b2ddff;
  background: #eff8ff;
  color: #175cd3;
}

.clients-filter-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1.55fr) repeat(4, minmax(118px, 0.7fr)) auto;
  gap: 8px;
  align-items: end;
  padding-bottom: 12px;
}

.clients-search-field {
  position: relative;
}

.clients-search-field input {
  padding-left: 38px;
  padding-right: 38px;
}

.clients-search-icon {
  position: absolute;
  left: 12px;
  bottom: 11px;
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.clients-search-icon svg,
.clients-filter-reset svg,
.client-row-open svg,
.clients-pagination svg,
.clients-empty-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.clients-search-clear {
  position: absolute;
  right: 5px;
  bottom: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: none;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.clients-search-clear[data-visible="true"] {
  display: grid;
}

.clients-search-clear:hover {
  background: var(--color-neutral-bg);
  color: var(--color-text);
}

.clients-filter-reset {
  width: 40px;
  min-width: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.clients-filter-reset[hidden] {
  display: none;
}

.clients-active-filters {
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 0 12px;
}

.clients-active-filters:empty {
  display: none;
}

.client-filter-chip {
  min-height: 28px;
  padding: 4px 6px 4px 9px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #b2ddff;
  border-radius: var(--radius-pill);
  background: #eff8ff;
  color: #175cd3;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
}

.client-filter-chip button {
  width: 20px;
  height: 20px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.client-filter-chip button:hover {
  background: rgba(23, 92, 211, 0.1);
}

.clients-registry-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--color-surface);
}

.clients-tablewrap {
  min-width: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.clients-table {
  min-width: 940px !important;
  table-layout: fixed;
}

.clients-table th {
  top: 0;
  z-index: 3;
  height: 42px;
  padding: 10px 12px;
  white-space: nowrap;
  background: #f8fafc;
}

.clients-table td {
  height: 62px;
  padding: 9px 12px;
  vertical-align: middle;
}

.clients-table th:nth-child(1),
.clients-table td:nth-child(1) {
  width: 29%;
}

.clients-table th:nth-child(2),
.clients-table td:nth-child(2) {
  width: 16%;
}

.clients-table th:nth-child(3),
.clients-table td:nth-child(3) {
  width: 15%;
}

.clients-table th:nth-child(4),
.clients-table td:nth-child(4) {
  width: 17%;
}

.clients-table th:nth-child(5),
.clients-table td:nth-child(5) {
  width: 16%;
}

.clients-table th:nth-child(6),
.clients-table td:nth-child(6) {
  width: 7%;
  position: sticky;
  right: 0;
  z-index: 2;
  text-align: right;
  background: var(--color-surface);
  box-shadow: -8px 0 12px -12px rgba(15, 23, 42, 0.35);
}

.clients-table th:nth-child(6) {
  z-index: 4;
  background: #f8fafc;
}

.clients-table tbody tr {
  cursor: pointer;
}

.clients-table tbody tr:hover td,
.clients-table tbody tr:hover td:nth-child(6) {
  background: #f8fbff;
}

.clients-table tbody tr.selected-row td,
.clients-table tbody tr.selected-row td:nth-child(6) {
  background: #eff6ff !important;
}

.clients-table tbody tr:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: -3px;
}

.client-main-name,
.client-main-meta,
.client-contact-preview,
.client-services-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-main-name {
  color: var(--color-text);
  font-size: 13px;
  line-height: 18px;
  font-weight: 650;
}

.client-main-meta,
.client-services-preview {
  margin-top: 3px;
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 16px;
}

.client-contract-count {
  color: var(--color-text);
  font-size: 13px;
  line-height: 18px;
  font-weight: 650;
}

.client-contact-preview {
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 18px;
}

.client-status-badge,
.client-verification-badge {
  max-width: 100%;
  min-height: 24px;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: 11px;
  line-height: 16px;
  font-weight: 650;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.client-status-dot,
.client-verification-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: currentColor;
}

.client-status-badge.active {
  border-color: #abefc6;
  background: #ecfdf3;
  color: #067647;
}

.client-status-badge.attention {
  border-color: #fedf89;
  background: #fffaeb;
  color: #b54708;
}

.client-status-badge.critical {
  border-color: #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.client-verification-badge.unverified {
  border-color: #d0d5dd;
  background: #f9fafb;
  color: #475467;
}

.client-verification-badge.verified {
  border-color: #abefc6;
  background: #ecfdf3;
  color: #067647;
}

.client-verification-badge.discrepancy {
  border-color: #fecdca;
  background: #fef3f2;
  color: #b42318;
}

.client-row-open {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.client-row-open:hover {
  border-color: #b2ddff;
  background: #eff8ff;
}

.clients-registry-footer {
  min-height: 54px;
  flex: 0 0 auto;
  padding: 8px 12px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.clients-range {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 18px;
}

.clients-pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}

.clients-page-label {
  min-width: 76px;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.clients-pagination .btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
}

.clients-empty-state {
  min-height: 340px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 32px;
  text-align: center;
  color: var(--color-text-muted);
}

.clients-empty-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--color-neutral-bg);
  color: var(--color-text-muted);
}

.clients-empty-icon svg {
  width: 24px;
  height: 24px;
}

.clients-empty-state b {
  color: var(--color-text);
  font-size: 15px;
  line-height: 22px;
}

.clients-empty-state p {
  max-width: 360px;
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 19px;
}

/* Client detail panel */
.clients-detail-panel {
  position: sticky;
  top: calc(var(--shell-topbar-height, 64px) + 12px);
  min-width: 0;
  height: calc(100vh - var(--shell-topbar-height, 64px) - 24px);
  max-height: calc(100vh - var(--shell-topbar-height, 64px) - 24px);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
}

.clients-detail-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 20px;
}

.clients-detail-header {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -16px;
  padding: 16px 16px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
}

.clients-detail-heading {
  min-width: 0;
}

.clients-detail-id {
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 15px;
}

.clients-detail-header h3 {
  max-width: 350px;
  margin: 2px 0 7px;
  overflow-wrap: break-word;
  color: var(--color-text);
  font-size: 17px;
  line-height: 23px;
  font-weight: 650;
}

.clients-detail-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.clients-detail-tabs {
  position: sticky;
  top: 92px;
  z-index: 3;
  margin: 0 -16px 14px;
  padding: 10px 16px 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  scrollbar-width: none;
}

.clients-detail-tabs::-webkit-scrollbar {
  display: none;
}

.clients-detail-tab {
  min-height: 36px;
  padding: 0 9px;
  flex: 0 0 auto;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 12px;
  line-height: 18px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.clients-detail-tab:hover {
  color: var(--color-primary-hover);
}

.clients-detail-tab.active,
.clients-detail-tab[aria-selected="true"] {
  border-bottom-color: var(--color-primary);
  color: var(--color-primary-hover);
}

.client-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.client-summary-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
}

.client-summary-label {
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.035em;
}

.client-summary-value {
  margin-top: 4px;
  overflow-wrap: break-word;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
}

.client-attention-block {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #fedf89;
  border-radius: var(--radius-md);
  background: #fffaeb;
  color: #93370d;
}

.client-attention-block.critical {
  border-color: #fecdca;
  background: #fef3f2;
  color: #912018;
}

.client-attention-block h4 {
  margin: 0 0 6px;
  color: inherit;
  font-size: 13px;
  line-height: 19px;
}

.client-attention-block ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 18px;
}

.client-contact-card,
.client-verification-card,
.client-comments-card,
.client-edit-card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.client-pane-title {
  margin: 0 0 10px;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
}

.client-contact-text {
  overflow-wrap: break-word;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 20px;
  white-space: pre-wrap;
}

.client-contracts-table {
  min-width: 700px !important;
  table-layout: fixed;
}

.client-contracts-table th,
.client-contracts-table td {
  padding: 9px 10px;
}

.client-contracts-table th:nth-child(1),
.client-contracts-table td:nth-child(1) {
  width: 25%;
}

.client-contracts-table th:nth-child(2),
.client-contracts-table td:nth-child(2) {
  width: 14%;
}

.client-contracts-table th:nth-child(3),
.client-contracts-table td:nth-child(3) {
  width: 19%;
}

.client-contracts-table th:nth-child(4),
.client-contracts-table td:nth-child(4) {
  width: 18%;
}

.client-contracts-table th:nth-child(5),
.client-contracts-table td:nth-child(5) {
  width: 17%;
}

.client-contracts-table th:nth-child(6),
.client-contracts-table td:nth-child(6) {
  width: 7%;
  text-align: right;
}

.client-contracts-table tbody tr {
  cursor: pointer;
}

.client-contracts-table tbody tr:hover td {
  background: #f8fbff;
}

.client-verification-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.client-verification-copy {
  min-width: 0;
}

.client-verification-copy h4 {
  margin: 0 0 4px;
  font-size: 14px;
  line-height: 20px;
}

.client-verification-copy p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 18px;
}

.client-registry-grid {
  display: grid;
  grid-template-columns: 145px minmax(0, 1fr);
  gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.client-registry-grid > div {
  min-width: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  overflow-wrap: break-word;
  font-size: 12px;
  line-height: 18px;
}

.client-registry-grid > div:nth-child(odd) {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  font-weight: 600;
}

.client-registry-grid > div:nth-child(even) {
  color: var(--color-text-secondary);
}

.client-registry-grid > div:nth-last-child(-n+2) {
  border-bottom: 0;
}

.client-verification-warning {
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid #fecdca;
  border-radius: var(--radius-md);
  background: #fef3f2;
  color: #912018;
  font-size: 12px;
  line-height: 18px;
}

.client-verification-meta {
  margin-top: 10px;
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 17px;
}

.client-comments-list {
  display: grid;
  gap: 8px;
}

.client-comment-message {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
}

.client-comment-meta {
  margin-bottom: 4px;
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 15px;
}

.client-comment-text {
  overflow-wrap: break-word;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 19px;
  white-space: pre-wrap;
}

.client-comment-composer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.client-edit-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 10px;
}

.client-edit-grid .wide {
  grid-column: 1 / -1;
}

.client-edit-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.clients-detail-footer {
  min-height: 60px;
  flex: 0 0 auto;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.04);
}

.clients-detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

body.clients-detail-lock {
  overflow: hidden;
}

@media (max-width: 1440px) {
  .clients-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .clients-detail-panel {
    position: fixed;
    right: 0;
    top: 0;
    z-index: 50;
    width: min(540px, calc(100vw - 48px));
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: var(--radius-xl) 0 0 var(--radius-xl);
    transform: translateX(105%);
    transition: transform var(--motion-slow) var(--motion-ease);
    box-shadow: -18px 0 48px rgba(7, 26, 51, 0.22);
  }

  .clients-detail-panel.drawer-open {
    transform: translateX(0);
  }

  .clients-registry {
    height: calc(100vh - var(--shell-topbar-height, 64px) - 112px);
  }
}

@media (max-width: 1180px) {
  .clients-filter-bar {
    grid-template-columns: minmax(240px, 1fr) repeat(2, minmax(130px, 0.55fr)) auto;
  }

  .clients-filter-bar .field:nth-of-type(4),
  .clients-filter-bar .field:nth-of-type(5) {
    display: none;
  }
}

@media (max-width: 900px) {
  .clients-registry {
    height: calc(100vh - 160px);
    min-height: 520px;
  }

  .clients-registry-head {
    padding-inline: 12px;
  }

  .clients-filter-bar {
    grid-template-columns: minmax(0, 1fr) minmax(124px, 0.45fr) auto;
  }

  .clients-filter-bar .field:nth-of-type(n+3) {
    display: none;
  }

  .clients-detail-panel {
    width: min(580px, 100vw);
    border-radius: 0;
  }
}

@media (max-width: 680px) {
  .clients-registry {
    height: calc(100vh - 150px);
    min-height: 480px;
  }

  .clients-registry-title {
    align-items: center;
  }

  .clients-registry-title h3 {
    font-size: 16px;
    line-height: 22px;
  }

  .clients-registry-subtitle {
    display: none;
  }

  .clients-primary-action {
    width: 40px;
    min-width: 40px;
    padding: 0;
    overflow: hidden;
    position: relative;
    color: transparent;
  }

  .clients-primary-action::after {
    content: "+";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
  }

  .clients-filter-bar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .clients-filter-bar .field:not(.clients-search-field) {
    display: none;
  }

  .clients-registry-footer {
    padding-left: 12px;
  }

  .clients-range {
    max-width: 145px;
  }

  .clients-page-label {
    min-width: 54px;
  }

  .client-summary-grid {
    grid-template-columns: 1fr;
  }

  .client-verification-head,
  .clients-detail-footer,
  .client-edit-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .clients-detail-actions,
  .clients-detail-footer .btn,
  .client-verification-head .btn {
    width: 100%;
  }

  .client-edit-grid {
    grid-template-columns: 1fr;
  }

  .client-edit-grid .wide {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .clients-detail-panel,
  .clients-view-btn,
  .client-row-open {
    transition: none !important;
  }
}
