:root {
  --paper: #e9eef0;
  --paper-raised: #f6f8f8;
  --ink: #0f252d;
  --ink-2: #3f5a64;
  --ink-3: #546d77;
  --line: #b8c8ce;
  --line-strong: #8aa3ac;
  --signal: #174fca;
  --signal-soft: #dbe4fa;
  --jade: #1b6b58;
  --jade-bg: #deece7;
  --amber: #8a5300;
  --amber-bg: #f3e6cd;
  --danger: #9c342a;
  --danger-bg: #f4ded8;
  --font-display: "Noto Serif", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --font-ui: "Noto Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.75;
  font-feature-settings: "palt" 1;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(15, 37, 45, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(15, 37, 45, 0.045) 1px, transparent 1px);
  background-size: 32px 32px;
}

a {
  color: var(--signal);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

a:hover {
  text-decoration-thickness: 2px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

code,
pre {
  font-family: var(--font-mono);
}

.page {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 40px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Masthead --------------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}

.masthead-right {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.2;
  color: var(--ink-2);
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--ink-3);
  flex: none;
}

.status-pill[data-state="ready"]::before {
  background: var(--jade);
}

.status-pill[data-state="cooling"]::before,
.status-pill[data-state="stale"]::before {
  background: var(--amber);
}

.status-pill[data-state="empty"]::before,
.status-pill[data-state="error"]::before {
  background: var(--danger);
}

.user-chip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.button-primary:hover:not(:disabled) {
  background: var(--signal);
  border-color: var(--signal);
}

.button-outline {
  border-color: var(--line-strong);
  background: var(--paper-raised);
}

.button-outline:hover:not(:disabled) {
  border-color: var(--ink);
}

.button-quiet {
  color: var(--ink-2);
}

.button-quiet:hover:not(:disabled) {
  background: rgba(15, 37, 45, 0.06);
  color: var(--ink);
}

.button-danger {
  color: var(--danger);
}

.button-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

.button-small {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.button-block {
  width: 100%;
}

/* Login ------------------------------------------------------------------ */

.login {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(340px, 0.88fr);
  border-bottom: 1px solid var(--line);
}

.login-hero {
  padding: 68px 64px 72px 0;
  border-right: 1px solid var(--line);
}

.login-hero h1 {
  margin: 0 0 24px;
  font-family: var(--font-display);
  font-size: clamp(36px, 4.6vw, 58px);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: 0.01em;
}

.lede {
  max-width: 32em;
  margin: 0;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.9;
}

.schematic {
  max-width: 300px;
  margin-top: 44px;
}

.relay-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.rail-line {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1;
}

.rail-draw {
  fill: none;
  stroke: var(--signal);
  stroke-width: 1.5;
  stroke-dasharray: 282;
  stroke-dashoffset: 282;
  animation: draw-line 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) 0.1s forwards;
}

.node circle {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.5;
}

.node text {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink-2);
  letter-spacing: 0.02em;
}

.node .node-value {
  font-size: 10px;
  fill: var(--ink);
}

.token {
  fill: var(--signal);
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: token-flow 3.4s linear infinite;
}

.token-2 {
  animation-delay: 1.13s;
}

.token-3 {
  animation-delay: 2.26s;
}

.login-panel {
  padding: 68px 0 72px 64px;
}

.login-panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
}

.hint {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.8;
}

.hint-warn {
  margin-top: 18px;
  padding: 10px 12px;
  border-left: 2px solid var(--amber);
  background: var(--amber-bg);
  color: var(--ink);
}

.notice {
  margin-top: 20px;
  padding: 10px 12px;
  border-left: 2px solid var(--signal);
  background: var(--signal-soft);
  font-size: 13px;
  line-height: 1.7;
}

