/*
 * /secrets — read-only list of non-TOTP items in the active context.
 * Plus the `.context-switcher` popover that sits inside the sidebar
 * footer on every vault route. Stylistic cousin of vault.css — these
 * are just different rooms of the same building.
 */

/* ----- Context switcher (sidebar footer) ------------------------------- */

.context-switcher {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.context-switcher__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.context-switcher__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.context-switcher__select {
  /* Native <select> reset + re-skin. Keeping the caret glyph native
     is deliberate: we don't need to chase cross-browser styling
     of the down-arrow for V1.x. */
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 32px 10px var(--space-3);
  font-size: var(--text-base);
  color: var(--color-fg);
  line-height: var(--leading-tight);
  cursor: pointer;
  min-height: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-muted) 50%),
    linear-gradient(135deg, var(--color-muted) 50%, transparent 50%);
  background-position: right 14px top 18px, right 9px top 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color var(--motion-fast) var(--easing-out),
              box-shadow var(--motion-fast) var(--easing-out);
}

.context-switcher__select:hover {
  border-color: var(--color-border-strong);
}

.context-switcher__select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.context-switcher__actions {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  gap: 4px;
  align-items: center;
}

.context-switcher__actions .icon-btn {
  width: 32px;
  height: 32px;
}

.context-switcher__actions .icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ----- Secrets page header -------------------------------------------- */

.secrets-header {
  padding: var(--space-6) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 340px) auto;
  align-items: center;
  gap: var(--space-4);
}

.secrets-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-semi);
  font-size: var(--text-2xl);
  letter-spacing: -0.01em;
  color: var(--color-fg);
}

.secrets-subtitle {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  max-width: 72ch;
}

.secrets-subtitle code {
  font-size: 0.95em;
}

.secrets-toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.secrets-search {
  position: relative;
  display: block;
  min-width: 0;
}

.secrets-search input {
  width: 100%;
  min-height: 40px;
  padding: 9px 76px 9px var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-fg);
  font: inherit;
  font-size: var(--text-base);
}

.secrets-search input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(139, 90, 60, 0.16);
}

.secrets-search input::-webkit-search-cancel-button { appearance: none; }

.secrets-search__clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.secrets-search__clear:hover,
.secrets-search__clear:focus-visible {
  color: var(--color-fg);
  border-color: var(--color-border);
  background: var(--color-surface-2);
}

.secrets-search__summary {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-tight);
}

.secrets-paywall {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.secrets-paywall strong {
  color: var(--color-accent);
  font-weight: var(--weight-semi);
}

.secrets-paywall__actions {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* Loading state — the Ring plus a label, centered on the surface. */
.secrets-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

@media (max-width: 720px) {
  .secrets-paywall {
    align-items: stretch;
    flex-direction: column;
  }

  .secrets-paywall__actions {
    margin-left: 0;
  }

  .secrets-paywall__actions .btn {
    flex: 1;
  }
}

.secrets-loading :first-child {
  /* Give the ring a gentle continuous spin during load. Matches the
     marketing hero variant cadence; respects reduced-motion. */
  animation: secrets-spin 2.4s linear infinite;
}

@keyframes secrets-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .secrets-loading :first-child { animation: none; }
}

/* ----- Secrets list --------------------------------------------------- */

.secrets-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-5);
  max-width: 840px;
  margin: 0 auto;
  width: 100%;
}

.secret-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--motion-fast) var(--easing-out),
              box-shadow var(--motion-fast) var(--easing-out);
}

.secret-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-sm);
}

.secret-card__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
}

.secret-card__head-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.secret-card__kind {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  white-space: nowrap;
  font-family: var(--font-mono);
}

.secret-card__name {
  font-weight: var(--weight-semi);
  color: var(--color-fg);
  font-size: var(--text-base);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secret-card__body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.secret-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.secret-copy {
  min-width: 96px;
  justify-content: center;
}

.secret-copy--copied {
  color: var(--color-success);
  border-color: color-mix(in srgb, var(--color-success) 38%, var(--color-border));
  background: color-mix(in srgb, var(--color-success) 10%, transparent);
}

/* ----- Key-value grid (passwords, api tokens, ssh keys, certs) -------- */

.kv {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.kv dt {
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
  align-self: center;
}

.kv dd {
  margin: 0;
  color: var(--color-fg);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  min-width: 0;
  word-break: break-word;
}

/* Action rows inside .kv span the full width. A trailing <dd> with
   only a button sits under the preceding value. */
.kv dd:has(> .btn),
.kv dd:has(> .masked) {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ----- Masked value toggle ------------------------------------------- */

.masked {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  flex-wrap: wrap;
}

.masked > span:first-child {
  min-width: 8ch;
  color: var(--color-fg);
  word-break: break-all;
}

/* ----- Text-secret viewer -------------------------------------------- */

.secret-text {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-2);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  color: var(--color-fg);
}

/* ----- Env (KEY=VALUE) table ----------------------------------------- */

.env-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  table-layout: fixed;
}

.env-table th,
.env-table td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
}

.env-table th {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--color-muted);
  font-weight: var(--weight-semi);
  background: var(--color-surface-2);
  width: 30%;
}

.env-table tbody tr:last-child td { border-bottom: 0; }

.env-table td { word-break: break-all; }

/* ----- Narrow-viewport collapse (phones) ----------------------------- */

@media (max-width: 720px) {
  .secrets-header {
    align-items: stretch;
    grid-template-columns: 1fr;
    padding: var(--space-5) var(--space-4) var(--space-3);
  }
  .secrets-toolbar { order: 2; }
  .secrets-header > .btn {
    order: 3;
    justify-content: center;
    width: 100%;
  }
  .secrets-list   { padding: var(--space-4) var(--space-3); }

  /* Stack definition lists — 128px / fr grid gets cramped under ~480px. */
  .kv {
    grid-template-columns: 1fr;
    gap: 4px var(--space-3);
  }
  .kv dt {
    margin-top: var(--space-2);
  }

  /* Env table: reduce padding, let the KEY column stretch a bit. */
  .env-table th,
  .env-table td { padding: var(--space-2); }
  .env-table th:first-child { width: 40%; }

  .secret-card__head {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .secret-card__head-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
  }
}
