/* pay.speare.org: a plain, calm payment page. Neutrals plus one accent (pine,
   #0E6B5C), the platform's system font, light with a dark counterpart.
   Hooks: body.page-<name>, .state-<open|paid|cancelled|expired>, .panel,
   .notice-*, .code-form, .admin, .link-form, .links-table. All copy lives in
   app/templates/. */

:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --sunken: #eef1f0;
  --ink: #16201d;
  --ink-2: #4f5c57;
  --line: #dde3e0;
  --line-strong: #85928d;
  --accent: #0e6b5c;
  --accent-hover: #0a574b;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ed;
  --accent-text: #0b5a4d;
  --selection: #bfe3d9;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #7a4a00;
  --warn-soft: #fff3d6;
  --shadow: 0 1px 2px rgb(22 32 29 / 0.06), 0 6px 20px rgb(22 32 29 / 0.05);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1412;
    --surface: #151d1a;
    --sunken: #1c2622;
    --ink: #e7edea;
    --ink-2: #a5b2ad;
    --line: #28332f;
    --line-strong: #6b7a75;
    --accent: #5cc9b0;
    --accent-hover: #7dd7c2;
    --accent-ink: #06201a;
    --accent-soft: #143530;
    --accent-text: #7dd7c2;
    --selection: #1f5a4e;
    --danger: #f28b80;
    --danger-soft: #3a1815;
    --warn: #eabb62;
    --warn-soft: #33270e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  accent-color: var(--accent);
  caret-color: var(--accent);
  scrollbar-color: var(--line-strong) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); color: var(--ink); }

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.015em; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }

a {
  color: var(--accent-text);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon { flex: none; width: 1.25em; height: 1.25em; }
.icon-lg { width: 2.5rem; height: 2.5rem; }
.nowrap { white-space: nowrap; }

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

/* A code as printed: tabular, spaced, never broken across lines. */
.code-sample {
  display: inline-block;
  padding: 0 0.35em;
  border-radius: 5px;
  background: var(--sunken);
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

/* ---------- Frame ---------- */

.test-banner {
  padding: 0.5rem 1rem;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
}

.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 72rem;
  min-height: 3.5rem;
  margin: 0 auto;
  padding: 0.5rem 1rem;
}
.site-name { font-weight: 650; font-size: 1.0625rem; letter-spacing: -0.01em; }
.site-name a { color: var(--ink); text-decoration: none; }
.site-name a:hover { color: var(--accent-text); }

.site-main {
  flex: 1;
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

.site-footer {
  padding: 1.5rem 1rem 2rem;
  color: var(--ink-2);
  font-size: 0.875rem;
  text-align: center;
}
.site-footer p { display: flex; align-items: center; justify-content: center; gap: 0.4rem; }
.site-footer .build { margin-top: 0.25rem; font-size: 0.75rem; font-variant-numeric: tabular-nums; }

/* ---------- Surfaces ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.25rem;
}

.panel > h1 { font-size: 1.625rem; font-weight: 700; }
.lede { margin-top: 0.625rem; color: var(--ink-2); }
.panel > .lede strong { color: var(--ink); }

.aside {
  margin-top: 1.25rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
  text-align: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-top: 1.5rem;
}

@media (min-width: 30rem) {
  .site-main { padding-top: 3.5rem; }
  .panel { padding: 2rem; }
  .panel > h1 { font-size: 1.875rem; }
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 1.125rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease),
    color 160ms var(--ease), transform 120ms var(--ease);
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

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

.button-secondary { background: var(--surface); border-color: var(--line-strong); }
.button-secondary:hover:not(:disabled) { background: var(--sunken); }

.button-quiet { color: var(--ink-2); }
.button-quiet:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
.button-danger { color: var(--danger); }
.button-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

.button-small { min-height: 2.25rem; padding: 0 0.75rem; font-size: 0.875rem; }

.text-link { font-weight: 600; }

/* ---------- Form fields ---------- */

.field-label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
}
.optional { font-weight: 400; color: var(--ink-2); }
.field-hint { margin-top: 0.125rem; font-size: 0.9375rem; color: var(--ink-2); }
.field-error {
  margin-top: 0.625rem;
  color: var(--danger);
  font-size: 0.9375rem;
  font-weight: 500;
}
.field-error:empty { display: none; }

input[type="text"], input[type="email"], input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.375rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 160ms var(--ease);
}
textarea { min-height: 5.5rem; resize: vertical; line-height: 1.45; }
select { padding-right: 2rem; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  border-radius: var(--radius-sm);
}
input[aria-invalid="true"] { border-color: var(--danger); }
input:disabled { background: var(--sunken); color: var(--ink-2); }

