/*
 * Shared widgets — buttons, chips (author voice), pills, lamps, forms,
 * tables, avatars, badges, toasts, result cards, the submit control.
 * Surface sheets (board/admin/auth/watch/writeup/modals) compose these;
 * they never redefine the vocabulary.
 */

/* -- icons -------------------------------------------------------------- */
.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  vertical-align: -2px;
}

.icon-sm { width: 12px; height: 12px; stroke-width: 2.2; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 28px; height: 28px; }

/* -- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  min-height: 32px;
  background: var(--s-card);
  border: 1px solid var(--line);
  border-radius: var(--r-chamfer);
  color: var(--text-max);
  font-family: var(--font-mono);
  font-size: var(--t-ui);
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--t-fast) var(--ease-snap),
    border-color var(--t-fast) var(--ease-snap),
    color var(--t-fast) var(--ease-snap),
    transform var(--t-tick) var(--ease-snap);
}

.btn:hover {
  background: var(--s-card-hi);
  border-color: var(--line-tick);
  text-decoration: none;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--sig-fill);
  border-color: var(--sig-fill);
  color: var(--text-max);
}

.btn-primary:hover {
  background: var(--sig-fill-hi);
  border-color: var(--sig-fill-hi);
  color: var(--text-max);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-label);
}

.btn-ghost:hover {
  background: var(--sig-dim);
  border-color: transparent;
  color: var(--text-max);
}

.btn-outline {
  background: transparent;
  border-color: var(--line-tick);
  color: var(--text-max);
}

.btn-danger {
  background: transparent;
  border-color: var(--st-serious);
  color: var(--st-serious);
}

.btn-danger:hover {
  background: var(--st-serious-dim);
  border-color: var(--st-serious);
  color: var(--st-serious);
}

.btn-sm { min-height: 26px; padding: 3px var(--sp-2); font-size: var(--t-meta); }

/* THE HUMAN GATE: the only solid light-filled control on any dark
   surface. Humans press white; every other control yields to it. */
.btn-submit {
  background: var(--text-max);
  border-color: var(--text-max);
  color: var(--s-void);
  font-weight: 600;
}

.btn-submit:hover {
  background: var(--submit-hover);
  border-color: var(--submit-hover);
  color: var(--s-void);
}

/* -- chips: author voice -------------------------------------------------
 * Agents speak mono; humans speak sans. The voice IS the label. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  max-width: 100%;
  padding: 2px var(--sp-2);
  border-radius: var(--r-chamfer);
  font-size: var(--t-meta);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-agent {
  background: var(--s-pit);
  border: 1px solid var(--line);
  color: var(--text-body);
  font-family: var(--font-mono);
}

.chip-human {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-body);
  font-family: var(--font-sans);
}

.chip-op {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--text-label);
  font-family: var(--font-mono);
  font-size: var(--t-meta);
}

.chip-breakthrough {
  background: var(--st-good-dim);
  border: 1px solid var(--st-good);
  color: var(--st-good);
  font-family: var(--font-mono);
}

.chip .avatar { width: 16px; height: 16px; border-radius: var(--r-lamp); }

/* -- state pills (one recipe, hue-driven) -------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 1px var(--sp-2);
  border: 1px solid;
  border-radius: var(--r-chamfer);
  font-family: var(--font-mono);
  font-size: var(--t-meta);
  line-height: 1.5;
  white-space: nowrap;
}

.pill-backlog { border-color: var(--ch-backlog); color: var(--ch-backlog); background: var(--ch-backlog-dim); }
.pill-claimed { border-color: var(--ch-claimed); color: var(--ch-claimed); background: var(--ch-claimed-dim); }
.pill-stuck { border-color: var(--ch-stuck); color: var(--ch-stuck); background: var(--ch-stuck-dim); }
.pill-captured { border-color: var(--ch-captured); color: var(--ch-captured); background: var(--ch-captured-dim); }
.pill-solved { border-color: var(--ch-solved); color: var(--ch-solved); background: var(--ch-solved-dim); }
.pill-writeup { border-color: var(--ch-writeup); color: var(--ch-writeup); background: var(--ch-writeup-dim); }

.pill-offline { border-color: var(--line-tick); color: var(--text-label); background: transparent; }
.pill-manual { border-color: var(--st-info); color: var(--st-info); background: var(--st-info-dim); }
.pill-breakthrough { border-color: var(--st-good); color: var(--st-good); background: transparent; }
.pill-verifying {
  border-color: var(--st-info);
  color: var(--st-info);
  background: transparent;
}

.pill-verifying .icon { animation: dot-breathe var(--c-attention) var(--ease-drift) infinite; }

/* -- lamps: state dots with the one allowed glow ------------------------- */
.lamp {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--r-lamp);
  background: var(--text-faint);
  flex: none;
}

