/*
  weave.css — the whole front-end, hand-authored. Replaces vendored Bulma (ADR-0030).

  One file on purpose: small, hand-editable, no build step, no CDN, no third-party request.
  Token-driven via custom properties on :root / .theme-light so a dark theme is a later variable
  swap behind the existing <html class="theme-light"> seam.

  Fonts are self-hosted woff2 (latin subset) referenced by plain /static paths — this file is NOT
  templated, so it cannot call static_url(). The font files therefore carry no ?v= cache-bust and
  must be renamed on change (treat as immutable; see ImmutableStaticFiles in core/templating.py).

  Aesthetic: brutalist + contemporary. Structural, blunt, high-contrast, honest about money.
  Hard 2px ink borders, zero radius, a signature 4px offset shadow, one sharp vermilion accent,
  monospace for every figure (money-as-data = honest). Motion is latency-first: a single CSS-only
  staggered page-load reveal, and a snappy press that collapses the shadow. Nothing else moves.
*/

/* --- Self-hosted type (woff2, latin subset). Both weights live in one variable file per family. --- */
@font-face {
  font-family: "DxBurst";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/dx-burst-smooth.woff2") format("woff2");
}
@font-face {
  font-family: "DxBurst";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/dx-burst-smooth.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/noto-sans-mono-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/noto-sans-mono-latin.woff2") format("woff2");
}

/* --- Design tokens. Light palette today; :root + .theme-light so a .theme-dark just overrides. --- */
:root,
.theme-light {
  --paper: #f4f1e9; /* warm off-white field */
  --paper-2: #ece7da; /* a half-step down, for inset rows / static chips */
  --ink: #14110e; /* near-black — text, borders, the offset shadow */
  --ink-60: #5b554c; /* muted ink for secondary text */
  --accent: #ff4a1c; /* vermilion — brand + primary action */
  --accent-ink: #ffffff; /* text on the accent */
  --ok: #1f7a45; /* flat green — settled */
  --warn: #b8761a; /* amber — outstanding / caution */
  --line: 2px; /* the one border weight */
  --shadow: 4px 4px 0 var(--ink); /* signature offset shadow */
  --shadow-press: 1px 1px 0 var(--ink);
  --display: "DxBurst", system-ui, sans-serif;
  --sans: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: "Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --gut: 1.25rem; /* base gutter */
  --maxw: 56rem; /* content measure */
}

/* --- Reset-ish base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 1.0625rem;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Money, codes, status, weights — every figure is monospace + tabular so columns line up. */
.mono,
.num,
.chip,
code,
input[inputmode="decimal"],
input[inputmode="numeric"],
input[type="tel"] {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* --- Skip link (a11y) --- */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  font-weight: 700;
}
.skip-link:focus {
  left: 0;
}

/* --- App header / global nav --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gut);
  flex-wrap: wrap;
  padding: 0.85rem clamp(1rem, 4vw, 2rem);
  background: var(--paper);
  border-bottom: var(--line) solid var(--ink);
}
.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-right: 0.55rem;
  background: var(--accent);
  vertical-align: baseline;
}
.nav {
  display: flex;
  align-items: center;
  gap: 0.4rem 1.1rem;
  flex-wrap: wrap;
}
.nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.35rem 0;
  border-bottom: var(--line) solid transparent;
}
.nav a:hover,
.nav a[aria-current="page"] {
  border-bottom-color: var(--accent);
}
.nav form {
  margin: 0;
  display: inline;
}
.nav-phone {
  /* the logged-in phone number, sitting at the head of the authed nav */
  font-size: 0.85rem;
  color: var(--ink-60);
  align-self: center;
}

/* Archived-threads disclosure on the list page */
.archived-list {
  margin-top: 2rem;
}
.archived-list summary {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.9rem;
  cursor: pointer;
}
.archived-list ul {
  margin: 0.8rem 0 0;
  padding-left: 1.1rem;
}

/* --- Page shell + footer --- */
.shell {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.75rem) clamp(1rem, 4vw, 2rem) 3.5rem;
}
.site-footer {
  flex-shrink: 0;
  border-top: var(--line) solid var(--ink);
  background: var(--paper-2);
  padding: 1.25rem clamp(1rem, 4vw, 2rem);
  font-size: 0.85rem;
  color: var(--ink-60);
}
.site-footer a {
  color: var(--ink);
}