/* The payment code: big, spaced, uppercase even before any JS runs. */
.code-form { margin-top: 1.75rem; }
.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.code-row .code-input { margin-top: 0; }
.code-input {
  min-height: 3.5rem;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}
.code-row .button { min-height: 3.5rem; padding: 0 1.25rem; font-size: 1.0625rem; }
.code-input-small { min-height: 3rem; font-size: 1.125rem; letter-spacing: 0.15em; }

/* Four one-character boxes (code-boxes.js reveals them; no-JS keeps the single
   input above). One group, big and tabular, sized to fit a 320px phone. */
.code-boxes { margin: 0; padding: 0; border: 0; min-width: 0; }
.code-boxes > legend { padding: 0; }
.code-boxes-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.code-box-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 4rem));
  gap: 0.5rem;
}
.code-boxes input.code-box {
  width: 100%;
  min-height: 4rem;
  margin: 0;
  padding: 0;
  font-size: 2rem;
  font-weight: 650;
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  text-align: center;
  text-transform: uppercase;
  caret-color: transparent;
}
.code-boxes input.code-box:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-soft);
}
.code-boxes-submit { min-height: 3.5rem; font-size: 1.0625rem; }
@media (min-width: 30rem) {
  .code-boxes-row { grid-template-columns: auto auto; justify-content: start; align-items: center; }
  .code-boxes-submit { min-height: 4rem; padding: 0 1.5rem; }
}

/* ---------- Payment request ---------- */

.request-title { font-size: 1.625rem; font-weight: 700; }
.request-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  margin-top: 0.5rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.request-description { margin-top: 1rem; white-space: pre-line; overflow-wrap: anywhere; }

.request-amount {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.amount-label { color: var(--ink-2); font-size: 0.9375rem; font-weight: 500; }
.amount {
  margin-top: 0.125rem;
  font-size: clamp(2.25rem, 9vw, 3rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.request-expiry { margin-top: 0.5rem; color: var(--ink-2); font-size: 0.9375rem; }
.state-cancelled .amount, .state-expired .amount { color: var(--ink-2); }

.pay-form { margin-top: 1.5rem; display: grid; gap: 1rem; }
.pay-form .button-pay { margin-top: 0.25rem; }
.stripe-element { min-height: 2.5rem; }
.pay-message { margin: 0; }
.button-pay {
  width: 100%;
  min-height: 3.5rem;
  font-size: 1.125rem;
}
.pay-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  color: var(--ink-2);
  font-size: 0.875rem;
  text-align: center;
}

@media (min-width: 30rem) {
  .request-title { font-size: 1.875rem; }
}

/* ---------- Notices ---------- */

.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  margin-top: 1.25rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
}
.notice .icon { margin-top: 0.1em; color: var(--ink-2); }
.notice-paid { background: var(--accent-soft); }
.notice-paid .icon { color: var(--accent-text); }
.notice-paid span { font-weight: 600; }
.notice-review, .notice-processing, .notice-disabled { background: var(--warn-soft); }
.notice-review .icon, .notice-processing .icon, .notice-disabled .icon { color: var(--warn); }
.notice-error { background: var(--danger-soft); }
.notice-error .icon { color: var(--danger); }

/* ---------- Message Nick (fleet feedback widget) ---------- */

.message-nick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}
.notice + .message-nick { justify-content: flex-start; margin-top: 1rem; }
/* The widget's own floating pill: our buttons open it instead. */
.fbw-root { display: none !important; }
:root { --fbw-accent: var(--accent); }

/* ---------- Thanks ---------- */

