/* Issue #61 — UI-POLISH-01.
   Presentation-only overrides for right-side CRM panels. */

/* Client primary navigation: four destinations must fit without horizontal scrolling. */
.clients-detail-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  display: grid;
  align-items: stretch;
  gap: 2px;
  overflow-x: visible;
  scrollbar-width: auto;
}

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

.clients-detail-tab {
  width: 100%;
  min-width: 0;
  padding-inline: 6px;
  white-space: normal;
  text-align: center;
  overflow-wrap: anywhere;
}

/* The canonical comments/edit panes remain available from footer actions only. */
.clients-detail-tab[data-ui-polish-secondary="true"] {
  display: none;
}

/* Client contracts keep their canonical rows/click handlers, but the drawer
   presents them as a compact vertical card list instead of a wide desktop table. */
.clients-detail-scroll .tablewrap:has(> .client-contracts-table) {
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.client-contracts-table {
  min-width: 0 !important;
  width: 100%;
  table-layout: auto;
  border-collapse: separate;
  background: transparent;
}

/* Keep column headers in the accessibility tree while removing their visual row.
   `display:none` would make the table-card labels unavailable to assistive tech. */
.client-contracts-table thead {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.client-contracts-table tbody {
  display: grid;
  gap: 10px;
}

.client-contracts-table tbody tr {
  width: 100%;
  min-width: 0;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(112px, auto);
  grid-template-areas:
    "number status"
    "service payment"
    "account action";
  gap: 8px 12px;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs, 0 1px 2px rgba(15, 23, 42, 0.04));
}

.client-contracts-table tbody tr:hover {
  border-color: #b2ddff;
  background: #f8fbff;
}

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

.client-contracts-table td {
  width: auto !important;
  max-width: none;
  min-width: 0;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent !important;
  overflow-wrap: anywhere;
  word-break: normal;
}

.client-contracts-table td:nth-child(1) {
  grid-area: number;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
}

.client-contracts-table td:nth-child(1)::before {
  content: "№ ";
  font-weight: 650;
}

.client-contracts-table td:nth-child(1) b {
  overflow-wrap: anywhere;
}

.client-contracts-table td:nth-child(2) {
  grid-area: service;
}

.client-contracts-table td:nth-child(2) .pill {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.client-contracts-table td:nth-child(3) {
  grid-area: account;
  display: flex;
  align-items: baseline;
  gap: 4px;
  flex-wrap: wrap;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 18px;
}

.client-contracts-table td:nth-child(3)::before {
  content: "ЛС";
  color: var(--color-text-muted);
}

.client-contracts-table td:nth-child(3) .small {
  margin: 0;
  display: inline;
}

.client-contracts-table td:nth-child(3) .small::before {
  content: " · R12 ";
  color: var(--color-text-muted);
}

.client-contracts-table td:nth-child(4) {
  grid-area: status;
  justify-self: end;
  text-align: right;
}

.client-contracts-table td:nth-child(5) {
  grid-area: payment;
  justify-self: end;
  text-align: right;
}

.client-contracts-table td:nth-child(4) .pill,
.client-contracts-table td:nth-child(5) .pill {
  max-width: 100%;
  white-space: normal;
  text-align: left;
}

.client-contracts-table td:nth-child(6) {
  grid-area: action;
  justify-self: end;
  text-align: right;
}

.client-contracts-table td:nth-child(6) .client-row-open {
  width: auto;
  max-width: 100%;
  min-width: 0;
  padding: 6px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--color-primary);
}

.client-contracts-table td:nth-child(6) .client-row-open::before {
  content: "Открыть";
  font-size: 12px;
  line-height: 18px;
  font-weight: 650;
}

.client-contracts-table td:nth-child(6) .client-row-open svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
}

/* Long client/contract/service values must wrap inside the panel instead of
   increasing its intrinsic width. */
.clients-detail-panel,
.clients-detail-scroll,
.clients-detail-heading,
.clients-detail-header h3,
.client-summary-card,
.client-summary-value,
.client-contact-card,
.client-verification-card,
.client-comments-card,
.client-edit-card {
  min-width: 0;
}

.clients-detail-header h3,
.client-summary-value,
.client-contact-text,
.client-comment-text,
.client-verification-copy,
.client-registry-grid > div {
  overflow-wrap: anywhere;
}

/* Focused action containment audit: scoped to the existing right panels only.
   Do not truncate action meaning; allow actions and their text to wrap. */
.clients-detail-footer,
.contracts-detail-footer,
.issues-detail-footer,
.payments-detail-footer {
  min-width: 0;
  flex-wrap: wrap;
}

.clients-detail-actions,
.contracts-detail-actions,
.issues-detail-actions,
.payments-detail-actions,
.client-edit-actions,
.issue-edit-actions {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 220px;
  flex-wrap: wrap;
}

.clients-detail-panel .btn,
.contracts-detail-panel .btn,
.issues-detail-panel .btn,
.payments-detail-panel .btn {
  min-width: 0;
  max-width: 100%;
}

.clients-detail-panel .btn:not(.icon-btn),
.contracts-detail-panel .btn:not(.icon-btn),
.issues-detail-panel .btn:not(.icon-btn),
.payments-detail-panel .btn:not(.icon-btn) {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.25;
  text-align: center;
}

/* Existing workspace CSS stacks detail footers at <=680px. In that column
   direction the desktop flex-basis would become a vertical 220px basis, so
   release it for the entire stacked-footer range. */
@media (max-width: 680px) {
  .clients-detail-actions,
  .contracts-detail-actions,
  .issues-detail-actions,
  .payments-detail-actions,
  .client-edit-actions,
  .issue-edit-actions {
    flex: 1 1 auto;
  }
}

@media (max-width: 540px) {
  .clients-detail-tabs {
    padding-inline: 10px;
  }

  .clients-detail-tab {
    padding-inline: 4px;
    font-size: 11px;
  }

  .client-contracts-table tbody tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "number status"
      "service service"
      "account account"
      "payment action";
  }
}

@media (max-width: 420px) {
  .client-contracts-table tbody tr {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "number"
      "status"
      "service"
      "account"
      "payment"
      "action";
  }

  .client-contracts-table td:nth-child(4),
  .client-contracts-table td:nth-child(5),
  .client-contracts-table td:nth-child(6) {
    justify-self: start;
    text-align: left;
  }
}
