.site-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "mark nav sync cta";
  align-items: center;
  column-gap: var(--space-6);
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-6) 0;
}

.wordmark {
  grid-area: mark;
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-weight: 600;
  text-decoration: none;
}

.site-nav {
  grid-area: nav;
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-5);
}

.site-nav a {
  padding: 10px 0 8px;
  border-bottom: 2px solid transparent;
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  border-bottom-color: var(--ink);
  font-weight: 700;
}

.sync-status {
  grid-area: sync;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  color: var(--muted);
  font-size: var(--text-meta);
  text-decoration: none;
}

.sync-status:hover .sync-label {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
}

.sync-status[data-state="logged-out"] .sync-dot {
  display: none;
}

.sync-status[data-state="saving"] .sync-dot {
  background: var(--muted);
  animation: sync-pulse 1s ease-in-out infinite;
}

.sync-status[data-state="error"] {
  color: var(--red-ink);
}

.sync-status[data-state="error"] .sync-dot {
  background: var(--red-ink);
}

@keyframes sync-pulse {
  50% {
    opacity: 0.3;
  }
}

.site-cta {
  grid-area: cta;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  max-width: var(--content-width);
  margin: var(--space-9) auto 0;
  padding: var(--space-6) var(--space-6) var(--space-7);
  color: var(--muted);
  font-size: var(--text-meta);
}

.site-footer a {
  color: var(--muted);
}

.site-footer-note {
  flex-basis: 100%;
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: var(--radius-control);
  font: 700 var(--text-body) / 1 var(--font-sans);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-icon {
  width: var(--control-height);
  padding: 0;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
}

.btn-quiet {
  background: transparent;
  color: var(--ink);
}

.btn-danger {
  border-color: var(--red-ink);
  background: var(--red-ink);
  color: var(--sheet);
}

.is-liability {
  color: var(--red-ink);
}

.page {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.btn-danger-quiet {
  border-color: var(--red-ink);
  background: transparent;
  color: var(--red-ink);
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--muted);
  border-radius: var(--radius-control);
}

.segmented button {
  min-width: 48px;
  min-height: var(--control-height);
  padding: 0 14px;
  border: 0;
  border-left: 1px solid var(--muted);
  background: transparent;
  color: var(--ink);
  font-size: var(--text-meta);
  cursor: pointer;
}

.segmented button:first-child {
  border-left: 0;
}

.segmented button[aria-pressed="true"] {
  background: var(--highlighter);
  font-weight: 700;
}

.segmented button:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

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

.toast-container {
  position: fixed;
  top: var(--space-4);
  left: 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(30rem, calc(100% - 2 * var(--space-4)));
  max-width: none;
  transform: translateX(-50%);
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-toast);
  box-shadow: var(--shadow-raised);
  color: var(--paper);
}

.toast-success {
  background: var(--ink);
}

.toast-error {
  background: var(--red-ink);
}

.toast-message {
  flex: 1;
  margin: 0;
}

.toast-dismiss {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.toast :focus-visible {
  outline-color: var(--paper);
}


.sheet {
  width: min(32rem, calc(100% - 2 * var(--space-4)));
  max-height: calc(100% - 2 * var(--space-4));
  padding: var(--space-5);
  border: 0;
  border-radius: var(--radius-dialog);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
}

.sheet::backdrop {
  background: rgb(30 42 68 / 0.4);
}

.sheet-title {
  margin-bottom: var(--space-3);
}

.sheet-text {
  margin: 0;
}

.sheet-subtitle {
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
  color: var(--muted);
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.sheet-action-start {
  margin-right: auto;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-label {
  font-weight: 700;
}

.form-choices {
  min-width: 0;
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

.form-choices legend {
  padding: 0;
}

.form-choice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
}

.form-choice input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--ink);
}

.form-choice-hint {
  padding-left: 26px;
}

.form-input {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--muted);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
}

.form-input:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

input[aria-invalid="true"] {
  border-color: var(--red-ink);
  box-shadow: inset 0 0 0 1px var(--red-ink);
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-meta);
}

.form-error {
  margin: 0;
  color: var(--red-ink);
  font-size: var(--text-meta);
}

.money-input {
  position: relative;
  display: flex;
  align-items: center;
}

.money-input > span {
  position: absolute;
  left: var(--space-3);
  color: var(--muted);
  font-family: var(--font-serif);
  pointer-events: none;
}

.money-input .form-input {
  padding-left: 28px;
  font-family: var(--font-serif);
  font-variant-numeric: tabular-nums lining-nums;
  text-align: right;
}

@media (max-width: 40rem) {
  .site-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-4) var(--space-4) 0;
  }

  .site-header::after {
    content: "";
    flex-basis: 100%;
    order: 3;
  }

  .wordmark {
    flex: 1;
    order: 1;
  }

  .site-cta {
    order: 2;
  }

  .site-nav {
    flex: 1;
    order: 4;
    column-gap: var(--space-4);
  }

  .sync-status {
    order: 5;
  }

  .site-footer {
    padding-inline: var(--space-4);
  }

  .page {
    padding: 0 var(--space-4);
  }
}
