/* Keys: key cards, the Add key / Rotate / Revoke / Rollout note dialogs and the key sheet (#/apps/:name/keys/:id).
   Page-specific rules only: shared components live in app.css and charts.css, colors in tokens.css.
   Prefix every selector with this page's root class (see js/README.md, "CSS conventions"). Key cards also render on
   the app page, so they're scoped by .key-cards-wrap / .key-card; dialogs live in #dialogs, under .key-dialog. */

/* ---------- Key cards (inside the app page's Keys section) ---------- */

.key-cards-wrap { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.key-cards-wrap .key-cards {
  display: grid; gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
}
.key-cards-wrap .key-cards[hidden], .key-cards-wrap .key-cards-empty[hidden] { display: none; }
.key-cards-wrap .key-revoked-toggle { align-self: flex-start; }

/* A key card is a hairline box on the section's surface: no shadow, no second fill */
.key-card {
  display: flex; flex-direction: column; gap: var(--space-3);
  min-width: 0; padding: var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-control);
}
.key-card.is-revoked { color: var(--ink-2); }
.key-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.key-card-title { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 14px; font-weight: 600; min-width: 0; }
.key-card-state { font-size: var(--text-secondary); }
.key-card .key-prefix, .key-dialog .key-prefix, .page-keys .key-prefix { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* The rotation advice on a replaced key: what to do next */
.key-card-advice {
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--warning);
  background: var(--warning-wash);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  font-size: var(--text-secondary); color: var(--ink);
}
.key-card-advice[hidden] { display: none; }

.key-card .key-card-facts { font-size: var(--text-secondary); }

/* Requests today / 7 days / 30 days: three small figures in a row */
.key-card-counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); padding: var(--space-2) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.key-card-counts .key-count { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.key-card-counts dt { font-size: var(--text-meta); color: var(--ink-3); }
.key-card-counts dd { font-size: 16px; font-weight: 600; color: var(--ink); }

/* Note: text + Edit, or the inline editor */
.key-card-note-view { display: flex; align-items: flex-start; gap: var(--space-2); }
.key-card-note-text { flex: 1; min-width: 0; font-size: var(--text-secondary); overflow-wrap: anywhere; padding-top: 4px; }
.key-card-note-view .btn { flex: none; }
.key-card-note-edit { display: flex; flex-direction: column; gap: var(--space-2); }
.key-card-note[hidden] { display: none; }

/* Regional ranking: switch, inline error, boosted countries, the short explanation */
.key-card-regional { display: flex; flex-direction: column; gap: var(--space-1); }
.key-card-regional[hidden], .key-card-regional > [hidden] { display: none; }
.key-card-boosted { font-size: var(--text-meta); color: var(--ink-2); }
.key-card .key-regional-help { font-size: var(--text-secondary); }
.key-card .key-regional-help .disclosure-body { color: var(--ink-2); max-width: 60ch; }

.key-card-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: auto; padding-top: var(--space-1); }

@media (max-width: 767px) {
  .key-card-actions .btn, .key-card-note-view .btn, .key-card-note-edit .btn { min-height: var(--touch); }
  .key-card-actions .btn { flex: 1 1 auto; }
  .key-card .switch { min-height: var(--touch); }
  .key-card .key-regional-help > summary { min-height: var(--touch); }
  .key-cards-wrap .key-revoked-toggle { min-height: var(--touch); }
  /* 16 px keeps iOS from zooming in when the note field takes focus */
  .key-card .textarea { font-size: 16px; }
}
@media (max-width: 479px) {
  .key-card { padding: var(--space-3); }
}

/* ---------- Key dialogs (native dialog in #dialogs) ---------- */

.key-dialog .key-form { gap: var(--space-4); }
.key-dialog .key-fixed-app { font-weight: 600; }
.key-dialog .key-app-preview { min-height: 1.5em; }
.key-dialog .key-app-suggest:empty { display: none; }
.key-dialog .key-app-suggest .link-button { min-height: 28px; font-size: var(--text-secondary); }
.key-dialog .key-form-row { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 480px) { .key-dialog .key-form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.key-dialog .key-percent, .key-dialog .key-day { max-width: 100%; }
.key-dialog .select-wrap { display: flex; }

/* The new key, shown once: a monospace field that wraps instead of scrolling, and Copy beside it */
.key-dialog .key-secret-row { display: flex; gap: var(--space-2); align-items: stretch; }
.key-dialog .key-secret {
  flex: 1; min-width: 0; min-height: 0; resize: none;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  word-break: break-all; background: var(--page);
  field-sizing: content; /* Grows to show the whole key where supported; rows=2 otherwise */
}
.key-dialog .key-copy { flex: none; }
.key-dialog .key-copy-status { font-size: var(--text-meta); color: var(--ink-2); }
.key-dialog .key-copy-status:empty { display: none; }
.key-dialog .key-revoke-facts { color: var(--ink); }
.key-dialog .key-revoke-env { font-size: var(--text-secondary); color: var(--ink-2); }
.key-dialog .key-revoke-env[hidden], .key-dialog .field[hidden] { display: none; }

@media (max-width: 767px) {
  /* 16 px keeps iOS from zooming in when a field takes focus */
  .key-dialog .key-secret, .key-dialog .input, .key-dialog .textarea, .key-dialog .select { font-size: 16px; }
  .key-dialog .key-app-suggest .link-button { min-height: var(--touch); }
}
@media (max-width: 479px) {
  .key-dialog .key-secret-row { flex-direction: column; }
  .key-dialog .key-copy { min-height: var(--touch); }
}

/* ---------- Key sheet (#/apps/:name/keys/:id) ---------- */

.page-keys .key-sheet-facts .kv { max-width: 720px; }
.page-keys .key-endpoint { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-width: 0; }
.page-keys .key-endpoint code { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.page-keys .key-card-advice { max-width: 720px; }
@media (max-width: 767px) {
  .page-keys .key-sheet-facts .btn { min-height: var(--touch); }
}

@media (forced-colors: active) {
  .key-card-advice { border-left-color: CanvasText; }
  .key-card { border-color: CanvasText; }
}
