
:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #0d9488;
  --invert-bg: #18181b;
  --invert-text: #fafafa;
  --danger: #b91c1c;

  --ok-bg: #dcfce7;    --ok-text: #14532d;
  --warn-bg: #fef3c7;  --warn-text: #78350f;
  --bad-bg: #fee2e2;   --bad-text: #7f1d1d;
  --muted-bg: #f4f4f5; --muted-text: #52525b;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

/* ── Top bar ──────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

/* The mark is an SVG that carries its own tile and colours. */
.brand__mark { display: inline-flex; width: 26px; height: 26px; flex: none; }
.brand__mark svg { display: block; width: 100%; height: 100%; }

.brand__name { font-size: 15px; }
.brand__name span { color: var(--text-muted); font-weight: 500; }

.nav { display: flex; gap: 2px; margin-right: auto; }

.nav__link {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav__link:hover { background: var(--surface-2); color: var(--text); }
.nav__link[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

.user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.user__name { max-width: 15ch; overflow: hidden; text-overflow: ellipsis; }
.user__exit { text-decoration: none; }
.user__exit:hover { color: var(--text); text-decoration: underline; }

/* Below this width the bar splits into two rows: identity, then navigation. */
@media (max-width: 720px) {
  .topbar__inner { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 10px 12px; }
  .nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav__link { padding: 8px 13px; }
  .user { margin-left: auto; }
}

/* ── Page frame ───────────────────────────────────────────────────────── */

.page { max-width: 640px; margin: 0 auto; padding: 32px 20px 64px; }
.page--wide { max-width: 1100px; }

@media (max-width: 720px) { .page { padding: 20px 14px 48px; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}
.card + .card { margin-top: 20px; }
@media (max-width: 720px) { .card { padding: 20px 16px; } }

.card--center { text-align: center; padding: 44px 26px; }

h1 { margin: 0 0 5px; font-size: 20px; font-weight: 650; letter-spacing: -0.015em; }

.lede { margin: 0 0 22px; font-size: 14px; color: var(--text-muted); }
.card--center .lede { margin-bottom: 0; }

.hint { color: var(--text-muted); font-weight: 400; }
/*
 * A hint sits directly under the field it explains. The gap is owned by the
 * hint, not by a negative margin pulling it upwards: .field:last-of-type
 * zeroes the bottom margin of the field above, and a negative pull on top of
 * that made the two overlap.
 */
.field-hint { margin: 7px 0 16px; font-size: 13px; color: var(--text-muted); }
.field:has(+ .field-hint) { margin-bottom: 0; }

/* ── Forms ────────────────────────────────────────────────────────────── */

.field { display: block; margin-bottom: 16px; }
.field:last-of-type { margin-bottom: 0; }

.field__label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }

input[type="text"], input:not([type]), input[type="password"], input[type="number"], textarea {
  width: 100%;
  /* 44px keeps the tap target comfortable on phones. */
  min-height: 44px;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: .7; }
input:hover, textarea:hover { border-color: var(--text-muted); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.field--amount input {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

button {
  width: 100%;
  min-height: 46px;
  margin-top: 22px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 600;
  color: var(--invert-text);
  background: var(--invert-bg);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity .15s, transform .06s;
}
button:hover { opacity: .88; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; transform: none; }

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

/* ── Result panel under the new-invoice form ──────────────────────────── */

.result { display: none; margin-top: 20px; padding: 16px; border-radius: var(--radius-sm); font-size: 14px; }
.result.is-visible { display: block; }
.result.is-ok  { background: var(--ok-bg);  color: var(--ok-text);  border: 1px solid color-mix(in srgb, var(--ok-text) 22%, transparent); }
.result.is-bad { background: var(--bad-bg); color: var(--bad-text); border: 1px solid color-mix(in srgb, var(--bad-text) 22%, transparent); }

.result__title { display: block; font-weight: 650; margin-bottom: 10px; }

.link-box {
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  word-break: break-all;
}

.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions > * { flex: 1; margin: 0; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-secondary.is-disabled { opacity: .4; pointer-events: none; }

/* ── Payment list ─────────────────────────────────────────────────────── */

.invoices { display: flex; flex-direction: column; gap: 10px; }

.invoice {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .15s;
}
.invoice:hover { border-color: var(--border-strong); }

.invoice__row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 112px 132px 158px;
  gap: 14px;
  align-items: start;
  padding: 14px;
}

.invoice__when { font-size: 13px; font-variant-numeric: tabular-nums; }
.invoice__meta { display: block; margin-top: 3px; font-size: 12.5px; color: var(--text-muted); }

.invoice__purpose { min-width: 0; word-break: break-word; }
.invoice__destination { display: block; }

.invoice__amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill--ok    { background: var(--ok-bg);    color: var(--ok-text); }
.pill--warn  { background: var(--warn-bg);  color: var(--warn-text); }
.pill--bad   { background: var(--bad-bg);   color: var(--bad-text); }
.pill--muted { background: var(--muted-bg); color: var(--muted-text); }

/* One consistent cluster per row, right-aligned and in the same place always. */
.invoice__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
}
.invoice__actions a { text-decoration: none; }

.inline-form { display: inline; margin: 0; }

/*
 * Ghost icon button. Muted until the row is hovered or the control is focused,
 * so a page of payments reads as data rather than as a wall of toolbars — but
 * never invisible, because a touch screen has no hover to reveal it with.
 *
 * The explicit reset matters: without it the generic button rule above turns
 * these into full-width black blocks.
 */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  margin: 0; padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  opacity: .5;
  transition: opacity .15s, background .15s, color .15s;
}
.icon-btn:hover { opacity: 1; color: var(--text); background: var(--surface-2); }
.icon-btn.is-done { opacity: 1; color: var(--ok-text); background: var(--ok-bg); }
.invoice:hover .icon-btn { opacity: .8; }
.invoice:hover .icon-btn:hover, .icon-btn:focus-visible { opacity: 1; }

.empty { padding: 40px 10px; text-align: center; color: var(--text-muted); }

/*
 * Below this width the row stops being a table and becomes a card:
 *
 *   date            amount
 *   purpose
 *   status          actions
 *
 * Amount and status keep their own line ends so a column of cards can be
 * scanned the same way the table was.
 */
@media (max-width: 860px) {
  .invoice__row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "when    amount"
      "purpose purpose"
      "status  actions";
    gap: 2px 12px;
    padding: 14px;
  }

  .invoice__when    { grid-area: when; }
  .invoice__amount  { grid-area: amount; font-size: 17px; }
  .invoice__purpose { grid-area: purpose; margin-top: 8px; }

  .invoice__status  { grid-area: status; align-self: center; margin-top: 12px; }
  .invoice__actions { grid-area: actions; margin-top: 12px; margin-right: -6px; }

  /* Fingers are not mouse pointers: bigger targets, and always visible because
     a touch screen has no hover to reveal them with. */
  .icon-btn { width: 40px; height: 40px; opacity: .75; border-radius: 9px; }
  .invoice:hover .icon-btn { opacity: .75; }
  .icon-btn:active { background: var(--surface-2); opacity: 1; }
}

@media (max-width: 560px) {
  .pager { gap: 8px; flex-wrap: wrap; }
  .pager .btn-secondary { flex: 1; padding: 11px 10px; }
  .pager__page { order: -1; width: 100%; text-align: center; }

  .archive-link { text-align: center; }
  .archive-link a { display: inline-block; padding: 8px 4px; }
}

/* ── Pagination ───────────────────────────────────────────────────────── */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.pager__page { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

/* ── Archive ──────────────────────────────────────────────────────────── */

/* Deliberately small and quiet: the archive is a rarely used side door. */
.archive-link { margin: 18px 0 0; text-align: right; font-size: 13px; }
.archive-link a { color: var(--text-muted); text-decoration: none; }
.archive-link a:hover { color: var(--text); text-decoration: underline; }

/* Archived rows read as set aside, without becoming unreadable. */
.invoice--archived { background: var(--surface-2); }
.invoice--archived .invoice__when,
.invoice--archived .invoice__purpose,
.invoice--archived .invoice__amount { opacity: .72; }

/* ── Status page shown to the payer ───────────────────────────────────── */

.status-icon { font-size: 44px; line-height: 1; margin: 0 0 16px; }
.status-note {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Standalone pages (login, errors, result): no top bar ─────────────── */

.solo { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.solo .card { width: 100%; max-width: 400px; }

.solo__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-bottom: 22px;
  font-weight: 650;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
