/* Payment Encryption UI.
 * Steel greys and a navy ink for the tool itself; teal is reserved for "verified" key
 * state so it always means the same thing. System fonts only — the CSP allows no
 * third-party font origin. */

:root {
  --paper: #f3f5f8;
  --surface: #ffffff;
  --ink: #142033;
  --ink-soft: #2a3850;
  --steel: #556274;
  --rule: #d8dee6;
  --rule-strong: #b9c2ce;
  --seal: #0e6e5c;
  --seal-tint: #e2f2ed;
  --warn: #8a5a00;
  --warn-tint: #fbf0d9;
  --danger: #b42318;
  --danger-tint: #fdecea;
  --focus: #2f6fdb;
  --on-ink: #ffffff;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --radius-sm: 6px;
  --radius: 10px;
  --page: 1080px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f141b;
    --surface: #161d27;
    --ink: #e7ecf2;
    --ink-soft: #c9d2dd;
    --steel: #98a4b3;
    --rule: #283241;
    --rule-strong: #3a4657;
    --seal: #4cc4a6;
    --seal-tint: #13302a;
    --warn: #e7b453;
    --warn-tint: #33280f;
    --danger: #ff8a80;
    --danger-tint: #3a1715;
    --focus: #79a8ff;
    --on-ink: #0f141b;
  }
}

/* --- Base ------------------------------------------------------------------ */

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--font);
}

