/* Reusable components. Every colour here comes from a token. */

/* Buttons ----------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: var(--s2) var(--s4);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--accent); color: var(--accent-fg);
  font-size: var(--fs-sm); font-weight: 650; line-height: 1.2;
  text-decoration: none; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--accent-hover); color: var(--accent-fg); }
.btn:active { background: var(--accent-active); }

.btn.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn.secondary:hover { background: var(--surface-2); border-color: var(--text-faint); color: var(--text); }

.btn.quiet { background: transparent; color: var(--text-muted); }
.btn.quiet:hover { background: var(--surface-2); color: var(--text); }

.btn.danger { background: var(--danger); color: var(--surface); }
.btn.danger:hover { background: var(--danger); filter: brightness(1.08); color: var(--surface); }

.btn.danger-quiet { background: transparent; border-color: var(--danger-line); color: var(--danger); }
.btn.danger-quiet:hover { background: var(--danger-soft); color: var(--danger); }

.btn.sm { min-height: 32px; padding: var(--s1) var(--s3); font-size: var(--fs-xs); }
.btn.lg { min-height: 48px; padding: var(--s3) var(--s5); font-size: var(--fs-base); }
.btn.block { width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.btn-icon {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon.sm { width: 26px; height: 26px; }
.btn-icon.sm svg { width: 14px; height: 14px; }
.btn-icon:disabled { opacity: 0.35; pointer-events: none; }

/* Cards ------------------------------------------------------------------- */

.card {
  padding: var(--s5);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.card.tint { background: var(--surface-2); box-shadow: none; }
.card.flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  flex-wrap: wrap; margin-bottom: var(--s4);
}
.card-head p { color: var(--text-muted); font-size: var(--fs-sm); }
.card-sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--s1); }

.stat { display: flex; flex-direction: column; gap: var(--s1); }
.stat-label { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.stat-value { font-size: var(--fs-xl); font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-note { color: var(--text-faint); font-size: var(--fs-xs); }

/* Pills. State is always text plus colour, never colour alone. ------------ */

.pill {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 2px var(--s2); border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap;
}
.pill svg { width: 12px; height: 12px; }
.pill.ok      { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.pill.warn    { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }
.pill.bad     { background: var(--danger-soft);  border-color: var(--danger-line);  color: var(--danger); }
.pill.info    { background: var(--info-soft);    border-color: var(--info-line);    color: var(--info); }
.pill.accent  { background: var(--accent-soft);  border-color: var(--accent-line);  color: var(--accent); }

.dot { width: 7px; height: 7px; border-radius: var(--r-full); background: currentColor; flex: none; }

/* Banners ----------------------------------------------------------------- */

.banner {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); font-size: var(--fs-sm);
}
.banner svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.banner .banner-body { min-width: 0; overflow-wrap: anywhere; }
.banner strong { display: block; }
.banner.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }
.banner.ok   { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.banner.warn { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning); }
.banner.bad  { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* Forms ------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.field > label { font-size: var(--fs-sm); font-weight: 650; }
.field .optional { color: var(--text-faint); font-weight: 500; }
.hint { color: var(--text-muted); font-size: var(--fs-xs); }
.field-error { display: flex; align-items: center; gap: var(--s1); color: var(--danger); font-size: var(--fs-xs); font-weight: 600; }
.field-error svg { width: 13px; height: 13px; flex: none; }

.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: var(--s2) var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-muted); }
.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: var(--s6);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

