/* Components of js/ui/*. Every control has a hit area of at least 44 x 44 px. */

/* -- buttons ----------------------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--hit);
  min-width: var(--hit);
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r3);
  background: var(--bg3);
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, filter 0.15s;
}

.btn:hover {
  border-color: var(--accent2);
  color: var(--fg);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn[aria-busy="true"] {
  cursor: progress;
}

.btn-primary {
  border: 0;
  background: var(--grad);
  color: var(--bg);
  font-weight: 600;
}

.btn-primary:hover {
  color: var(--bg);
  filter: brightness(1.08);
}

.btn-secondary {
  background: var(--bg3);
}

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

.btn-ghost:hover {
  background: var(--bg3);
  border-color: var(--line);
  color: var(--fg);
}

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

.btn-danger:hover {
  background: var(--tint-err);
  color: var(--fg);
}

.btn-icon {
  padding: 0;
  width: var(--hit);
  border-radius: var(--r1);
}

.btn .icon {
  flex: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
}

/* -- header chips, pills and badges ------------------------------------------------------------------ */

.chip-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  min-height: var(--hit);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r3);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.88rem;
  white-space: nowrap;
}

.chip-link:hover {
  border-color: var(--accent2);
}

.chip-link .icon {
  color: var(--muted);
}

.worker-chip.is-active .icon {
  color: var(--ok);
}

.identity-chip.is-empty {
  border-style: dashed;
  color: var(--accent);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: var(--r3);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--fg);
  white-space: nowrap;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.pill-live .pill-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--tint-ok);
}

.pill-reconnecting .pill-dot,
.pill-connecting .pill-dot {
  background: transparent;
  border: 2px solid var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}

.pill-offline .pill-dot {
  background: var(--err);
  border-radius: 2px;
  transform: rotate(45deg);
}

.pill-paused {
  border-color: var(--warn);
}

.pill-paused .pill-dot {
  background: var(--warn);
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: var(--r3);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: normal;
  overflow-wrap: anywhere;
  border: 1px solid var(--line-strong);
  color: var(--fg);
  background: var(--bg3);
}

.badge-fake {
  border-color: var(--accent2);
  color: var(--accent2-text);
  background: var(--tint-accent2);
}

.gateway-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  text-decoration: none;
}

.gateway-link:hover .badge-fake {
  color: var(--fg);
}

.badge-you {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--tint-accent);
  font-weight: 500;
}

.badge-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge-warn {
  border-color: var(--warn);
  color: var(--warn);
}

.badge-err {
  border-color: var(--err);
  color: var(--err);
}

/* -- language switch --------------------------------------------------------------------------------- */

.lang-switch {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r3);
}

.lang-btn {
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0 var(--s2);
  border: 0;
  border-radius: var(--r3);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.lang-btn[aria-pressed="true"] {
  background: var(--bg3);
  color: var(--fg);
  font-weight: 600;
}

/* -- banners ----------------------------------------------------------------------------------------- */

.banner {
  display: flex;
  gap: var(--s3);
  align-items: flex-start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--r1);
  background: var(--bg2);
  margin-bottom: var(--s4);
}

.banner > .icon {
  flex: none;
  margin-top: 2px;
}

.banner .banner-text {
  flex: 1;
  min-width: 0;
  margin: 0;
}

/* On narrow phones the action goes under the text instead of squeezing it into a column. */
@media (max-width: 479.98px) {
  .banner {
    flex-wrap: wrap;
  }

  .banner .banner-text {
    flex-basis: calc(100% - 40px);
  }

  .banner .banner-action {
    flex-basis: 100%;
  }
}

.banner-info {
  border-left-color: var(--accent2);
}

.banner-info > .icon {
  color: var(--accent2-text);
}

.banner-ok {
  border-left-color: var(--ok);
}

.banner-ok > .icon {
  color: var(--ok);
}

.banner-warn {
  border-left-color: var(--warn);
  background: var(--tint-warn);
}

.banner-warn > .icon {
  color: var(--warn);
}

.banner-error {
  border-left-color: var(--err);
  background: var(--tint-err);
}

.banner-error > .icon {
  color: var(--err);
}

.banner-action {
  flex: none;
}

/* -- cards ------------------------------------------------------------------------------------------- */

.card {
  padding: var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  background: var(--bg2);
  min-width: 0;
}

.card > :last-child {
  margin-bottom: 0;
}

/* -- states ------------------------------------------------------------------------------------------ */

.state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s5) var(--s4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r2);
  background: var(--bg2);
}

.state-loading {
  border-style: solid;
  border-color: var(--line);
}

.state-title {
  font-weight: 600;
  margin: 0;
}

.state-text {
  color: var(--muted);
  margin: 0;
}