.notice[data-kind="error"] {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.notice[data-kind="success"] {
  border-color: var(--jade);
  background: var(--jade-bg);
}

.form {
  margin-top: 28px;
}

.field {
  margin: 0 0 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color 140ms ease;
}

.input:hover {
  border-color: var(--ink-3);
}

.input:focus {
  border-color: var(--signal);
  outline: 2px solid var(--signal);
  outline-offset: 1px;
}

.input::placeholder {
  color: var(--ink-3);
}

.input-inline {
  width: auto;
  min-height: 32px;
  padding: 4px 8px;
  border-color: transparent;
  background: transparent;
  font-size: 12px;
}

.input-inline:hover {
  border-color: var(--line-strong);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--ink-3);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.fineprint {
  margin: 24px 0 0;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.8;
}

/* App -------------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  align-items: start;
}

.rail {
  position: sticky;
  top: 0;
  min-height: calc(100vh - 76px);
  padding: 40px 36px 48px 0;
  border-right: 1px solid var(--line);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.rail-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}

.readouts {
  margin: 0;
}

.readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.readout dt {
  color: var(--ink-2);
  font-size: 12px;
}

.readout dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  text-align: right;
}

.readout dd[data-state="warn"] {
  color: var(--amber);
}

.readout dd[data-state="bad"] {
  color: var(--danger);
}

.rail .schematic {
  margin: 30px 0 24px;
}

.rail-note {
  margin: 0;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.8;
}

.content {
  min-width: 0;
  padding: 40px 0 88px 56px;
}

.section {
  scroll-margin-top: 24px;
}

.section + .section {
  margin-top: 56px;
  padding-top: 40px;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.section-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.section-head p {
  max-width: 30em;
  margin: 0;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.7;
  text-align: right;
  text-wrap: balance;
}

.inline-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin: 0 0 24px;
}

.inline-form .field {
  flex: 1 1 220px;
  margin: 0;
}

.inline-form .field-narrow {
  flex: 0 1 150px;
}

.inline-form .button {
  flex: none;
  min-height: 44px;
}

/* Tables ----------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: rgba(15, 37, 45, 0.035);
}

td:first-child,
th:first-child {
  padding-left: 0;
}

td:last-child,
th:last-child {
  padding-right: 0;
  text-align: right;
}

.key-prefix,
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
}

.key-label {
  display: block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-muted {
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--ink-3);
}

.status[data-state="active"] {
  color: var(--jade);
}

.status[data-state="active"]::before {
  background: var(--jade);
}

.status[data-state="revoked"] {
  color: var(--ink-3);
}

.status[data-state="revoked"]::before {
  background: var(--ink-3);
}

.status[data-state="disabled"] {
  color: var(--danger);
}

.status[data-state="disabled"]::before {
  background: var(--danger);
}

.status[data-state="admin"] {
  color: var(--signal);
}

.status[data-state="admin"]::before {
  background: var(--signal);
}

.empty {
  margin: 0;
  padding: 26px 0;
  color: var(--ink-2);
  font-size: 14px;
}

/* Endpoint and snippet --------------------------------------------------- */

.endpoint-list {
  margin: 0;
}

.endpoint {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.endpoint dt {
  color: var(--ink-2);
  font-size: 12px;
}

.endpoint dd {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0;
  min-width: 0;
}

.endpoint code {
  padding: 2px 6px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  font-size: 12px;
  word-break: break-all;
}

.snippet {
  margin: 20px 0 0;
  padding: 20px;
  overflow-x: auto;
  border-left: 3px solid var(--signal);
  background: var(--ink);
  color: #dde7e8;
  font-size: 12px;
  line-height: 1.85;
  white-space: pre;
}

/* Modal and toast -------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 37, 45, 0.44);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  padding: 32px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper-raised);
  box-shadow: 0 24px 64px rgba(15, 37, 45, 0.2);
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
}

.modal-body {
  margin: 0;
  color: var(--ink-2);
  font-size: 14px;
}

.modal-key-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
}

.modal-key {
  flex: 1 1 280px;
  font-size: 12px;
  word-break: break-all;
}

.modal-warning {
  margin: 0 0 22px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast[data-kind="error"] {
  background: var(--danger);
}

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

.footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 20px 0 32px;
  border-top: 1px solid var(--line);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10px;
}

.footer-sep {
  width: 1px;
  height: 10px;
  background: var(--line-strong);
}

/* Motion ----------------------------------------------------------------- */

@keyframes draw-line {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes token-flow {
  0% {
    transform: translateY(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  86% {
    opacity: 1;
  }
  100% {
    transform: translateY(228px);
    opacity: 0;
  }
}

/* Responsive ------------------------------------------------------------- */

@media (max-width: 1024px) {
  .page {
    padding: 0 28px;
  }

  .app {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .content {
    padding-left: 40px;
  }

  .login-hero {
    padding-right: 44px;
  }

  .login-panel {
    padding-left: 44px;
  }
}

@media (max-width: 860px) {
  .page {
    padding: 0 20px;
  }

  .masthead {
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 0;
  }

  .masthead-right {
    gap: 8px;
  }

  .user-chip {
    display: none;
  }

  .login {
    grid-template-columns: 1fr;
  }

  .login-hero {
    padding: 36px 0 22px;
    border-right: 0;
  }

  .login-hero .schematic {
    display: none;
  }

  .login-panel {
    padding: 24px 0 44px;
    border-top: 1px solid var(--line);
  }

  .schematic {
    max-width: 260px;
    margin-top: 28px;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    min-height: 0;
    padding: 24px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail .schematic {
    display: none;
  }

  .readouts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 24px;
  }

  .content {
    padding: 32px 0 64px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .section-head p {
    max-width: none;
    text-align: left;
  }

  table {
    min-width: 620px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .page {
    padding: 0 16px;
  }

  .brand-mark {
    font-size: 23px;
  }

  .brand-sub {
    display: none;
  }

  .login-hero h1 {
    font-size: 34px;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form .field,
  .inline-form .field-narrow {
    flex: 1 1 auto;
  }

  .inline-form .button {
    width: 100%;
  }

  .endpoint {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .section-head h2 {
    white-space: normal;
  }

  .modal-panel {
    padding: 24px;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .snippet {
    padding: 16px;
    font-size: 11px;
  }

  .table-wrap {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  #keys-table,
  #users-table {
    display: block;
  }

  #keys-table thead,
  #users-table thead {
    display: none;
  }

  #keys-table tbody,
  #users-table tbody {
    display: block;
  }

  #keys-table tr,
  #users-table tr {
    display: block;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }

  #keys-table tbody tr:last-child,
  #users-table tbody tr:last-child {
    border-bottom: 0;
  }

  #keys-table td,
  #users-table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 5px 0;
    border: 0;
    text-align: right;
  }

  #keys-table td::before,
  #users-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--ink-2);
    font-size: 11px;
    font-weight: 500;
    text-align: left;
  }

  #keys-table td[data-label=""]::before,
  #users-table td[data-label=""]::before {
    display: none;
  }

  #keys-table td:last-child,
  #users-table td:last-child {
    justify-content: flex-end;
  }

  #keys-table tbody tr:hover,
  #users-table tbody tr:hover {
    background: transparent;
  }

  .key-label {
    max-width: 62vw;
  }

  .key-prefix {
    word-break: break-all;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .rail-draw {
    stroke-dashoffset: 0;
  }

  .token {
    display: none;
  }
}
