/* TC-017F — начисления и статусы оплат.
   Сумма начисления не интерпретируется как банковское поступление. */

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

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

.payments-registry {
  min-width: 0;
  height: calc(100vh - var(--shell-topbar-height, 64px) - 112px);
  min-height: 570px;
  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);
}

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

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

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

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

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

.payments-import-note {
  flex: 0 0 auto;
}

.payments-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

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

.payment-kpi.attention {
  border-color: var(--color-warning-border);
  background: var(--color-warning-bg);
}

.payment-kpi-value {
  overflow: hidden;
  color: var(--color-text);
  font-size: 15px;
  line-height: 22px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.payment-kpi-label {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

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

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

.payments-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);
}

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

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

.payments-filter-bar {
  display: grid;
  grid-template-columns: minmax(250px, 1.65fr) repeat(4, minmax(125px, 0.68fr)) auto;
  gap: 8px;
  align-items: end;
  padding-bottom: 12px;
}

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

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

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

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

.payments-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;
}

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

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

.payments-filter-reset {
  width: 40px;
  min-width: 40px;
  padding: 0;
}

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

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

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

.payment-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;
}

.payment-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;
}

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

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

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

.payments-table {
  min-width: 1050px !important;
  table-layout: fixed;
}

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

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

.payments-table th:nth-child(1),
.payments-table td:nth-child(1) { width: 11%; }
.payments-table th:nth-child(2),
.payments-table td:nth-child(2) { width: 25%; }
.payments-table th:nth-child(3),
.payments-table td:nth-child(3) { width: 10%; }
.payments-table th:nth-child(4),
.payments-table td:nth-child(4) { width: 14%; }
.payments-table th:nth-child(5),
.payments-table td:nth-child(5) { width: 11%; }
.payments-table th:nth-child(6),
.payments-table td:nth-child(6) { width: 17%; }
.payments-table th:nth-child(7),
.payments-table td:nth-child(7) { width: 8%; }
.payments-table th:nth-child(8),
.payments-table td:nth-child(8) {
  width: 4%;
  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);
}

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

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

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

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

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

.payment-period {
  color: var(--color-text);
  font-size: 13px;
  line-height: 18px;
  font-weight: 650;
  white-space: nowrap;
}

.payment-period-meta,
.payment-contract-meta,
.payment-source-meta {
  margin-top: 3px;
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payment-client-name,
.payment-contract-number {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.payment-contract-number {
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 17px;
}

.payment-money {
  color: var(--color-text);
  font-size: 13px;
  line-height: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

.payment-money.secondary {
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 500;
}

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

.payment-status-badge.paid {
  border-color: var(--color-success-border);
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.payment-status-badge.attention {
  border-color: var(--color-danger-border);
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
}

.payment-status-badge.pending {
  border-color: var(--color-warning-border);
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.payment-status-badge.zero {
  border-color: var(--color-neutral-border);
  background: var(--color-neutral-bg);
  color: var(--color-neutral-text);
}

.payment-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;
}

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

.payments-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);
}

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

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

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

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

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

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

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

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

/* Detail panel */
.payments-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);
  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);
}

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

.payments-detail-header {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -16px;
  padding: 16px;
  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);
}

.payments-detail-id {
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 16px;
}

.payments-detail-header h3 {
  margin: 2px 0 3px;
  color: var(--color-text);
  font-size: 17px;
  line-height: 23px;
  font-weight: 650;
}

.payments-detail-subtitle {
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 18px;
}

.payments-detail-badges {
  margin-top: 9px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.payments-detail-tabs {
  position: sticky;
  top: 96px;
  z-index: 3;
  margin: 0 -16px 14px;
  padding: 10px 16px 0;
  display: flex;
  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;
}

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

.payments-detail-tab {
  position: relative;
  min-height: 36px;
  padding: 8px 10px 10px;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.payments-detail-tab::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--color-primary);
  transform: scaleX(0);
  transition: transform var(--motion-medium) var(--motion-ease);
}

.payments-detail-tab.active {
  color: var(--color-primary);
}

.payments-detail-tab.active::after {
  transform: scaleX(1);
}

.payment-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

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

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

.payment-summary-value {
  margin-top: 4px;
  overflow: hidden;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.payment-data-quality {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #b2ddff;
  border-radius: var(--radius-md);
  background: #eff8ff;
  color: #1849a9;
  font-size: 12px;
  line-height: 18px;
}

.payment-data-quality b {
  color: #1849a9;
}

.payment-detail-section {
  margin-top: 14px;
}

.payment-detail-section h4 {
  margin: 0 0 8px;
  color: var(--color-text);
  font-size: 14px;
  line-height: 20px;
  font-weight: 650;
}

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

.payment-detail-kv > div {
  min-width: 0;
  padding: 9px 10px;
  border-bottom: 1px solid var(--color-border);
  overflow-wrap: break-word;
}

.payment-detail-kv > div:nth-last-child(-n+2) {
  border-bottom: 0;
}

.payment-detail-kv > div:nth-child(odd) {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
}

.payment-detail-kv > div:nth-child(even) {
  color: var(--color-text-secondary);
  font-size: 12px;
}

.payment-history-table {
  min-width: 620px !important;
}

.payment-history-table th,
.payment-history-table td {
  padding: 9px 10px;
}

.payment-history-table td:nth-child(2),
.payment-history-table td:nth-child(3),
.payment-history-table td:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.payment-history-table tr.current td {
  background: #eff6ff;
}

.payment-raw-table {
  min-width: 560px !important;
}

.payment-raw-key {
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
}

.payment-raw-value {
  max-width: 340px;
  overflow-wrap: anywhere;
}

.payments-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);
}

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

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

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

  .payments-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);
  }

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

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

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

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

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

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

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

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

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

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

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

  .payments-registry-subtitle,
  .payments-import-note {
    display: none;
  }

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

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

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

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

  .payments-range {
    max-width: 150px;
  }

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

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

  .payments-detail-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .payments-detail-actions,
  .payments-detail-footer .btn {
    width: 100%;
  }
}

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