.thanks-mark { margin-bottom: 1rem; }
.thanks-mark-paid { color: var(--accent-text); }
.thanks-mark-pending { color: var(--warn); }

/* ---------- Admin ---------- */

.page-admin .site-main { max-width: 72rem; padding-top: 1.5rem; }

.admin-nav { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.admin-user {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.logout-form { margin: 0; flex: none; }

.admin { display: grid; gap: 1.5rem; }
.admin-status:empty { display: none; }
.admin-status {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}

.section-title { font-size: 1.25rem; font-weight: 700; }

.admin-form-section { container-type: inline-size; }
.link-form { margin-top: 1.25rem; display: grid; gap: 1rem; }
.field { min-width: 0; }
.field-row { display: grid; gap: 1rem; }
.field-row-amount { grid-template-columns: minmax(0, 1fr) 6.5rem; }
.amount-input { font-variant-numeric: tabular-nums; font-size: 1.125rem; font-weight: 600; }
.link-form .field-error { margin-top: 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

@container (min-width: 30rem) {
  .field-row:not(.field-row-amount) { grid-template-columns: 1fr 1fr; }
}
/* Wide: title, amount and currency on one line; the rest four across. */
@container (min-width: 52rem) {
  .link-form { grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: 1.25rem; }
  .link-form .field-row { display: contents; }
  .link-form > .field:first-of-type { grid-column: 1 / 3; grid-row: 1; }
  .field-row-amount > .field:first-child { grid-column: 3; grid-row: 1; }
  .field-row-amount > .field:last-child { grid-column: 4; grid-row: 1; }
  .link-form > .field:nth-of-type(2) { grid-column: 1 / -1; grid-row: 2; }
  .link-form > .field-error, .link-form > .form-actions { grid-column: 1 / -1; }
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}
.filter { display: flex; align-items: center; gap: 0.5rem; }
.filter select { width: auto; min-width: 8.5rem; margin-top: 0; min-height: 2.5rem; padding-block: 0.375rem; }

.table-wrap {
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.links-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.links-table th {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.links-table td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.links-table tbody tr:last-child td { border-bottom: 0; }
.links-table tbody tr:hover { background: color-mix(in srgb, var(--sunken) 55%, transparent); }
.links-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.link-code a { font-weight: 650; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.link-title { overflow-wrap: anywhere; }
.link-created, .link-paid { color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.link-actions { text-align: left; white-space: nowrap; }
.link-actions .button + .button { margin-left: 0.25rem; }
.links-empty { padding: 2rem 1rem; color: var(--ink-2); text-align: center; }
.list-paging { margin-top: 1rem; text-align: center; }
.list-paging:has(> [hidden]) { display: none; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  background: var(--sunken);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 0.5rem; height: 0.5rem;
  border-radius: 50%;
  background: currentColor;
}
.status-open::before { background: var(--accent); }
.status-paid { background: var(--accent-soft); color: var(--accent-text); }
.status-expired { color: var(--ink-2); }
.status-cancelled { background: var(--danger-soft); color: var(--danger); }

/* Narrow lists: each link becomes a stacked row with its own labels. */
@container (max-width: 47.99rem) {
  .links-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .links-table, .links-table tbody { display: block; }
  .links-table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.25rem 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--line);
  }
  .links-table tbody tr:last-child { border-bottom: 0; }
  .links-table td { display: block; padding: 0; border: 0; }
  .link-code { grid-row: 1; grid-column: 1; }
  .link-title { grid-row: 1; grid-column: 2; font-weight: 600; }
  .links-table .link-amount { grid-row: 1; grid-column: 3; font-weight: 650; }
  .link-status { grid-row: 2; grid-column: 1 / -1; }
  .link-created, .link-paid { grid-column: 1 / -1; font-size: 0.875rem; }
  .link-created::before, .link-paid::before { content: attr(data-label) " "; }
  .link-paid:empty { display: none; }
  .link-actions { grid-column: 1 / -1; margin-top: 0.5rem; text-align: left; white-space: normal; }
  .link-actions .button + .button { margin-left: 0.25rem; }
}

@media (min-width: 48rem) {
  .admin { gap: 2rem; }
  .admin-form-section { padding: 1.75rem 2rem 2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