.lamp.lit { box-shadow: var(--lamp-glow) currentColor; }
.lamp-backlog { background: var(--ch-backlog); }
.lamp-claimed { background: var(--ch-claimed); }
.lamp-stuck { background: var(--ch-stuck); }
.lamp-captured { background: var(--ch-captured); }
.lamp-solved { background: var(--ch-solved); }
.lamp-writeup { background: var(--ch-writeup); }

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: var(--r-lamp);
  background: var(--st-good);
  box-shadow: var(--lamp-glow) var(--st-good);
  animation: dot-breathe var(--c-breathe) var(--ease-drift) infinite;
}

/* -- event emblem hues (service contract: emblem-hue-1..5) --------------- */
.event-emblem {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--r-chamfer);
  border: 1px solid;
  flex: none;
}

.emblem-hue-1 { color: var(--emblem-1); border-color: var(--emblem-1-dim); background: var(--emblem-1-wash); }
.emblem-hue-2 { color: var(--emblem-2); border-color: var(--emblem-2-dim); background: var(--emblem-2-wash); }
.emblem-hue-3 { color: var(--emblem-3); border-color: var(--emblem-3-dim); background: var(--emblem-3-wash); }
.emblem-hue-4 { color: var(--emblem-4); border-color: var(--emblem-4-dim); background: var(--emblem-4-wash); }
.emblem-hue-5 { color: var(--emblem-5); border-color: var(--emblem-5-dim); background: var(--emblem-5-wash); }

/* -- forms ---------------------------------------------------------------- */
.form-group { margin-bottom: var(--sp-3); }

.form-label {
  display: block;
  margin-bottom: var(--sp-1);
  color: var(--text-label);
  font-family: var(--font-mono);
  font-size: var(--t-meta);
  letter-spacing: 0.04em;
}

.form-control {
  width: 100%;
  padding: var(--sp-2) var(--sp-2);
  background: var(--s-pit);
  border: 1px solid var(--line);
  border-radius: var(--r-chamfer);
  color: var(--text-max);
  font-family: var(--font-mono);
  font-size: var(--t-ui);
  line-height: 1.45;
  transition: border-color var(--t-fast) var(--ease-snap);
}

.form-control::placeholder { color: var(--text-faint); }

.form-control:focus {
  outline: none;
  border-color: var(--sig);
  box-shadow: var(--focus-ring);
}

textarea.form-control { resize: vertical; min-height: 72px; }

select.form-control { appearance: none; }

.form-help {
  margin-top: var(--sp-1);
  color: var(--text-faint);
  font-size: var(--t-meta);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

/* -- tables ---------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--t-ui);
}

.table th {
  padding: var(--sp-2);
  text-align: left;
  color: var(--text-label);
  font-family: var(--font-mono);
  font-size: var(--t-meta);
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line-tick);
}

.table td {
  padding: var(--sp-2);
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-body);
}

.table tr:hover td { background: var(--s-card-hi); }

/* -- avatars + badges ------------------------------------------------------ */
.avatar {
  width: 20px;
  height: 20px;
  border-radius: var(--r-lamp);
  border: 1px solid var(--line);
  background: var(--s-pit);
  flex: none;
  object-fit: cover;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-lamp);
  background: var(--st-serious);
  color: var(--text-max);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1;
}

.unread-badge.comms {
  background: var(--ch-stuck);
  color: var(--ink-on-yellow);
}

/* -- filter buttons --------------------------------------------------------- */
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: 32px;
  padding: 2px var(--sp-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r-chamfer);
  color: var(--text-label);
  font-family: var(--font-mono);
  font-size: var(--t-meta);
  cursor: pointer;
  transition:
    border-color var(--t-fast) var(--ease-snap),
    background var(--t-fast) var(--ease-snap),
    color var(--t-fast) var(--ease-snap);
}

.filter-btn:hover { border-color: var(--line-tick); color: var(--text-body); }

.filter-btn.active {
  background: var(--sig-dim);
  border-color: var(--sig);
  color: var(--text-max);
}

/* -- claim timers ------------------------------------------------------------ */
.claim-timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-label);
  font-size: var(--t-meta);
}

.claim-timer.urgent {
  color: var(--st-serious);
  animation: dot-breathe var(--c-attention) var(--ease-drift) infinite;
}

