/* Append after the existing stylesheet; scope to the issued-Key project groups. */
.api-key-project-groups,
.api-key-project-card {
  min-width: 0;
  max-width: 100%;
}

.api-key-project-card {
  container: issued-key-project / inline-size;
  border-color: #dfe6ef;
  border-radius: 10px;
}

.api-key-project-card > .api-key-project-header {
  flex-wrap: wrap;
  gap: 12px;
  padding: 11px 16px;
  background: #f8fafc;
  border-bottom-color: #e5ebf2;
  border-radius: 9px 9px 0 0;
}

.api-key-project-card .api-key-project-header > div {
  flex: 1 1 220px;
  min-width: 0;
  gap: 3px;
}

.api-key-project-card .api-key-project-header strong {
  font-size: 14px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.api-key-project-card .api-key-project-header small {
  color: #64748b;
  font-weight: 400;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.api-key-project-card .api-key-project-header > span {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  color: #64748b;
  font-weight: 500;
  white-space: nowrap;
}

.api-key-project-card > .table-wrap {
  min-width: 0;
  overflow: visible;
}

.api-key-project-card > .table-wrap > table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.api-key-project-card > .table-wrap > table :is(th, td) {
  padding: 14px 16px;
  vertical-align: top;
  border-bottom-color: #edf1f5;
  line-height: 1.5;
}

.api-key-project-card > .table-wrap > table th {
  padding-block: 10px;
  background: #ffffff;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  white-space: normal;
}

.api-key-project-card > .table-wrap > table tbody tr {
  height: auto;
}

.api-key-project-card > .table-wrap > table tbody tr:hover td {
  background: #fbfcfe;
}

.api-key-project-card > .table-wrap > table tbody tr:last-child td {
  border-bottom: 0;
}

.api-key-project-card .table-cell-content {
  min-width: 0;
  max-width: 100%;
  max-height: none;
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.api-key-project-card td:nth-child(1) .table-cell-content > span,
.api-key-project-card td:nth-child(2) .table-cell-content > span {
  display: block;
  min-width: 0;
  max-width: 100%;
}

.api-key-project-card td:nth-child(1) strong {
  color: #0f172a;
  font-size: 13px;
  font-weight: 600;
}

.api-key-project-card td:nth-child(1) small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
}

.api-key-project-card td:nth-child(3) .status {
  max-width: 100%;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: normal;
}

/* Target only the prefix, leaving an expanded full Key free to wrap. */
.api-key-project-card td:nth-child(2) .table-cell-content > span > div:first-child > code {
  display: block;
  max-width: 100%;
  overflow: visible;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.api-key-project-card td:nth-child(2) .table-cell-content > span > div:first-child > :is(.link, .sync-pending-note) {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-top: 6px;
  margin-left: 0 !important; /* Existing JSX has an inline left margin. */
  text-align: left;
  white-space: normal;
}

.api-key-project-card .secret-inline {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  grid-template-columns: minmax(0, 1fr) 28px;
}

.api-key-project-card .secret-inline code {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.api-key-project-card .alias-edit-inline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 8px;
  min-width: 0;
  max-width: 100%;
}

.api-key-project-card .alias-edit-inline > :is(strong, input) {
  grid-column: 1 / -1;
  min-width: 0;
  max-width: 100%;
}

.api-key-project-card .alias-edit-inline > input {
  width: 100% !important; /* Existing JSX sets width: 140px. */
  margin-left: 0 !important;
}

.api-key-project-card .alias-edit-inline > button {
  justify-self: start;
  margin-left: 0 !important;
}

/* Model names remain fully visible and wrap within their own column. */
.api-key-project-card .issued-key-models {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.api-key-project-card .issued-key-model-chip {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  padding: 4px 7px;
  border: 1px solid #e4eaf2;
  border-radius: 5px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.api-key-project-card .issued-key-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 12px;
  min-width: 0;
}

.api-key-project-card .issued-key-metric {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.api-key-project-card .issued-key-metric > small {
  color: #64748b;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
}

.api-key-project-card .issued-key-metric > strong {
  color: #334155;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.api-key-project-card :is(.issued-key-metric--wide, .issued-key-metrics-note) {
  grid-column: 1 / -1;
}

.api-key-project-card .issued-key-metrics-note {
  color: #64748b;
  font-size: 11px;
  line-height: 1.5;
}

.api-key-project-card .lifecycle-cell {
  min-width: 0;
  width: 100%;
  gap: 7px;
}

.api-key-project-card .lifecycle-cell > strong {
  color: #334155;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}

.api-key-project-card .lifecycle-cell > small {
  color: #64748b;
  font-size: 11px;
  line-height: 1.5;
  white-space: normal;
  overflow-wrap: anywhere;
}

.api-key-project-card .lifecycle-cell .quota-progress {
  height: 5px;
  background: #eaf0f7;
}

.api-key-project-card .key-action-cell {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.api-key-project-card .sync-key-button {
  max-width: 100%;
  padding: 6px 8px;
  font-size: 11px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.api-key-project-card > .table-wrap > table th:last-child {
  text-align: center;
}

.api-key-project-card button.link {
  border: 1px solid #dbe5f6;
  border-radius: 5px;
  padding: 4px 7px;
  background: #f4f7ff;
  color: #245bc2;
  font-family: inherit;
  line-height: 1.5;
  cursor: pointer;
}

.api-key-project-card :is(button, summary):focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

.api-key-project-card .issued-key-empty { color: #64748b; font-size: 12px; }
.api-key-project-card .lifecycle-cell > small.danger-text { color: #b42318; }

/* A readable card layout is the fallback, including browsers without container queries. */
.api-key-project-card > .table-wrap > table,
.api-key-project-card > .table-wrap > table > tbody {
  display: block;
}

.api-key-project-card > .table-wrap > table > thead {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.api-key-project-card > .table-wrap > table > tbody > tr {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid #e5ebf2;
}

.api-key-project-card > .table-wrap > table > tbody > tr:last-child {
  border-bottom: 0;
}

.api-key-project-card > .table-wrap > table > tbody > tr > td {
  display: block;
  width: auto;
  min-width: 0;
  padding: 0;
  border: 0;
  text-align: left;
}

.api-key-project-card > .table-wrap > table > tbody > tr > td[data-label]::before {
  display: block;
  margin-bottom: 6px;
  color: #64748b;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  content: attr(data-label);
}

.api-key-project-card > .table-wrap > table > tbody > tr > td[colspan] {
  grid-column: 1 / -1;
}

.api-key-project-card .key-action-cell {
  justify-content: flex-start;
}

/* Measure the project card, so sidebars and browser zoom also trigger reflow. */
@container issued-key-project (min-width: 400px) {
  .api-key-project-card > .table-wrap > table > tbody > tr {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 24px;
  }

  .api-key-project-card > .table-wrap > table > tbody > tr > td:is(:nth-child(1), :nth-child(4), :nth-child(7)) {
    grid-column: 1 / -1;
  }
}

@container issued-key-project (min-width: 700px) {
  .api-key-project-card > .table-wrap > table > tbody > tr {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .65fr);
    gap: 18px 24px;
  }

  .api-key-project-card > .table-wrap > table > tbody > tr > td:is(:nth-child(1), :nth-child(7)) {
    grid-column: auto;
  }
}

@container issued-key-project (min-width: 1180px) {
  .api-key-project-card > .table-wrap > table { display: table; }
  .api-key-project-card > .table-wrap > table > tbody { display: table-row-group; }

  .api-key-project-card > .table-wrap > table > thead {
    display: table-header-group;
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    white-space: normal;
  }

  .api-key-project-card > .table-wrap > table > tbody > tr {
    display: table-row;
    padding: 0;
    border: 0;
  }

  .api-key-project-card > .table-wrap > table > tbody > tr > td {
    display: table-cell;
    padding: 14px 12px;
    border-bottom: 1px solid #edf1f5;
  }

  .api-key-project-card > .table-wrap > table > tbody > tr:last-child > td { border-bottom: 0; }
  .api-key-project-card > .table-wrap > table th { padding-inline: 12px; }
  .api-key-project-card > .table-wrap > table > tbody > tr > td[data-label]::before { display: none; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(1) { width: 15%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(2) { width: 15%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(3) { width: 8%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(4) { width: 27%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(5) { width: 12%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(6) { width: 16%; }
  .api-key-project-card > .table-wrap > table :is(th, td):nth-child(7) { width: 7%; }
  .api-key-project-card .key-action-cell { justify-content: center; }
}