h1, h2, p { margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Top bar & tabs ---------------------------------------------------------- */

.topbar { background: var(--surface); border-bottom: 1px solid var(--rule); }

.topbar__inner,
.tabs__inner,
.page {
  width: min(100% - 32px, var(--page));
  margin-inline: auto;
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
}

.brand__mark { width: 28px; height: 28px; flex: none; }
.brand__mark rect:first-child { fill: var(--ink); }
.brand__mark path { fill: none; stroke: var(--paper); stroke-width: 2.4; }
.brand__body { fill: var(--seal); }

.brand__name { font-weight: 650; font-size: 16px; white-space: nowrap; }

.brand__org {
  color: var(--steel);
  padding-left: 10px;
  border-left: 1px solid var(--rule);
}

.account { display: flex; align-items: center; gap: 12px; min-width: 0; }

.account__identity {
  color: var(--steel);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs { background: var(--surface); border-bottom: 1px solid var(--rule); }
.tabs__inner { display: flex; gap: 4px; }

.tab {
  appearance: none;
  border: 0;
  background: none;
  color: var(--steel);
  font: 500 14px/1 var(--font);
  padding: 14px 4px 12px;
  margin-right: 20px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

/* --- Page & panels ------------------------------------------------------------ */

.page { flex: 1; padding-block: 28px 40px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 24px;
}

.panel__header { margin-bottom: 20px; }
.panel__title { font-size: 22px; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
.panel__lede { color: var(--steel); margin-top: 6px; max-width: 62ch; }

/* --- Sign-in notice ------------------------------------------------------------ */

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--ink);
  border-radius: var(--radius);
}

.notice__title { font-size: 17px; font-weight: 650; }
.notice__body { color: var(--steel); margin-top: 4px; max-width: 60ch; }

/* --- Dropzone & file list -------------------------------------------------------- */

.dropzone {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 36px 20px;
  text-align: center;
  border: 1.5px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.dropzone:hover,
.dropzone.is-dragover { border-color: var(--ink); }
.dropzone.is-dragover { background: var(--seal-tint); }

fieldset:disabled .dropzone { cursor: not-allowed; opacity: 0.55; }
fieldset:disabled .dropzone:hover { border-color: var(--rule-strong); }

.dropzone__icon {
  width: 30px;
  height: 30px;
  margin-bottom: 4px;
  fill: none;
  stroke: var(--steel);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone__title { font-weight: 600; }
.dropzone__link { color: var(--focus); text-decoration: underline; text-underline-offset: 3px; }
.dropzone__hint { color: var(--steel); font-size: 13.5px; }

.files { margin-top: 16px; border: 1px solid var(--rule); border-radius: var(--radius); }

.files__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  color: var(--steel);
  font-size: 13.5px;
}

.files__list { list-style: none; margin: 0; padding: 0; }

.file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}

.file + .file { border-top: 1px solid var(--rule); }
.file.is-invalid { background: var(--danger-tint); }

.file__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__size { color: var(--steel); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.file__problem { grid-column: 1 / -1; color: var(--danger); font-size: 13px; margin-top: -4px; }

.file__remove {
  appearance: none;
  border: 0;
  background: none;
  color: var(--steel);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.file__remove:hover { background: var(--paper); color: var(--ink); }

.link-button {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--focus);
  font: inherit;
  cursor: pointer;
}

.link-button:hover { text-decoration: underline; }

/* --- Fields ---------------------------------------------------------------------- */

.field { display: grid; gap: 6px; margin-top: 16px; }
.field__label { font-size: 13.5px; font-weight: 600; color: var(--ink-soft); }
.field__hint { font-size: 13px; color: var(--steel); }
.field--inline { max-width: 420px; margin: 0 0 20px; }

.input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.input:hover { border-color: var(--steel); }
.input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.input--mono { font-family: var(--mono); font-size: 13.5px; }
.input--file { padding: 7px 8px; }

.input--file::file-selector-button {
  margin-right: 12px;
  padding: 5px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: 500 13.5px var(--font);
  cursor: pointer;
}

/* --- Buttons ----------------------------------------------------------------------- */

.actions { display: flex; gap: 12px; margin-top: 20px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: 600 14.5px/1 var(--font);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.button--primary { background: var(--ink); color: var(--on-ink); }
.button--primary:hover { background: var(--ink-soft); }

.button--quiet { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.button--quiet:hover { border-color: var(--ink); }

.button--wide { min-width: 180px; }

.button:disabled { opacity: 0.45; cursor: not-allowed; }
.button[aria-busy="true"] { cursor: progress; }

/* --- Status messages ------------------------------------------------------------------ */

.status { margin-top: 16px; font-size: 14px; }
.status:empty { display: none; }

.status--busy,
.status--success,
.status--error,
.status--warn {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 3px solid currentColor;
}

.status--busy { color: var(--steel); background: var(--paper); }
.status--success { color: var(--seal); background: var(--seal-tint); }
.status--error { color: var(--danger); background: var(--danger-tint); }
.status--warn { color: var(--warn); background: var(--warn-tint); }

/* --- Sealing chain (the one expressive element) ----------------------------------------- */

.chain { position: sticky; top: 20px; }
.chain__title { font-size: 15px; font-weight: 650; margin-bottom: 18px; }
.chain__steps { list-style: none; margin: 0; padding: 0; }

.chain__step {
  position: relative;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 12px;
  padding-bottom: 20px;
}

.chain__step:last-child { padding-bottom: 0; }

/* The thread connecting the steps. */
.chain__step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 22px;
  bottom: 2px;
  width: 2px;
  background: var(--rule);
}

.chain__dot {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--rule-strong);
  background: var(--surface);
}

.chain__step.is-verified .chain__dot {
  border-color: var(--seal);
  background: var(--seal) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
}

.chain__step.is-warning .chain__dot { border-color: var(--warn); background: var(--warn-tint); }

.chain__name { font-weight: 600; }
.chain__meta { color: var(--steel); font-size: 13.5px; }
.chain__meta:empty { display: none; }
.chain__meta.is-warning { color: var(--warn); font-weight: 600; }

.fingerprint {
  margin: 6px 0 4px;
  font: 500 12.5px/1.6 var(--mono);
  letter-spacing: 0.02em;
  color: var(--ink);
  word-spacing: 0.15em;
}

.fingerprint:empty { display: none; }

/* In the narrow panel, break the fingerprint at its midpoint rather than mid-group. */
.chain .fingerprint { white-space: pre-line; }

.chain__limits {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  color: var(--steel);
  font-size: 13px;
}

.chain__limits:empty { display: none; }

/* --- Keys tab ---------------------------------------------------------------------------- */

.keys__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}

.keys__actions { display: flex; gap: 10px; flex-wrap: wrap; flex-shrink: 0; }

.key-test { margin-top: 20px; }
.key-test__title { font-size: 16px; font-weight: 650; }
.key-test__key { margin-top: 6px; font-size: 14px; overflow-wrap: anywhere; }
.key-test__key .fingerprint { display: inline; margin: 0; }
.key-test__checks { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.key-test__check { display: grid; grid-template-columns: 1.5em minmax(0, 1fr); gap: 2px 8px; }
.key-test__mark { grid-row: span 2; font-weight: 700; }
.key-test__label { font-weight: 600; }
.key-test__detail { color: var(--steel); font-size: 13.5px; overflow-wrap: anywhere; }
.key-test__check--pass .key-test__mark { color: var(--seal); }
.key-test__check--fail .key-test__mark,
.key-test__check--fail .key-test__label { color: var(--danger); }
.key-test__check--skip { opacity: 0.7; }

.key-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.key-cards:empty { display: none; }

.key-card { display: grid; gap: 14px; }

.key-card__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.key-card__title { font-size: 16px; font-weight: 650; }
.key-card__role { color: var(--steel); font-size: 13.5px; margin-top: 2px; }

.key-card__facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: baseline; gap: 6px 16px; margin: 0; }
.key-card__facts dt { color: var(--steel); font-size: 13.5px; }
.key-card__facts dd { margin: 0; overflow-wrap: anywhere; }
.key-card__facts .fingerprint { margin: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge--ok { color: var(--seal); background: var(--seal-tint); }
.badge--warn { color: var(--warn); background: var(--warn-tint); }

.replace { margin-top: 20px; }
.replace__title { font-size: 17px; font-weight: 650; }

.replace__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  gap: 0 20px;
}

.replace__grid .field:first-child,
.replace__grid .field:nth-child(2) { margin-top: 0; }
.replace__file { grid-column: 1 / -1; }

/* --- Footer --------------------------------------------------------------------------------- */

.footer {
  width: min(100% - 32px, var(--page));
  margin: 0 auto;
  padding: 16px 0 28px;
  border-top: 1px solid var(--rule);
  color: var(--steel);
  font-size: 13px;
}

/* --- Responsive & motion ---------------------------------------------------------------------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .chain { position: static; }
}

@media (max-width: 560px) {
  .page { padding-block: 20px 32px; }
  .panel { padding: 18px; }
  .brand__org { display: none; }
  .brand__name { font-size: 15px; }
  .account__identity { display: none; }
  .notice { flex-direction: column; align-items: stretch; }
  .keys__header { flex-direction: column; }
  .replace__grid { grid-template-columns: minmax(0, 1fr); }
  .replace__grid .field:nth-child(2) { margin-top: 16px; }
  .button--wide { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