.check { display: flex; align-items: flex-start; gap: var(--s3); font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

.filedrop {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  padding: var(--s6) var(--s4); text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface-2); color: var(--text-muted);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.filedrop.over { border-color: var(--accent); background: var(--accent-soft); }
.filedrop svg { width: 26px; height: 26px; color: var(--text-faint); }

/* Segmented control ------------------------------------------------------- */

.segmented {
  display: flex; gap: 2px; padding: 3px; overflow-x: auto;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex: none; padding: var(--s1) var(--s3); min-height: 30px;
  border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--text-muted); font-size: var(--fs-xs); font-weight: 650; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Wizard steps ------------------------------------------------------------ */

.steps { display: flex; gap: var(--s1); overflow-x: auto; padding-bottom: var(--s1); scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.steps a, .steps span {
  display: inline-flex; align-items: center; gap: var(--s2); flex: none;
  padding: var(--s2) var(--s3); border-radius: var(--r-md);
  color: var(--text-faint); font-size: var(--fs-xs); font-weight: 650;
  text-decoration: none; white-space: nowrap;
}
.steps a:hover { background: var(--surface-2); color: var(--text); }
.steps .n {
  display: grid; place-items: center; width: 20px; height: 20px; flex: none;
  border: 1px solid currentColor; border-radius: var(--r-full); font-size: 10px;
}
.steps .done { color: var(--text-muted); }
.steps .done .n { background: var(--success-soft); border-color: var(--success-line); color: var(--success); }
.steps [aria-current="step"] { background: var(--accent-soft); color: var(--accent); }
.steps [aria-current="step"] .n { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }

/* Lists and tables.
   One markup shape at every width: cards on small screens, a real column grid
   once there is room. The table is never squeezed, it reflows. */

.dl { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.dl-head { display: none; }
.dl-row {
  display: grid; gap: var(--s2) var(--s4); align-items: center;
  padding: var(--s4);
  border-top: 1px solid var(--border);
  text-align: left; width: 100%;
}
.dl-row:first-of-type { border-top: 0; }
button.dl-row, a.dl-row { background: transparent; color: inherit; text-decoration: none; border-left: 0; border-right: 0; border-bottom: 0; }
button.dl-row:hover, a.dl-row:hover { background: var(--surface-2); color: inherit; }
.dl-title { font-weight: 650; }
.dl-sub { color: var(--text-muted); font-size: var(--fs-sm); }
.dl-meta { color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.dl-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

@media (min-width: 46rem) {
  .dl-head {
    display: grid; gap: var(--s4); align-items: center;
    padding: var(--s2) var(--s4);
    background: var(--surface-2); border-bottom: 1px solid var(--border);
    color: var(--text-muted); font-size: var(--fs-xs); font-weight: 700;
    letter-spacing: 0.05em; text-transform: uppercase;
  }
  .dl-4 .dl-head, .dl-4 .dl-row { grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr) minmax(0, 1fr) auto; }
  .dl-3 .dl-head, .dl-3 .dl-row { grid-template-columns: minmax(0, 2.4fr) minmax(0, 1.2fr) auto; }
  .dl-2 .dl-head, .dl-2 .dl-row { grid-template-columns: minmax(0, 1fr) auto; }
  .dl-num { text-align: right; justify-self: end; }
}

.kv { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: var(--s2) var(--s4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.summary-row { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.summary-row:first-child { border-top: 0; }
.summary-row span { color: var(--text-muted); }
.summary-row strong { font-weight: 650; text-align: right; overflow-wrap: anywhere; }

.scroll-x { overflow-x: auto; }

.hash { font-family: var(--font-mono); font-size: var(--fs-xs); overflow-wrap: anywhere; color: var(--text-muted); }

/* Timeline ---------------------------------------------------------------- */

.timeline { display: flex; flex-direction: column; }
.timeline-item { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: var(--s3); padding-bottom: var(--s4); }
.timeline-rail { display: flex; flex-direction: column; align-items: center; gap: var(--s1); }
.timeline-dot { width: 9px; height: 9px; margin-top: 6px; border-radius: var(--r-full); background: var(--border-strong); flex: none; }
.timeline-dot.ok { background: var(--success); }
.timeline-dot.bad { background: var(--danger); }
.timeline-dot.accent { background: var(--accent); }
.timeline-line { width: 1px; flex: 1 1 auto; background: var(--border); }
.timeline-item:last-child .timeline-line { display: none; }
.timeline-body { min-width: 0; padding-bottom: var(--s1); }
.timeline-title { font-size: var(--fs-sm); font-weight: 650; }
.timeline-meta { color: var(--text-muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Empty, loading and error states ----------------------------------------- */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--s3);
  padding: var(--s7) var(--s4); text-align: center;
  border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface);
}
.empty-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r-full); background: var(--surface-2); color: var(--text-faint); }
.empty-icon svg { width: 22px; height: 22px; }
.empty h3 { font-size: var(--fs-md); }
.empty p { max-width: 40ch; color: var(--text-muted); font-size: var(--fs-sm); }

.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.skeleton-line { height: 12px; }
.skeleton-row { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); border-top: 1px solid var(--border); }
.skeleton-row:first-child { border-top: 0; }

.spinner {
  width: 16px; height: 16px; flex: none; border-radius: var(--r-full);
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 700ms linear infinite;
}

/* Toasts ------------------------------------------------------------------ */

.toasts {
  position: fixed; z-index: 60; inset: auto var(--s4) var(--s4) var(--s4);
  display: flex; flex-direction: column-reverse; gap: var(--s2);
  pointer-events: none;
}
@media (min-width: 40rem) { .toasts { left: auto; width: min(24rem, calc(100vw - var(--s8))); } }
.toast {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm); pointer-events: auto;
  animation: toast-in var(--dur) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.toast.ok  { border-color: var(--success-line); color: var(--success); }
.toast.bad { border-color: var(--danger-line); color: var(--danger); }
.toast .toast-body { min-width: 0; color: var(--text); overflow-wrap: anywhere; }

/* Dialog ------------------------------------------------------------------ */

.scrim {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  padding: var(--s4);
  background: var(--scrim);
  animation: fade var(--dur) var(--ease);
}
@media (min-width: 40rem) { .scrim { align-items: center; } }
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: 100%; max-width: 34rem; max-height: calc(100vh - var(--s7));
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-lg);
  animation: dialog-in var(--dur) var(--ease);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px); } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.dialog-body { padding: var(--s5); overflow-y: auto; }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); background: var(--surface-2); }