/* --- Headings & text --- */
h1,
h2,
h3 {
  font-family: var(--display);
}
h1 {
  font-weight: 700;
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}
h2 {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 2.25rem 0 0.5rem;
}
h3 {
  font-weight: 700;
  font-size: 1.15rem;
  margin: 1.5rem 0 0.4rem;
}
p {
  margin: 0 0 1rem;
}
a {
  color: var(--accent);
}
strong {
  font-weight: 700;
}
.lede {
  font-size: 1.15rem;
  color: var(--ink-60);
  margin: 0 0 1.5rem;
  max-width: 44rem;
}
.muted {
  color: var(--ink-60);
}
.eyebrow {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--ink-60);
  margin: 0 0 0.4rem;
}
.help {
  font-size: 0.85rem;
  color: var(--ink-60);
  margin: 0.4rem 0 0;
}
.help.error {
  color: var(--accent);
  font-weight: 700;
}
.prose > * + * {
  margin-top: 1rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px; /* mobile tap target */
  padding: 0.55rem 1.1rem;
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--paper);
  border: var(--line) solid var(--ink);
  cursor: pointer;
  transition: transform 0.04s linear, box-shadow 0.04s linear;
}
.btn:hover {
  background: var(--paper-2);
}
.btn:active {
  transform: translate(3px, 3px);
  box-shadow: var(--shadow-press);
}
.btn-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--ink);
  box-shadow: var(--shadow);
}
.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.06);
}
.btn-primary:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--ink);
}
.btn-ok {
  color: var(--accent-ink);
  background: var(--ok);
}
.btn-ok:hover {
  background: var(--ok);
  filter: brightness(1.08);
}
.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}
.btn-text {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  text-transform: none;
  letter-spacing: 0;
  text-decoration: underline;
  padding-left: 0;
  padding-right: 0;
  min-height: 0;
}
.btn-text:hover {
  background: transparent;
  color: var(--accent);
}
.btn-static {
  /* a non-interactive label that visually matches an input row (profile platform name) */
  cursor: default;
  background: var(--paper-2);
  justify-content: flex-start;
  text-transform: none;
  letter-spacing: 0;
}
.btn-static:active {
  transform: none;
  box-shadow: none;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 1.25rem 0 0;
}
.btn-row.end {
  justify-content: flex-end;
  margin: 0;
}

/* --- Forms --- */
.field {
  margin: 0 0 1.1rem;
}
.label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.4rem;
}
.input,
.textarea,
.select select {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.7rem;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: var(--line) solid var(--ink);
  border-radius: 0;
  appearance: none;
}
.textarea {
  resize: vertical;
  line-height: 1.4;
}
.input:focus,
.textarea:focus,
.select select:focus {
  outline: none;
  box-shadow: var(--shadow);
}
.select {
  position: relative;
  display: block;
}
.select::after {
  content: "";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-right: var(--line) solid var(--ink);
  border-bottom: var(--line) solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select select {
  padding-right: 2rem;
}

/* Addon row: input flush against a trailing button (invite, profile handle). */
.field.addons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: stretch;
}
.field.addons .input {
  flex: 1 1 12rem;
}
/* A form that contributes its controls directly to a parent .addons flex row (so a separate
   Save form and Remove form share one row — forms can't nest). */
.addons-form {
  display: contents;
}
.field.grouped {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  margin: 0 0 1.1rem;
}
.field-expand {
  flex: 1 1 auto;
}
.field-narrow {
  width: 7rem;
  flex: 0 0 auto;
}

/* --- Cards / panels --- */
.card {
  background: #fff;
  border: var(--line) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin: 0 0 1.25rem;
}
.card > :first-child {
  margin-top: 0;
}
.card > :last-child {
  margin-bottom: 0;
}

/* Pay-link list under a member's share (deep links + copy-paste fallbacks). */
.paylinks {
  margin-top: 0.4rem;
}
.paylinks a,
.paylinks span {
  display: block;
  font-size: 0.8rem;
  font-family: var(--sans);
}

