/* cd-cert-broker — microscopy-lab aesthetic.
   Porcelain light / deep dark, histology stain-violet primary, membrane-teal
   for verified states. All cryptographic material set in monospace. */

:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --ink: #16202b;
  --muted: #5c6879;
  --line: #e3e7ee;
  --stain: #6d28d9;
  --stain-soft: #ede9fe;
  --membrane: #0d9488;
  --membrane-soft: #ccfbf1;
  --danger: #b91c1c;
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #161b24;
    --ink: #e8ecf3;
    --muted: #8b96a8;
    --line: #232a38;
    --stain: #a78bfa;
    --stain-soft: #2a2150;
    --membrane: #2dd4bf;
    --membrane-soft: #113b37;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  align-items: center;
  padding: 0 1rem;
}

.mono { font-family: var(--mono); font-size: .85em; letter-spacing: .01em; }
.stain { color: var(--stain); }
.membrane { color: var(--membrane); }

/* ── masthead ── */
.masthead { width: 100%; max-width: 660px; padding-top: 2.5rem; }
.wordmark { display: flex; align-items: center; gap: .9rem; }
.wordmark-cell { width: 2.6rem; height: 2.6rem; color: var(--stain); flex: none; }
.wordmark h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -.04em;
}
.tagline { margin: .1rem 0 0; color: var(--muted); font-size: .85rem; }

/* identity: which directory address the keys in this browser answer for.
   Not a session — there is nothing to log into — so it reads as a state, not
   an account chip. */
.whoami {
  display: flex; align-items: center; gap: .45rem;
  margin-top: .9rem;
  padding: .3rem .8rem .3rem .6rem;
  border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  background: var(--card);
  cursor: pointer;
}
.whoami-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--muted); flex: none; }
.whoami-label { color: var(--muted); font-weight: 600; }
.whoami .mono { font-size: .78rem; color: var(--ink); word-break: break-all; }
.whoami.listed { border-color: var(--membrane); background: var(--membrane-soft); }
.whoami.listed .whoami-dot { background: var(--membrane); }
.whoami.pending { border-color: var(--stain); background: var(--stain-soft); }
.whoami.pending .whoami-dot { background: var(--stain); }
.whoami.none { border-style: dashed; }

.tabs {
  display: flex;
  gap: .25rem;
  margin: 1.75rem 0 1.25rem;
  padding: .25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: fit-content;
}
.tab {
  border: 0; background: none; color: var(--muted);
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: .45rem 1.1rem; border-radius: 999px; cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--stain); color: #fff; }
@media (prefers-color-scheme: dark) { .tab.active { color: #0e1116; } }

/* ── layout ── */
main { width: 100%; max-width: 660px; flex: 1; }
.view { display: flex; flex-direction: column; gap: 1rem; animation: rise .25s ease; }
.view[hidden], [hidden] { display: none !important; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
}
.card h2 { margin: 0 0 .35rem; font-size: 1.02rem; font-weight: 700; letter-spacing: -.02em; }
.hint { margin: 0 0 1rem; color: var(--muted); font-size: .85rem; }

.row { display: flex; align-items: center; }
.gap { gap: .6rem; }
.wrap { flex-wrap: wrap; }

input[type="text"], input[type="email"], input[type="number"], select, textarea {
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .8rem;
  flex: 1;
  min-width: 0;
}
textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: .9rem; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--stain); outline-offset: 1px;
}
.k-input { flex: 0 0 4.5rem; }

button {
  font: inherit; font-weight: 600; font-size: .92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem 1.05rem;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(.97); }
button:active { transform: translateY(1px); }
button.primary { background: var(--stain); border-color: var(--stain); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #0e1116; } }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ── keys ── */
.key-row {
  display: flex; align-items: center; gap: .85rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--line);
}
.key-row:last-of-type { border-bottom: 0; margin-bottom: .5rem; }
.key-row .cellprint { flex: none; }
.key-info { flex: 1; min-width: 0; }
.key-label { font-weight: 650; }
.key-fp { color: var(--muted); }
.key-email { color: var(--muted); font-size: .8rem; margin-top: .1rem; }
.key-badge {
  font-size: .72rem; font-weight: 700;
  color: var(--membrane); background: var(--membrane-soft);
  padding: .15rem .55rem; border-radius: 999px;
}
.key-badge.pending { color: var(--stain); background: var(--stain-soft); }
.key-badge.hw { color: var(--ink); background: var(--line); }
.filelink { color: var(--stain); text-decoration: underline; cursor: pointer; }