/* Fullscreen dialogs, for work that needs the whole of a phone — signing your name, mostly. */
.dialog.fullscreen { max-width: none; max-height: none; height: 100%; border-radius: 0; border: 0; }
.dialog.fullscreen .dialog-body { display: flex; flex-direction: column; }
.dialog.fullscreen .grow-panel { flex: 1 1 auto; display: flex; flex-direction: column; }
.dialog.fullscreen .sigpad-panel { flex: 1 1 auto; }
.dialog.fullscreen .sigpad { flex: 1 1 auto; aspect-ratio: auto; min-height: 40vh; }
.scrim:has(.dialog.fullscreen) { padding: 0; }

/* Small variants used by dense editors. */
.input.sm { min-height: 32px; padding: var(--s1) var(--s2); font-size: var(--fs-sm); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: var(--s3); }

/* Account menu ------------------------------------------------------------ */

.menu-wrap { position: relative; }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; flex: none;
  border: 1px solid var(--border); border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.02em;
}
.menu {
  position: absolute; right: 0; top: calc(100% + var(--s2)); z-index: 40;
  min-width: 14rem; padding: var(--s2);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow-lg);
}
.menu-label { padding: var(--s2) var(--s3); color: var(--text-muted); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.menu-sep { height: 1px; margin: var(--s1) 0; background: var(--border); }
.menu button, .menu a {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  padding: var(--s2) var(--s3); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text);
  font-size: var(--fs-sm); font-weight: 600; text-align: left; text-decoration: none;
}
.menu button:hover, .menu a:hover { background: var(--surface-2); color: var(--text); }
.menu svg { width: 15px; height: 15px; flex: none; color: var(--text-muted); }

/* Paging ------------------------------------------------------------------ */

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3); flex-wrap: wrap;
  padding: var(--s3) var(--s1) 0;
}

/* Section tabs -----------------------------------------------------------
   For a top-level section that holds several screens under one nav entry.
   State lives on aria-current, like .steps above. */
.subnav { display: flex; gap: var(--s1); overflow-x: auto; margin-bottom: var(--s5); scrollbar-width: none; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  flex: none; padding: var(--s2) var(--s3); border-radius: var(--r-full);
  color: var(--text-muted); font-size: var(--fs-sm); font-weight: 650;
  text-decoration: none; white-space: nowrap;
}
.subnav a:hover { background: var(--surface-2); color: var(--text); }
.subnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

/* A checkbox that sits inline in a toolbar row rather than stacking as a form field. */
.inline-check { display: inline-flex; align-items: center; gap: var(--s2); white-space: nowrap; cursor: pointer; }
.inline-check input { margin: 0; }