.state-error {
  border-style: solid;
  border-color: rgba(255, 107, 139, 0.45);
}

.state-error > .icon {
  color: var(--err);
}

.state-offline > .icon,
.state-paused > .icon {
  color: var(--warn);
}

.state-action {
  margin-top: var(--s2);
}

.skeleton {
  display: grid;
  gap: var(--s2);
  width: 100%;
}

.skeleton-line {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--bg3) 0%, var(--line-strong) 50%, var(--bg3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* -- stepper and timeline ---------------------------------------------------------------------------- */

.stepper {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  list-style: none;
  margin: 0 0 var(--s5);
  padding: 0;
}

.stepper-step {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  color: var(--muted);
  min-height: var(--hit);
}

.stepper-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  font-size: 0.85rem;
  flex: none;
}

.stepper-step.is-done {
  color: var(--fg);
}

.stepper-step.is-done .stepper-mark {
  border-color: var(--ok);
  color: var(--ok);
}

.stepper-step.is-current {
  color: var(--fg);
  font-weight: 600;
}

.stepper-step.is-current .stepper-mark {
  border: 0;
  background: var(--grad);
  color: var(--bg);
}

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

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: var(--s3);
  padding-bottom: var(--s4);
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 2px;
  background: var(--line);
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-mark {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--bg);
  color: var(--ok);
}

.timeline-item.is-done .timeline-mark {
  border-color: var(--ok);
}

.timeline-item.is-current .timeline-mark {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--tint-accent);
}

.timeline-status {
  margin: 0;
  font-weight: 600;
}

.timeline-item:not(.is-done):not(.is-current) .timeline-status {
  color: var(--muted);
  font-weight: 400;
}

.timeline-detail {
  margin-top: var(--s1);
  color: var(--muted);
}

/* -- forms ------------------------------------------------------------------------------------------- */

.field {
  display: grid;
  gap: var(--s1);
  margin-bottom: var(--s4);
  min-width: 0;
}

.field-label {
  font-weight: 600;
}

.field-required {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9em;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.field-error {
  margin: 0;
  color: var(--err);
  font-size: 0.92rem;
}

.input {
  width: 100%;
  min-height: var(--hit);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r1);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.input:focus-visible {
  border-color: var(--accent2);
}

.input[aria-invalid="true"] {
  border-color: var(--err);
}

.textarea {
  resize: vertical;
  line-height: 1.5;
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--s6);
}

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

.error-summary {
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s4);
  border: 1px solid var(--err);
  border-radius: var(--r1);
  background: var(--tint-err);
}

.error-summary-title {
  font-weight: 600;
}

.error-summary ul {
  margin: 0;
  padding-left: var(--s5);
}

.error-summary a {
  display: inline-flex;
  min-height: var(--hit);
  align-items: center;
  color: var(--fg);
}

/* -- chips ------------------------------------------------------------------------------------------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--hit);
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r3);
  background: var(--bg2);
  color: var(--fg);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-align: left;
}

.chip:hover {
  border-color: var(--accent2);
}

.chip-check {
  display: none;
}

.chip.is-on {
  border-color: var(--accent);
  background: var(--tint-accent);
}

.chip.is-on .chip-check {
  display: inline-flex;
  color: var(--accent);
}

/* -- tabs -------------------------------------------------------------------------------------------- */

.tablist {
  display: flex;
  gap: var(--s1);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s4);
  scrollbar-width: thin;
}