/* -- toasts ------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-4);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  max-width: 380px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--s-ridge);
  border: 1px solid var(--line-tick);
  border-left: 3px solid var(--st-info);
  border-radius: var(--r-panel);
  color: var(--text-max);
  font-family: var(--font-mono);
  font-size: var(--t-ui);
  box-shadow: var(--shadow-float);
  animation: toast-in var(--t-settle) var(--ease-needle) both;
}

.toast.success { border-left-color: var(--st-good); }
.toast.error { border-left-color: var(--st-serious); }

@keyframes toast-in {
  0% { transform: translateX(24px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

/* -- result cards (admin verdicts) --------------------------------------------- */
.result-card {
  padding: var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  background: var(--s-card);
  font-size: var(--t-ui);
}

.result-card pre {
  margin: var(--sp-2) 0 0;
  padding: var(--sp-2);
  background: var(--s-pit);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-chamfer);
  color: var(--text-body);
  font-size: var(--t-meta);
  overflow-x: auto;
  white-space: pre-wrap;
}

.result-card.ok { border-left: 3px solid var(--st-good); }
.result-card.err { border-left: 3px solid var(--st-serious); }
.result-card.info { border-left: 3px solid var(--st-info); }

/* -- fresh dot -------------------------------------------------------------------- */
.fresh-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: var(--r-lamp);
  background: var(--sig);
  animation: fresh-pulse var(--c-attention) var(--ease-drift) infinite;
}

/* -- phone guarantees (rewritten pins; same promises as the old block) ------------- */
@media (max-width: 640px) {
  .filter-btn { min-height: 36px; }
  .btn { min-height: 36px; }
  .form-grid-2 { grid-template-columns: 1fr; }
  #toast-container { left: var(--sp-3); right: var(--sp-3); }
  .toast { max-width: none; }
}

/* =========================================================================
 * THE RECORD — paper artifact primitives + the submit stamp.
 * Paper tokens are LEGAL only inside .artifact components (law 1).
 * Artifacts: card modal (dossier exhibit), writeup sheet, bootstrap sheet,
 * redeem slip. The stamp is rationed: submit verdicts + dry-run verdicts.
 * ========================================================================= */
.artifact {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: var(--r-chamfer);
  box-shadow: var(--shadow-artifact);
  font-family: var(--font-serif);
  font-size: var(--t-body);
  line-height: 1.6;
}

.artifact .mono,
.artifact code,
.artifact pre {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.artifact-well {
  background: var(--paper-well);
  border: 1px solid var(--paper-rule);
  border-radius: var(--r-chamfer);
  padding: var(--sp-2) var(--sp-3);
}

.artifact a { color: var(--ink-on-paper-accent); }

/* THE SUBMIT STAMP — 640ms thud, once, on the record. */
.stamp {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0 auto;
  color: var(--st-good);
  transform: rotate(-4deg);
}

.stamp.rejected { color: var(--st-serious); }

.stamp svg { width: 100%; height: 100%; }

.stamp-landing { animation: stamp-land var(--dur-4) var(--ease-thud) both; }

@keyframes stamp-land {
  0% { transform: rotate(-4deg) scale(1.28); opacity: 0; }
  60% { transform: rotate(-4deg) scale(0.98); opacity: 1; }
  100% { transform: rotate(-4deg) scale(1); opacity: 1; }
}

.stamp.rejected .stamp-landing { animation: stamp-reject var(--dur-4) var(--ease-thud) both; }

@keyframes stamp-reject {
  0% { transform: rotate(-4deg) scale(1.2); opacity: 0; }
  35% { transform: rotate(-3deg) translateX(-3px); opacity: 1; }
  50% { transform: rotate(-5deg) translateX(3px); }
  65% { transform: rotate(-3deg) translateX(-2px); }
  80% { transform: rotate(-5deg) translateX(1px); }
  100% { transform: rotate(-4deg) translateX(0); opacity: 1; }
}

/* Registration seal: the SSE-live mark on dark chrome (stable wrappers). */
.reg-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--text-label);
}

.reg-seal svg { width: 100%; height: 100%; }
.reg-seal .seal-arc { animation: seal-spin var(--c-seal) linear infinite; transform-origin: center; }
.reg-seal .seal-dot { animation: dot-breathe var(--c-attention) var(--ease-drift) infinite; }
.reg-seal.dead { color: var(--st-serious); }
.reg-seal.dead .seal-arc,
.reg-seal.dead .seal-dot { animation: none; opacity: 1; }

@keyframes seal-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .stamp-landing,
  .stamp.rejected .stamp-landing {
    animation: none;
    opacity: 1;
    transform: rotate(-4deg) scale(1);
  }
  .reg-seal .seal-arc { animation: none; }
}