.key-icon { font-size: 1.9rem; width: 44px; height: 44px; display: grid; place-items: center; flex: none; }

.key-edit { width: 100%; display: flex; flex-direction: column; gap: .6rem; padding: .35rem 0; }
.icon-picker { display: flex; flex-wrap: wrap; gap: .35rem; }
.icon-opt {
  width: 2.6rem; height: 2.6rem; padding: 0;
  display: grid; place-items: center; font-size: 1.25rem;
  border-radius: 10px;
}
.icon-opt .cellprint { width: 28px; height: 28px; }
.icon-opt.sel { border-color: var(--stain); background: var(--stain-soft); }

.sent-row {
  display: flex; align-items: center; gap: .85rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--line);
}
.sent-row:last-child { border-bottom: 0; }
.dl-log { color: var(--muted); font-size: .72rem; margin-top: .15rem; }

.dir-list #directory-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.dir-org {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .8rem .45rem .45rem;
  border-radius: 999px; font-size: .85rem; text-align: left;
}
.dir-org .cellprint { width: 30px; height: 30px; }
.dir-org .mono { color: var(--muted); font-size: .72rem; }
.key-actions { display: flex; gap: .4rem; }
.key-actions button { padding: .35rem .7rem; font-size: .8rem; }

/* the signature: deterministic cell identicon */
.cellprint { width: 44px; height: 44px; }

/* ── recipients ── */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .85rem; }
.chip {
  display: flex; align-items: center; gap: .5rem;
  background: var(--stain-soft);
  border: 1px solid var(--stain);
  border-radius: 999px;
  padding: .3rem .75rem .3rem .35rem;
  font-size: .85rem;
}
.chip .cellprint { width: 26px; height: 26px; }
.chip .mono { font-size: .72rem; color: var(--muted); }
.chip button { border: 0; background: none; padding: 0 .1rem; font-size: 1rem; color: var(--muted); }

.pin-warning {
  margin-top: .85rem;
  border: 1.5px solid var(--danger);
  border-radius: 10px;
  padding: .9rem 1rem;
  font-size: .9rem;
}
.pin-warning .meta { margin: .5rem 0; }
.pin-warning .hint { margin-bottom: .75rem; }

fieldset {
  border: 1px solid var(--line); border-radius: 10px;
  margin: 1rem 0 0; padding: .75rem 1rem;
  display: flex; flex-direction: column; gap: .45rem;
}
legend { font-size: .8rem; font-weight: 700; color: var(--muted); padding: 0 .4rem; }
fieldset label { font-size: .9rem; }

/* ── payload ── */
.seg { display: flex; gap: .25rem; margin-bottom: .8rem; }
.seg-btn { padding: .35rem .9rem; font-size: .82rem; border-radius: 999px; }
.seg-btn.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.drop {
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 1.4rem;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--stain); background: var(--stain-soft); }
.drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop p { margin: .15rem 0; font-size: .88rem; }

/* ── results / status ── */
.result { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.result .mono { word-break: break-all; user-select: all; }
.status { font-size: .85rem; color: var(--muted); }
.status.ok { color: var(--membrane); }
.status.err { color: var(--danger); }

.meta { display: grid; grid-template-columns: auto 1fr; gap: .25rem 1rem; margin: 0 0 1rem; font-size: .9rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-family: var(--mono); font-size: .85rem; word-break: break-all; }

.rx-text {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem; font-family: var(--mono); font-size: .88rem;
  white-space: pre-wrap; word-break: break-word; max-height: 20rem; overflow: auto;
}

.cap-slot { margin: .35rem 0 .8rem; min-height: 0; }
.cap-slot:not(:empty) { min-height: 3rem; }

/* membrane seal pulse on successful encrypt */
@keyframes seal {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--membrane) 55%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}
.sealed { animation: seal .6s ease-out; border-radius: 10px; }
@media (prefers-reduced-motion: reduce) { .sealed { animation: none; } }

footer { width: 100%; max-width: 660px; padding: 2rem 0 1.5rem; color: var(--muted); font-size: .78rem; }
footer a { color: inherit; }

#toast {
  position: fixed; bottom: 1.25rem; left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: var(--bg);
  border-radius: 999px; padding: .55rem 1.2rem;
  font-size: .88rem; font-weight: 600;
  transition: transform .25s ease;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%); }

@media (max-width: 480px) {
  .row.gap { flex-wrap: wrap; }
  .card { padding: 1.1rem; }
}
