/* TC-017C — contracts registry workspace.
   Scope: registry toolbar, saved views, table hierarchy, pagination and detail panel. */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.contracts-search-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

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

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

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

.contracts-filter-reset svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.contracts-table th:nth-child(6),
.contracts-table td:nth-child(6) {
  width: 13%;
}

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

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

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

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

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

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

.contract-main-cell {
  min-width: 0;
}

.contract-main-name,
.contract-main-meta,
.contract-secondary-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

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

.contract-secondary-value + .contract-secondary-value {
  margin-top: 2px;
}

.contracts-table .pill,
.contracts-table .source-badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.contract-row-open svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

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

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

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

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

.contracts-pagination svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

.contracts-empty-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

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

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

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

.contracts-detail-panel .detail-header {
  position: sticky;
  top: 0;
  z-index: 4;
  margin: 0 -16px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
}

.contracts-detail-panel .detail-header h3 {
  max-width: 320px;
  font-size: 17px;
  line-height: 23px;
}

.contracts-detail-panel .tabs {
  position: sticky;
  top: 76px;
  z-index: 3;
  margin: 0 -16px 14px;
  padding: 10px 16px 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  scrollbar-width: none;
}

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

.contracts-detail-panel .tab {
  flex: 0 0 auto;
  white-space: nowrap;
}

.contracts-detail-panel .kv {
  grid-template-columns: 132px minmax(0, 1fr);
}

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

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

.contracts-detail-close {
  flex: 0 0 auto;
}

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

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

  .contracts-detail-panel {
    position: fixed;
    right: 0;
    top: 0;
    z-index: 50;
    width: min(520px, 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);
  }

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

  .contracts-detail-panel .drawer-close {
    display: inline-grid;
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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