.tab {
  min-height: var(--hit);
  padding: 0 var(--s4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  color: var(--fg);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tabpanel:focus-visible {
  outline-offset: 4px;
}

/* -- tables (desktop form; cards under 600 px in layout.css) ------------------------------------------ */

.rtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.rtable caption {
  text-align: left;
  font-weight: 600;
  padding-bottom: var(--s2);
}

/* Cell padding, rules and right-aligned numbers only as a table: under 600 px layout.css turns rows into cards
   with the same specificity, and this file loads later, so these must not apply there. */
.rtable th,
.rtable td {
  text-align: left;
  vertical-align: top;
  min-width: 0;
}

@media (min-width: 600px) {
  .rtable th,
  .rtable td {
    padding: var(--s2) var(--s3);
    border-bottom: 1px solid var(--line);
  }

  .rtable .num {
    text-align: right;
  }
}

.rtable thead th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
}

.rtable tbody th {
  font-weight: 500;
}

/* -- progress ---------------------------------------------------------------------------------------- */

.progress {
  display: grid;
  gap: var(--s1);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.progress-label {
  grid-column: 1 / -1;
  font-size: 0.92rem;
}

.progress-bar {
  width: 100%;
  height: 10px;
  appearance: none;
  border: 0;
  border-radius: var(--r3);
  background: var(--bg3);
  overflow: hidden;
}

.progress-bar::-webkit-progress-bar {
  background: var(--bg3);
  border-radius: var(--r3);
}

.progress-bar::-webkit-progress-value {
  background: var(--grad);
  border-radius: var(--r3);
}

.progress-bar::-moz-progress-bar {
  background: var(--grad);
  border-radius: var(--r3);
}

.progress-text {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* -- code -------------------------------------------------------------------------------------------- */

.code {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--s1);
  border: 1px solid var(--line);
  border-radius: var(--r1);
  background: var(--bg);
  min-width: 0;
}

.code pre {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: var(--s3);
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.5;
}

.code-wrap pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-copy {
  flex: none;
}

/* On phones long lines wrap instead of scrolling sideways with no cue (hashes, JSON, one-line commands). */
@media (max-width: 599.98px) {
  .code pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}

.code-planned {
  border-style: dashed;
}

.code-planned pre {
  color: var(--muted);
}

/* -- amounts, addresses, times ------------------------------------------------------------------------ */

.amount {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.addr {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.addr-text {
  color: var(--fg);
}

a.addr-text {
  color: var(--accent2-text);
}

.time {
  color: var(--muted);
  font-size: 0.92em;
  white-space: nowrap;
}

/* -- agent hint -------------------------------------------------------------------------------------- */

.agent-hint {
  margin-top: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  background: var(--bg2);
}

.agent-hint > summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--hit);
  padding: 0 var(--s4);
  cursor: pointer;
  color: var(--accent2-text);
  list-style: none;
}

.agent-hint > summary::-webkit-details-marker {
  display: none;
}

.agent-hint > summary::after {
  content: "";
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.agent-hint[open] > summary::after {
  transform: rotate(-135deg);
}

.agent-body {
  padding: 0 var(--s4) var(--s4);
}

.agent-intro,
.agent-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.agent-line {
  margin-bottom: var(--s3);
}

.agent-kind {
  margin: 0 0 var(--s1);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.agent-more a {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
}

/* -- dialog ------------------------------------------------------------------------------------------ */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r2);
  background: var(--bg2);
  color: var(--fg);
  box-shadow: var(--shadow);
  overflow: auto;
}

.dialog-lg {
  width: min(820px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(3, 4, 8, 0.72);
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s3) 0 var(--s4);
}

.dialog-title {
  flex: 1;
  margin: 0;
  font-size: 1.2rem;
}

.dialog-body {
  padding: var(--s3) var(--s4);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s2);
  padding: 0 var(--s4) var(--s4);
}

/* -- toasts ------------------------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--s3));
  z-index: 200;
  display: grid;
  gap: var(--s2);
  justify-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s2);
  width: min(520px, 100%);
  padding: var(--s1) var(--s1) var(--s1) var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r2);
  background: var(--bg3);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.toast p {
  flex: 1;
  margin: 0;
}

.toast-error {
  border-color: var(--err);
}

.toast-error > .icon {
  color: var(--err);
}

.toast-warn > .icon {
  color: var(--warn);
}

@media (min-width: 960px) {
  .toasts {
    bottom: var(--s5);
  }
}

/* -- galaxy hero ------------------------------------------------------------------------------------- */

.galaxy {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(1100px 700px at 50% 30%, #221740, #0b0d12 72%);
}

.galaxy > canvas.gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* -- icons ------------------------------------------------------------------------------------------- */

.icon {
  display: inline-block;
  vertical-align: middle;
  flex: none;
}

/* -- placeholders (screens under construction) -------------------------------------------------------- */

.placeholder-note {
  color: var(--muted);
}

/* -- small screens ----------------------------------------------------------------------------------- */

/* The pill keeps its one word at every width (colour is never the only signal, WCAG 1.4.1). */
@media (max-width: 399.98px) {
  .pill {
    padding: 2px 8px;
    font-size: 0.78rem;
  }
}

/* Disclosures that fold part of a page: a chevron says they open (it turns when open). */
.job-asked-box > summary,
.job-tl-later > summary,
.feed-issue-events > summary,
.how-tech > summary {
  list-style: none;
  gap: var(--s2);
}

.job-asked-box > summary::-webkit-details-marker,
.job-tl-later > summary::-webkit-details-marker,
.feed-issue-events > summary::-webkit-details-marker,
.how-tech > summary::-webkit-details-marker {
  display: none;
}

.job-asked-box > summary::after,
.job-tl-later > summary::after,
.feed-issue-events > summary::after,
.how-tech > summary::after,
.learn-details > summary::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin-left: var(--s2);
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.job-asked-box[open] > summary::after,
.job-tl-later[open] > summary::after,
.feed-issue-events[open] > summary::after,
.how-tech[open] > summary::after,
.learn-details[open] > summary::after {
  transform: rotate(-135deg);
}