/* Secondary "use email instead / different number" link sitting below a form. */
.alt-action {
  margin-top: 1.6rem;
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto; /* mobile: scroll wide tables rather than crush them */
  border: var(--line) solid var(--ink);
  margin: 1.25rem 0;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 32rem;
}
.table th,
.table td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: var(--line) solid var(--ink);
  vertical-align: top;
}
.table thead th {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--ink);
  color: var(--paper);
}
.table tbody tr:last-child td {
  border-bottom: none;
}
.table tbody tr:nth-child(even) td {
  background: var(--paper);
}
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.right {
  text-align: right;
}

/* --- Status chips. Raw token stays in data-status (string-asserting tests); CSS supplies color. --- */
.chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem;
  border: var(--line) solid var(--ink);
  background: var(--paper-2);
  color: var(--ink);
  white-space: nowrap;
}
.chip[data-status="settled_external"],
.chip[data-status="accepted"],
.chip[data-status="active"] {
  background: var(--ok);
  color: #fff;
}
.chip[data-status="outstanding"],
.chip[data-status="invited"],
.chip[data-status="pending"],
.chip[data-status="draft"] {
  background: var(--warn);
  color: #fff;
}
.chip[data-status="waived"] {
  background: var(--paper-2);
  color: var(--ink-60);
}
.chip-flag {
  /* secondary informational chip (e.g. "paid reply received") */
  background: #fff;
  color: var(--ink);
  border-style: dashed;
}

/* --- Banners (notifications) --- */
.banner {
  border: var(--line) solid var(--ink);
  border-left-width: 8px;
  padding: 0.85rem 1rem;
  margin: 0 0 1.25rem;
  background: #fff;
  font-weight: 500;
}
.banner.error {
  border-left-color: var(--accent);
}
.banner.warn {
  border-left-color: var(--warn);
}
.banner.info {
  border-left-color: var(--ink);
}
.banner.ok {
  border-left-color: var(--ok);
}

/* --- Tab bar (thread workspace) --- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: var(--line) solid var(--ink);
  margin: 1.25rem 0 1.5rem;
}
.tab {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-decoration: none;
  color: var(--ink);
  background: transparent;
  border: var(--line) solid transparent;
  border-bottom: var(--line) solid var(--ink);
  margin-bottom: calc(-1 * var(--line));
}
.tab:hover {
  background: var(--paper-2);
}
.tab[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
}

/* --- Thread workspace header --- */
.thread-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.thread-head h1 {
  margin: 0;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
}

/* --- Landing hero --- */
.hero {
  border: var(--line) solid var(--ink);
  box-shadow: var(--shadow);
  background: #fff;
  padding: clamp(1.75rem, 5vw, 3rem);
  margin: 0 0 2rem;
}
.hero h1 {
  font-size: clamp(2.6rem, 9vw, 4.5rem);
}
.hero .lede {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  color: var(--ink);
}
.hero > :first-child {
  margin-top: 0;
}
.hero > :last-child {
  margin-bottom: 0;
}

/* --- How-it-works steps (landing page) --- */
.how-it-works {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.step {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  background: #fff;
  border: var(--line) solid var(--ink);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}
.step-num {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  flex-shrink: 0;
}
.step-text {
  margin: 0;
}
.step + .step {
  margin-top: 0.75rem;
}

/* --- A11y: hard, unmistakable focus ring (keyboard) --- */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* --- Motion: one staggered page-load reveal. Honors reduced-motion. --- */
@media (prefers-reduced-motion: no-preference) {
  .shell > * {
    animation: rise 0.4s both;
    animation-delay: calc(var(--reveal-step, 0) * 60ms);
  }
  .shell > *:nth-child(1) {
    --reveal-step: 0;
  }
  .shell > *:nth-child(2) {
    --reveal-step: 1;
  }
  .shell > *:nth-child(3) {
    --reveal-step: 2;
  }
  .shell > *:nth-child(4) {
    --reveal-step: 3;
  }
  .shell > *:nth-child(5) {
    --reveal-step: 4;
  }
  .shell > *:nth-child(n + 6) {
    --reveal-step: 5;
  }
  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* --- Small screens: stack the header, free up tap room --- */
@media (max-width: 30rem) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }
  h2 {
    margin-top: 1.75rem;
  }
}
